FCStack refactoring
authorkhizmax <khizmax@gmail.com>
Thu, 9 Oct 2014 07:35:59 +0000 (11:35 +0400)
committerkhizmax <khizmax@gmail.com>
Thu, 9 Oct 2014 07:35:59 +0000 (11:35 +0400)
cds/container/fcstack.h
cds/intrusive/fcstack.h
tests/test-hdr/stack/hdr_fcstack.cpp
tests/test-hdr/stack/hdr_intrusive_fcstack.cpp

index be0130a82de8d2a3d90edb0a3d5fc6a396b10a81..fac698ec7fdeccbad04416be3735a90f15ef8b2d 100644 (file)
@@ -47,23 +47,22 @@ namespace cds { namespace container {
         };
 
         /// FCStack type traits
-        struct type_traits: public cds::algo::flat_combining::type_traits
+        struct traits: public cds::algo::flat_combining::type_traits
         {
             typedef empty_stat      stat;   ///< Internal statistics
-            static CDS_CONSTEXPR_CONST bool enable_elimination = false; ///< Enable \ref cds_elimination_description "elimination"
+            static CDS_CONSTEXPR const bool enable_elimination = false; ///< Enable \ref cds_elimination_description "elimination"
         };
 
         /// Metafunction converting option list to traits
         /**
-            This is a wrapper for <tt> cds::opt::make_options< type_traits, Options...> </tt>
             \p Options are:
             - \p opt::lock_type - mutex type, default is \p cds::lock::Spin
             - \p opt::back_off - back-off strategy, defalt is \p cds::backoff::Default
             - \p opt::allocator - allocator type, default is \ref CDS_DEFAULT_ALLOCATOR
-            - \p opt::stat - internal statistics, possible type: \ref stat, \ref empty_stat (the default)
+            - \p opt::stat - internal statistics, possible type: \p fcstack::stat, \p fcstack::empty_stat (the default)
             - \p opt::memory_model - C++ memory ordering model.
-                List of all available memory ordering see opt::memory_model.
-                Default if cds::opt::v:relaxed_ordering
+                List of all available memory ordering see \p opt::memory_model.
+                Default is \p cds::opt::v:relaxed_ordering
             - \p opt::enable_elimination - enable/disable operation \ref cds_elimination_description "elimination"
                 By default, the elimination is disabled.
         */
@@ -73,7 +72,7 @@ namespace cds { namespace container {
             typedef implementation_defined type ;   ///< Metafunction result
 #   else
             typedef typename cds::opt::make_options<
-                typename cds::opt::find_type_traits< type_traits, Options... >::type
+                typename cds::opt::find_type_traits< traits, Options... >::type
                 ,Options...
             >::type   type;
 #   endif
@@ -91,12 +90,12 @@ namespace cds { namespace container {
         Template parameters:
         - \p T - a value type stored in the stack
         - \p Stack - sequential stack implementation, default is \p std::stack<T>
-        - \p Trats - type traits of flat combining, default is \p fcstack::type_traits
-            \p fcstack::make_traits metafunction can be used to construct specialized \p %type_traits
+        - \p Trats - type traits of flat combining, default is \p fcstack::traits
+            \p fcstack::make_traits metafunction can be used to construct specialized \p %fcstack::traits
     */
     template <typename T,
         class Stack = std::stack<T>,
-        typename Traits = fcstack::type_traits
+        typename Traits = fcstack::traits
     >
     class FCStack
 #ifndef CDS_DOXYGEN_INVOKED
@@ -106,10 +105,10 @@ namespace cds { namespace container {
     public:
         typedef T           value_type;     ///< Value type
         typedef Stack       stack_type;     ///< Sequential stack class
-        typedef Traits      type_traits;    ///< Stack type traits
+        typedef Traits      traits;         ///< Stack traits
 
-        typedef typename type_traits::stat  stat;   ///< Internal statistics type
-        static CDS_CONSTEXPR_CONST bool c_bEliminationEnabled = type_traits::enable_elimination; ///< \p true if elimination is enabled
+        typedef typename traits::stat  stat;   ///< Internal statistics type
+        static CDS_CONSTEXPR_CONST bool c_bEliminationEnabled = traits::enable_elimination; ///< \p true if elimination is enabled
 
     protected:
         //@cond
@@ -133,7 +132,7 @@ namespace cds { namespace container {
         //@endcond
 
         /// Flat combining kernel
-        typedef cds::algo::flat_combining::kernel< fc_record, type_traits > fc_kernel;
+        typedef cds::algo::flat_combining::kernel< fc_record, traits > fc_kernel;
 
     protected:
         //@cond
index f985ec77eec1b18583444b265f67ffdc72a16630..f70ec59fc0c8f4ba07bc18570e12957fd12d97db 100644 (file)
@@ -43,26 +43,25 @@ namespace cds { namespace intrusive {
         };
 
         /// FCStack type traits
-        struct type_traits: public cds::algo::flat_combining::type_traits
+        struct traits: public cds::algo::flat_combining::type_traits
         {
             typedef cds::intrusive::opt::v::empty_disposer  disposer ; ///< Disposer to erase removed elements. Used only in \p FCStack::clear() function
             typedef empty_stat      stat;   ///< Internal statistics
-            static CDS_CONSTEXPR_CONST bool enable_elimination = false; ///< Enable \ref cds_elimination_description "elimination"
+            static CDS_CONSTEXPR const bool enable_elimination = false; ///< Enable \ref cds_elimination_description "elimination"
         };
 
         /// Metafunction converting option list to traits
         /**
-            This is a wrapper for <tt> cds::opt::make_options< type_traits, Options...> </tt>
             \p Options are:
             - \p opt::lock_type - mutex type, default is \p cds::lock::Spin
             - \p opt::back_off - back-off strategy, defalt is \p cds::backoff::Default
-            - \p opt::disposer - the functor used for dispose removed items. Default is opt::intrusive::v::empty_disposer.
+            - \p opt::disposer - the functor used for dispose removed items. Default is \p opt::intrusive::v::empty_disposer.
                 This option is used only in \p FCStack::clear() function.
             - \p opt::allocator - allocator type, default is \ref CDS_DEFAULT_ALLOCATOR
-            - \p opt::stat - internal statistics, possible type: \ref stat, \ref empty_stat (the default)
+            - \p opt::stat - internal statistics, possible type: \p fcstack::stat, \p fcstack::empty_stat (the default)
             - \p opt::memory_model - C++ memory ordering model.
-                List of all available memory ordering see opt::memory_model.
-                Default if cds::opt::v:relaxed_ordering
+                List of all available memory ordering see \p opt::memory_model.
+                Default is \p cds::opt::v:relaxed_ordering
             - \p opt::enable_elimination - enable/disable operation \ref cds_elimination_description "elimination"
                 By default, the elimination is disabled.
         */
@@ -72,7 +71,7 @@ namespace cds { namespace intrusive {
             typedef implementation_defined type ;   ///< Metafunction result
 #   else
             typedef typename cds::opt::make_options<
-                typename cds::opt::find_type_traits< type_traits, Options... >::type
+                typename cds::opt::find_type_traits< traits, Options... >::type
                 ,Options...
             >::type   type;
 #   endif
@@ -91,12 +90,12 @@ namespace cds { namespace intrusive {
         - \p T - a value type stored in the stack
         - \p Container - sequential intrusive container with \p push_front and \p pop_front functions.
             Possible containers are \p boost::intrusive::slist (the default), \p boost::inrtrusive::list
-        - \p Traits - type traits of flat combining, default is \p fcstack::type_traits.
-            \p fcstack::make_traits metafunction can be used to construct specialized \p %type_traits
+        - \p Traits - type traits of flat combining, default is \p fcstack::traits.
+            \p fcstack::make_traits metafunction can be used to construct specialized \p %traits
     */
     template <typename T
         ,class Container = boost::intrusive::slist<T>
-        ,typename Traits = fcstack::type_traits
+        ,typename Traits = fcstack::traits
     >
     class FCStack
 #ifndef CDS_DOXYGEN_INVOKED
@@ -106,11 +105,11 @@ namespace cds { namespace intrusive {
     public:
         typedef T           value_type;     ///< Value type
         typedef Container   container_type; ///< Sequential container type
-        typedef Traits      type_traits;    ///< Stack type traits
+        typedef Traits      traits;         ///< Stack traits
 
-        typedef typename type_traits::disposer  disposer;   ///< The disposer functor. The disposer is used only in \ref clear() function
-        typedef typename type_traits::stat  stat;   ///< Internal statistics type
-        static CDS_CONSTEXPR_CONST bool c_bEliminationEnabled = type_traits::enable_elimination; ///< \p true if elimination is enabled
+        typedef typename traits::disposer  disposer;   ///< The disposer functor. The disposer is used only in \ref clear() function
+        typedef typename traits::stat  stat;   ///< Internal statistics type
+        static CDS_CONSTEXPR_CONST bool c_bEliminationEnabled = traits::enable_elimination; ///< \p true if elimination is enabled
 
     protected:
         //@cond
@@ -131,7 +130,7 @@ namespace cds { namespace intrusive {
         //@endcond
 
         /// Flat combining kernel
-        typedef cds::algo::flat_combining::kernel< fc_record, type_traits > fc_kernel;
+        typedef cds::algo::flat_combining::kernel< fc_record, traits > fc_kernel;
 
     protected:
         //@cond
index e360d232bb62d43e8cd81b477dc9615317cb6cab..48ebe9137d678c816e7767a7d1b0b0df9500e6c4 100644 (file)
@@ -99,11 +99,11 @@ namespace stack {
 
     void TestFCStack::FCStack_deque_elimination()
     {
-        typedef cds::container::FCStack< unsigned int, std::stack<unsigned int, std::deque<unsigned int> >,
-            cds::container::fcstack::make_traits<
-                cds::opt::enable_elimination< true >
-            >::type
-        > stack_type;
+        struct stack_traits : public cds::container::fcstack::traits
+        {
+            static CDS_CONSTEXPR const bool enable_elimination = true;
+        };
+        typedef cds::container::FCStack< unsigned int, std::stack<unsigned int, std::deque<unsigned int> >, stack_traits > stack_type;
         test<stack_type>();
     }
 
index c7bc6cd85436dfce451202c9efc5c06d888de555..48e22f7cb8c51fbc281fd77301173be0231f268c 100644 (file)
@@ -144,22 +144,23 @@ namespace stack {
     void TestIntrusiveFCStack::FCStack_slist_mutex()
     {
         typedef base_hook_item< boost::intrusive::slist_base_hook<> > value_type;
-        typedef cds::intrusive::FCStack< value_type, boost::intrusive::slist< value_type >,
-            cds::intrusive::fcstack::make_traits<
-                cds::opt::lock_type< std::mutex >
-            >::type
-        > stack_type;
+        struct stack_traits : public cds::intrusive::fcstack::traits
+        {
+            typedef std::mutex lock_type;
+        };
+        typedef cds::intrusive::FCStack< value_type, boost::intrusive::slist< value_type >, stack_traits > stack_type;
         test<stack_type>();
     }
 
     void TestIntrusiveFCStack::FCStack_slist_elimination()
     {
         typedef base_hook_item< boost::intrusive::slist_base_hook<> > value_type;
-        typedef cds::intrusive::FCStack< value_type, boost::intrusive::slist< value_type >,
-            cds::intrusive::fcstack::make_traits<
-                cds::opt::enable_elimination< true >
-            >::type
-        > stack_type;
+        struct stack_traits : public
+            cds::intrusive::fcstack::make_traits <
+                cds::opt::enable_elimination < true >
+            > ::type
+        {};
+        typedef cds::intrusive::FCStack< value_type, boost::intrusive::slist< value_type >, stack_traits > stack_type;
         test<stack_type>();
     }