Commit b8ac1889 authored by Alvarez, Gonzalo's avatar Alvarez, Gonzalo
Browse files

PredicateAwesome and related Predicate changes

PredicateAwesome ctor accepts an or separator,
which default to ,
and an and separator, which default to &
PredicateAnd accepts an and separator,
which default to &
Predicate Simple accepts a node separator,
which default to :
parent 42abd32b
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -7,11 +7,11 @@
namespace PsimagLite {

/* PSIDOC PredicateAnd
 PredicateAnd is a semicolon-separated list of simple predicates,
 PredicateAnd is a &-separated list of simple predicates,

 SimplePredicate0;SimplePredicate1;...
 SimplePredicate0&SimplePredicate1&...

 where ; means to AND the predicates.
 where & means to AND the predicates.
 */
class PredicateAnd {

@@ -20,11 +20,11 @@ public:
	typedef Vector<PredicateSimple>::Type VectorPredicateSimpleType;
	typedef PredicateSimple::VectorStringType VectorStringType;

	PredicateAnd(String pred)
	PredicateAnd(String pred, PsimagLite::String sep = "&")
	    : pred_(pred)
	{
		VectorStringType tokens;
		split(tokens, pred, ";");
		split(tokens, pred, sep);
		const SizeType n = tokens.size();
		for (SizeType i = 0; i < n; ++i)
			vPredicateSimple_.push_back(PredicateSimple(tokens[i]));
+6 −8
Original line number Diff line number Diff line
@@ -21,11 +21,11 @@ namespace PsimagLite {
 S1   /\[a-zA-Z]+/
 S2  /\[a-zA-Z]+=\[a-zA-Z\d\.\-]/

 Predicate is a semicolon-separated list of simple predicates,
 Predicate is a &-separated list of simple predicates,

 SimplePredicate0;SimplePredicate1;...
 SimplePredicate0&SimplePredicate1&...

 where ; means to AND the predicates.
 where & means to AND the predicates.

 where SimplePredicate is of the form
 word operator word
@@ -34,7 +34,7 @@ namespace PsimagLite {
 So l%%2 means that the simple predicate is true if l is divisible by 2.

 From this rules, the list of items
 M=2,l%%2;l!=0,l>=7,l<11
 M=2,l%%2&l!=0,l>=7,l<11
 will set M=2 and define a predicate that is true if l
 is in the set {2, 4, 6, 7, 8, 9, 10, 12, 14, 16, 18 ...}
 and false otherwise.
@@ -63,13 +63,11 @@ public:
	typedef Vector<PredicateAnd>::Type VectorPredicateAndType;
	typedef PredicateAnd::VectorStringType VectorStringType;

	PredicateAwesome(String pred, char orSep = ',', SpecType* spec = nullptr)
	PredicateAwesome(String pred, String orSeparator = ",", String andSeparator = "&", SpecType* spec = nullptr)
	    : pred_(pred)
	{
		if (pred_ == "") return;
		VectorStringType tokens;
		String orSeparator(",");
		orSeparator[0] = orSep;
		split(tokens, pred, orSeparator);
		const SizeType n = tokens.size();
		for (SizeType i = 0; i < n; ++i) {
@@ -81,7 +79,7 @@ public:
				continue;
			}

			predicateAnd_.push_back(PredicateAnd(tokens[i]));
			predicateAnd_.push_back(PredicateAnd(tokens[i], andSeparator));
		}
	}

+7 −6
Original line number Diff line number Diff line
@@ -19,8 +19,8 @@ public:

	typedef Vector<String>::Type VectorStringType;

	PredicateSimple(String pred)
	    : pred_(pred)
	PredicateSimple(String pred, String separator = ":")
	    : pred_(pred), separator_(separator)
	{
		SizeType length = 0;
		size_t location = String::npos;
@@ -109,13 +109,13 @@ private:
	}

	template<typename SomeVectorType>
	static typename SomeVectorType::value_type getValue(String hs,
	typename SomeVectorType::value_type getValue(String hs,
	                                             const VectorStringType& names,
	                                             const SomeVectorType& vals)
	{
		String numericHs = replaceVariables(hs, names, vals);
		VectorStringType tokens;
		split(tokens, numericHs, "|");
		split(tokens, numericHs, separator_);
		typedef ExpressionCalculator<typename SomeVectorType::value_type> ExpressionCalculatorType;
		ExpressionCalculatorType expressionCalculator(tokens);
		return expressionCalculator();
@@ -157,6 +157,7 @@ private:

	static VectorStringType ops_;
	String pred_;
	String separator_;
	String lhs_;
	String op_;
	String rhs_;