DGtal  0.9.2
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)
BOOST_STATIC_CONSTANT(bool, value=(detail::HasNestedTypeCategory< ContainerTraits< T > >::value &&detail::IsUniqueAssociativeContainerFromCategory< typename ContainerTraits< T >::Category >::value))
BOOST_STATIC_CONSTANT(bool, value=(detail::HasNestedTypeCategory< ContainerTraits< T > >::value &&detail::IsPairAssociativeContainerFromCategory< typename ContainerTraits< T >::Category >::value))
Definition: Boost.dox:28
BOOST_STATIC_CONSTANT(bool, value=(boost::is_base_of< SimpleAssociativeCategory, TCategory >::value))
BOOST_STATIC_CONSTANT(bool, value=(boost::is_base_of< PairAssociativeCategory, TCategory >::value))
BOOST_STATIC_CONSTANT(bool, value=(detail::HasNestedTypeCategory< ContainerTraits< T > >::value &&detail::IsOrderedAssociativeContainerFromCategory< typename ContainerTraits< T >::Category >::value))
BOOST_STATIC_CONSTANT(bool, value=(detail::HasNestedTypeCategory< ContainerTraits< T > >::value &&detail::IsMultipleAssociativeContainerFromCategory< typename ContainerTraits< T >::Category >::value))
BOOST_STATIC_CONSTANT(bool, value=(detail::HasNestedTypeCategory< ContainerTraits< T > >::value &&detail::IsSequenceContainerFromCategory< typename ContainerTraits< T >::Category >::value))
BOOST_STATIC_CONSTANT(bool, value=(boost::is_base_of< SequenceCategory, TCategory >::value))
STL namespace.
BOOST_STATIC_CONSTANT(bool, value=(boost::is_base_of< ContainerCategory, TCategory >::value))
BOOST_STATIC_CONSTANT(bool, value=sizeof(test< T >(0))==sizeof(yes))
static yes & test(typename C::Category *)
BOOST_STATIC_CONSTANT(bool, value=(boost::is_base_of< UniqueAssociativeCategory, TCategory >::value))
BOOST_STATIC_CONSTANT(bool, value=(boost::is_base_of< MultipleAssociativeCategory, TCategory >::value))
NotContainerCategory Category
BOOST_STATIC_CONSTANT(bool, value=(detail::HasNestedTypeCategory< ContainerTraits< T > >::value &&detail::IsContainerFromCategory< typename ContainerTraits< T >::Category >::value))
BOOST_STATIC_CONSTANT(bool, value=(boost::is_base_of< AssociativeCategory, TCategory >::value))
BOOST_STATIC_CONSTANT(bool, value=(detail::HasNestedTypeCategory< ContainerTraits< T > >::value &&detail::IsAssociativeContainerFromCategory< typename ContainerTraits< T >::Category >::value))
BOOST_STATIC_CONSTANT(bool, value=(boost::is_base_of< UnorderedAssociativeCategory, TCategory >::value))
BOOST_STATIC_CONSTANT(bool, value=(detail::HasNestedTypeCategory< ContainerTraits< T > >::value &&detail::IsSimpleAssociativeContainerFromCategory< typename ContainerTraits< T >::Category >::value))
BOOST_STATIC_CONSTANT(bool, value=(detail::HasNestedTypeCategory< ContainerTraits< T > >::value &&detail::IsUnorderedAssociativeContainerFromCategory< typename ContainerTraits< T >::Category >::value))
DGtal is the top-level namespace which contains all DGtal functions and types.
BOOST_STATIC_CONSTANT(bool, value=(boost::is_base_of< OrderedAssociativeCategory, TCategory >::value))
Aim: Checks whether type T has a nested type called 'Category' or not. NB: from en.wikipedia.org/wiki/Substitution_failure_is_not_an_error NB: to avoid various compiler issues, we use BOOST_STATIC_CONSTANT according to http://www.boost.org/development/int_const_guidelines.html.
Defines default container traits for arbitrary types.