Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r73957 - in sandbox/enums/boost/enums: ordinal pp scoped
From: vicente.botet_at_[hidden]
Date: 2011-08-20 14:28:00


Author: viboes
Date: 2011-08-20 14:27:59 EDT (Sat, 20 Aug 2011)
New Revision: 73957
URL: http://svn.boost.org/trac/boost/changeset/73957

Log:
Enums: Specialize explicit_converter_cp instead of overload explicit_convert_to
Text files modified:
   sandbox/enums/boost/enums/ordinal/size.hpp | 14 ++++----
   sandbox/enums/boost/enums/pp/enum_declaration.hpp | 58 +++++++++++++++++++++++++++++++++++
   sandbox/enums/boost/enums/scoped/emulation.hpp | 66 ++++++++++++++++++++++++++++++++++++++++
   3 files changed, 131 insertions(+), 7 deletions(-)

Modified: sandbox/enums/boost/enums/ordinal/size.hpp
==============================================================================
--- sandbox/enums/boost/enums/ordinal/size.hpp (original)
+++ sandbox/enums/boost/enums/ordinal/size.hpp 2011-08-20 14:27:59 EDT (Sat, 20 Aug 2011)
@@ -12,8 +12,8 @@
 
 /*!
  \file
- \brief
- The header \c <boost/enums/size.hpp> declares a class template \c meta::size<> and
+ \brief
+ The header \c <boost/enums/size.hpp> declares a class template \c meta::size<> and
  a function \c size() returning the number of elements in the enumeration.
  */
 
@@ -27,23 +27,23 @@
   namespace enums {
     namespace meta {
         //! meta-function used to get the number of elements of an enumeration.
-
+ //!
         //! @Note This meta-function must be specialized for each enumeration.
         template <typename EC>
 #ifndef BOOST_ENUMS_DOXYGEN_INVOKED
- struct size;
+ struct size;
 #else
- struct size
+ struct size
         {
             //! The nested @c value to be defined for each specialization.
             constexpr std::size_t value=<to be defined for each specialization>;
- };
+ };
 #endif
     }
     //! @Returns the number of elements of an enumeration @c EC.
     //! @NoThrow
     template <typename EC>
- std::size_t size()
+ std::size_t size()
     {
         return meta::size<EC>();
     }

Modified: sandbox/enums/boost/enums/pp/enum_declaration.hpp
==============================================================================
--- sandbox/enums/boost/enums/pp/enum_declaration.hpp (original)
+++ sandbox/enums/boost/enums/pp/enum_declaration.hpp 2011-08-20 14:27:59 EDT (Sat, 20 Aug 2011)
@@ -87,6 +87,48 @@
     } \
   } \
 
+#define BOOST_ENUMS_DCL_STRING_CONVERSIONS_SPECIALIZATIONS(ENUM, EL) \
+ namespace boost { \
+ namespace conversion { \
+ template <> \
+ struct explicit_converter_cp<ENUM,const char*> : true_type { \
+ ENUM operator()(const char* str) { \
+ BOOST_PP_SEQ_FOR_EACH( \
+ BOOST_ENUMS_ENUM_DCL_STR_TO_ID, \
+ ENUM, \
+ EL \
+ ) \
+ throw "invalid string for " \
+ BOOST_PP_STRINGIZE(ENUM); \
+ } \
+ }; \
+ template <> \
+ struct explicit_converter_cp<ENUM,std::string> : true_type { \
+ ENUM operator()(std::string const& str) { \
+ return boost::conversion::explicit_convert_to<ENUM>( \
+ str.c_str() \
+ ); \
+ } \
+ }; \
+ } \
+ } \
+ inline \
+ const char* c_str(ENUM e) \
+ { \
+ switch (boost::enums::native_value(e)) \
+ { \
+ BOOST_PP_SEQ_FOR_EACH( \
+ BOOST_ENUMS_ENUM_DCL_ID_TO_STR, \
+ ENUM, \
+ EL \
+ ) \
+ default: \
+ throw "invalid value for " \
+ BOOST_PP_STRINGIZE(ENUM); \
+ } \
+ } \
+
+
 /**
 
  @brief Generates a @c boost::enums::meta::size specialization.
@@ -266,9 +308,13 @@
   } \
   BOOST_ENUM_NS_TYPE_CONS_END(NS_EC, UT) \
   BOOST_ENUMS_ENUM_DCL_SPE(NS_EC, EL, TRAITER) \
+ BOOST_ENUMS_DCL_STRING_CONVERSIONS_SPECIALIZATIONS(BOOST_ENUMS_NAMESPACES_CLASS_QNAME(NS_EC), EL)
+
+#if 0
   BOOST_ENUMS_NAMESPACES_OPEN(BOOST_ENUMS_NAMESPACES_CLASS_NS(NS_EC)) \
   BOOST_ENUMS_DCL_STRING_CONVERSIONS(BOOST_ENUMS_NAMESPACES_CLASS_ENUM(NS_EC), EL) \
   BOOST_ENUMS_NAMESPACES_CLOSE(BOOST_ENUMS_NAMESPACES_CLASS_NS(NS_EC))
+#endif
 
 /**
 
@@ -329,9 +375,13 @@
   } \
   BOOST_ENUM_NS_TYPE_NO_CONS_END(NS_EC, UT) \
   BOOST_ENUMS_ENUM_DCL_SPE(NS_EC, EL, TRAITER) \
+ BOOST_ENUMS_DCL_STRING_CONVERSIONS_SPECIALIZATIONS(BOOST_ENUMS_NAMESPACES_CLASS_QNAME(NS_EC), EL)
+
+#if 0
   BOOST_ENUMS_NAMESPACES_OPEN(BOOST_ENUMS_NAMESPACES_CLASS_NS(NS_EC)) \
   BOOST_ENUMS_DCL_STRING_CONVERSIONS(BOOST_ENUMS_NAMESPACES_CLASS_ENUM(NS_EC), EL) \
   BOOST_ENUMS_NAMESPACES_CLOSE(BOOST_ENUMS_NAMESPACES_CLASS_NS(NS_EC))
+#endif
 
 /**
 
@@ -362,9 +412,13 @@
   } \
   BOOST_ENUM_NS_CLASS_CONS_END(NS_EC, UT) \
   BOOST_ENUMS_ENUM_DCL_SPE(NS_EC, EL, TRAITER) \
+ BOOST_ENUMS_DCL_STRING_CONVERSIONS_SPECIALIZATIONS(BOOST_ENUMS_NAMESPACES_CLASS_QNAME(NS_EC), EL)
+
+#if 0
   BOOST_ENUMS_NAMESPACES_OPEN(BOOST_ENUMS_NAMESPACES_CLASS_NS(NS_EC)) \
   BOOST_ENUMS_DCL_STRING_CONVERSIONS(BOOST_ENUMS_NAMESPACES_CLASS_ENUM(NS_EC), EL) \
   BOOST_ENUMS_NAMESPACES_CLOSE(BOOST_ENUMS_NAMESPACES_CLASS_NS(NS_EC))
+#endif
 
 /**
 
@@ -395,9 +449,13 @@
   } \
   BOOST_ENUM_NS_CLASS_NO_CONS_END(NS_EC, UT) \
   BOOST_ENUMS_ENUM_DCL_SPE(NS_EC, EL, TRAITER) \
+ BOOST_ENUMS_DCL_STRING_CONVERSIONS_SPECIALIZATIONS(BOOST_ENUMS_NAMESPACES_CLASS_QNAME(NS_EC), EL)
+
+#if 0
   BOOST_ENUMS_NAMESPACES_OPEN(BOOST_ENUMS_NAMESPACES_CLASS_NS(NS_EC)) \
   BOOST_ENUMS_DCL_STRING_CONVERSIONS(BOOST_ENUMS_NAMESPACES_CLASS_ENUM(NS_EC), EL) \
   BOOST_ENUMS_NAMESPACES_CLOSE(BOOST_ENUMS_NAMESPACES_CLASS_NS(NS_EC))
+#endif
 
 
 

Modified: sandbox/enums/boost/enums/scoped/emulation.hpp
==============================================================================
--- sandbox/enums/boost/enums/scoped/emulation.hpp (original)
+++ sandbox/enums/boost/enums/scoped/emulation.hpp 2011-08-20 14:27:59 EDT (Sat, 20 Aug 2011)
@@ -133,6 +133,32 @@
     { \
       return boost::enums::underlying_value(v); \
     }
+
+ #define BOOST_ENUMS_DETAIL_CONVERSIONS_SPECIALIZATIONS(EC, UT) \
+ namespace boost { \
+ namespace conversion { \
+ template <> \
+ struct explicit_converter_cp<EC,UT> : true_type { \
+ EC operator()(UT const &v) { \
+ return EC(v); \
+ } \
+ }; \
+ template <> \
+ struct explicit_converter_cp<UT,EC> : true_type { \
+ UT operator()(EC const &v) { \
+ return boost::enums::underlying_value(v); \
+ } \
+ }; \
+ template <> \
+ struct explicit_converter_cp<EC,boost::enums::native_type<EC>::type> \
+ : true_type { \
+ EC operator()(boost::enums::native_type<EC>::type const &v) { \
+ return v; \
+ } \
+ }; \
+ } \
+ } \
+
 #else
 
 #define BOOST_ENUMS_DETAIL_CONSTRUCTORS(EC, UT) \
@@ -180,6 +206,37 @@
     return boost::enums::native_value(v); \
   }
 
+ #define BOOST_ENUMS_DETAIL_CONVERSIONS_SPECIALIZATIONS(EC, UT) \
+ namespace boost { \
+ namespace conversion { \
+ template <> \
+ struct explicit_converter_cp<EC,UT> : true_type { \
+ EC operator()(UT const &v) { \
+ return EC::explicit_convert_to(v); \
+ } \
+ }; \
+ template <> \
+ struct explicit_converter_cp<UT,EC> : true_type { \
+ UT operator()(EC const &v) { \
+ return boost::enums::underlying_value(v); \
+ } \
+ }; \
+ template <> \
+ struct explicit_converter_cp<EC,boost::enums::native_type<EC>::type> \
+ : true_type { \
+ EC operator()(boost::enums::native_type<EC>::type const &v) { \
+ return EC::explicit_convert_to(v); \
+ } \
+ }; \
+ template <> \
+ struct explicit_converter_cp<boost::enums::native_type<EC>::type, EC> \
+ : true_type { \
+ boost::enums::native_type<EC>::type operator()(EC const &v) { \
+ return boost::enums::native_value(v); \
+ } \
+ }; \
+ } \
+ } \
 
 #define BOOST_ENUMS_DETAIL_END_2(EC, UT) \
   EC& operator =(type rhs) { \
@@ -257,9 +314,13 @@
 
   #define BOOST_ENUMS_OUT(NS_EC, UT) \
   BOOST_ENUMS_SPECIALIZATIONS(BOOST_ENUMS_NAMESPACES_CLASS_QNAME(NS_EC), UT) \
+ BOOST_ENUMS_DETAIL_CONVERSIONS_SPECIALIZATIONS(BOOST_ENUMS_NAMESPACES_CLASS_QNAME(NS_EC),UT)
+
+#if 0
   BOOST_ENUMS_NAMESPACES_OPEN(BOOST_ENUMS_NAMESPACES_CLASS_NS(NS_EC)) \
   BOOST_ENUMS_DETAIL_FRIEND_CONVERSIONS(BOOST_ENUMS_NAMESPACES_CLASS_ENUM(NS_EC), UT) \
   BOOST_ENUMS_NAMESPACES_CLOSE(BOOST_ENUMS_NAMESPACES_CLASS_NS(NS_EC))
+#endif
 
 #else // BOOST_NO_SCOPED_ENUMS
 
@@ -321,9 +382,14 @@
 
   #define BOOST_ENUMS_OUT(NS_EC, UT) \
   BOOST_ENUMS_SPECIALIZATIONS(BOOST_ENUMS_NAMESPACES_CLASS_QNAME(NS_EC), UT) \
+ BOOST_ENUMS_DETAIL_CONVERSIONS_SPECIALIZATIONS(BOOST_ENUMS_NAMESPACES_CLASS_QNAME(NS_EC),UT)
+
+#if 0
   BOOST_ENUMS_NAMESPACES_OPEN(BOOST_ENUMS_NAMESPACES_CLASS_NS(NS_EC)) \
   BOOST_ENUMS_DETAIL_FRIEND_CONVERSIONS(BOOST_ENUMS_NAMESPACES_CLASS_ENUM(NS_EC), UT) \
   BOOST_ENUMS_NAMESPACES_CLOSE(BOOST_ENUMS_NAMESPACES_CLASS_NS(NS_EC))
+#endif
+
 
 #endif
 #define BOOST_ENUM_NS_CLASS_START(NS_EC, UT) \


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk