Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r76777 - in trunk/boost/thread: . detail
From: vicente.botet_at_[hidden]
Date: 2012-01-29 13:27:27


Author: viboes
Date: 2012-01-29 13:27:26 EST (Sun, 29 Jan 2012)
New Revision: 76777
URL: http://svn.boost.org/trac/boost/changeset/76777

Log:
Thread: Added detail/scoped_enumm.hpp file and adaptat enum classes to the new interface
Added:
   trunk/boost/thread/detail/scoped_enum.hpp (contents, props changed)
Text files modified:
   trunk/boost/thread/cv_status.hpp | 8 ++++----
   trunk/boost/thread/detail/config.hpp | 32 +++++++-------------------------
   trunk/boost/thread/future.hpp | 23 ++++++++++++-----------
   3 files changed, 23 insertions(+), 40 deletions(-)

Modified: trunk/boost/thread/cv_status.hpp
==============================================================================
--- trunk/boost/thread/cv_status.hpp (original)
+++ trunk/boost/thread/cv_status.hpp 2012-01-29 13:27:26 EST (Sun, 29 Jan 2012)
@@ -9,18 +9,18 @@
 #ifndef BOOST_THREAD_CV_STATUS_HPP
 #define BOOST_THREAD_CV_STATUS_HPP
 
-#include <boost/thread/detail/config.hpp>
+#include <boost/thread/detail/scoped_enum.hpp>
 
 namespace boost
 {
 
   // enum class cv_status;
- BOOST_DECLARE_STRONG_ENUM_BEGIN(cv_status)
+ BOOST_SCOPED_ENUM_DECLARE_BEGIN(cv_status)
   {
     no_timeout,
     timeout
- };
- BOOST_DECLARE_STRONG_ENUM_END(cv_status)
+ }
+ BOOST_SCOPED_ENUM_DECLARE_END(cv_status)
 }
 
 #endif // header

Modified: trunk/boost/thread/detail/config.hpp
==============================================================================
--- trunk/boost/thread/detail/config.hpp (original)
+++ trunk/boost/thread/detail/config.hpp 2012-01-29 13:27:26 EST (Sun, 29 Jan 2012)
@@ -10,7 +10,6 @@
 #include <boost/config.hpp>
 #include <boost/detail/workaround.hpp>
 
-
 #if !defined BOOST_THREAD_VERSION
 #define BOOST_THREAD_VERSION 1
 #else
@@ -19,34 +18,17 @@
 #endif
 #endif
 
-#if ! defined BOOST_THREAD_DONT_USE_CHRONO
+#if ! defined BOOST_THREAD_DONT_USE_SYSTEM
+#define BOOST_THREAD_USES_SYSTEM
+#endif
+
+#if ! defined BOOST_THREAD_DONT_USE_CHRONO && ! defined BOOST_THREAD_DONT_USE_SYSTEM
 #define BOOST_THREAD_USES_CHRONO
 #endif
 
+#if ! defined BOOST_THREAD_DONT_USE_MOVE
 #define BOOST_THREAD_USES_MOVE
-
-#ifdef BOOST_NO_SCOPED_ENUMS
-#define BOOST_DECLARE_STRONG_ENUM_BEGIN(x) \
- struct x { \
- enum enum_type
-
-#define BOOST_DECLARE_STRONG_ENUM_END(x) \
- enum_type v_; \
- inline x() {} \
- inline x(enum_type v) : v_(v) {} \
- inline operator int() const {return v_;} \
- friend inline bool operator ==(x lhs, int rhs) {return lhs.v_==rhs;} \
- friend inline bool operator ==(int lhs, x rhs) {return lhs==rhs.v_;} \
- friend inline bool operator !=(x lhs, int rhs) {return lhs.v_!=rhs;} \
- friend inline bool operator !=(int lhs, x rhs) {return lhs!=rhs.v_;} \
- };
-
-#define BOOST_STRONG_ENUM_NATIVE(x) x::enum_type
-#else // BOOST_NO_SCOPED_ENUMS
-#define BOOST_DECLARE_STRONG_ENUM_BEGIN(x) enum class x
-#define BOOST_DECLARE_STRONG_ENUM_END(x)
-#define BOOST_STRONG_ENUM_NATIVE(x) x
-#endif // BOOST_NO_SCOPED_ENUMS
+#endif
 
 #if BOOST_WORKAROUND(__BORLANDC__, < 0x600)
 # pragma warn -8008 // Condition always true/false

Added: trunk/boost/thread/detail/scoped_enum.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/thread/detail/scoped_enum.hpp 2012-01-29 13:27:26 EST (Sun, 29 Jan 2012)
@@ -0,0 +1,113 @@
+// Copyright (C) 2012
+// Vicente J. Botet Escriba
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_THREAD_DETAIL_SCOPED_ENUM_HPP
+#define BOOST_THREAD_DETAIL_SCOPED_ENUM_HPP
+
+#include <boost/config.hpp>
+#include <boost/detail/workaround.hpp>
+
+namespace boost
+{
+
+#ifdef BOOST_NO_SCOPED_ENUMS
+ template <typename NT>
+ struct underlying_type
+ {
+ typedef typename NT::underlying_type type;
+ };
+
+ template <typename UT, typename NT>
+ UT underlying_cast(NT v)
+ {
+ return v.underlying();
+ }
+
+ template <typename EC>
+ inline
+ typename EC::enum_type native_value(EC e)
+ {
+ return e.native();
+ }
+
+#else // BOOST_NO_SCOPED_ENUMS
+
+ template <typename NT>
+ struct underlying_type
+ {
+ //typedef typename std::underlying_type<NT>::type type;
+ };
+
+ template <typename UT, typename NT>
+ UT underlying_cast(NT v)
+ {
+ return static_cast<UT>(v);
+ }
+
+ template <typename EC>
+ inline
+ EC native_value(EC e)
+ {
+ return e;
+ }
+
+#endif
+}
+
+
+#ifdef BOOST_NO_SCOPED_ENUMS
+
+#ifndef BOOST_NO_EXPLICIT_CONVERSION_OPERATORS
+
+#define BOOST_SCOPED_ENUM_UT_DECLARE_CONVERSION_OPERATOR \
+ explicit operator underlying_type() const { return underlying(); }
+
+#else
+
+#define BOOST_SCOPED_ENUM_UT_DECLARE_CONVERSION_OPERATOR
+
+#endif
+
+#define BOOST_SCOPED_ENUM_UT_DECLARE_BEGIN(NT, UT) \
+ struct NT { \
+ typedef UT underlying_type; \
+ enum enum_type
+
+#define BOOST_SCOPED_ENUM_DECLARE_END(NT) \
+ ; \
+ NT() {} \
+ NT(enum_type v) : v_(v) {} \
+ explicit NT(underlying_type v) : v_(v) {} \
+ underlying_type underlying() const { return v_; } \
+ enum_type native() const { return enum_type(v_); } \
+ BOOST_SCOPED_ENUM_UT_DECLARE_CONVERSION_OPERATOR \
+ friend bool operator ==(NT lhs, enum_type rhs) { return enum_type(lhs.v_)==rhs; } \
+ friend bool operator ==(enum_type lhs, NT rhs) { return lhs==enum_type(rhs.v_); } \
+ friend bool operator !=(NT lhs, enum_type rhs) { return enum_type(lhs.v_)!=rhs; } \
+ friend bool operator !=(enum_type lhs, NT rhs) { return lhs!=enum_type(rhs.v_); } \
+ private: \
+ underlying_type v_; \
+ };
+
+#define BOOST_SCOPED_ENUM_DECLARE_BEGIN(NT) \
+ BOOST_SCOPED_ENUM_UT_DECLARE_BEGIN(NT,int)
+
+#define BOOST_SCOPED_ENUM_NATIVE(NT) NT::enum_type
+#define BOOST_SCOPED_ENUM_FORWARD_DECLARE(NT) struct NT
+
+#else // BOOST_NO_SCOPED_ENUMS
+
+#define BOOST_SCOPED_ENUM_UT_DECLARE_BEGIN(NT,UT) enum class NT:UT
+#define BOOST_SCOPED_ENUM_DECLARE_BEGIN(NT) enum class NT
+#define BOOST_SCOPED_ENUM_DECLARE_END(NT) ;
+
+#define BOOST_SCOPED_ENUM_NATIVE(NT) NT
+#define BOOST_SCOPED_ENUM_FORWARD_DECLARE(NT) enum class NT
+
+#endif // BOOST_NO_SCOPED_ENUMS
+
+
+#endif // BOOST_THREAD_DETAIL_SCOPED_ENUM_HPP

Modified: trunk/boost/thread/future.hpp
==============================================================================
--- trunk/boost/thread/future.hpp (original)
+++ trunk/boost/thread/future.hpp 2012-01-29 13:27:26 EST (Sun, 29 Jan 2012)
@@ -8,6 +8,7 @@
 #define BOOST_THREAD_FUTURE_HPP
 
 #include <boost/thread/detail/config.hpp>
+#include <boost/thread/detail/scoped_enum.hpp>
 #include <stdexcept>
 #include <boost/thread/detail/move.hpp>
 #include <boost/thread/thread_time.hpp>
@@ -45,14 +46,14 @@
 {
 
   //enum class future_errc
- BOOST_DECLARE_STRONG_ENUM_BEGIN(future_errc)
+ BOOST_SCOPED_ENUM_DECLARE_BEGIN(future_errc)
   {
       broken_promise,
       future_already_retrieved,
       promise_already_satisfied,
       no_state
- };
- BOOST_DECLARE_STRONG_ENUM_END(future_errc)
+ }
+ BOOST_SCOPED_ENUM_DECLARE_END(future_errc)
 
   namespace system
   {
@@ -66,22 +67,22 @@
   }
 
   //enum class launch
- BOOST_DECLARE_STRONG_ENUM_BEGIN(launch)
+ BOOST_SCOPED_ENUM_DECLARE_BEGIN(launch)
   {
       async = 1,
       deferred = 2,
       any = async | deferred
- };
- BOOST_DECLARE_STRONG_ENUM_END(launch)
+ }
+ BOOST_SCOPED_ENUM_DECLARE_END(launch)
 
   //enum class future_status
- BOOST_DECLARE_STRONG_ENUM_BEGIN(future_status)
+ BOOST_SCOPED_ENUM_DECLARE_BEGIN(future_status)
   {
       ready,
       timeout,
       deferred
- };
- BOOST_DECLARE_STRONG_ENUM_END(future_status)
+ }
+ BOOST_SCOPED_ENUM_DECLARE_END(future_status)
 
   BOOST_THREAD_DECL
   const system::error_category& future_category();
@@ -92,14 +93,14 @@
     error_code
     make_error_code(future_errc e)
     {
- return error_code(static_cast<int>(e), boost::future_category());
+ return error_code(underlying_cast<int>(e), boost::future_category());
     }
 
     inline BOOST_THREAD_DECL
     error_condition
     make_error_condition(future_errc e)
     {
- return error_condition(static_cast<int>(e), future_category());
+ return error_condition(underlying_cast<int>(e), future_category());
     }
   }
 


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