knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
knowrob::NumericTemplate< T1, T2 > Class Template Reference

#include <Numeric.h>

Inheritance diagram for knowrob::NumericTemplate< T1, T2 >:
Collaboration diagram for knowrob::NumericTemplate< T1, T2 >:

Public Member Functions

 NumericTemplate (T1 numericForm)
 
 NumericTemplate (std::string_view stringForm)
 
 ~NumericTemplate () override=default
 
T1 operator() () const
 
T1 numericForm () const
 
double asDouble () const override
 
float asFloat () const override
 
int asInteger () const override
 
long asLong () const override
 
short asShort () const override
 
unsigned int asUnsignedInteger () const override
 
unsigned long asUnsignedLong () const override
 
unsigned short asUnsignedShort () const override
 
bool asBoolean () const override
 
std::string_view stringForm () const override
 
bool isSameNumeric (const Numeric &other) const override
 
void write (std::ostream &os) const override
 
 NumericTemplate (T1 numericForm)
 
 NumericTemplate (std::string_view stringForm)
 
 ~NumericTemplate () override=default
 
T1 operator() () const
 
T1 numericForm () const
 
double asDouble () const override
 
float asFloat () const override
 
int asInteger () const override
 
long asLong () const override
 
short asShort () const override
 
unsigned int asUnsignedInteger () const override
 
unsigned long asUnsignedLong () const override
 
unsigned short asUnsignedShort () const override
 
bool asBoolean () const override
 
std::string_view stringForm () const override
 
bool isSameNumeric (const Numeric &other) const override
 
void write (std::ostream &os) const override
 
- Public Member Functions inherited from knowrob::Numeric
 Numeric (XSDType xsdType)
 
 ~Numeric () override=default
 
bool isFloatingNumber () const
 
 Numeric (XSDType xsdType)
 
 ~Numeric () override=default
 
bool isFloatingNumber () const
 
- Public Member Functions inherited from knowrob::XSDAtomic
 XSDAtomic (XSDType xsdType)
 
std::string_view xsdTypeIRI () const
 
XSDType xsdType () const
 
 XSDAtomic (XSDType xsdType)
 
std::string_view xsdTypeIRI () const
 
XSDType xsdType () const
 
- Public Member Functions inherited from knowrob::RDFNode
 RDFNode (RDFNodeType rdfNodeType)
 
auto rdfNodeType () const
 
 RDFNode (RDFNodeType rdfNodeType)
 
auto rdfNodeType () const
 
- Public Member Functions inherited from knowrob::Atomic
 Atomic (AtomicType atomicType)
 
 ~Atomic () override=default
 
bool isSameAtomic (const Atomic &other) const
 
AtomicType atomicType () const
 
size_t hashOfAtomic () const
 
const std::set< std::string_view > & variables () const final
 
 Atomic (AtomicType atomicType)
 
 ~Atomic () override=default
 
bool isSameAtomic (const Atomic &other) const
 
AtomicType atomicType () const
 
size_t hashOfAtomic () const
 
const std::set< std::string_view > & variables () const final
 
- Public Member Functions inherited from knowrob::Term
 Term (TermType termType)
 
 ~Term () override=default
 
bool operator== (const Term &other) const
 
bool operator!= (const Term &other) const
 
TermType termType () const
 
bool isGround () const
 
bool isAtomic () const
 
bool isAtom () const
 
bool isVariable () const
 
bool isFunction () const
 
bool isNumeric () const
 
bool isString () const
 
bool isIRI () const
 
bool isBlank () const
 
size_t hash () const
 
 Term (TermType termType)
 
 ~Term () override=default
 
bool operator== (const Term &other) const
 
bool operator!= (const Term &other) const
 
TermType termType () const
 
bool isGround () const
 
bool isAtomic () const
 
bool isAtom () const
 
bool isVariable () const
 
bool isFunction () const
 
bool isNumeric () const
 
bool isString () const
 
bool isIRI () const
 
bool isBlank () const
 
size_t hash () const
 
- Public Member Functions inherited from knowrob::Printable
virtual ~Printable ()=default
 
virtual std::string format () const
 
virtual ~Printable ()=default
 
virtual std::string format () const
 

Additional Inherited Members

- Static Public Member Functions inherited from knowrob::Numeric
static std::shared_ptr< NumerictrueAtom ()
 
static std::shared_ptr< NumericfalseAtom ()
 
static std::shared_ptr< NumerictrueAtom ()
 
static std::shared_ptr< NumericfalseAtom ()
 
- Static Public Member Functions inherited from knowrob::XSDAtomic
static std::shared_ptr< XSDAtomiccreate (std::string_view lexicalForm, std::string_view xsdTypeIRI)
 
static std::shared_ptr< XSDAtomiccreate (std::string_view lexicalForm, std::string_view xsdTypeIRI)
 
- Static Public Member Functions inherited from knowrob::Atomic
static std::shared_ptr< AtomicmakeTripleValue (const Triple &triple)
 
static std::shared_ptr< AtomicmakeTripleValue (const Triple &triple)
 
- Protected Attributes inherited from knowrob::XSDAtomic
XSDType xsdType_
 
- Protected Attributes inherited from knowrob::RDFNode
const RDFNodeType rdfNodeType_
 
- Protected Attributes inherited from knowrob::Atomic
const AtomicType atomicType_
 
- Protected Attributes inherited from knowrob::Term
const TermType termType_
 
bool isBlank_ = false
 
bool isIRI_ = false
 
- Static Protected Attributes inherited from knowrob::Term
static const std::set< std::string_view > noVariables_ = {}
 

Detailed Description

template<typename T1, XSDType T2>
class knowrob::NumericTemplate< T1, T2 >

A template class for numeric terms which stores a numeric of type T1, and also provides access to string representation of the numeric.

Template Parameters
T1the type of the numeric
T2the XSD type of the numeric

Definition at line 98 of file Numeric.h.

Constructor & Destructor Documentation

◆ NumericTemplate() [1/4]

template<typename T1 , XSDType T2>
knowrob::NumericTemplate< T1, T2 >::NumericTemplate ( T1  numericForm)
inlineexplicit
Parameters
numericFormthe numeric form of the term

Definition at line 103 of file Numeric.h.

103 : Numeric(T2), numericForm_(numericForm) {}
Numeric(XSDType xsdType)
Definition: Numeric.h:20
T1 numericForm() const
Definition: Numeric.h:117

◆ NumericTemplate() [2/4]

template<typename T1 , XSDType T2>
knowrob::NumericTemplate< T1, T2 >::NumericTemplate ( std::string_view  stringForm)
inlineexplicit
Parameters
stringFormthe string form of the term

Definition at line 108 of file Numeric.h.

108 : Numeric(T2), stringForm_(stringForm) {}
std::string_view stringForm() const override
Definition: Numeric.h:156

◆ ~NumericTemplate() [1/2]

template<typename T1 , XSDType T2>
knowrob::NumericTemplate< T1, T2 >::~NumericTemplate ( )
overridedefault

◆ NumericTemplate() [3/4]

template<typename T1 , XSDType T2>
knowrob::NumericTemplate< T1, T2 >::NumericTemplate ( T1  numericForm)
inlineexplicit
Parameters
numericFormthe numeric form of the term

Definition at line 103 of file Numeric.h.

103 : Numeric(T2), numericForm_(numericForm) {}

◆ NumericTemplate() [4/4]

template<typename T1 , XSDType T2>
knowrob::NumericTemplate< T1, T2 >::NumericTemplate ( std::string_view  stringForm)
inlineexplicit
Parameters
stringFormthe string form of the term

Definition at line 108 of file Numeric.h.

108 : Numeric(T2), stringForm_(stringForm) {}

◆ ~NumericTemplate() [2/2]

template<typename T1 , XSDType T2>
knowrob::NumericTemplate< T1, T2 >::~NumericTemplate ( )
overridedefault

Member Function Documentation

◆ asBoolean() [1/2]

template<typename T1 , XSDType T2>
bool knowrob::NumericTemplate< T1, T2 >::asBoolean ( ) const
inlineoverridevirtual
Returns
the numeric as a boolean

Implements knowrob::Numeric.

Definition at line 153 of file Numeric.h.

153 { return static_cast<bool>(numericForm()); }

◆ asBoolean() [2/2]

template<typename T1 , XSDType T2>
bool knowrob::NumericTemplate< T1, T2 >::asBoolean ( ) const
inlineoverridevirtual
Returns
the numeric as a boolean

Implements knowrob::Numeric.

Definition at line 153 of file Numeric.h.

153 { return static_cast<bool>(numericForm()); }

◆ asDouble() [1/2]

template<typename T1 , XSDType T2>
double knowrob::NumericTemplate< T1, T2 >::asDouble ( ) const
inlineoverridevirtual
Returns
the numeric as a double

Implements knowrob::Numeric.

Definition at line 129 of file Numeric.h.

129 { return static_cast<double>(numericForm()); }

◆ asDouble() [2/2]

template<typename T1 , XSDType T2>
double knowrob::NumericTemplate< T1, T2 >::asDouble ( ) const
inlineoverridevirtual
Returns
the numeric as a double

Implements knowrob::Numeric.

Definition at line 129 of file Numeric.h.

129 { return static_cast<double>(numericForm()); }

◆ asFloat() [1/2]

template<typename T1 , XSDType T2>
float knowrob::NumericTemplate< T1, T2 >::asFloat ( ) const
inlineoverridevirtual
Returns
the numeric as a float

Implements knowrob::Numeric.

Definition at line 132 of file Numeric.h.

132 { return static_cast<float>(numericForm()); }

◆ asFloat() [2/2]

template<typename T1 , XSDType T2>
float knowrob::NumericTemplate< T1, T2 >::asFloat ( ) const
inlineoverridevirtual
Returns
the numeric as a float

Implements knowrob::Numeric.

Definition at line 132 of file Numeric.h.

132 { return static_cast<float>(numericForm()); }

◆ asInteger() [1/2]

template<typename T1 , XSDType T2>
int knowrob::NumericTemplate< T1, T2 >::asInteger ( ) const
inlineoverridevirtual
Returns
the numeric as an integer

Implements knowrob::Numeric.

Definition at line 135 of file Numeric.h.

135 { return static_cast<int>(numericForm()); }

◆ asInteger() [2/2]

template<typename T1 , XSDType T2>
int knowrob::NumericTemplate< T1, T2 >::asInteger ( ) const
inlineoverridevirtual
Returns
the numeric as an integer

Implements knowrob::Numeric.

Definition at line 135 of file Numeric.h.

135 { return static_cast<int>(numericForm()); }

◆ asLong() [1/2]

template<typename T1 , XSDType T2>
long knowrob::NumericTemplate< T1, T2 >::asLong ( ) const
inlineoverridevirtual
Returns
the numeric as a long

Implements knowrob::Numeric.

Definition at line 138 of file Numeric.h.

138 { return static_cast<long>(numericForm()); }

◆ asLong() [2/2]

template<typename T1 , XSDType T2>
long knowrob::NumericTemplate< T1, T2 >::asLong ( ) const
inlineoverridevirtual
Returns
the numeric as a long

Implements knowrob::Numeric.

Definition at line 138 of file Numeric.h.

138 { return static_cast<long>(numericForm()); }

◆ asShort() [1/2]

template<typename T1 , XSDType T2>
short knowrob::NumericTemplate< T1, T2 >::asShort ( ) const
inlineoverridevirtual
Returns
the numeric as a short

Implements knowrob::Numeric.

Definition at line 141 of file Numeric.h.

141 { return static_cast<short>(numericForm()); }

◆ asShort() [2/2]

template<typename T1 , XSDType T2>
short knowrob::NumericTemplate< T1, T2 >::asShort ( ) const
inlineoverridevirtual
Returns
the numeric as a short

Implements knowrob::Numeric.

Definition at line 141 of file Numeric.h.

141 { return static_cast<short>(numericForm()); }

◆ asUnsignedInteger() [1/2]

template<typename T1 , XSDType T2>
unsigned int knowrob::NumericTemplate< T1, T2 >::asUnsignedInteger ( ) const
inlineoverridevirtual
Returns
the numeric as an unsigned integer

Implements knowrob::Numeric.

Definition at line 144 of file Numeric.h.

144 { return static_cast<unsigned int>(numericForm()); }

◆ asUnsignedInteger() [2/2]

template<typename T1 , XSDType T2>
unsigned int knowrob::NumericTemplate< T1, T2 >::asUnsignedInteger ( ) const
inlineoverridevirtual
Returns
the numeric as an unsigned integer

Implements knowrob::Numeric.

Definition at line 144 of file Numeric.h.

144 { return static_cast<unsigned int>(numericForm()); }

◆ asUnsignedLong() [1/2]

template<typename T1 , XSDType T2>
unsigned long knowrob::NumericTemplate< T1, T2 >::asUnsignedLong ( ) const
inlineoverridevirtual
Returns
the numeric as an unsigned long

Implements knowrob::Numeric.

Definition at line 147 of file Numeric.h.

147 { return static_cast<unsigned long>(numericForm()); }

◆ asUnsignedLong() [2/2]

template<typename T1 , XSDType T2>
unsigned long knowrob::NumericTemplate< T1, T2 >::asUnsignedLong ( ) const
inlineoverridevirtual
Returns
the numeric as an unsigned long

Implements knowrob::Numeric.

Definition at line 147 of file Numeric.h.

147 { return static_cast<unsigned long>(numericForm()); }

◆ asUnsignedShort() [1/2]

template<typename T1 , XSDType T2>
unsigned short knowrob::NumericTemplate< T1, T2 >::asUnsignedShort ( ) const
inlineoverridevirtual
Returns
the numeric as an unsigned short

Implements knowrob::Numeric.

Definition at line 150 of file Numeric.h.

150 { return static_cast<unsigned short>(numericForm()); }

◆ asUnsignedShort() [2/2]

template<typename T1 , XSDType T2>
unsigned short knowrob::NumericTemplate< T1, T2 >::asUnsignedShort ( ) const
inlineoverridevirtual
Returns
the numeric as an unsigned short

Implements knowrob::Numeric.

Definition at line 150 of file Numeric.h.

150 { return static_cast<unsigned short>(numericForm()); }

◆ isSameNumeric() [1/2]

template<typename T1 , XSDType T2>
bool knowrob::NumericTemplate< T1, T2 >::isSameNumeric ( const Numeric other) const
inlineoverridevirtual
Parameters
otheranother numeric
Returns
true if both numerics are equal

Implements knowrob::Numeric.

Definition at line 166 of file Numeric.h.

166  {
167  if (xsdType() != other.xsdType()) {
168  return false;
169  }
170  const auto otherNumeric = static_cast<const NumericTemplate<T1, T2> *>(&other);
171  return numericForm() == otherNumeric->numericForm();
172  }
XSDType xsdType() const
Definition: XSDAtomic.h:43

◆ isSameNumeric() [2/2]

template<typename T1 , XSDType T2>
bool knowrob::NumericTemplate< T1, T2 >::isSameNumeric ( const Numeric other) const
inlineoverridevirtual
Parameters
otheranother numeric
Returns
true if both numerics are equal

Implements knowrob::Numeric.

Definition at line 166 of file Numeric.h.

166  {
167  if (xsdType() != other.xsdType()) {
168  return false;
169  }
170  const auto otherNumeric = static_cast<const NumericTemplate<T1, T2> *>(&other);
171  return numericForm() == otherNumeric->numericForm();
172  }

◆ numericForm() [1/2]

template<typename T1 , XSDType T2>
T1 knowrob::NumericTemplate< T1, T2 >::numericForm ( ) const
inline
Returns
the numeric form of this term.

Definition at line 117 of file Numeric.h.

117  {
118  if (!numericForm_) {
119  std::istringstream iss(*stringForm_);
120  auto &value = numericForm_.emplace();
121  iss >> std::fixed >> value;
122  return value;
123  } else {
124  return numericForm_.value();
125  }
126  }

◆ numericForm() [2/2]

template<typename T1 , XSDType T2>
T1 knowrob::NumericTemplate< T1, T2 >::numericForm ( ) const
inline
Returns
the numeric form of this term.

Definition at line 117 of file Numeric.h.

117  {
118  if (!numericForm_) {
119  std::istringstream iss(*stringForm_);
120  auto &value = numericForm_.emplace();
121  iss >> std::fixed >> value;
122  return value;
123  } else {
124  return numericForm_.value();
125  }
126  }

◆ operator()() [1/2]

template<typename T1 , XSDType T2>
T1 knowrob::NumericTemplate< T1, T2 >::operator() ( ) const
inline

Definition at line 112 of file Numeric.h.

112 { return numericForm(); }

◆ operator()() [2/2]

template<typename T1 , XSDType T2>
T1 knowrob::NumericTemplate< T1, T2 >::operator() ( ) const
inline

Definition at line 112 of file Numeric.h.

112 { return numericForm(); }

◆ stringForm() [1/2]

template<typename T1 , XSDType T2>
std::string_view knowrob::NumericTemplate< T1, T2 >::stringForm ( ) const
inlineoverridevirtual

Get the lexical form of this atomic term.

Returns
the lexical form of this atomic term.

Implements knowrob::Atomic.

Definition at line 156 of file Numeric.h.

156  {
157  if (!stringForm_) {
158  std::ostringstream oss;
159  oss << std::fixed << std::boolalpha << *numericForm_;
160  stringForm_ = oss.str();
161  }
162  return *stringForm_;
163  }

◆ stringForm() [2/2]

template<typename T1 , XSDType T2>
std::string_view knowrob::NumericTemplate< T1, T2 >::stringForm ( ) const
inlineoverridevirtual

Get the lexical form of this atomic term.

Returns
the lexical form of this atomic term.

Implements knowrob::Atomic.

Definition at line 156 of file Numeric.h.

156  {
157  if (!stringForm_) {
158  std::ostringstream oss;
159  oss << std::fixed << std::boolalpha << *numericForm_;
160  stringForm_ = oss.str();
161  }
162  return *stringForm_;
163  }

◆ write() [1/2]

template<typename T1 , XSDType T2>
void knowrob::NumericTemplate< T1, T2 >::write ( std::ostream &  os) const
inlineoverridevirtual

Print this object to a stream.

Parameters
osthe stream to print to.

Reimplemented from knowrob::Atomic.

Definition at line 175 of file Numeric.h.

175 { os << std::defaultfloat << std::boolalpha << numericForm(); }

◆ write() [2/2]

template<typename T1 , XSDType T2>
void knowrob::NumericTemplate< T1, T2 >::write ( std::ostream &  os) const
inlineoverridevirtual

Print this object to a stream.

Parameters
osthe stream to print to.

Reimplemented from knowrob::Atomic.

Definition at line 175 of file Numeric.h.

175 { os << std::defaultfloat << std::boolalpha << numericForm(); }

The documentation for this class was generated from the following file: