libtenum
include/tenum/detail/helper.hpp
Go to the documentation of this file.
00001 
00008 #ifndef TENUM_DETAIL_HELPER_HPP_
00009 #define TENUM_DETAIL_HELPER_HPP_
00010 
00011 #ifndef IN_TENUM_HPP_
00012 #  error "This header should not be included directly. Please use tenum.hpp."
00013 #endif
00014 
00015 #include <boost/type_traits/integral_constant.hpp>
00016 #include <boost/static_assert.hpp>
00017 
00018 #include <string>
00019 
00020 namespace tenum {
00021 
00025   template< typename EnumType >
00026   struct is_dynamic: ::boost::false_type {
00027   };
00028 
00032   template< typename EnumType >
00033   struct is_bit_field: ::boost::false_type {
00034   };
00035 
00039   template< typename EnumType >
00040   struct enum_helper {
00046       static inline EnumType get_base_of(EnumType const value_in);
00047 
00055       template< bool const IsDynamic, bool const IsBitField >
00056       static inline ::std::string serialize_impl(EnumType const enum_value_in,
00057                                                  ::boost::integral_constant< bool, IsDynamic > const& is_dynamic,
00058                                                  ::boost::integral_constant< bool, IsBitField > const& is_bit_field) {
00059         BOOST_STATIC_ASSERT_MSG(!IsDynamic, "serialization of dynamic enum is not supported for EnumType.");
00060         BOOST_STATIC_ASSERT_MSG(!IsBitField, "serialization of bit flags is not supported for EnumType.");
00061         BOOST_STATIC_ASSERT_MSG(IsDynamic && IsBitField, "serialization of enum is not supported for EnumType.");
00062         BOOST_STATIC_ASSERT_MSG(!IsDynamic && !IsBitField, "serialization of dynamic bit flags is not supported.");
00063         return "";
00064       }
00065 
00073       template< bool const IsDynamic, bool const IsBitField >
00074       static inline EnumType deserialize_impl(::std::string const& value_in,
00075                                               ::boost::integral_constant< bool, IsDynamic > const& is_dynamic,
00076                                               ::boost::integral_constant< bool, IsBitField > const& is_bit_field) {
00077         BOOST_STATIC_ASSERT_MSG(!IsDynamic, "deserialization of dynamic enum is not supported for EnumType.");
00078         BOOST_STATIC_ASSERT_MSG(!IsBitField, "deserialization of bit flags is not supported for EnumType.");
00079         BOOST_STATIC_ASSERT_MSG(IsDynamic && IsBitField, "deserialization of enum is not supported for EnumType.");
00080         BOOST_STATIC_ASSERT_MSG(!IsDynamic && !IsBitField, "deserialization of dynamic bit flags is not supported.");
00081         return static_cast< EnumType > (0);
00082       }
00083 
00089       static inline ::std::string serialize(EnumType const value_in) {
00090         return serialize_impl(value_in, is_dynamic< EnumType > (), is_bit_field< EnumType > ());
00091       }
00092 
00098       static inline EnumType deserialize(::std::string const& value_in) {
00099         return deserialize_impl(value_in, is_dynamic< EnumType > (), is_bit_field< EnumType > ());
00100       }
00101   };
00102 
00103 } // namespace tenum
00104 
00105 #endif /* TENUM_DETAIL_HELPER_HPP_ */
 All Classes Namespaces Files Functions Defines