7 #ifndef __FWTOOLS_TYPE_HPP__ 8 #define __FWTOOLS_TYPE_HPP__ 10 #include "fwTools/config.hpp" 11 #include "fwTools/Stringizer.hpp" 13 #include <fwCore/base.hpp> 15 #include <boost/any.hpp> 16 #include <boost/cstdint.hpp> 17 #include <boost/lexical_cast.hpp> 18 #include <boost/type_traits/is_signed.hpp> 23 #include <type_traits> 32 class FWTOOLS_CLASS_API
Type 39 FWTOOLS_API
virtual ~ToolBase()
42 FWTOOLS_API ToolBase(
const std::type_info& typeinfo);
43 FWTOOLS_API
virtual std::string toString( ::boost::any value )
const;
44 FWTOOLS_API
virtual std::string toString(
const void* )
const;
46 const std::type_info& m_typeinfo;
56 virtual std::string toString( ::boost::any value )
const;
57 virtual std::string toString(
const void* )
const;
60 typedef std::map<std::string, Type> TypeMapType;
64 FWTOOLS_API Type(
const std::string& type);
69 FWTOOLS_API
bool operator==(
const Type&)
const;
74 FWTOOLS_API
bool operator!=(
const Type&)
const;
79 FWTOOLS_API
bool operator<(
const Type& )
const;
93 bool isOfType()
const;
98 FWTOOLS_API
unsigned char sizeOf()
const;
101 FWTOOLS_API
const std::string& string()
const;
104 FWTOOLS_API
const std::type_info& typeId()
const;
110 const std::pair<T, T> minMax()
const;
113 FWTOOLS_API
bool isFixedPrecision()
const;
116 FWTOOLS_API
bool isSigned()
const;
118 FWTOOLS_API std::string toString(
const void* )
const;
120 template <
int SIZEOF,
bool SIGNED,
bool ISINTEGRAL>
121 static const std::string& traitsToString();
123 template <
typename T>
124 static Type create();
126 FWTOOLS_API
static Type create(std::string name);
131 unsigned char m_sizeof;
133 bool m_isFixedPrecision;
145 FWTOOLS_API
static const Type s_UNSPECIFIED_TYPE;
147 FWTOOLS_API
static const Type s_INT8;
148 FWTOOLS_API
static const Type s_INT16;
149 FWTOOLS_API
static const Type s_INT32;
150 FWTOOLS_API
static const Type s_INT64;
152 FWTOOLS_API
static const Type s_UINT8;
153 FWTOOLS_API
static const Type s_UINT16;
154 FWTOOLS_API
static const Type s_UINT32;
155 FWTOOLS_API
static const Type s_UINT64;
157 FWTOOLS_API
static const Type s_FLOAT;
158 FWTOOLS_API
static const Type s_DOUBLE;
160 FWTOOLS_API
static const std::string s_UNSPECIFIED_TYPENAME;
162 FWTOOLS_API
static const std::string s_INT8_TYPENAME;
163 FWTOOLS_API
static const std::string s_INT16_TYPENAME;
164 FWTOOLS_API
static const std::string s_INT32_TYPENAME;
165 FWTOOLS_API
static const std::string s_INT64_TYPENAME;
167 FWTOOLS_API
static const std::string s_UINT8_TYPENAME;
168 FWTOOLS_API
static const std::string s_UINT16_TYPENAME;
169 FWTOOLS_API
static const std::string s_UINT32_TYPENAME;
170 FWTOOLS_API
static const std::string s_UINT64_TYPENAME;
172 FWTOOLS_API
static const std::string s_FLOAT_TYPENAME;
173 FWTOOLS_API
static const std::string s_DOUBLE_TYPENAME;
175 typedef std::int8_t Int8Type;
176 typedef std::int16_t Int16Type;
177 typedef std::int32_t Int32Type;
178 typedef std::int64_t Int64Type;
180 typedef std::uint8_t UInt8Type;
181 typedef std::uint16_t UInt16Type;
182 typedef std::uint32_t UInt32Type;
183 typedef std::uint64_t UInt64Type;
185 typedef float FloatType;
186 typedef double DoubleType;
192 template<
typename T >
195 return ::fwTools::getString( boost::any_cast<const T> (value));
200 template<
typename T >
203 const T& v = *(
static_cast< const T*
> (value));
204 return ::fwTools::getString( v );
208 template<
typename T >
216 template <
typename T>
226 template <
typename T>
229 return *
this == create<T>();
234 template <
typename T>
237 m_name = Type::traitsToString< sizeof(T), std::is_signed<T>::value, std::is_integral<T>::value >();
239 m_sizeof =
sizeof(T);
240 m_isSigned = std::is_signed<T>::value;
241 m_isFixedPrecision = std::is_integral<T>::value;
245 T min =
static_cast< T
>( std::numeric_limits< T >::lowest() );
246 T max =
static_cast< T
>( std::numeric_limits< T >::max() );
255 FWTOOLS_API
void Type::setType< void >();
260 FWTOOLS_API
void Type::setType< char >();
267 FWTOOLS_API
void Type::setType< std::int64_t >();
272 FWTOOLS_API
void Type::setType< std::uint64_t >();
278 template <
int SIZEOF,
bool SIGNED,
bool ISINTEGRAL>
279 const std::string& Type::traitsToString()
281 OSLM_ERROR(
"unknown " << (SIGNED ?
"signed" :
"unsigned")
282 <<
" " << (ISINTEGRAL ?
"integral" :
"floating")
283 <<
" type with size : " << SIZEOF);
284 return Type::s_UNSPECIFIED_TYPENAME;
289 template <
typename T>
292 return std::pair<T, T>(
293 boost::any_cast< T >(m_min),
294 boost::any_cast< T >(m_max)
300 template<> FWTOOLS_API
const std::string& Type::traitsToString< 1, true, true > ();
301 template<> FWTOOLS_API
const std::string& Type::traitsToString< 2, true, true > ();
302 template<> FWTOOLS_API
const std::string& Type::traitsToString< 4, true, true > ();
303 template<> FWTOOLS_API
const std::string& Type::traitsToString< 8, true, true > ();
305 template<> FWTOOLS_API
const std::string& Type::traitsToString< 1, false, true > ();
306 template<> FWTOOLS_API
const std::string& Type::traitsToString< 2, false, true > ();
307 template<> FWTOOLS_API
const std::string& Type::traitsToString< 4, false, true > ();
308 template<> FWTOOLS_API
const std::string& Type::traitsToString< 8, false, true > ();
310 template<> FWTOOLS_API
const std::string& Type::traitsToString< 4, true, false > ();
311 template<> FWTOOLS_API
const std::string& Type::traitsToString< 8, true, false > ();
317 FWTOOLS_API std::ostream& operator<< (std::ostream& os, const ::fwTools::Type& type);
#define OSLM_ERROR(message)