Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 1 | // Boost string_algo library sequence_traits.hpp header file ---------------------------// |
| 2 | |
| 3 | // Copyright Pavol Droba 2002-2003. |
| 4 | // |
| 5 | // Distributed under the Boost Software License, Version 1.0. |
| 6 | // (See accompanying file LICENSE_1_0.txt or copy at |
| 7 | // http://www.boost.org/LICENSE_1_0.txt) |
| 8 | |
| 9 | // See http://www.boost.org/ for updates, documentation, and revision history. |
| 10 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 11 | #ifndef NDNBOOST_STRING_SEQUENCE_TRAITS_HPP |
| 12 | #define NDNBOOST_STRING_SEQUENCE_TRAITS_HPP |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 13 | |
| 14 | #include <ndnboost/config.hpp> |
| 15 | #include <ndnboost/mpl/bool.hpp> |
| 16 | #include <ndnboost/algorithm/string/yes_no_type.hpp> |
| 17 | |
| 18 | /*! \file |
| 19 | Traits defined in this header are used by various algorithms to achieve |
| 20 | better performance for specific containers. |
| 21 | Traits provide fail-safe defaults. If a container supports some of these |
| 22 | features, it is possible to specialize the specific trait for this container. |
| 23 | For lacking compilers, it is possible of define an override for a specific tester |
| 24 | function. |
| 25 | |
| 26 | Due to a language restriction, it is not currently possible to define specializations for |
| 27 | stl containers without including the corresponding header. To decrease the overhead |
| 28 | needed by this inclusion, user can selectively include a specialization |
Jeff Thompson | 9939dcd | 2013-10-15 15:12:24 -0700 | [diff] [blame] | 29 | header for a specific container. They are located in ndnboost/algorithm/string/stl |
| 30 | directory. Alternatively she can include ndnboost/algorithm/string/std_collection_traits.hpp |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 31 | header which contains specializations for all stl containers. |
| 32 | */ |
| 33 | |
| 34 | namespace ndnboost { |
| 35 | namespace algorithm { |
| 36 | |
| 37 | // sequence traits -----------------------------------------------// |
| 38 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 39 | #ifdef NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 40 | |
| 41 | //! Native replace tester |
| 42 | /*! |
| 43 | Declare an override of this tester function with return |
| 44 | type ndnboost::string_algo::yes_type for a sequence with this property. |
| 45 | |
| 46 | \return yes_type if the container has basic_string like native replace |
| 47 | method. |
| 48 | */ |
| 49 | no_type has_native_replace_tester(...); |
| 50 | |
| 51 | //! Stable iterators tester |
| 52 | /*! |
| 53 | Declare an override of this tester function with return |
| 54 | type ndnboost::string_algo::yes_type for a sequence with this property. |
| 55 | |
| 56 | \return yes_type if the sequence's insert/replace/erase methods do not invalidate |
| 57 | existing iterators. |
| 58 | */ |
| 59 | no_type has_stable_iterators_tester(...); |
| 60 | |
| 61 | //! const time insert tester |
| 62 | /*! |
| 63 | Declare an override of this tester function with return |
| 64 | type ndnboost::string_algo::yes_type for a sequence with this property. |
| 65 | |
| 66 | \return yes_type if the sequence's insert method is working in constant time |
| 67 | */ |
| 68 | no_type has_const_time_insert_tester(...); |
| 69 | |
| 70 | //! const time erase tester |
| 71 | /*! |
| 72 | Declare an override of this tester function with return |
| 73 | type ndnboost::string_algo::yes_type for a sequence with this property. |
| 74 | |
| 75 | \return yes_type if the sequence's erase method is working in constant time |
| 76 | */ |
| 77 | no_type has_const_time_erase_tester(...); |
| 78 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 79 | #endif //NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 80 | |
| 81 | //! Native replace trait |
| 82 | /*! |
| 83 | This trait specifies that the sequence has \c std::string like replace method |
| 84 | */ |
| 85 | template< typename T > |
| 86 | class has_native_replace |
| 87 | { |
| 88 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 89 | #ifdef NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 90 | private: |
| 91 | static T* t; |
| 92 | public: |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 93 | NDNBOOST_STATIC_CONSTANT(bool, value=( |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 94 | sizeof(has_native_replace_tester(t))==sizeof(yes_type) ) ); |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 95 | #else // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 96 | public: |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 97 | # if NDNBOOST_WORKAROUND( __IBMCPP__, <= 600 ) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 98 | enum { value = false }; |
| 99 | # else |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 100 | NDNBOOST_STATIC_CONSTANT(bool, value=false); |
| 101 | # endif // NDNBOOST_WORKAROUND( __IBMCPP__, <= 600 ) |
| 102 | #endif // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 103 | |
| 104 | |
| 105 | typedef mpl::bool_<has_native_replace<T>::value> type; |
| 106 | }; |
| 107 | |
| 108 | |
| 109 | //! Stable iterators trait |
| 110 | /*! |
| 111 | This trait specifies that the sequence has stable iterators. It means |
| 112 | that operations like insert/erase/replace do not invalidate iterators. |
| 113 | */ |
| 114 | template< typename T > |
| 115 | class has_stable_iterators |
| 116 | { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 117 | #ifdef NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 118 | private: |
| 119 | static T* t; |
| 120 | public: |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 121 | NDNBOOST_STATIC_CONSTANT(bool, value=( |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 122 | sizeof(has_stable_iterators_tester(t))==sizeof(yes_type) ) ); |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 123 | #else // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 124 | public: |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 125 | # if NDNBOOST_WORKAROUND( __IBMCPP__, <= 600 ) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 126 | enum { value = false }; |
| 127 | # else |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 128 | NDNBOOST_STATIC_CONSTANT(bool, value=false); |
| 129 | # endif // NDNBOOST_WORKAROUND( __IBMCPP__, <= 600 ) |
| 130 | #endif // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 131 | |
| 132 | typedef mpl::bool_<has_stable_iterators<T>::value> type; |
| 133 | }; |
| 134 | |
| 135 | |
| 136 | //! Const time insert trait |
| 137 | /*! |
| 138 | This trait specifies that the sequence's insert method has |
| 139 | constant time complexity. |
| 140 | */ |
| 141 | template< typename T > |
| 142 | class has_const_time_insert |
| 143 | { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 144 | #ifdef NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 145 | private: |
| 146 | static T* t; |
| 147 | public: |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 148 | NDNBOOST_STATIC_CONSTANT(bool, value=( |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 149 | sizeof(has_const_time_insert_tester(t))==sizeof(yes_type) ) ); |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 150 | #else // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 151 | public: |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 152 | # if NDNBOOST_WORKAROUND( __IBMCPP__, <= 600 ) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 153 | enum { value = false }; |
| 154 | # else |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 155 | NDNBOOST_STATIC_CONSTANT(bool, value=false); |
| 156 | # endif // NDNBOOST_WORKAROUND( __IBMCPP__, <= 600 ) |
| 157 | #endif // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 158 | |
| 159 | typedef mpl::bool_<has_const_time_insert<T>::value> type; |
| 160 | }; |
| 161 | |
| 162 | |
| 163 | //! Const time erase trait |
| 164 | /*! |
| 165 | This trait specifies that the sequence's erase method has |
| 166 | constant time complexity. |
| 167 | */ |
| 168 | template< typename T > |
| 169 | class has_const_time_erase |
| 170 | { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 171 | #ifdef NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 172 | private: |
| 173 | static T* t; |
| 174 | public: |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 175 | NDNBOOST_STATIC_CONSTANT(bool, value=( |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 176 | sizeof(has_const_time_erase_tester(t))==sizeof(yes_type) ) ); |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 177 | #else // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 178 | public: |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 179 | # if NDNBOOST_WORKAROUND( __IBMCPP__, <= 600 ) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 180 | enum { value = false }; |
| 181 | # else |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 182 | NDNBOOST_STATIC_CONSTANT(bool, value=false); |
| 183 | # endif // NDNBOOST_WORKAROUND( __IBMCPP__, <= 600 ) |
| 184 | #endif // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 185 | |
| 186 | typedef mpl::bool_<has_const_time_erase<T>::value> type; |
| 187 | }; |
| 188 | |
| 189 | } // namespace algorithm |
| 190 | } // namespace ndnboost |
| 191 | |
| 192 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 193 | #endif // NDNBOOST_STRING_SEQUENCE_TRAITS_HPP |