00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef BINARY_OPERATION_HPP
00021 #define BINARY_OPERATION_HPP
00022
00023 #include <ErrorHandler.hpp>
00024 #include <string>
00025
00033 class BinaryOperation
00034 {
00035 public:
00036 enum Type {
00037 sum,
00038 difference,
00039 division,
00040 modulo,
00041 power,
00042 product,
00043
00044 min,
00045 max,
00046
00047 gt,
00048 lt,
00049 ge,
00050 le,
00051 eq,
00052 ne,
00053 or_,
00054 xor_,
00055 and_,
00056
00057 undefined
00058 };
00059
00060 private:
00061 const Type __type;
00063 static BinaryOperation::Type
00064 __getType(const std::string& typeName)
00065 {
00066 if (typeName == "min") return BinaryOperation::min;
00067 if (typeName == "max") return BinaryOperation::max;
00068 return BinaryOperation::undefined;
00069 }
00070
00071 public:
00080 friend std::ostream& operator<<(std::ostream& os,
00081 const BinaryOperation& b)
00082 {
00083 os << b.name();
00084 return os;
00085 }
00086
00092 std::string name() const
00093 {
00094 switch(__type) {
00095 case sum: {
00096 return "+";
00097 }
00098 case difference: {
00099 return "-";
00100 }
00101 case product: {
00102 return "*";
00103 }
00104 case division: {
00105 return "/";
00106 }
00107 case modulo: {
00108 return "%";
00109 }
00110 case power: {
00111 return "^";
00112 }
00113 case min: {
00114 return "min";
00115 }
00116 case max: {
00117 return "max";
00118 }
00119 case gt: {
00120 return ">";
00121 }
00122 case lt: {
00123 return "<";
00124 }
00125 case ge: {
00126 return ">=";
00127 }
00128 case le: {
00129 return "<=";
00130 }
00131 case eq: {
00132 return "==";
00133 }
00134 case ne: {
00135 return "!=";
00136 }
00137 case or_: {
00138 return "or";
00139 }
00140 case xor_: {
00141 return "xor";
00142 }
00143 case and_: {
00144 return "and";
00145 }
00146 case undefined: {
00147 return "undefined";
00148 }
00149 default: {
00150 throw ErrorHandler(__FILE__,__LINE__,
00151 "unknown operator type",
00152 ErrorHandler::unexpected);
00153 }
00154 }
00155 return "undefined";
00156 }
00157
00163 const BinaryOperation::Type&
00164 type() const
00165 {
00166 return __type;
00167 }
00168
00174 BinaryOperation(const std::string& typeName)
00175 : __type(BinaryOperation::__getType(typeName))
00176 {
00177 ;
00178 }
00179
00185 BinaryOperation(const BinaryOperation::Type& type)
00186 : __type(type)
00187 {
00188 ;
00189 }
00190
00196 BinaryOperation(const BinaryOperation& b)
00197 : __type(b.__type)
00198 {
00199 ;
00200 }
00201
00206 ~BinaryOperation()
00207 {
00208 ;
00209 }
00210 };
00211
00212 #endif // BINARY_OPERATION_HPP