3 #ifndef CDSLIB_INTRUSIVE_OPTIONS_H
4 #define CDSLIB_INTRUSIVE_OPTIONS_H
6 #include <cds/opt/options.h>
7 #include <cds/details/allocator.h>
9 namespace cds { namespace intrusive {
11 /// Common options for intrusive containers
12 /** @ingroup cds_intrusive_helper
13 This namespace contains options for intrusive containers.
14 It imports all definitions from cds::opt namespace and introduces a lot
15 of options specific for intrusive approach.
18 using namespace cds::opt;
22 struct member_hook_tag;
23 struct traits_hook_tag;
28 Hook is a class that a user must add as a base class or as a member to make the user class compatible with intrusive containers.
29 \p Hook template parameter strongly depends on the type of intrusive container you use.
31 template <typename Hook>
34 template <typename Base> struct pack: public Base
41 /// Item disposer option setter
43 The option specifies a functor that is used for dispose removed items.
44 The interface of \p Type functor is:
47 void operator ()( T * val );
51 Predefined types for \p Type:
52 - opt::v::empty_disposer - the disposer that does nothing
53 - opt::v::delete_disposer - the disposer that calls operator \p delete
55 Usually, the disposer should be stateless default-constructible functor.
56 It is called by garbage collector in deferred mode.
58 template <typename Type>
61 template <typename Base> struct pack: public Base
63 typedef Type disposer;
68 /// Values of \ref cds::intrusive::opt::link_checker option
69 enum link_check_type {
70 never_check_link, ///< no link checking performed
71 debug_check_link, ///< check only in debug build
72 always_check_link ///< check in debug and release build
77 The option specifies a type of link checking.
78 Possible values for \p Value are is one of \ref link_check_type enum:
79 - \ref never_check_link - no link checking performed
80 - \ref debug_check_link - check only in debug build
81 - \ref always_check_link - check in debug and release build (not yet implemented for release mode).
83 When link checking is on, the container tests that the node's link fields
84 must be \p nullptr before inserting the item. If the link is not \p nullptr an assertion is generated
86 template <link_check_type Value>
89 template <typename Base> struct pack: public Base
91 static const link_check_type link_checker = Value;
96 /// Predefined option values
98 using namespace cds::opt::v;
102 template <typename Node>
103 struct empty_link_checker
106 typedef Node node_type;
108 static void is_empty( const node_type * /*pNode*/ )
114 /// Empty item disposer
116 The disposer does nothing.
117 This is one of possible values of opt::disposer option.
119 struct empty_disposer
121 /// Empty dispose functor
122 template <typename T>
123 void operator ()( T * )
127 /// Deletion item disposer
129 Analogue of operator \p delete call.
130 The disposer that calls \p T destructor and deallocates the item via \p Alloc allocator.
132 template <typename Alloc = CDS_DEFAULT_ALLOCATOR >
133 struct delete_disposer
136 template <typename T>
137 void operator ()( T * p )
139 cds::details::Allocator<T, Alloc> alloc;
146 // Lazy-list specific option (for split-list support)
147 template <typename Type>
148 struct boundary_node_type {
150 template <typename Base> struct pack: public Base
152 typedef Type boundary_node_type;
159 }} // namespace cds::intrusive
161 #endif // #ifndef CDSLIB_INTRUSIVE_OPTIONS_H