constant.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #if !defined(INCLUDED_GENERIC_CONSTANT_H)
00023 #define INCLUDED_GENERIC_CONSTANT_H
00024
00027
00029 template<typename Type>
00030 struct ConstantWrapper
00031 {
00032 typedef typename Type::Value Value;
00033 operator Value () const
00034 {
00035 return Type::evaluate();
00036 }
00037 };
00038 template<typename TextOutputStreamType, typename Type>
00039 inline TextOutputStreamType& ostream_write (TextOutputStreamType& ostream, const ConstantWrapper<Type>& c)
00040 {
00041 return ostream_write(ostream, typename Type::Value(c));
00042 }
00043
00044 #define TYPE_CONSTANT(name, value, type) struct name##_CONSTANT_ { typedef type Value; static Value evaluate() { return value; } }; typedef ConstantWrapper<name##_CONSTANT_> name
00045 #define STRING_CONSTANT(name, value) TYPE_CONSTANT(name, value, const char *)
00046 #define INTEGER_CONSTANT(name, value) TYPE_CONSTANT(name, value, int)
00047
00048 STRING_CONSTANT(EmptyString, "");
00049
00050 #endif