My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
DataTypeTruthFn.h
Go to the documentation of this file.
1 #ifndef GCP_UTIL_DATATYPETRUTHFN_H
2 #define GCP_UTIL_DATATYPETRUTHFN_H
3 
11 #include "gcp/util/common/DataType.h"
12 
13 #define DATATYPE_TRUTH_FN0(fn) bool (fn)(DataType& compVal)
14 #define DATATYPE_TRUTH_FN1(fn) bool (fn)(DataType& compVal, DataType& op1)
15 #define DATATYPE_TRUTH_FN2(fn) bool (fn)(DataType& compVal, DataType& op1, DataType& op2)
16 
17 namespace gcp {
18  namespace util {
19 
25  public:
26 
27  enum Type {
28  FN0 = 0x0,
29  FN1 = 0x1,
30  FN2 = 0x2
31  };
32 
36  DataTypeTruthFn(DATATYPE_TRUTH_FN0(*fn)=0);
37  DataTypeTruthFn(DATATYPE_TRUTH_FN1(*fn));
38  DataTypeTruthFn(DATATYPE_TRUTH_FN2(*fn));
39 
43  virtual ~DataTypeTruthFn();
44 
45  bool evaluate(DataType& compVal);
46  bool evaluate(DataType& compVal, DataType& op1);
47  bool evaluate(DataType& compVal, DataType& op1, DataType& op2);
48 
49  static bool alwaysTrue( DataType& compVal);
50 
51  static bool equals( DataType& compVal, DataType& op1);
52  static bool greaterThan( DataType& compVal, DataType& op1);
53  static bool lessThan( DataType& compVal, DataType& op1);
54  static bool greaterThanEq( DataType& compVal, DataType& op1);
55  static bool lessThanEq( DataType& compVal, DataType& op1);
56 
57  static bool greaterThanAndLessThan( DataType& compVal, DataType& op1, DataType& op2);
58  static bool greaterThanAndLessThanEq( DataType& compVal, DataType& op1, DataType& op2);
59  static bool greaterThanEqAndLessThan( DataType& compVal, DataType& op1, DataType& op2);
60  static bool greaterThanEqAndLessThanEq(DataType& compVal, DataType& op1, DataType& op2);
61  static bool lessThanOrGreaterThan( DataType& compVal, DataType& op1, DataType& op2);
62  static bool lessThanEqOrGreaterThan( DataType& compVal, DataType& op1, DataType& op2);
63  static bool lessThanOrGreaterThanEq( DataType& compVal, DataType& op1, DataType& op2);
64  static bool lessThanEqOrGreaterThanEq( DataType& compVal, DataType& op1, DataType& op2);
65 
66  bool isZeroValued();
67  bool isSingleValued();
68  bool isDualValued();
69 
70  Type type() {
71  return type_;
72  }
73 
74  std::string format(std::string& reg, DataType& op1, DataType& op2);
75 
76  private:
77 
78  union {
79  DATATYPE_TRUTH_FN0(*fn0_);
80  DATATYPE_TRUTH_FN1(*fn1_);
81  DATATYPE_TRUTH_FN2(*fn2_);
82  } fn_;
83 
84  Type type_;
85 
86  void checkType(Type);
87 
88  // Methods for formatting an outputted string
89 
90  std::string formatZeroValuedFn(std::string& reg);
91  std::string formatSingleValuedFn (std::string& reg, DataType& op1_);
92  std::string formatDualValuedFn(std::string& reg, DataType& op1_, DataType& op2_);
93 
94  std::string formatOp(DATATYPE_TRUTH_FN1(*fn_));
95  std::string formatOp1(DATATYPE_TRUTH_FN2(*fn_));
96  std::string formatOp2(DATATYPE_TRUTH_FN2(*fn_));
97  std::string formatLogical(DATATYPE_TRUTH_FN2(*fn_));
98 
99  std::string formatVal(DataType& val);
100  std::string formatReg(std::string& reg);
101 
102  }; // End class DataTypeTruthFn
103 
104  } // End namespace util
105 } // End namespace gcp
106 
107 
108 
109 #endif // End #ifndef GCP_UTIL_DATATYPETRUTHFN_H
virtual ~DataTypeTruthFn()
Definition: DataTypeTruthFn.cc:33
Definition: DataTypeTruthFn.h:24
DataTypeTruthFn(DATATYPE_TRUTH_FN0(*fn)=0)
Definition: DataTypeTruthFn.cc:12
Definition: DataType.h:27