00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef ENUM_PARAMETER_HPP
00022 #define ENUM_PARAMETER_HPP
00023
00024 #include <Parameter.hpp>
00025 #include <LabeledEnum.hpp>
00026
00027 #include <IdentifierSet.hpp>
00028
00029 #include <Stringify.hpp>
00030 #include <ErrorHandler.hpp>
00031
00038 template <typename EnumType>
00039 class EnumParameter
00040 : public Parameter
00041 {
00042 private:
00043 LabeledEnum<EnumType> __switch;
00044
00045 void reset()
00046 {
00047 __enumValue = __defaultEnumValue;
00048 }
00049
00050 const EnumType __defaultEnumValue;
00051 EnumType __enumValue;
00052
00053 std::ostream& put (std::ostream& os) const
00054 {
00055 os << __enumValue;
00056 return os;
00057 }
00058
00059 public:
00061 void get(IdentifierSet& I)
00062 {
00063 __switch.get(I);
00064 }
00065
00066 void addSwitch(const char* c, const EnumType t)
00067 {
00068 __switch.add(c,t);
00069 }
00070
00071 void set(const real_t d)
00072 {
00073 throw ErrorHandler(__FILE__,__LINE__,
00074 "cannot assignate the real value '"+stringify(d)
00075 +"' to an enum parameter",
00076 ErrorHandler::normal);
00077 }
00078
00079 void set(const int i)
00080 {
00081 throw ErrorHandler(__FILE__,__LINE__,
00082 "cannot assignate the integer value '"+stringify(i)
00083 +"' to an enum parameter",
00084 ErrorHandler::normal);
00085 }
00086
00087 void set(const char* c)
00088 {
00089 __enumValue = __switch(c);
00090 }
00091
00092 operator EnumType&()
00093 {
00094 return __enumValue;
00095 }
00096
00097 operator const EnumType&() const
00098 {
00099 return __enumValue;
00100 }
00101
00102 const std::string typeName() const
00103 {
00104 return "enum";
00105 }
00106
00107 EnumParameter(const EnumParameter& sp)
00108 : Parameter(sp),
00109 __switch(sp.__switch),
00110 __defaultEnumValue(sp.__defaultEnumValue),
00111 __enumValue(sp.__enumValue)
00112 {
00113 ;
00114 }
00115
00116 EnumParameter(const EnumType defaultEnum , const char* label)
00117 : Parameter(Parameter::Enum, label),
00118 __defaultEnumValue(defaultEnum),
00119 __enumValue(defaultEnum)
00120 {
00121 ;
00122 }
00123
00124 ~EnumParameter()
00125 {
00126 ;
00127 }
00128 };
00129
00130 #endif // ENUM_PARAMETER_HPP