6 #ifndef KNOWROB_NUMERIC_TERM_H
7 #define KNOWROB_NUMERIC_TERM_H
18 class Numeric :
public XSDAtomic {
97 template<
typename T1, XSDType T2>
119 std::istringstream iss(*stringForm_);
120 auto &value = numericForm_.emplace();
121 iss >> std::fixed >> value;
124 return numericForm_.value();
158 std::ostringstream oss;
159 oss << std::fixed << std::boolalpha << *numericForm_;
160 stringForm_ = oss.str();
167 if (
xsdType() != other.xsdType()) {
171 return numericForm() == otherNumeric->numericForm();
175 void write(std::ostream &os)
const override { os << std::defaultfloat << std::boolalpha <<
numericForm(); }
179 mutable std::optional<std::string> stringForm_;
180 mutable std::optional<T1> numericForm_;
186 using Integer = NumericTemplate<int, XSDType::INTEGER>;
191 using Long = NumericTemplate<long, XSDType::LONG>;
196 using Short = NumericTemplate<short, XSDType::SHORT>;
201 using UnsignedLong = NumericTemplate<unsigned long, XSDType::UNSIGNED_LONG>;
206 using UnsignedInt = NumericTemplate<unsigned int, XSDType::UNSIGNED_INT>;
211 using UnsignedShort = NumericTemplate<unsigned short, XSDType::UNSIGNED_SHORT>;
216 using Float = NumericTemplate<float, XSDType::FLOAT>;
221 using Double = NumericTemplate<double, XSDType::DOUBLE>;
226 using Boolean = NumericTemplate<bool, XSDType::BOOLEAN>;
bool isFloatingNumber() const
virtual float asFloat() const =0
virtual short asShort() const =0
virtual long asLong() const =0
virtual bool isSameNumeric(const Numeric &other) const =0
virtual int asInteger() const =0
static std::shared_ptr< Numeric > falseAtom()
virtual unsigned long asUnsignedLong() const =0
virtual unsigned short asUnsignedShort() const =0
virtual double asDouble() const =0
virtual bool asBoolean() const =0
virtual unsigned int asUnsignedInteger() const =0
static std::shared_ptr< Numeric > trueAtom()
~Numeric() override=default
void write(std::ostream &os) const override
std::string_view stringForm() const override
~NumericTemplate() override=default
bool asBoolean() const override
bool isSameNumeric(const Numeric &other) const override
double asDouble() const override
short asShort() const override
int asInteger() const override
float asFloat() const override
unsigned short asUnsignedShort() const override
NumericTemplate(std::string_view stringForm)
long asLong() const override
unsigned long asUnsignedLong() const override
unsigned int asUnsignedInteger() const override
NumericTemplate(T1 numericForm)
NumericTemplate< unsigned int, XSDType::UNSIGNED_INT > UnsignedInt
NumericTemplate< bool, XSDType::BOOLEAN > Boolean
NumericTemplate< unsigned short, XSDType::UNSIGNED_SHORT > UnsignedShort
NumericTemplate< int, XSDType::INTEGER > Integer
NumericTemplate< long, XSDType::LONG > Long
NumericTemplate< unsigned long, XSDType::UNSIGNED_LONG > UnsignedLong
NumericTemplate< double, XSDType::DOUBLE > Double
NumericTemplate< float, XSDType::FLOAT > Float
XSDType
The XSDType enum Enumeration of the XSD types.
NumericTemplate< short, XSDType::SHORT > Short