fw4spl
TypeInfo.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/TypeInfo.hpp"
8 
9 #include <fwCore/base.hpp>
10 
11 #include <string.h>
12 
13 namespace fwTools
14 {
15 
17 {
18  class Nil
19  {
20  };
21  pInfo_ = &typeid(Nil);
22  SLM_ASSERT("pInfo_ not instanced", pInfo_);
23 }
24 
25 TypeInfo::TypeInfo(const std::type_info& ti) :
26  pInfo_(&ti)
27 {
28  SLM_ASSERT("pInfo_ not instanced", pInfo_);
29 }
30 
31 //------------------------------------------------------------------------------
32 
33 bool TypeInfo::before(const TypeInfo& rhs) const
34 {
35  SLM_ASSERT("pInfo_ not instanced", pInfo_);
36  // type_info::before return type is int in some VC libraries
37  return pInfo_->before(*rhs.pInfo_) != 0;
38 }
39 
40 //------------------------------------------------------------------------------
41 
42 const std::type_info& TypeInfo::type_info() const
43 {
44  SLM_ASSERT("pInfo_ not instanced", pInfo_);
45  return *pInfo_;
46 }
47 
48 //------------------------------------------------------------------------------
49 
50 const char* TypeInfo::name() const
51 {
52  SLM_ASSERT("pInfo_ not instanced", pInfo_);
53  return pInfo_->name();
54 }
55 
56 //------------------------------------------------------------------------------
57 
59 {
60  pInfo_ = rhs.pInfo_;
61  return *this;
62 }
63 
64 // Comparison operators
65 
66 bool operator==(const TypeInfo& lhs, const TypeInfo& rhs)
67 // type_info::operator== return type is int in some VC libraries
68 // typeinfo can have different ptr on the same strucure !!!!
69 //http://gcc.gnu.org/ml/gcc/2002-05/msg02085.html
70 {
71  return strcmp(lhs.type_info().name(), rhs.type_info().name() ) == 0;
72 }
73 
74 //------------------------------------------------------------------------------
75 
76 bool operator!=(const TypeInfo& lhs, const TypeInfo& rhs)
77 {
78  return !(lhs == rhs);
79 }
80 
81 //------------------------------------------------------------------------------
82 
83 bool operator<(const TypeInfo& lhs, const TypeInfo& rhs)
84 {
85  return strcmp(lhs.type_info().name(), rhs.type_info().name() ) < 0;
86 }
87 
88 //------------------------------------------------------------------------------
89 
90 bool operator>(const TypeInfo& lhs, const TypeInfo& rhs)
91 {
92  return strcmp(lhs.type_info().name(), rhs.type_info().name() ) > 0;
93 }
94 
95 //------------------------------------------------------------------------------
96 
97 bool operator<=(const TypeInfo& lhs, const TypeInfo& rhs)
98 {
99  return strcmp(lhs.type_info().name(), rhs.type_info().name() ) <= 0;
100 }
101 
102 //------------------------------------------------------------------------------
103 
104 bool operator>=(const TypeInfo& lhs, const TypeInfo& rhs)
105 {
106  return strcmp(lhs.type_info().name(), rhs.type_info().name() ) >= 0;
107 }
108 
109 } // end namespace fwTools
110 
Purpose: offer a first-class, comparable wrapper over std::type_info ( but copy construcible ) ...
Definition: TypeInfo.hpp:22
FWTOOLS_API const std::type_info & type_info() const
access for the wrapped std::type_info
Definition: TypeInfo.cpp:42
The namespace fwTools contains several tools like UUID, factory, dispatche, stringizer, macros, helper.
FWTOOLS_API TypeInfo()
default constructor
Definition: TypeInfo.cpp:16
FWTOOLS_API bool before(const TypeInfo &rhs) const
compatibility functions ( std::type_info like)
Definition: TypeInfo.cpp:33
#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
FWTOOLS_API const char * name() const
compatibility functions ( std::type_info like)
Definition: TypeInfo.cpp:50
FWTOOLS_API TypeInfo & operator=(const TypeInfo &ti)
copy method
Definition: TypeInfo.cpp:58