DGtal  1.3.beta
ContainerTraits.h
1 
17 #pragma once
18 
31 #if defined(ContainerTraits_RECURSES)
32 #error Recursive header files inclusion detected in ContainerTraits.h
33 #else // defined(ContainerTraits_RECURSES)
34 
35 #define ContainerTraits_RECURSES
36 
37 #if !defined ContainerTraits_h
38 
39 #define ContainerTraits_h
40 
42 // Inclusions
43 #include <iostream>
44 #include <vector>
45 #include <list>
46 #include <deque>
47 #include <set>
48 #include <map>
49 #include <boost/type_traits.hpp>
50 #include <boost/unordered_set.hpp>
51 #include <boost/unordered_map.hpp>
52 #include <unordered_set>
53 #include <unordered_map>
54 #include <forward_list>
55 #include <array>
56 
57 #include "DGtal/base/Common.h"
59 
60 namespace DGtal
61 {
62 
63  // Tag classes for containers
65  struct ContainerCategory {};
82 
84  template <typename TContainer>
86  {
88  };
89 
91  template < class T, class Alloc >
92  struct ContainerTraits< std::vector<T, Alloc> >
93  {
95  };
96 
98  template < class T, class Alloc >
99  struct ContainerTraits< std::list<T, Alloc> >
100  {
102  };
103 
105  template < class T, class Alloc >
106  struct ContainerTraits< std::deque<T, Alloc> >
107  {
109  };
110 
112  template < class T, class Alloc >
113  struct ContainerTraits< std::forward_list<T, Alloc> >
114  {
116  };
117 
119  template < class T, size_t N >
120  struct ContainerTraits< std::array<T, N> >
121  {
123  };
124 
126  template < class T, class Compare, class Alloc >
127  struct ContainerTraits< std::set<T, Compare, Alloc> >
128  {
130  };
131 
133  template < class Key, class T, class Compare, class Alloc >
134  struct ContainerTraits< std::map<Key, T, Compare, Alloc> >
135  {
137  };
138 
140  template < class T, class Compare, class Alloc >
141  struct ContainerTraits< std::multiset<T, Compare, Alloc> >
142  {
144  };
145 
147  template < class Key, class T, class Compare, class Alloc >
148  struct ContainerTraits< std::multimap<Key, T, Compare, Alloc> >
149  {
151  };
152 
154  template < typename Value, typename Hash, typename Pred, typename Alloc >
155  struct ContainerTraits< boost::unordered_set<Value, Hash, Pred, Alloc> >
156  {
158  };
159 
161  template < typename Value, typename Hash, typename Pred, typename Alloc >
162  struct ContainerTraits< boost::unordered_multiset<Value, Hash, Pred, Alloc> >
163  {
165  };
166 
168  template < typename Value, typename T, typename Hash, typename Pred, typename Alloc >
169  struct ContainerTraits< boost::unordered_map<Value, T, Hash, Pred, Alloc> >
170  {
172  };
173 
175  template < typename Value, typename T, typename Hash, typename Pred, typename Alloc >
176  struct ContainerTraits< boost::unordered_multimap<Value, T, Hash, Pred, Alloc> >
177  {
179  };
180 
182  template < class Key, class Hash, class Pred, class Alloc >
183  struct ContainerTraits< std::unordered_set<Key, Hash, Pred, Alloc> >
184  {
186  };
187 
189  template < class Key, class Hash, class Pred, class Alloc >
190  struct ContainerTraits< std::unordered_multiset<Key, Hash, Pred, Alloc> >
191  {
193  };
194 
196  template < class Key, class T, class Hash, class Pred, class Alloc >
197  struct ContainerTraits< std::unordered_map<Key, T, Hash, Pred, Alloc> >
198  {
200  };
201 
203  template < class Key, class T, class Hash, class Pred, class Alloc >
204  struct ContainerTraits< std::unordered_multimap<Key, T, Hash, Pred, Alloc> >
205  {
207  };
208 
209  namespace detail
210  {
211 
213 
222  template <typename T>
224  {
225  typedef char yes[1];
226  typedef char no[2];
227 
228  template <typename C>
229  static yes& test(typename C::Category*);
230 
231  template <typename C>
232  static no& test(...);
233 
234  BOOST_STATIC_CONSTANT(bool, value = sizeof(test<T>(0)) == sizeof(yes));
235  };
236 
241  template <typename TCategory>
243  BOOST_STATIC_CONSTANT(bool, value = ( boost::is_base_of<ContainerCategory,TCategory>::value ) );
244  };
245 
249  template <typename TCategory>
251  BOOST_STATIC_CONSTANT(bool, value = ( boost::is_base_of<SequenceCategory,TCategory>::value ) );
252  };
253 
257  template <typename TCategory>
259  BOOST_STATIC_CONSTANT(bool, value = ( boost::is_base_of<AssociativeCategory,TCategory>::value ) );
260  };
261 
265  template <typename TCategory>
267  BOOST_STATIC_CONSTANT(bool, value = ( boost::is_base_of<OrderedAssociativeCategory,TCategory>::value ) );
268  };
269 
273  template <typename TCategory>
275  BOOST_STATIC_CONSTANT(bool, value = ( boost::is_base_of<UnorderedAssociativeCategory,TCategory>::value ) );
276  };
277 
281  template <typename TCategory>
283  BOOST_STATIC_CONSTANT(bool, value = ( boost::is_base_of<SimpleAssociativeCategory,TCategory>::value ) );
284  };
285 
289  template <typename TCategory>
291  BOOST_STATIC_CONSTANT(bool, value = ( boost::is_base_of<PairAssociativeCategory,TCategory>::value ) );
292  };
293 
297  template <typename TCategory>
299  BOOST_STATIC_CONSTANT(bool, value = ( boost::is_base_of<UniqueAssociativeCategory,TCategory>::value ) );
300  };
301 
305  template <typename TCategory>
307  BOOST_STATIC_CONSTANT(bool, value = ( boost::is_base_of<MultipleAssociativeCategory,TCategory>::value ) );
308  };
309 
310  }
311 
316  template <typename T>
317  struct IsContainer {
318  BOOST_STATIC_CONSTANT( bool,
321  };
322 
326  template <typename T>
328  BOOST_STATIC_CONSTANT( bool,
331  };
332 
336  template <typename T>
338  BOOST_STATIC_CONSTANT( bool,
341  };
342 
346  template <typename T>
348  BOOST_STATIC_CONSTANT( bool,
351  };
352 
356  template <typename T>
358  BOOST_STATIC_CONSTANT( bool,
361  };
362 
366  template <typename T>
368  BOOST_STATIC_CONSTANT( bool,
371  };
372 
376  template <typename T>
378  BOOST_STATIC_CONSTANT( bool,
381  };
382 
386  template <typename T>
388  BOOST_STATIC_CONSTANT( bool,
391  };
392 
396  template <typename T>
398  BOOST_STATIC_CONSTANT( bool,
401  };
402 
403 
404 } // namespace DGtal
405 
406 
407 
408 // //
410 
411 #endif // !defined ContainerTraits_h
412 
413 #undef ContainerTraits_RECURSES
414 #endif // else defined(ContainerTraits_RECURSES)
DGtal::SequenceCategory
Definition: ContainerTraits.h:66
DGtal::detail::IsOrderedAssociativeContainerFromCategory
Definition: ContainerTraits.h:266
DGtal::detail::IsSimpleAssociativeContainerFromCategory
Definition: ContainerTraits.h:282
DGtal::ContainerTraits< std::unordered_set< Key, Hash, Pred, Alloc > >::Category
UnorderedSetAssociativeCategory Category
Definition: ContainerTraits.h:185
DGtal::IsUnorderedAssociativeContainer
Definition: ContainerTraits.h:357
DGtal::UnorderedMapAssociativeCategory
Definition: ContainerTraits.h:80
DGtal::detail::IsSequenceContainerFromCategory
Definition: ContainerTraits.h:250
DGtal::IsSequenceContainer
Definition: ContainerTraits.h:327
DGtal::PairAssociativeCategory
Definition: ContainerTraits.h:69
DGtal::detail::IsContainerFromCategory::BOOST_STATIC_CONSTANT
BOOST_STATIC_CONSTANT(bool, value=(boost::is_base_of< ContainerCategory, TCategory >::value))
DGtal::IsPairAssociativeContainer::BOOST_STATIC_CONSTANT
BOOST_STATIC_CONSTANT(bool, value=(detail::HasNestedTypeCategory< ContainerTraits< T > >::value &&detail::IsPairAssociativeContainerFromCategory< typename ContainerTraits< T >::Category >::value))
DGtal::IsOrderedAssociativeContainer::BOOST_STATIC_CONSTANT
BOOST_STATIC_CONSTANT(bool, value=(detail::HasNestedTypeCategory< ContainerTraits< T > >::value &&detail::IsOrderedAssociativeContainerFromCategory< typename ContainerTraits< T >::Category >::value))
DGtal::IsUniqueAssociativeContainer::BOOST_STATIC_CONSTANT
BOOST_STATIC_CONSTANT(bool, value=(detail::HasNestedTypeCategory< ContainerTraits< T > >::value &&detail::IsUniqueAssociativeContainerFromCategory< typename ContainerTraits< T >::Category >::value))
DGtal::ContainerTraits< boost::unordered_set< Value, Hash, Pred, Alloc > >::Category
UnorderedSetAssociativeCategory Category
Definition: ContainerTraits.h:157
DGtal::IsSimpleAssociativeContainer
Definition: ContainerTraits.h:367
DGtal::ContainerTraits::Category
NotContainerCategory Category
Definition: ContainerTraits.h:87
DGtal::UniqueAssociativeCategory
Definition: ContainerTraits.h:70
DGtal::ContainerTraits< std::unordered_map< Key, T, Hash, Pred, Alloc > >::Category
UnorderedMapAssociativeCategory Category
Definition: ContainerTraits.h:199
DGtal::ContainerTraits< std::map< Key, T, Compare, Alloc > >::Category
MapAssociativeCategory Category
Definition: ContainerTraits.h:136
DGtal::detail::IsPairAssociativeContainerFromCategory::BOOST_STATIC_CONSTANT
BOOST_STATIC_CONSTANT(bool, value=(boost::is_base_of< PairAssociativeCategory, TCategory >::value))
DGtal::IsMultipleAssociativeContainer
Definition: ContainerTraits.h:397
DGtal::detail::HasNestedTypeCategory::test
static yes & test(typename C::Category *)
DGtal::detail::HasNestedTypeCategory::BOOST_STATIC_CONSTANT
BOOST_STATIC_CONSTANT(bool, value=sizeof(test< T >(0))==sizeof(yes))
boost
Definition: Boost.dox:28
DGtal::detail::IsContainerFromCategory
Definition: ContainerTraits.h:242
DGtal::ContainerTraits< std::unordered_multimap< Key, T, Hash, Pred, Alloc > >::Category
UnorderedMultimapAssociativeCategory Category
Definition: ContainerTraits.h:206
DGtal::detail::HasNestedTypeCategory
Aim: Checks whether type T has a nested type called 'Category' or not. NB: from en....
Definition: ContainerTraits.h:223
DGtal::IsOrderedAssociativeContainer
Definition: ContainerTraits.h:347
DGtal::IsContainer::BOOST_STATIC_CONSTANT
BOOST_STATIC_CONSTANT(bool, value=(detail::HasNestedTypeCategory< ContainerTraits< T > >::value &&detail::IsContainerFromCategory< typename ContainerTraits< T >::Category >::value))
DGtal::NotContainerCategory
Definition: ContainerTraits.h:64
DGtal::detail::IsUniqueAssociativeContainerFromCategory
Definition: ContainerTraits.h:298
DGtal::IsUnorderedAssociativeContainer::BOOST_STATIC_CONSTANT
BOOST_STATIC_CONSTANT(bool, value=(detail::HasNestedTypeCategory< ContainerTraits< T > >::value &&detail::IsUnorderedAssociativeContainerFromCategory< typename ContainerTraits< T >::Category >::value))
DGtal::ContainerTraits< boost::unordered_multiset< Value, Hash, Pred, Alloc > >::Category
UnorderedMultisetAssociativeCategory Category
Definition: ContainerTraits.h:164
DGtal::detail::HasNestedTypeCategory::no
char no[2]
Definition: ContainerTraits.h:226
DGtal::detail::IsUnorderedAssociativeContainerFromCategory::BOOST_STATIC_CONSTANT
BOOST_STATIC_CONSTANT(bool, value=(boost::is_base_of< UnorderedAssociativeCategory, TCategory >::value))
DGtal::IsAssociativeContainer::BOOST_STATIC_CONSTANT
BOOST_STATIC_CONSTANT(bool, value=(detail::HasNestedTypeCategory< ContainerTraits< T > >::value &&detail::IsAssociativeContainerFromCategory< typename ContainerTraits< T >::Category >::value))
DGtal::detail::IsAssociativeContainerFromCategory::BOOST_STATIC_CONSTANT
BOOST_STATIC_CONSTANT(bool, value=(boost::is_base_of< AssociativeCategory, TCategory >::value))
DGtal::detail::IsSequenceContainerFromCategory::BOOST_STATIC_CONSTANT
BOOST_STATIC_CONSTANT(bool, value=(boost::is_base_of< SequenceCategory, TCategory >::value))
DGtal::IsMultipleAssociativeContainer::BOOST_STATIC_CONSTANT
BOOST_STATIC_CONSTANT(bool, value=(detail::HasNestedTypeCategory< ContainerTraits< T > >::value &&detail::IsMultipleAssociativeContainerFromCategory< typename ContainerTraits< T >::Category >::value))
DGtal::detail::IsMultipleAssociativeContainerFromCategory
Definition: ContainerTraits.h:306
DGtal::MapAssociativeCategory
Definition: ContainerTraits.h:76
DGtal::MultipleAssociativeCategory
Definition: ContainerTraits.h:71
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::detail::IsAssociativeContainerFromCategory
Definition: ContainerTraits.h:258
DGtal::ContainerTraits< std::list< T, Alloc > >::Category
SequenceCategory Category
Definition: ContainerTraits.h:101
DGtal::detail::HasNestedTypeCategory::yes
char yes[1]
Definition: ContainerTraits.h:225
DGtal::UnorderedMultisetAssociativeCategory
Definition: ContainerTraits.h:79
DGtal::ContainerTraits
Defines default container traits for arbitrary types.
Definition: ContainerTraits.h:85
DGtal::ContainerCategory
Definition: ContainerTraits.h:65
DGtal::MultimapAssociativeCategory
Definition: ContainerTraits.h:77
DGtal::detail::IsSimpleAssociativeContainerFromCategory::BOOST_STATIC_CONSTANT
BOOST_STATIC_CONSTANT(bool, value=(boost::is_base_of< SimpleAssociativeCategory, TCategory >::value))
DGtal::IsContainer
Definition: ContainerTraits.h:317
DGtal::detail::IsUniqueAssociativeContainerFromCategory::BOOST_STATIC_CONSTANT
BOOST_STATIC_CONSTANT(bool, value=(boost::is_base_of< UniqueAssociativeCategory, TCategory >::value))
DGtal::ContainerTraits< std::array< T, N > >::Category
SequenceCategory Category
Definition: ContainerTraits.h:122
DGtal::ContainerTraits< std::unordered_multiset< Key, Hash, Pred, Alloc > >::Category
UnorderedMultisetAssociativeCategory Category
Definition: ContainerTraits.h:192
DGtal::detail::IsPairAssociativeContainerFromCategory
Definition: ContainerTraits.h:290
DGtal::MultisetAssociativeCategory
Definition: ContainerTraits.h:75
DGtal::SetAssociativeCategory
Definition: ContainerTraits.h:74
DGtal::detail::IsOrderedAssociativeContainerFromCategory::BOOST_STATIC_CONSTANT
BOOST_STATIC_CONSTANT(bool, value=(boost::is_base_of< OrderedAssociativeCategory, TCategory >::value))
DGtal::IsSimpleAssociativeContainer::BOOST_STATIC_CONSTANT
BOOST_STATIC_CONSTANT(bool, value=(detail::HasNestedTypeCategory< ContainerTraits< T > >::value &&detail::IsSimpleAssociativeContainerFromCategory< typename ContainerTraits< T >::Category >::value))
DGtal::ContainerTraits< std::vector< T, Alloc > >::Category
SequenceCategory Category
Definition: ContainerTraits.h:94
DGtal::detail::IsMultipleAssociativeContainerFromCategory::BOOST_STATIC_CONSTANT
BOOST_STATIC_CONSTANT(bool, value=(boost::is_base_of< MultipleAssociativeCategory, TCategory >::value))
DGtal::ContainerTraits< std::set< T, Compare, Alloc > >::Category
SetAssociativeCategory Category
Definition: ContainerTraits.h:129
DGtal::ContainerTraits< std::multiset< T, Compare, Alloc > >::Category
MultisetAssociativeCategory Category
Definition: ContainerTraits.h:143
DGtal::ContainerTraits< boost::unordered_multimap< Value, T, Hash, Pred, Alloc > >::Category
UnorderedMultimapAssociativeCategory Category
Definition: ContainerTraits.h:178
DGtal::IsAssociativeContainer
Definition: ContainerTraits.h:337
DGtal::ContainerTraits< boost::unordered_map< Value, T, Hash, Pred, Alloc > >::Category
UnorderedMapAssociativeCategory Category
Definition: ContainerTraits.h:171
DGtal::UnorderedAssociativeCategory
Definition: ContainerTraits.h:73
DGtal::AssociativeCategory
Definition: ContainerTraits.h:67
DGtal::detail::IsUnorderedAssociativeContainerFromCategory
Definition: ContainerTraits.h:274
DGtal::ContainerTraits< std::forward_list< T, Alloc > >::Category
SequenceCategory Category
Definition: ContainerTraits.h:115
DGtal::ContainerTraits< std::multimap< Key, T, Compare, Alloc > >::Category
MultimapAssociativeCategory Category
Definition: ContainerTraits.h:150
DGtal::OrderedAssociativeCategory
Definition: ContainerTraits.h:72
DGtal::IsUniqueAssociativeContainer
Definition: ContainerTraits.h:387
DGtal::UnorderedSetAssociativeCategory
Definition: ContainerTraits.h:78
DGtal::IsPairAssociativeContainer
Definition: ContainerTraits.h:377
DGtal::IsSequenceContainer::BOOST_STATIC_CONSTANT
BOOST_STATIC_CONSTANT(bool, value=(detail::HasNestedTypeCategory< ContainerTraits< T > >::value &&detail::IsSequenceContainerFromCategory< typename ContainerTraits< T >::Category >::value))
DGtal::ContainerTraits< std::deque< T, Alloc > >::Category
SequenceCategory Category
Definition: ContainerTraits.h:108
DGtal::UnorderedMultimapAssociativeCategory
Definition: ContainerTraits.h:81
DGtal::SimpleAssociativeCategory
Definition: ContainerTraits.h:68