libtenum
|
00001 00008 #ifndef TENUM_STATIC_ENUM_HPP_ 00009 #define TENUM_STATIC_ENUM_HPP_ 00010 00011 #define IN_TENUM_HPP_ 00012 #include <tenum/detail/enum.hpp> 00013 #include <tenum/detail/operator.hpp> 00014 #include <tenum/detail/stream.hpp> 00015 #undef IN_TENUM_HPP_ 00016 00017 #include <tenum/default.hpp> 00018 00022 #define TENUM_GET_BASE_OF_SIGNATURE(type_m,tuples_m) \ 00023 template< > \ 00024 inline TENUM_TYPE(type_m) \ 00025 enum_helper< TENUM_TYPE(type_m) >::get_base_of(TENUM_TYPE(type_m) const value_in) 00026 00027 #define TENUM_GET_BASE_OF_DECLARATION(type_m,tuples_m) \ 00028 TENUM_GET_BASE_OF_SIGNATURE(type_m,tuples_m); 00029 00034 #define TENUM_GET_BASE_OF_DEFINITION_EACH(_,type_m,tuple_m) \ 00035 if(TENUM_CAST_UINT(value_in) >= TENUM_CAST_UINT(TENUM_VALUE(type_m,TENUM_TUPLE_GET_VALUE(tuple_m)))) { \ 00036 return TENUM_VALUE(type_m,TENUM_TUPLE_GET_VALUE(tuple_m)); \ 00037 } else \ 00038 00039 #define TENUM_GET_BASE_OF_DEFINITION(type_m,tuples_m) \ 00040 TENUM_GET_BASE_OF_SIGNATURE(type_m,tuples_m) { \ 00041 if(TENUM_CAST_UINT(value_in) >= TENUM_CAST_UINT(TENUM_VALUE_UNKNOWN(type_m))) { \ 00042 return TENUM_VALUE_UNKNOWN(type_m); \ 00043 } \ 00044 BOOST_PP_SEQ_FOR_EACH(TENUM_GET_BASE_OF_DEFINITION_EACH,type_m,BOOST_PP_SEQ_REVERSE(tuples_m)) { \ 00045 return TENUM_VALUE_UNKNOWN(type_m); \ 00046 } \ 00047 } 00048 00052 #define TENUM_SERIALIZE_SIGNATURE(type_m,tuples_m) \ 00053 template< > \ 00054 template< > \ 00055 inline ::std::string \ 00056 enum_helper< TENUM_TYPE(type_m) >::serialize_impl< false, false >(TENUM_TYPE(type_m) const value_in, \ 00057 ::boost::false_type const&, \ 00058 ::boost::false_type const&) 00059 00060 #define TENUM_SERIALIZE_DECLARATION(type_m,tuples_m) \ 00061 TENUM_SERIALIZE_SIGNATURE(type_m,tuples_m); 00062 00063 #define TENUM_SERIALIZE_DEFINITION_EACH(_,type_m,tuple_m) \ 00064 case TENUM_VALUE(type_m,TENUM_TUPLE_GET_VALUE(tuple_m)): \ 00065 return TENUM_DEFAULT_NAME(type_m,TENUM_TUPLE_GET_NAME(tuple_m)) ; \ 00066 00067 #define TENUM_SERIALIZE_DEFINITION(type_m,tuples_m) \ 00068 TENUM_SERIALIZE_SIGNATURE(type_m,tuples_m) { \ 00069 switch (value_in) { \ 00070 BOOST_PP_SEQ_FOR_EACH(TENUM_SERIALIZE_DEFINITION_EACH,type_m,tuples_m) \ 00071 default: \ 00072 return TENUM_DEFAULT_NAME(type_m,"lte_unknown"); \ 00073 } \ 00074 } 00075 00079 #define TENUM_DESERIALIZE_SIGNATURE(type_m,tuples_m) \ 00080 template< > \ 00081 template< > \ 00082 inline TENUM_TYPE(type_m) \ 00083 enum_helper< TENUM_TYPE(type_m) >::deserialize_impl< false, false >(::std::string const& value_in, \ 00084 ::boost::false_type const&, \ 00085 ::boost::false_type const&) 00086 00087 #define TENUM_DESERIALIZE_DECLARATION(type_m,tuples_m) \ 00088 TENUM_DESERIALIZE_SIGNATURE(type_m,tuples_m); 00089 00090 #define TENUM_DESERIALIZE_DEFINITION_EACH(_,type_m,tuple_m) \ 00091 if (value_in == TENUM_DEFAULT_NAME(type_m,TENUM_TUPLE_GET_NAME(tuple_m))) { \ 00092 return TENUM_VALUE(type_m,TENUM_TUPLE_GET_VALUE(tuple_m)); \ 00093 } else \ 00094 00095 #define TENUM_DESERIALIZE_DEFINITION(type_m,tuples_m) \ 00096 TENUM_DESERIALIZE_SIGNATURE(type_m,tuples_m) { \ 00097 BOOST_PP_SEQ_FOR_EACH(TENUM_DESERIALIZE_DEFINITION_EACH,type_m,tuples_m) \ 00098 { \ 00099 return TENUM_VALUE_UNKNOWN(type_m); \ 00100 } \ 00101 } 00102 00106 #define TENUM_STATIC_ENUM_SERIALIZATION_DECLARATION(type_m,tuples_m) \ 00107 namespace tenum { \ 00108 TENUM_GET_BASE_OF_DECLARATION(type_m,tuples_m) \ 00109 TENUM_SERIALIZE_DECLARATION(type_m,tuples_m) \ 00110 TENUM_DESERIALIZE_DECLARATION(type_m,tuples_m) \ 00111 } \ 00112 TENUM_STREAM_OPERATORS_DECLARATION(type_m) 00113 00114 #define TENUM_STATIC_ENUM_SERIALIZATION_DEFINITION(type_m,tuples_m) \ 00115 namespace tenum { \ 00116 TENUM_GET_BASE_OF_DEFINITION(type_m,tuples_m) \ 00117 TENUM_SERIALIZE_DEFINITION(type_m,tuples_m) \ 00118 TENUM_DESERIALIZE_DEFINITION(type_m,tuples_m) \ 00119 } \ 00120 TENUM_STREAM_OPERATORS_DEFINITION(type_m) 00121 00122 #define TENUM_STATIC_ENUM_DECLARATION(type_m,tuples_m,underlying_m) \ 00123 TENUM_ENUM_DEFINITION(type_m,BOOST_PP_SEQ_PUSH_BACK(tuples_m,TENUM_TUPLE(lte_unknown)),underlying_m) \ 00124 TENUM_ENUM_OPERATORS_DECLARATION(type_m) \ 00125 TENUM_STATIC_ENUM_SERIALIZATION_DECLARATION(type_m,tuples_m) 00126 00127 #define TENUM_STATIC_ENUM_DEFINITION(type_m,tuples_m) \ 00128 TENUM_ENUM_OPERATORS_DEFINITION(type_m) \ 00129 TENUM_STATIC_ENUM_SERIALIZATION_DEFINITION(type_m,tuples_m) 00130 00131 #define TENUM_STATIC_ENUM_I(type_m,tuples_m,underlying_m) \ 00132 TENUM_STATIC_ENUM_DECLARATION(type_m,tuples_m,underlying_m) \ 00133 TENUM_STATIC_ENUM_DEFINITION(type_m,tuples_m) 00134 00135 #define TENUM_STATIC_ENUM(type_m,tuples_m,underlying_m) \ 00136 TENUM_STATIC_ENUM_I(type_m,tuples_m,:underlying_m) 00137 #define TENUM_SIMPLE_STATIC_ENUM(type_m,values_m) \ 00138 TENUM_STATIC_ENUM_I(type_m,TENUM_ENUM_VALUES_COMPLETE(values_m),BOOST_PP_EMPTY()) 00139 00140 #endif /* TENUM_STATIC_ENUM_HPP_ */