uLib-0.2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Types.h
Go to the documentation of this file.
1 /*//////////////////////////////////////////////////////////////////////////////
2 // CMT Cosmic Muon Tomography project //////////////////////////////////////////
4 
5  Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
6  All rights reserved
7 
8  Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
9 
10  ------------------------------------------------------------------
11  This library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU Lesser General Public
13  License as published by the Free Software Foundation; either
14  version 3.0 of the License, or (at your option) any later version.
15 
16  This library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  Lesser General Public License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public
22  License along with this library.
23 
25 
26 
27 
28 #ifndef U_CORE_TYPES_H
29 #define U_CORE_TYPES_H
30 
31 #include <iostream>
32 #include <typeinfo>
33 
34 #include <boost/preprocessor.hpp>
35 
36 //#include <ltk/ltktypes.h>
37 
38 #include "Core/Macros.h"
39 #include "Core/Mpl.h"
40 
41 
42 
43 
44 
45 
46 
47 namespace uLib {
48 
49 
51 
52 namespace detail {
53 
54 struct TypeIntrospection {
55 
56  // BOOST IMPL //
57  BOOST_MPL_HAS_XXX_TRAIT_DEF(type_info)
58 
59  // SFINAE IMPL //
60  /*
61  template <typename T>
62  struct has_type_info {
63  typedef char yes[1];
64  typedef char no[2];
65  template <typename U> static yes& test(typename U::type_info::BaseList*);
66  template <typename > static no& test(...);
67  // struct apply {
68  static const bool value = sizeof(test<T>(0)) == sizeof(yes);
69  typedef boost::mpl::bool_<value> type;
70  // };
71  };
72  */
73 
75  template <class T>
76  struct IsIntrospectable : has_type_info<T> {};
77 
78  template <typename T> struct access {
79  typedef typename T::type_info type_info;
80  };
81 
82  template <typename T>
84 
85  template <class T1, bool cond>
86  struct lambda_CFList_f {
87  typedef mpl::vector<T1> type;
88  };
89 
90  template <class T1>
91  struct lambda_CFList_f<T1,true> {
92  // typedef typename T1::type_info::CFList type;
94  };
95 
96  template <class T1>
97  struct lambda_CFList : lambda_CFList_f<T1, has_type_info<T1>::value> {};
98 
100  typedef typename mpl::transform_view < typename access<T>::type_info::BaseList
103 
105  typedef typename mpl::fold< CFListSeq
106  , mpl::vector<>
107  , mpl::copy< mpl::_1
108  , mpl::back_inserter<mpl::_2>
109  >
111 
113  typedef typename mpl::copy< Childs
114  , mpl::back_inserter< mpl::vector<T> >
116  };
117 
118 
122  template <typename T>
123  struct child_first : mpl::if_< has_type_info<T>
124  , child_first_impl<T>
125  , mpl::vector<>
126  >::type {};
127 
128 
129 };
130 
131 
132 
136 // TYPE ADAPTERS // FINIRE !!!
137 
138 //#define _REPETITION_V(vz,vn,vdata)
139 
140 
141 //template < class TypeList >
142 //class TypeAdapterInputInterface {
143 // virtual ~TypeAdapterInputInterface() {}
144 //public:
145 
146 
147 
148 // virtual void operator()(int val) {}
149 // virtual void operator()(std::string val) {}
150 //};
151 
152 
153 
154 
155 
156 
157 
158 } // detail ////////////////////////////////////////////////////////////////////
159 
160 
161 #define CONSTEXPR BOOST_CONSTEXPR
162 
163 
164 //typedef ltk::Real_t Real_t;
165 #ifndef LTK_DOUBLE_PRECISION
166 typedef float Real_t;
167 #else
168 typedef double Real_t;
169 #endif
170 //typedef ltk::Id_t Id_t;
171 typedef id_t Id_t;
173 //typedef ltk::Pointer_t Pointer_t;
174 typedef void * Pointer_t;
175 typedef bool Bool_t; //Boolean (0=false, 1=true) (bool)
176 
177 
178 
179 //--- bit manipulation ---------------------------------------------------------
180 #ifndef BIT
181 #define BIT(n) (1ULL << (n))
182 #endif
183 
184 #ifndef SETBIT
185 #define SETBIT(n,i) ((n) |= BIT(i))
186 #endif
187 
188 #ifndef CLRBIT
189 #define CLRBIT(n,i) ((n) &= ~BIT(i))
190 #endif
191 
192 #ifndef TESTBIT
193 #define TESTBIT(n,i) ((Bool_t)(((n) & BIT(i)) != 0))
194 #endif
195 
196 
200 // TYPE INTROSPECTION FOR OBJECTS //
201 
202 
203 
204 #define uLibTypeMacro(thisClass,...) \
205  \
206  /* Friendship detail for accessing introspection */ \
207  template <typename> friend class uLib::detail::TypeIntrospection::access; \
208  \
209  /* type info structure*/ public: \
210  /* in GCC 4.8 must be public or dynamic_cast wont work */ \
211  struct type_info { \
212  /*WARNING: -std=c++0x required for this! */ \
213  constexpr static const char *name = BOOST_PP_STRINGIZE(thisClass); \
214  typedef BOOST_PP_VARIADIC_ELEM(0,__VA_ARGS__) BaseClass; \
215  typedef thisClass ThisClass; \
216  typedef uLib::mpl::vector<__VA_ARGS__,thisClass> TypeList; \
217  typedef uLib::mpl::vector<__VA_ARGS__> BaseList; \
218  typedef uLib::detail::TypeIntrospection::child_first<ThisClass>::type CFList; \
219  }; \
220  \
221  public: \
222  typedef type_info::BaseClass BaseClass; \
223  virtual const char *type_name() const { return type_info::name; } \
224  /* Object Props fwd declaration*/ \
225  struct ObjectProps; \
226 
227 
228 
233  template <typename T>
235 
236 };
237 
238 
239 
240 
241 
242 
243 // SISTEMARE //
244 struct PrintTypeId {
245  template <class T>
246  void operator()(T) const
247  { std::cout << typeid(T).name() << std::endl; }
248 
249  template <typename SeqT>
250  static void PrintMplSeq(SeqT *p = NULL) { boost::mpl::for_each<SeqT>(PrintTypeId()); }
251 
252  template <typename Class>
253  static void PrintType(Class *p = NULL) { std::cout << typeid(Class).name() << std::endl; }
254 };
255 
256 
257 
258 
259 
260 
261 
262 } // uLib
263 
264 #endif // U_CORE_TYPES_H
265 
266 
267 
268 
269 
270 
271 
272 
273 
274 
275 
276 
277 
278 
279 
280 
281 
282 
283 
284 
285 
access< T1 >::type_info::CFList type
Definition: Types.h:93
float Real_t
Definition: Types.h:166
static void PrintType(Class *p=NULL)
Definition: Types.h:253
static void PrintMplSeq(SeqT *p=NULL)
Definition: Types.h:250
mpl::copy< Childs, mpl::back_inserter< mpl::vector< T > > >::type type
Definition: Types.h:115
void operator()(T) const
Definition: Types.h:246
bool Bool_t
Definition: Types.h:175
Definition: Types.h:232
T::type_info type_info
Definition: Types.h:79
mpl::fold< CFListSeq, mpl::vector<>, mpl::copy< mpl::_1, mpl::back_inserter< mpl::_2 > > >::type Childs
Definition: Types.h:110
void * Pointer_t
Definition: Types.h:174
mpl::transform_view< typename access< T >::type_info::BaseList, lambda_CFList< mpl::_ > >::type CFListSeq
Definition: Types.h:102
#define p()
Definition: ObjectProps.h:59
id_t Id_t
Definition: Types.h:171
Definition: Types.h:244