![]() |
VR-Forces 5.0.2 Developer's Guide
|
This section provides details about the different types of conditional expressions.
The first two subsections discuss DtSimCondExpr and DtEvaluator. These objects are created by factories in VR-Forces. You can extend the set of existing conditional expressions by creating and registering new subclasses with the appropriate factories. For details, please see the examples Add Conditional (addConditionalGui) and Add Conditional (addConditionalSim).
DtSimCondExpr objects represent conditional expressions. They are used to test the properties of entities and units.
A simple conditional expression can be represented by just a single object. More complicated expressions are formed as tree structures of simpler expressions (sub-expressions) combined by the operators: AND, OR and NOT, which are themselves conditional expressions.
For example:
would be represented in objects as:
When If, Trigger, or While statements want to test the current state of a conditional expression, they call the evaluate() member function, which recursively evaluates all operators and their sub-expressions.
DtSimCondExprs are evaluated by calling their evaluate() member functions. The DtSimCondExpr class does not actually perform the evaluation of the expression itself. Instead, in its evaluate() function, it uses a DtEvaluator object to actually perform the test. In the VR-Forces back-end, DtSimCondExpr instances are always configured with a corresponding DtEvaluator class (a DtEvaluator is always created and set in a DtSimCondExpr class, whenever a DtSimCondExpr is created). DtSimCondExpr instances that are configured with a DtEvaluator invoke DtEvaluator::evaluate() member function whenever its evaluate() function is called. Each DtEvaluator subclass is designed to work with a particular DtSimCondExpr, so there is a one-to-one correspondence between DtSimCondExpr subclasses and DtEvaluator subclasses.
In a remote application (an application that uses the VR-Forces Remote Control API, such as a GUI), conditional expressions are created and used without DtEvaluators. They only need the data aspect of a conditional express to be able to do things such as display and edit plans. They never need to actually evaluate the expression, so the DtSimCondExpr::evaluate() function is never invoked. They only need to hold the parameters associated with a particular conditional expression.
The two logical constants (True and False) are implemented by the same class: DtCeConstant. It stores its value as a bool flag. The DtCeConstant class is configured with the DtEvalConstant evaluator.
The three logical operators (DtCeAnd, DtCeOr, and DtCeNot) are very similar. They only differ in:
Each logical operator stores its sub-expressions as pointers to other DtSimCondExpr objects, which could also be logical operators. The AND and OR operators sub-expressions are called leftCondExpr() and rightCondExpr(). The NOT operator sub-expression is called condExpr().
The following evaluators are configured with the three logical operators:
VR-Forces comes with several conditional expressions for testing simulation object status, such as:
Each test is given a unique identifier (the string returned by DtVrfObject::uuid()) and an optional modifier string. (Currently only the "ANY" modifier is implemented.) The unique identifier is the unique identifier for VR-Forces simulation objects, and is the simulation object identifier for non-VR-Forces remote simulation objects. The tests take other test-specific input.
The "ANY" modifier changes the way a test operates when it is applied to a unit or the force level. When ANY is not applied, a test is true only if it is true for all members of the unit. Therefore, the test terminates the first time it sees a simulation object that does not match the criteria. With the "ANY" modifier, a test is true if any one member of the unit satisfies the condition. Therefore, the search terminates the first time it finds a simulation object that matches the criteria.
Conditional tests can be applied to:
To apply their tests to the appropriate combination of simulation objects, the conditional expression simulation object tests use matching classes derived from DtSimSubordinateSearch (subSearch.h) to do the actual evaluate() work. DtCeEntDestroyed uses the DtEntDestroyedSearch (entDstroySrch.h) class; DtCeEntInArea uses the DtEntInAreaSearch (entInAreaSrch.h) class; and DtCeEntLeftOfLine uses the DtEntLeftOfLineSearch (entLOLineSrch.h) class.