7 #include "fwTools/Type.hpp" 13 std::ostream& operator<< (std::ostream& os, const ::fwTools::Type& type)
23 const std::string Type::s_UNSPECIFIED_TYPENAME(
"UNSPECIFIED TYPE");
25 const std::string Type::s_INT8_TYPENAME(
"int8");
26 const std::string Type::s_INT16_TYPENAME(
"int16");
27 const std::string Type::s_INT32_TYPENAME(
"int32");
28 const std::string Type::s_INT64_TYPENAME(
"int64");
30 const std::string Type::s_UINT8_TYPENAME(
"uint8");
31 const std::string Type::s_UINT16_TYPENAME(
"uint16");
32 const std::string Type::s_UINT32_TYPENAME(
"uint32");
33 const std::string Type::s_UINT64_TYPENAME(
"uint64");
35 const std::string Type::s_FLOAT_TYPENAME(
"float");
36 const std::string Type::s_DOUBLE_TYPENAME(
"double");
38 const Type::TypeMapType Type::s_TYPEMAP = {{
39 {Type::s_INT8_TYPENAME, Type::create< ::fwTools::Type::Int8Type >()},
40 {Type::s_INT16_TYPENAME, Type::create< ::fwTools::Type::Int16Type >()},
41 {Type::s_INT32_TYPENAME, Type::create< ::fwTools::Type::Int32Type >()},
42 {Type::s_INT64_TYPENAME, Type::create< ::fwTools::Type::Int64Type >()},
44 {Type::s_UINT8_TYPENAME, Type::create< ::fwTools::Type::UInt8Type >()},
45 {Type::s_UINT16_TYPENAME, Type::create< ::fwTools::Type::UInt16Type >()},
46 {Type::s_UINT32_TYPENAME, Type::create< ::fwTools::Type::UInt32Type >()},
47 {Type::s_UINT64_TYPENAME, Type::create< ::fwTools::Type::UInt64Type >()},
49 {Type::s_FLOAT_TYPENAME, Type::create< ::fwTools::Type::FloatType >()},
50 {Type::s_DOUBLE_TYPENAME, Type::create< ::fwTools::Type::DoubleType >()}
53 const Type Type::s_UNSPECIFIED_TYPE;
55 const Type Type::s_INT8 = ::fwTools::Type::create< ::fwTools::Type::Int8Type >();
56 const Type Type::s_INT16 = ::fwTools::Type::create< ::fwTools::Type::Int16Type >();
57 const Type Type::s_INT32 = ::fwTools::Type::create< ::fwTools::Type::Int32Type >();
58 const Type Type::s_INT64 = ::fwTools::Type::create< ::fwTools::Type::Int64Type >();
60 const Type Type::s_UINT8 = ::fwTools::Type::create< ::fwTools::Type::UInt8Type >();
61 const Type Type::s_UINT16 = ::fwTools::Type::create< ::fwTools::Type::UInt16Type >();
62 const Type Type::s_UINT32 = ::fwTools::Type::create< ::fwTools::Type::UInt32Type >();
63 const Type Type::s_UINT64 = ::fwTools::Type::create< ::fwTools::Type::UInt64Type >();
65 const Type Type::s_FLOAT = ::fwTools::Type::create< ::fwTools::Type::FloatType >();
66 const Type Type::s_DOUBLE = ::fwTools::Type::create< ::fwTools::Type::DoubleType >();
70 template<>
const std::string& Type::traitsToString< 1, true, true > ()
72 return Type::s_INT8_TYPENAME;
76 template<>
const std::string& Type::traitsToString< 2, true, true > ()
78 return Type::s_INT16_TYPENAME;
82 template<>
const std::string& Type::traitsToString< 4, true, true > ()
84 return Type::s_INT32_TYPENAME;
88 template<>
const std::string& Type::traitsToString< 8, true, true > ()
90 return Type::s_INT64_TYPENAME;
95 template<>
const std::string& Type::traitsToString< 1, false, true > ()
97 return Type::s_UINT8_TYPENAME;
101 template<>
const std::string& Type::traitsToString< 2, false, true > ()
103 return Type::s_UINT16_TYPENAME;
107 template<>
const std::string& Type::traitsToString< 4, false, true > ()
109 return Type::s_UINT32_TYPENAME;
113 template<>
const std::string& Type::traitsToString< 8, false, true > ()
115 return Type::s_UINT64_TYPENAME;
120 template<>
const std::string& Type::traitsToString< 4, true, false > ()
122 return Type::s_FLOAT_TYPENAME;
126 template<>
const std::string& Type::traitsToString< 8, true, false > ()
128 return Type::s_DOUBLE_TYPENAME;
135 Type::setType<void>();
140 Type::Type(
const std::string& type)
142 *
this = Type::create(type);
147 bool Type::operator==(
const Type& _other)
const 149 return m_name == _other.m_name;
154 bool Type::operator!=(
const Type& _other)
const 156 return m_name != _other.m_name;
161 bool Type::operator<(
const Type& _other)
const 163 return m_name < _other.m_name;
168 unsigned char Type::sizeOf()
const 175 const std::string& Type::string()
const 182 const std::type_info& Type::typeId()
const 184 return m_tool->m_typeinfo;
189 bool Type::isFixedPrecision()
const 191 return m_isFixedPrecision;
196 bool Type::isSigned()
const 203 Type Type::create(std::string name)
205 TypeMapType::const_iterator iter = s_TYPEMAP.find(name);
206 if (iter != s_TYPEMAP.end())
210 return s_UNSPECIFIED_TYPE;
215 std::string Type::toString(
const void* value)
const 217 return m_tool->toString(value);
222 Type::ToolBase::ToolBase() :
223 m_typeinfo(
typeid(
void))
229 Type::ToolBase::ToolBase(
const std::type_info& typeinfo) :
236 std::string Type::ToolBase::toString(::boost::any value)
const 238 FwCoreNotUsedMacro(value);
239 SLM_ASSERT(
"unable to convert an unspecified type value", 0);
245 std::string Type::ToolBase::toString(
const void* value)
const 247 FwCoreNotUsedMacro(value);
248 SLM_ASSERT(
"unable to convert an unspecified type value", 0);
255 void Type::setType<char>()
257 this->setType<signed char>();
262 #if (defined(linux) || defined(__linux)) && !defined(ANDROID) 265 void Type::setType<std::int64_t>()
267 this->setType<long long>();
273 void Type::setType<std::uint64_t>()
275 this->setType<unsigned long long>();
283 void Type::setType<void>()
285 m_name = s_UNSPECIFIED_TYPENAME;
288 m_isFixedPrecision =
false;
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...