The Sparta Modeling Framework
Loading...
Searching...
No Matches
Traits.hpp
Go to the documentation of this file.
1// <Event.h> -*- C++ -*-
2
3
11#pragma once
12
13#include <type_traits>
14
15template <typename T>
17{
18 typedef char yep;
19 typedef long nope;
20
21 // Determine if the data type has a get() method
22 template <typename C> static yep hasGetMethod (decltype(&C::get) );
23 template <typename C> static nope hasGetMethod (...);
24
25 // Determine if the data type should use -> or . accessors
26 template <typename C> static yep hasPointerOperator( decltype(&C::operator->) ) ;
27 template <typename C> static nope hasPointerOperator(...);
28
29 // Determine if the data type has an iterator type defined
30 template <typename C> static typename C::iterator hasIterator(int);
31 template <typename> static void hasIterator(...);
32
33public:
34
36 enum { is_smartptr = sizeof(hasGetMethod<T>(0)) == sizeof(yep) };
37 enum { stl_smartptr = !std::is_void<decltype(hasPointerOperator<T>(0))>::value };
38 enum { stl_iterable = !std::is_void<decltype(hasIterator<T>(0))>::value };
39
40};
41
51template<class value_type>
52inline static typename std::enable_if<sparta_traits<value_type>::is_smartptr == false,
53 const value_type*>::type
54getAsPointer(const value_type & obj)
55{
56 return &obj;
57}
58
69template<class value_type>
70inline static typename std::enable_if<sparta_traits<value_type>::is_smartptr == true,
71 const typename value_type::element_type*>::type
72getAsPointer(const value_type & obj)
73{
74 return obj.get();
75}
76
77// template<class value_type>
78// inline static typename std::enable_if<std::is_pointer<value_type>::value == true,
79// const value_type>::type
80// getAsPointer(const value_type & obj)
81// {
82// return obj;
83// }
84
static std::enable_if< sparta_traits< value_type >::is_smartptr==false, constvalue_type * >::type getAsPointer(const value_type &obj)
getAsPointer Intended to convert what object is given to a pointer type
Definition Traits.hpp:54