fw4spl
DynamicType.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #ifndef __FWTOOLS_DYNAMICTYPE_HPP__
8 #define __FWTOOLS_DYNAMICTYPE_HPP__
9 
10 #include <string>
11 #include <list>
12 #include <vector>
13 #include <stdexcept>
14 
15 #include <boost/mpl/vector.hpp>
16 
17 #include "fwTools/Stringizer.hpp"
18 #include "fwTools/config.hpp"
19 
20 
21 namespace fwTools
22 {
23 
31 class FWTOOLS_CLASS_API DynamicType
32 {
33 public:
35  FWTOOLS_API DynamicType();
36 
38  FWTOOLS_API DynamicType(const DynamicType &);
39 
43  FWTOOLS_API bool operator==(const DynamicType &) const;
44 
48  FWTOOLS_API bool operator!=(const DynamicType &) const;
49 
50 
54  FWTOOLS_API bool operator<( const DynamicType& ) const;
55 
60  template< class TYPE>
61  void setType();
62 
63 
68  template< class TYPE>
69  bool isType() const;
70 
74  FWTOOLS_API unsigned char sizeOf() const;
75 
76 
82  template<class NEWTYPE>
83  static void registerNewType(const std::string &newKey);
84 
85 
87  FWTOOLS_API virtual ~DynamicType();
88 
90  FWTOOLS_API const std::string &string() const;
91 
97  template<class TYPE>
98  static const std::string string();
99 
103  template<class T>
104  std::pair<T,T> minMax();
105 
107  FWTOOLS_API bool isFixedPrecision();
108 
110  FWTOOLS_API bool isSigned();
111 
112  typedef boost::mpl::vector<
113  signed char,
114  unsigned char,
115  signed short,
116  unsigned short,
117  signed int,
118  unsigned int,
119  unsigned long,
120  signed long,
121  float,
122  double
123  >::type SupportedTypes;
124 
125 protected:
126 
127  std::string m_value; // aka key
128  unsigned char m_sizeof;
129 
131  FWTOOLS_API static std::list< std::string > m_managedTypes;
132 
134  FWTOOLS_API static const std::string m_unSpecifiedType;
135 };
136 
137 
138 
140 template<class TYPE>
142 
148 // #include "KEYTYPEMapping.hpp" is mandatory
149 template<class KEYTYPE>
150 DynamicType makeDynamicType(const KEYTYPE &keyType);
151 
152 
153 template<>
154 FWTOOLS_API std::string getString(const DynamicType &dt);
155 
156 template<>
157 FWTOOLS_API std::string getString(const std::vector<DynamicType> &dtv);
158 
159 } //end namespace fwTools
160 
161 
162 #include "fwTools/DynamicType.hxx"
163 
164 
165 #endif /*__FWTOOLS_DYNAMICTYPE_HPP__*/
static FWTOOLS_API std::list< std::string > m_managedTypes
Container of types managed by DynamicType.
The namespace fwTools contains several tools like UUID, factory, dispatche, stringizer, macros, helper.
Class defining an elementary C++ type aka unsigned char, signed char, .... signed long...
Definition: DynamicType.hpp:31
DynamicType makeDynamicType()
Helper to create object DynamicType from a given type TYPE in { (un)signed char, ... , double }.
Definition: DynamicType.hxx:21
static FWTOOLS_API const std::string m_unSpecifiedType
Value for not specified type.