86 template<
class EnumType,
class ETMapping>
class FFaEnum
119 if (!text || strlen(text) < 1)
123 size_t istart = 0, iend = strlen(text)-1;
124 while (isspace(text[istart]))
132 while (iend > istart && isspace(text[iend]))
135 for (
const std::pair<EnumType,const char*>&
ep : ETMapping::map())
136 if (strncmp(
ep.second,text+istart,iend-istart+1) == 0)
144 for (
size_t i = istart; i <= iend; i++)
145 if (!isdigit(text[i]))
149 this->
myValue = EnumType(atoi(text+istart));
154 operator EnumType()
const {
return this->
myValue; }
159 for (
const std::pair<EnumType,const char*>&
ep : ETMapping::map())
160 if (
ep.first == this->myValue)
164 static char text[16];
165 snprintf(text,16,
"%d",this->
myValue);
185 template<
class EnumType,
class ETMapping>
192 template<
class EnumType,
class ETMapping>
197 while (iend < 127 && s.get(enumText[iend]))
198 if (!isspace(enumText[iend]))
205 else if (enumText[0] ==
'"' && enumText[iend-1])
207 if (iend < 3)
return s;
213 enumText[iend] =
'\0';
221 #define FFaEnumMapping(EnumType) \
222 class EnumType##Mapping; \
223 typedef FFaEnum<EnumType,EnumType##Mapping> EnumType##Enum; \
224 class EnumType##Mapping \
226 typedef std::pair<EnumType,const char*> EnumType##Pair; \
228 static const std::vector<EnumType##Pair> map() \
230 std::vector<EnumType##Pair> enumMap; \
234 #define FFaEnumEntry(EnumValue,EnumText) \
235 enumMap.push_back(std::make_pair(EnumValue,EnumText));
238 #define FFaEnumEntryEnd \
std::ostream & operator<<(std::ostream &s, const FFaEnum< EnumType, ETMapping > &e)
Global output stream operator.
Definition: FFaEnum.H:186
std::istream & operator>>(std::istream &s, FFaEnum< EnumType, ETMapping > &e)
Global input stream operator.
Definition: FFaEnum.H:193
Class to be used as a enum variable with text representations.
Definition: FFaEnum.H:87
FFaEnum< EnumType, ETMapping > & operator=(const EnumType &val)
Overloaded assignment operator.
Definition: FFaEnum.H:103
bool operator!=(const FFaEnum< EnumType, ETMapping > &e) const
Unequality operator.
Definition: FFaEnum.H:175
bool operator==(const FFaEnum< EnumType, ETMapping > &e) const
Equality operator.
Definition: FFaEnum.H:170
EnumType myValue
The actual enum value.
Definition: FFaEnum.H:180
FFaEnum< EnumType, ETMapping > & operator=(const FFaEnum< EnumType, ETMapping > &val)
Assignment operator.
Definition: FFaEnum.H:95
FFaEnum(EnumType val=EnumType(0))
Default constructor.
Definition: FFaEnum.H:90
bool operator==(const EnumType &e) const
Overloaded equality operator.
Definition: FFaEnum.H:172
FFaEnum(const char *val)
Constructor obtaining its value from a string.
Definition: FFaEnum.H:92
const char * getText() const
Returns the text representation of the enum value.
Definition: FFaEnum.H:157
FFaEnum< EnumType, ETMapping > & operator=(const int &val)
Overloaded assignment operator.
Definition: FFaEnum.H:110
bool operator!=(const EnumType &e) const
Overloaded unequality operator.
Definition: FFaEnum.H:177
FFaEnum< EnumType, ETMapping > & operator=(const char *text)
Overloaded assignment operator.
Definition: FFaEnum.H:117
integer(ptr), save, private ep
Definition: extCtrlSysRoutinesModule.f90:16