Getting started page

To define a rule R3, with precedents R1 and R2 rules, think of a class declaration (actually, a rule is class):

DEFINE_RULE(R3, "R1,R2", t->tm_hour == 5, tm* t);
A rule with an extra argument:

DEFINE_RULE_ARGS(R4, "", t->tm_hour == t2->tm_hour, tm* t, tm* t2);
To apply a rule (evaluate the boolean expression and take an action) you can e.g. go on (do nothing) or if it fails throw an exception:

APPLY_RULE(R3, t, GO_ON, throw logic_error("R3 not accomplished"));
And with an additional argument:

APPLY_RULE(R4, t, cout << "Rule R4 OK", throw logic_error("R4 not accomplished"), t2);

And to apply the rule to all objects in a list:

  APPLY_RULE(R3, t, GO_ON, throw logic_error("R3 not accomplished")));

To get the rule std::map (STL) of the current scope:

To apply an expression of rules R1 & R2 (VRE is a macro to get the rule's last evaluation):

  cout << "R1 and R2 = true" << endl,
  cout << "R1 and R2 = false" << endl);

To create a validation scope, simply create an instance of ValidationRules::ValidationScope. When the instance is destroyed, the current scope is set to the last one on the stack:

ValidationScope scope;

For a comprehensive demo and test of this library see

Last edited Jun 12, 2013 at 11:30 PM by kuritsu, version 6


No comments yet.