X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=gdax-orderbook-hpp%2Fdemo%2Fdependencies%2Flibcds-2.3.2%2Fcds%2Fintrusive%2Fdetails%2Fnode_traits.h;fp=gdax-orderbook-hpp%2Fdemo%2Fdependencies%2Flibcds-2.3.2%2Fcds%2Fintrusive%2Fdetails%2Fnode_traits.h;h=958ee6a7c50e1e5ae76ccb922f9d4de1a64f0b34;hb=4223430d9168223029c7639149025c79e69b4f37;hp=0000000000000000000000000000000000000000;hpb=7ea7751a31c0388bf888052517be181a2989b113;p=c11concurrency-benchmarks.git diff --git a/gdax-orderbook-hpp/demo/dependencies/libcds-2.3.2/cds/intrusive/details/node_traits.h b/gdax-orderbook-hpp/demo/dependencies/libcds-2.3.2/cds/intrusive/details/node_traits.h new file mode 100644 index 0000000..958ee6a --- /dev/null +++ b/gdax-orderbook-hpp/demo/dependencies/libcds-2.3.2/cds/intrusive/details/node_traits.h @@ -0,0 +1,195 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef CDSLIB_INTRUSIVE_DETAILS_NODE_TRAITS_H +#define CDSLIB_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 + //TODO: delete + template + struct node_to_value { + typename Container::value_type * operator()( typename Container::node_type * p ) const + { + typedef typename Container::node_traits node_traits; + return node_traits::to_value_ptr( p ); + } + }; + //@endcond + +}} // namespace cds::intrusuve + +#endif // #ifndef CDSLIB_INTRUSIVE_DETAILS_NODE_TRAITS_H