1 #ifndef _ValueRef_h_
2 #define _ValueRef_h_
3 
4 #include "ScriptingContext.h"
5 #include "../util/Export.h"
6 
7 #include <string>
8 
9 namespace ValueRef {
10 
11 /** The base class for all ValueRef classes.  This class provides the public
12   * interface for a ValueRef expression tree. */
13 template <typename T>
14 struct FO_COMMON_API ValueRef
15 {
~ValueRefValueRef16     virtual ~ValueRef()
17     {}
18 
19     virtual bool operator==(const ValueRef<T>& rhs) const;
20 
21     bool operator!=(const ValueRef<T>& rhs) const
22     { return !(*this == rhs); }
23 
24     /** Evaluates the expression tree with an empty context.  Useful for
25       * evaluating expressions that do not depend on context. */
EvalValueRef26     T Eval() const
27     { return Eval(::ScriptingContext()); }
28 
29     /** Evaluates the expression tree and return the results; \a context
30       * is used to fill in any instances of the "Value" variable or references
31       * to objects such as the source, effect target, or condition candidates
32       * that exist in the tree. */
33     virtual T Eval(const ScriptingContext& context) const = 0;
34 
RootCandidateInvariantValueRef35     virtual bool RootCandidateInvariant() const
36     { return false; }
37 
LocalCandidateInvariantValueRef38     virtual bool LocalCandidateInvariant() const
39     { return false; }
40 
TargetInvariantValueRef41     virtual bool TargetInvariant() const
42     { return false; }
43 
SourceInvariantValueRef44     virtual bool SourceInvariant() const
45     { return false; }
46 
SimpleIncrementValueRef47     virtual bool SimpleIncrement() const
48     { return false; }
49 
ConstantExprValueRef50     virtual bool ConstantExpr() const
51     { return false; }
52 
53     virtual std::string Description() const = 0;
54 
55     /** Returns a text description of this type of special. */
56     virtual std::string Dump(unsigned short ntabs = 0) const = 0;
57 
SetTopLevelContentValueRef58     virtual void SetTopLevelContent(const std::string& content_name)
59     {}
60 
GetCheckSumValueRef61     virtual unsigned int GetCheckSum() const
62     { return 0; }
63 
64 private:
65     friend class boost::serialization::access;
66     template <typename Archive>
67     void serialize(Archive& ar, const unsigned int version);
68 };
69 
70 enum StatisticType : int {
71     INVALID_STATISTIC_TYPE = -1,
72     COUNT,  // returns the number of objects matching the condition
73     UNIQUE_COUNT,   // returns the number of distinct property values of objects matching the condition. eg. if 3 objects have the property value "small", and two have "big", then this value is 2, as there are 2 unique property values.
74     IF,     // returns T(1) if anything matches the condition, or T(0) otherwise
75     SUM,    // returns the sum of the property values of all objects matching the condition
76     MEAN,   // returns the mean of the property values of all objects matching the condition
77     RMS,    // returns the sqrt of the mean of the squares of the property values of all objects matching the condition
78     MODE,   // returns the most common property value of objects matching the condition.  supported for non-numeric types such as enums.
79     MAX,    // returns the maximum value of the property amongst objects matching the condition
80     MIN,    // returns the minimum value of the property amongst objects matching the condition
81     SPREAD, // returns the (positive) difference between the maximum and minimum values of the property amongst objects matching the condition
82     STDEV,  // returns the standard deviation of the property values of all objects matching the condition
83     PRODUCT // returns the product of the property values of all objects matching the condition
84 };
85 
86 }
87 
88 #endif // _ValueRef_h_
89