| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#if !defined( INCLUDED_GENERIC_CONSTANT_H ) |
| 23 |
#define INCLUDED_GENERIC_CONSTANT_H |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
template<typename Type> |
| 30 |
struct ConstantWrapper |
| 31 |
{ |
| 32 |
typedef typename Type::Value Value; |
| 33 |
operator Value() const |
| 34 |
{ |
| 35 |
return Type::evaluate(); |
| 36 |
} |
| 37 |
}; |
| 38 |
template<typename TextOutputStreamType, typename Type> |
| 39 |
inline TextOutputStreamType& ostream_write( TextOutputStreamType& ostream, const ConstantWrapper<Type>& c ){ |
| 40 |
return ostream_write( ostream, typename Type::Value( c ) ); |
| 41 |
} |
| 42 |
|
| 43 |
#define TYPE_CONSTANT( name, value, type ) struct name##_CONSTANT_ { typedef type Value; static Value evaluate() { return value; } }; typedef ConstantWrapper<name##_CONSTANT_> name |
| 44 |
#define STRING_CONSTANT( name, value ) TYPE_CONSTANT ( name, value, const char* ) |
| 45 |
#define INTEGER_CONSTANT( name, value ) TYPE_CONSTANT ( name, value, int ) |
| 46 |
#define UINT_CONSTANT( name, value ) TYPE_CONSTANT ( name, value, unsigned int ) |
| 47 |
|
| 48 |
STRING_CONSTANT( EmptyString, "" ); |
| 49 |
|
| 50 |
#endif |