This project is read-only.
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:

FOREACH_APPLY_RULE(list, tm* t,
  APPLY_RULE(R3, t, GO_ON, throw logic_error("R3 not accomplished")));

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

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

APPLY_RULE_EXPR(VRE(R1) && VRE(R2),
  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 https://validrulescpp.codeplex.com/SourceControl/latest#validrules/test/main.cpp.

Last edited Jun 13, 2013 at 12:30 AM by kuritsu, version 6

Comments

No comments yet.