fw4spl
core/fwAtoms/include/fwAtoms/Base.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 __FWATOMS_BASE_HPP__
8 #define __FWATOMS_BASE_HPP__
9 
10 
11 #include <string>
12 
13 #include <fwCore/base.hpp>
14 
15 #include "fwAtoms/factory/new.hpp"
16 #include "fwAtoms/registry/detail.hpp"
17 #include "fwAtoms/config.hpp"
18 
19 
20 namespace fwAtoms
21 {
22 
26 class FWATOMS_CLASS_API Base : public ::fwCore::BaseObject
27 {
28 public:
29  typedef ::fwAtoms::factory::Key Key;
30 
32  FWATOMS_API static const std::string s_VERSION;
33 
40  template <typename T>
41  class Registrar
42  {
43  public:
44  Registrar()
45  {
46  ::fwAtoms::registry::get()->addFactory(T::classname(), &::fwAtoms::factory::New<T>);
47  }
48  };
49 
50  typedef enum
51  {
52  BOOLEAN = 1,
53  NUMERIC,
54  STRING,
55  OBJECT,
56  SEQUENCE,
57  MAP,
58  BLOB
59  } AtomType;
60 
63 
64  virtual ~Base()
65  {
66  }
67 
71  virtual Base::sptr clone() const = 0;
72 
77  bool isValue() const
78  {
79  return (type() == BOOLEAN) || (type() == NUMERIC) || (type() == STRING);
80  }
81 
86  bool isBoolean() const
87  {
88  return (type() == BOOLEAN);
89  }
90 
95  bool isNumeric() const
96  {
97  return (type() == NUMERIC);
98  }
99 
104  bool isString() const
105  {
106  return (type() == STRING);
107  }
108 
113  bool isSequence() const
114  {
115  return (type() == SEQUENCE);
116  }
117 
122  bool isMapping() const
123  {
124  return (type() == MAP);
125  }
126 
131  bool isBlob() const
132  {
133  return (type() == BLOB);
134  }
135 
140  bool isObject() const
141  {
142  return (type() == OBJECT);
143  }
144 
149  FWATOMS_API virtual std::string getString() const;
150 
154  virtual AtomType type() const = 0;
155 
156 protected:
161  {
162  }
163 
164 };
165 
166 }
167 
168 #endif /* __FWATOMS_BASE_HPP__ */
169 
#define fwCoreNonInstanciableClassDefinitionsMacro(_classinfo_)
Generate common code for Non Instanciable classes (Interfaces, Abstract classes, ...)
fwAtoms contains basic objects to represent any other kind of object
Base class for all FW4SPL&#39;s classes.
Definition: BaseObject.hpp:22
bool isBoolean() const
Test if the current base is a boolean.
bool isValue() const
Test if the current base is a value or not (Value = {string;numeric;boolean})
bool isBlob() const
Test if the current base is a blob (a object with a buffer)
bool isMapping() const
Test if the current base is a mapping.
bool isNumeric() const
Test if the current base is a Numeric (real or integer)
Class used to register a class factory in factory registry. This class defines also the object factor...
#define fwCoreAllowSharedFromThis()
Generate getSptr and getConstSptr methods.
static FWATOMS_API const std::string s_VERSION
Defines fwAtoms version.
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
bool isString() const
Test if the current base is a string.
Base class for all Atom classes.
bool isSequence() const
Test if the current base is a sequence.
bool isObject() const
Test if the current base is an object (representation of fwData)