FEDEM Solver  R8.0
Source code of the dynamics solver
Public Member Functions | Private Attributes | List of all members
FFaEnum< EnumType, ETMapping > Class Template Reference

Class to be used as a enum variable with text representations. More...

#include <FFaEnum.H>

Public Member Functions

 FFaEnum (EnumType val=EnumType(0))
 Default constructor. More...
 
 FFaEnum (const char *val)
 Constructor obtaining its value from a string. More...
 
FFaEnum< EnumType, ETMapping > & operator= (const FFaEnum< EnumType, ETMapping > &val)
 Assignment operator. More...
 
FFaEnum< EnumType, ETMapping > & operator= (const EnumType &val)
 Overloaded assignment operator. More...
 
FFaEnum< EnumType, ETMapping > & operator= (const int &val)
 Overloaded assignment operator. More...
 
FFaEnum< EnumType, ETMapping > & operator= (const char *text)
 Overloaded assignment operator. More...
 
 operator EnumType () const
 Returns the actual enum value. More...
 
const char * getText () const
 Returns the text representation of the enum value. More...
 
bool operator== (const FFaEnum< EnumType, ETMapping > &e) const
 Equality operator. More...
 
bool operator== (const EnumType &e) const
 Overloaded equality operator. More...
 
bool operator!= (const FFaEnum< EnumType, ETMapping > &e) const
 Unequality operator. More...
 
bool operator!= (const EnumType &e) const
 Overloaded unequality operator. More...
 

Private Attributes

EnumType myValue
 The actual enum value. More...
 

Detailed Description

template<class EnumType, class ETMapping>
class FFaEnum< EnumType, ETMapping >

Class to be used as a enum variable with text representations.

The class contains stream operators for input and output as text, and overloaded assignment operators such that its value can be assigned also from the text representation.

Usage:

class ClassWithEnum
{
public:
ClassWithEnum() {}
enum SomeEnumType {
AONE,
ATWO,
ATHREE
};
FFaEnumMapping(SomeEnumType) {
FFaEnumEntry(AONE, "AONE");
FFaEnumEntry(ATWO, "ATWO");
FFaEnumEntry(ATHREE,"ATHREE");
};
// Use either as a normal enum:
// Or within a field:
FFaField<SomeEnumTypeEnum> myEnumField;
};
#define FFaEnumEntryEnd
Defines the end of an enum mapping definition.
Definition: FFaEnum.H:238
#define FFaEnumMapping(EnumType)
Defines the start of an enum mapping definition.
Definition: FFaEnum.H:221
#define FFaEnumEntry(EnumValue, EnumText)
Adds one entry to the current enum mapping definition.
Definition: FFaEnum.H:234
Class to be used as a enum variable with text representations.
Definition: FFaEnum.H:87

As you can see, the initialization of the text to enum mappings are to be set up using the macros FFaEnumMapping(), FFaEnumEntry() and FFaEnumEntryEnd(). The FFaEnum class supports all kinds of assigning, so it can be used as a normal enum variable.

...
ClassWithEnum::ClassWithEnum()
{
...
FFA_FIELD_INIT(myEnumField, AONE, "ENUM_FIELD_NAME");
...
}
...
ClassWithEnum a;
a.myEnum = ClassWithEnum::ATHREE;
ClassWithEnum b;
b.myEnum = a.myEnum;
a.myEnum = "ATWO";
ClassWithEnum::SomeEnumType en = a.myEnum;
int v = a.myEnum;
std::cout << a.myEnum << std::endl;
std::cin >> a.myEnum;
if (b.myEnum == a.myEnum) std::cout <<"a and b are equal\n";
if (b.myEnum != a.myEnum) std::cout <<"a and b are not equal\n";
real(sp), dimension(:,:,:), pointer b
Definition: diffractionModule.f90:22
real(sp), dimension(:,:,:), pointer a
Definition: diffractionModule.f90:21

Constructor & Destructor Documentation

◆ FFaEnum() [1/2]

template<class EnumType , class ETMapping >
FFaEnum< EnumType, ETMapping >::FFaEnum ( EnumType  val = EnumType(0))
inline

Default constructor.

◆ FFaEnum() [2/2]

template<class EnumType , class ETMapping >
FFaEnum< EnumType, ETMapping >::FFaEnum ( const char *  val)
inline

Constructor obtaining its value from a string.

Member Function Documentation

◆ getText()

template<class EnumType , class ETMapping >
const char* FFaEnum< EnumType, ETMapping >::getText ( ) const
inline

Returns the text representation of the enum value.

◆ operator EnumType()

template<class EnumType , class ETMapping >
FFaEnum< EnumType, ETMapping >::operator EnumType ( ) const
inline

Returns the actual enum value.

◆ operator!=() [1/2]

template<class EnumType , class ETMapping >
bool FFaEnum< EnumType, ETMapping >::operator!= ( const EnumType &  e) const
inline

Overloaded unequality operator.

◆ operator!=() [2/2]

template<class EnumType , class ETMapping >
bool FFaEnum< EnumType, ETMapping >::operator!= ( const FFaEnum< EnumType, ETMapping > &  e) const
inline

Unequality operator.

◆ operator=() [1/4]

template<class EnumType , class ETMapping >
FFaEnum<EnumType,ETMapping>& FFaEnum< EnumType, ETMapping >::operator= ( const char *  text)
inline

Overloaded assignment operator.

◆ operator=() [2/4]

template<class EnumType , class ETMapping >
FFaEnum<EnumType,ETMapping>& FFaEnum< EnumType, ETMapping >::operator= ( const EnumType &  val)
inline

Overloaded assignment operator.

◆ operator=() [3/4]

template<class EnumType , class ETMapping >
FFaEnum<EnumType,ETMapping>& FFaEnum< EnumType, ETMapping >::operator= ( const FFaEnum< EnumType, ETMapping > &  val)
inline

Assignment operator.

◆ operator=() [4/4]

template<class EnumType , class ETMapping >
FFaEnum<EnumType,ETMapping>& FFaEnum< EnumType, ETMapping >::operator= ( const int &  val)
inline

Overloaded assignment operator.

◆ operator==() [1/2]

template<class EnumType , class ETMapping >
bool FFaEnum< EnumType, ETMapping >::operator== ( const EnumType &  e) const
inline

Overloaded equality operator.

◆ operator==() [2/2]

template<class EnumType , class ETMapping >
bool FFaEnum< EnumType, ETMapping >::operator== ( const FFaEnum< EnumType, ETMapping > &  e) const
inline

Equality operator.

Member Data Documentation

◆ myValue

template<class EnumType , class ETMapping >
EnumType FFaEnum< EnumType, ETMapping >::myValue
private

The actual enum value.


The documentation for this class was generated from the following file: