From: khizmax Date: Sat, 27 Sep 2014 15:12:50 +0000 (+0400) Subject: Move cds/intrusive/node_traits.h to cds/intrusive/details directory X-Git-Tag: v2.0.0~277 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=fc54f7bd81666e2b6e1b701a69d32005cf3b7885;p=libcds.git Move cds/intrusive/node_traits.h to cds/intrusive/details directory --- diff --git a/cds/intrusive/details/base.h b/cds/intrusive/details/base.h index 0845569c..68c1449c 100644 --- a/cds/intrusive/details/base.h +++ b/cds/intrusive/details/base.h @@ -3,7 +3,7 @@ #ifndef __CDS_INTRUSIVE_DETAILS_BASE_H #define __CDS_INTRUSIVE_DETAILS_BASE_H -#include +#include #include #include diff --git a/cds/intrusive/details/node_traits.h b/cds/intrusive/details/node_traits.h new file mode 100644 index 00000000..0bccc641 --- /dev/null +++ b/cds/intrusive/details/node_traits.h @@ -0,0 +1,166 @@ +//$$CDS-header$$ + +#ifndef __CDS_INTRUSIVE_DETAILS_NODE_TRAITS_H +#define __CDS_INTRUSIVE_DETAILS_NODE_TRAITS_H + +#include + +namespace cds { namespace intrusive { + +#ifdef CDS_DOXYGEN_INVOKED + /// Container's node traits + /** @ingroup cds_intrusive_helper + This traits is intended for converting between type \p T of value stored in the intrusive container + and container's node type \p NodeType. + + There are separate specializations for each \p Hook type. + */ + template + struct node_traits + { + typedef T value_type ; ///< Value type + typedef NodeType node_type ; ///< Node type + + /// Convert value reference to node pointer + static node_type * to_node_ptr( value_type& v ); + + /// Convert value pointer to node pointer + static node_type * to_node_ptr( value_type * v ); + + /// Convert value reference to node pointer (const version) + static const node_type * to_node_ptr( value_type const& v ); + + /// Convert value pointer to node pointer (const version) + static const node_type * to_node_ptr( value_type const * v ); + + /// Convert node refernce to value pointer + static value_type * to_value_ptr( node_type& n ); + + /// Convert node pointer to value pointer + static value_type * to_value_ptr( node_type * n ); + + /// Convert node reference to value pointer (const version) + static const value_type * to_value_ptr( node_type const & n ); + + /// Convert node pointer to value pointer (const version) + static const value_type * to_value_ptr( node_type const * n ); + }; + +#else + template + struct node_traits; +#endif + + //@cond + template + struct node_traits + { + typedef T value_type; + typedef NodeType node_type; + + static node_type * to_node_ptr( value_type& v ) + { + return static_cast( &v ); + } + static node_type * to_node_ptr( value_type * v ) + { + return v ? static_cast(v) : nullptr; + } + static const node_type * to_node_ptr( const value_type& v ) + { + return static_cast( &v ); + } + static const node_type * to_node_ptr( const value_type * v ) + { + return v ? static_cast(v) : nullptr; + } + static value_type * to_value_ptr( node_type& n ) + { + return static_cast( &n ); + } + static value_type * to_value_ptr( node_type * n ) + { + return n ? static_cast(n) : nullptr; + } + static const value_type * to_value_ptr( const node_type& n ) + { + return static_cast( &n ); + } + static const value_type * to_value_ptr( const node_type * n ) + { + return n ? static_cast(n) : nullptr; + } + }; + + template + struct node_traits + { + typedef T value_type; + typedef NodeType node_type; + + static node_type * to_node_ptr( value_type& v ) + { + return reinterpret_cast( reinterpret_cast(&v) + Hook::c_nMemberOffset ); + } + static node_type * to_node_ptr( value_type * v ) + { + return v ? to_node_ptr( *v ) : nullptr; + } + static const node_type * to_node_ptr( const value_type& v ) + { + return reinterpret_cast( reinterpret_cast(&v) + Hook::c_nMemberOffset ); + } + static const node_type * to_node_ptr( const value_type * v ) + { + return v ? to_node_ptr( *v ) : nullptr; + } + static value_type * to_value_ptr( node_type& n ) + { + return reinterpret_cast( reinterpret_cast(&n) - Hook::c_nMemberOffset ); + } + static value_type * to_value_ptr( node_type * n ) + { + return n ? to_value_ptr( *n ) : nullptr; + } + static const value_type * to_value_ptr( const node_type& n ) + { + return reinterpret_cast( reinterpret_cast(&n) - Hook::c_nMemberOffset ); + } + static const value_type * to_value_ptr( const node_type * n ) + { + return n ? to_value_ptr( *n ) : nullptr; + } + }; + + template + struct node_traits: public Hook::node_traits + {}; + //@endcond + + /// Node traits selector metafunction + /** @ingroup cds_intrusive_helper + The metafunction selects appropriate \ref node_traits specialization based on value type \p T, node type \p NodeType, and hook type \p Hook. + */ + template + struct get_node_traits + { + //@cond + typedef node_traits type; + //@endcond + }; + + //@cond + /// Functor converting container's node type to value type + template + struct node_to_value { + typename Container::value_type * operator()( typename Container::node_type * p ) + { + typedef typename Container::node_traits node_traits; + return node_traits::to_value_ptr( p ); + } + }; + //@endcond + +}} // namespace cds::intrusuve + +#endif // #ifndef __CDS_INTRUSIVE_DETAILS_NODE_TRAITS_H diff --git a/cds/intrusive/node_traits.h b/cds/intrusive/node_traits.h deleted file mode 100644 index 0f2c8c6d..00000000 --- a/cds/intrusive/node_traits.h +++ /dev/null @@ -1,166 +0,0 @@ -//$$CDS-header$$ - -#ifndef __CDS_INTRUSIVE_NODE_TRAITS_H -#define __CDS_INTRUSIVE_NODE_TRAITS_H - -#include - -namespace cds { namespace intrusive { - -#ifdef CDS_DOXYGEN_INVOKED - /// Container's node traits - /** @ingroup cds_intrusive_helper - This traits is intended for converting between type \p T of value stored in the intrusive container - and container's node type \p NodeType. - - There are separate specializations for each \p Hook type. - */ - template - struct node_traits - { - typedef T value_type ; ///< Value type - typedef NodeType node_type ; ///< Node type - - /// Convert value reference to node pointer - static node_type * to_node_ptr( value_type& v ); - - /// Convert value pointer to node pointer - static node_type * to_node_ptr( value_type * v ); - - /// Convert value reference to node pointer (const version) - static const node_type * to_node_ptr( value_type const& v ); - - /// Convert value pointer to node pointer (const version) - static const node_type * to_node_ptr( value_type const * v ); - - /// Convert node refernce to value pointer - static value_type * to_value_ptr( node_type& n ); - - /// Convert node pointer to value pointer - static value_type * to_value_ptr( node_type * n ); - - /// Convert node reference to value pointer (const version) - static const value_type * to_value_ptr( node_type const & n ); - - /// Convert node pointer to value pointer (const version) - static const value_type * to_value_ptr( node_type const * n ); - }; - -#else - template - struct node_traits; -#endif - - //@cond - template - struct node_traits - { - typedef T value_type; - typedef NodeType node_type; - - static node_type * to_node_ptr( value_type& v ) - { - return static_cast( &v ); - } - static node_type * to_node_ptr( value_type * v ) - { - return v ? static_cast(v) : nullptr; - } - static const node_type * to_node_ptr( const value_type& v ) - { - return static_cast( &v ); - } - static const node_type * to_node_ptr( const value_type * v ) - { - return v ? static_cast(v) : nullptr; - } - static value_type * to_value_ptr( node_type& n ) - { - return static_cast( &n ); - } - static value_type * to_value_ptr( node_type * n ) - { - return n ? static_cast(n) : nullptr; - } - static const value_type * to_value_ptr( const node_type& n ) - { - return static_cast( &n ); - } - static const value_type * to_value_ptr( const node_type * n ) - { - return n ? static_cast(n) : nullptr; - } - }; - - template - struct node_traits - { - typedef T value_type; - typedef NodeType node_type; - - static node_type * to_node_ptr( value_type& v ) - { - return reinterpret_cast( reinterpret_cast(&v) + Hook::c_nMemberOffset ); - } - static node_type * to_node_ptr( value_type * v ) - { - return v ? to_node_ptr( *v ) : nullptr; - } - static const node_type * to_node_ptr( const value_type& v ) - { - return reinterpret_cast( reinterpret_cast(&v) + Hook::c_nMemberOffset ); - } - static const node_type * to_node_ptr( const value_type * v ) - { - return v ? to_node_ptr( *v ) : nullptr; - } - static value_type * to_value_ptr( node_type& n ) - { - return reinterpret_cast( reinterpret_cast(&n) - Hook::c_nMemberOffset ); - } - static value_type * to_value_ptr( node_type * n ) - { - return n ? to_value_ptr( *n ) : nullptr; - } - static const value_type * to_value_ptr( const node_type& n ) - { - return reinterpret_cast( reinterpret_cast(&n) - Hook::c_nMemberOffset ); - } - static const value_type * to_value_ptr( const node_type * n ) - { - return n ? to_value_ptr( *n ) : nullptr; - } - }; - - template - struct node_traits: public Hook::node_traits - {}; - //@endcond - - /// Node traits selector metafunction - /** @ingroup cds_intrusive_helper - The metafunction selects appropriate \ref node_traits specialization based on value type \p T, node type \p NodeType, and hook type \p Hook. - */ - template - struct get_node_traits - { - //@cond - typedef node_traits type; - //@endcond - }; - - //@cond - /// Functor converting container's node type to value type - template - struct node_to_value { - typename Container::value_type * operator()( typename Container::node_type * p ) - { - typedef typename Container::node_traits node_traits; - return node_traits::to_value_ptr( p ); - } - }; - //@endcond - -}} // namespace cds::intrusuve - -#endif // #ifndef __CDS_INTRUSIVE_NODE_TRAITS_H diff --git a/projects/Win/vc12/cds.vcxproj b/projects/Win/vc12/cds.vcxproj index c564cb4c..207785a0 100644 --- a/projects/Win/vc12/cds.vcxproj +++ b/projects/Win/vc12/cds.vcxproj @@ -742,6 +742,7 @@ + @@ -753,7 +754,6 @@ - diff --git a/projects/Win/vc12/cds.vcxproj.filters b/projects/Win/vc12/cds.vcxproj.filters index 4cb12974..0a381360 100644 --- a/projects/Win/vc12/cds.vcxproj.filters +++ b/projects/Win/vc12/cds.vcxproj.filters @@ -1010,9 +1010,6 @@ Header Files\cds\intrusive - - Header Files\cds\intrusive - Header Files\cds\intrusive @@ -1280,5 +1277,8 @@ Header Files\cds\intrusive\details + + Header Files\cds\intrusive\details + \ No newline at end of file