7 #include "fwAtoms/Numeric.hpp" 9 #include "fwAtoms/Exception.hpp" 10 #include "fwAtoms/Numeric.hxx" 11 #include "fwAtoms/registry/macros.hpp" 15 #include <boost/lexical_cast.hpp> 27 clone->m_value = m_value;
35 FW_RAISE_EXCEPTION_IF( ::
fwAtoms::Exception(
"Empty numeric atom"), m_value.which() == 0);
36 return ::boost::lexical_cast<std::string>(m_value);
41 template <
typename T >
42 bool lexicalCast( Numeric::ValueType& v,
const std::string& s )
48 T val = ::boost::lexical_cast< T >( s );
52 catch ( const ::boost::bad_lexical_cast&)
54 OSLM_TRACE(
"lexicalCast failed for '" << s <<
"'" <<
" to type: " <<
typeid(T).name() );
63 Numeric::ValueType res;
64 SLM_ASSERT(
"Invalid variant type requested", EMPTY <= type && type <= DOUBLE);
68 FW_RAISE_EXCEPTION_IF(
70 !(lexicalCast< std::int64_t >(res, s)
71 || lexicalCast< std::uint64_t >(res, s)
72 || lexicalCast< double >(res, s))
75 else if ( type == INT)
77 FW_RAISE_EXCEPTION_IF(
79 !lexicalCast< std::int64_t >(res, s)
82 else if ( type == UINT)
84 FW_RAISE_EXCEPTION_IF(
86 !lexicalCast< std::uint64_t >(res, s)
89 else if ( type == DOUBLE)
91 FW_RAISE_EXCEPTION_IF(
93 !lexicalCast< double >(res, s)
Implements atoms exception.
FWATOMS_API void setFromString(const std::string &s, NumericType type=EMPTY)
Sets Numeric's value from given string, using Numeric::valueFromString.
static FWATOMS_API ValueType valueFromString(const std::string &s, NumericType type=EMPTY)
Retuns a ValueType from a std::string.
fwAtoms contains basic objects to represent any other kind of object
#define OSLM_TRACE(message)
static Numeric::sptr New(T value)
Build a new numeric type.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
virtual FWATOMS_API Base::sptr clone() const override
Returns a clone object.
virtual FWATOMS_API std::string getString() const override
Returns a string representing the currently held numeric value.
This file defines SpyLog macros. These macros are used to log messages to a file or to the console du...