fw4spl
Numeric.hpp
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 #ifndef __FWATOMS_NUMERIC_HPP__
8 #define __FWATOMS_NUMERIC_HPP__
9 
10 #include "fwAtoms/Base.hpp"
11 #include "fwAtoms/config.hpp"
12 #include "fwAtoms/factory/new.hpp"
13 
14 #include <boost/blank.hpp>
15 #include <boost/variant/variant.hpp>
16 
17 #include <string>
18 
19 namespace fwAtoms
20 {
21 
25 class FWATOMS_CLASS_API Numeric : public Base
26 {
27 public:
28 
29  fwCoreClassDefinitionsWithFactoryMacro( (Numeric)(::fwAtoms::Base), (()), ::fwAtoms::factory::New< Numeric >);
30 
31  typedef enum
32  {
33  EMPTY = 0,
34  INT,
35  UINT,
36  FLOAT,
37  DOUBLE
38  } NumericType;
39 
40  typedef ::boost::variant< ::boost::blank, std::int64_t, std::uint64_t, float, double > ValueType;
41 
47  {
48  }
49 
53  virtual ~Numeric()
54  {
55  }
56 
62  template< typename T >
63  static Numeric::sptr New(T value);
64 
68  FWATOMS_API virtual Base::sptr clone() const override;
69 
73  ::fwAtoms::Base::AtomType type() const override
74  {
75  return ::fwAtoms::Base::NUMERIC;
76  }
77 
81  NumericType variantType() const
82  {
83  return static_cast< NumericType >(m_value.which());
84  }
85 
91  const ValueType& getVariant() const
92  {
93  return m_value;
94  }
95 
99  FWATOMS_API virtual std::string getString() const override;
100 
104  FWATOMS_API void setFromString(const std::string& s, NumericType type = EMPTY);
105 
119  FWATOMS_API static ValueType valueFromString(const std::string& s, NumericType type = EMPTY);
120 
129  template <typename T>
130  T getValue() const;
131 
132 protected:
133 
134  ValueType m_value;
135 
136 };
137 
138 }
139 
140 #endif /* __FWATOMS_NUMERIC_HPP__ */
141 
Numeric(::fwAtoms::Base::Key key)
Constructor.
Definition: Numeric.hpp:46
virtual ~Numeric()
Destructor.
Definition: Numeric.hpp:53
fwAtoms contains basic objects to represent any other kind of object
NumericType variantType() const
Returns currently held numeric type.
Definition: Numeric.hpp:81
::fwAtoms::Base::AtomType type() const override
returns Atom type
Definition: Numeric.hpp:73
#define fwCoreClassDefinitionsWithFactoryMacro(_classinfo_, _parameters_, _factory_)
Generate common construction methods for classes with one factory.
const ValueType & getVariant() const
Returns const reference to numeric&#39;s variant.
Definition: Numeric.hpp:91
Storing a numeric value.
Definition: Numeric.hpp:25
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
Base class for all Atom classes.