fw4spl
DynamicType.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
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 #include "fwTools/DynamicType.hpp"
8 
9 #include "fwCore/spyLog.hpp"
10 
11 #include "fwTools/Dispatcher.hpp"
12 #include "fwTools/DynamicTypeKeyTypeMapping.hpp"
13 
14 #include <type_traits>
15 
16 namespace fwTools
17 {
18 
19 std::list< std::string > DynamicType::m_managedTypes = {{ ("unsigned char"),
20  ("signed char"),
21  ("unsigned short"),
22  ("signed short"),
23  ("unsigned int"),
24  ("signed int"),
25  ("unsigned long"),
26  ("signed long"),
27  ("float"),
28  ("double")}};
29 
30 const std::string DynamicType::m_unSpecifiedType = std::string("UNSPECIFIED TYPE");
31 
32 typedef boost::mpl::vector< signed char, unsigned char, signed short, unsigned short, signed int, unsigned int, float,
33  double >::type SupportedTypes;
34 
35 //------------------------------------------------------------------------------
36 
37 bool DynamicType::operator==(const DynamicType& d2) const
38 {
39  return m_value == d2.m_value;
40 }
41 
42 //------------------------------------------------------------------------------
43 
44 bool DynamicType::operator!=(const DynamicType& d2) const
45 {
46  return m_value != d2.m_value;
47 }
48 
49 //------------------------------------------------------------------------------
50 
51 bool DynamicType::operator<(const DynamicType& d2) const
52 {
53  return m_value < d2.m_value;
54 }
55 
57  m_value( m_unSpecifiedType),
58  m_sizeof(0)
59 {
60 }
61 
63 {
64  this->m_value = d2.m_value;
65  this->m_sizeof = d2.m_sizeof;
66 }
67 
69 {
70 }
71 
72 //------------------------------------------------------------------------------
73 
74 const std::string& DynamicType::string() const
75 {
76  return m_value;
77 }
78 
79 //------------------------------------------------------------------------------
80 
81 unsigned char DynamicType::sizeOf() const
82 {
83  SLM_ASSERT("Sizeof not specified.", m_sizeof != 0);
84  return m_sizeof;
85 }
86 
87 //------------------------------------------------------------------------------
88 
90 {
91  return !isType<float>() && !isType<double>();
92 }
93 
95 {
96 public:
97 
98  //------------------------------------------------------------------------------
99 
100  template< typename PIXEL >
101  void operator()( bool& isSigned )
102  {
103  isSigned = !std::is_unsigned<PIXEL>::value;
104  }
105 };
106 
107 //------------------------------------------------------------------------------
108 
110 {
111  bool isSigned;
113  return isSigned;
114 }
115 
116 //------------------------------------------------------------------------------
117 
118 template<>
119 std::string getString(const DynamicType& dt)
120 {
121  return dt.string();
122 }
123 
124 //------------------------------------------------------------------------------
125 
126 template<>
127 std::string getString(const std::vector<DynamicType>& dtv)
128 {
129  return getString(dtv.begin(), dtv.end());
130 }
131 
132 } // end namespace fwTools {
133 
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.
FWTOOLS_API unsigned char sizeOf() const
Return the sizeof of the type.
Definition: DynamicType.cpp:81
Class defining an elementary C++ type aka unsigned char, signed char, .... signed long...
Definition: DynamicType.hpp:31
FWTOOLS_API bool isSigned()
return true iff the type is signed
FWTOOLS_API bool operator<(const DynamicType &) const
define an order (lexicographic) for dynamicType
Definition: DynamicType.cpp:51
FWTOOLS_API DynamicType()
Default constructor.
Definition: DynamicType.cpp:56
virtual FWTOOLS_API ~DynamicType()
Default destrucor : do nothing.
Definition: DynamicType.cpp:68
#define SLM_ASSERT(message, cond)
work like &#39;assert&#39; from &#39;cassert&#39;, with in addition a message logged by spylog (with FATAL loglevel) ...
Definition: spyLog.hpp:308
static void invoke()
Instanciate and invoke all functors.
Definition: Dispatcher.hpp:99
FWTOOLS_API const std::string & string() const
Return a human readable string.
Definition: DynamicType.cpp:74
FWTOOLS_API bool operator==(const DynamicType &) const
comparison operator
Definition: DynamicType.cpp:37
FWTOOLS_API bool operator!=(const DynamicType &) const
comparison operator
Definition: DynamicType.cpp:44
FWTOOLS_API bool isFixedPrecision()
return true iff the type use a fixed precision
Definition: DynamicType.cpp:89
static FWTOOLS_API const std::string m_unSpecifiedType
Value for not specified type.
This file defines SpyLog macros. These macros are used to log messages to a file or to the console du...