knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
knowrob::Token Class Reference

#include <Token.h>

Inheritance diagram for knowrob::Token:
Collaboration diagram for knowrob::Token:

Public Member Functions

 Token (TokenType tokenType)
 
virtual ~Token ()=default
 
TokenType tokenType () const
 
size_t hash () const
 
std::string stringForm () const
 
bool isControlToken () const
 
bool isAnswerToken () const
 
bool indicatesEndOfEvaluation () const
 
void write (std::ostream &os) const override
 
 Token (TokenType tokenType)
 
virtual ~Token ()=default
 
TokenType tokenType () const
 
size_t hash () const
 
std::string stringForm () const
 
bool isControlToken () const
 
bool isAnswerToken () const
 
bool indicatesEndOfEvaluation () const
 
void write (std::ostream &os) const override
 
- Public Member Functions inherited from knowrob::Printable
virtual ~Printable ()=default
 
virtual std::string format () const
 
virtual ~Printable ()=default
 
virtual std::string format () const
 

Protected Attributes

TokenType tokenType_
 
bool isTerminalToken_ = false
 

Detailed Description

A token is a single element in a query evaluation pipeline.

Definition at line 29 of file Token.h.

Constructor & Destructor Documentation

◆ Token() [1/2]

knowrob::Token::Token ( TokenType  tokenType)
inlineexplicit

Definition at line 31 of file Token.h.

31 : tokenType_(tokenType) {};
TokenType tokenType_
Definition: Token.h:69
TokenType tokenType() const
Definition: Token.h:38

◆ ~Token() [1/2]

virtual knowrob::Token::~Token ( )
virtualdefault

◆ Token() [2/2]

knowrob::Token::Token ( TokenType  tokenType)
inlineexplicit

Definition at line 31 of file Token.h.

31 : tokenType_(tokenType) {};

◆ ~Token() [2/2]

virtual knowrob::Token::~Token ( )
virtualdefault

Member Function Documentation

◆ hash() [1/2]

size_t Token::hash ( ) const
Returns
the hash of this token.

Definition at line 15 of file Token.cpp.

15  {
16  size_t val = 0;
17  switch (tokenType()) {
19  // note currently there is only one control token type, so nothing needs to be done here for the moment.
20  hashCombine(val, uint8_t(tokenType()));
21  break;
23  hashCombine(val, ((const Answer *) this)->hashOfAnswer());
24  break;
25  }
26  return val;
27 }
void hashCombine(std::size_t &seed, const std::size_t &v)
Definition: knowrob.cpp:39

◆ hash() [2/2]

size_t knowrob::Token::hash ( ) const
Returns
the hash of this token.

◆ indicatesEndOfEvaluation() [1/2]

bool knowrob::Token::indicatesEndOfEvaluation ( ) const
inline
Returns
true if this token indicates the end of an evaluation.

Definition at line 63 of file Token.h.

63 { return isTerminalToken_; }
bool isTerminalToken_
Definition: Token.h:70

◆ indicatesEndOfEvaluation() [2/2]

bool knowrob::Token::indicatesEndOfEvaluation ( ) const
inline
Returns
true if this token indicates the end of an evaluation.

Definition at line 63 of file Token.h.

63 { return isTerminalToken_; }

◆ isAnswerToken() [1/2]

bool knowrob::Token::isAnswerToken ( ) const
inline
Returns
true if this token is an answer token.

Definition at line 58 of file Token.h.

58 { return tokenType() == TokenType::ANSWER_TOKEN; }

◆ isAnswerToken() [2/2]

bool knowrob::Token::isAnswerToken ( ) const
inline
Returns
true if this token is an answer token.

Definition at line 58 of file Token.h.

58 { return tokenType() == TokenType::ANSWER_TOKEN; }

◆ isControlToken() [1/2]

bool knowrob::Token::isControlToken ( ) const
inline
Returns
true if this token is a control token.

Definition at line 53 of file Token.h.

53 { return tokenType() == TokenType::CONTROL_TOKEN; }

◆ isControlToken() [2/2]

bool knowrob::Token::isControlToken ( ) const
inline
Returns
true if this token is a control token.

Definition at line 53 of file Token.h.

53 { return tokenType() == TokenType::CONTROL_TOKEN; }

◆ stringForm() [1/2]

std::string Token::stringForm ( ) const
Returns
a programmer-readable string representation of this token.

Definition at line 29 of file Token.cpp.

29  {
30  switch (tokenType()) {
32  // note currently there is only one control token type, so nothing needs to be done here for the moment.
33  return "EndOfEvaluation";
35  return ((const Answer *) this)->stringFormOfAnswer();
36  }
37  return "UnknownToken";
38 }

◆ stringForm() [2/2]

std::string knowrob::Token::stringForm ( ) const
Returns
a programmer-readable string representation of this token.

◆ tokenType() [1/2]

TokenType knowrob::Token::tokenType ( ) const
inline
Returns
the type of this token.

Definition at line 38 of file Token.h.

38 { return tokenType_; }

◆ tokenType() [2/2]

TokenType knowrob::Token::tokenType ( ) const
inline
Returns
the type of this token.

Definition at line 38 of file Token.h.

38 { return tokenType_; }

◆ write() [1/2]

void knowrob::Token::write ( std::ostream &  os) const
inlineoverridevirtual

Print this object to a stream.

Parameters
osthe stream to print to.

Implements knowrob::Printable.

Definition at line 66 of file Token.h.

66 { os << stringForm(); }
std::string stringForm() const
Definition: Token.cpp:29

◆ write() [2/2]

void knowrob::Token::write ( std::ostream &  os) const
inlineoverridevirtual

Print this object to a stream.

Parameters
osthe stream to print to.

Implements knowrob::Printable.

Definition at line 66 of file Token.h.

66 { os << stringForm(); }

Member Data Documentation

◆ isTerminalToken_

bool knowrob::Token::isTerminalToken_ = false
protected

Definition at line 70 of file Token.h.

◆ tokenType_

TokenType knowrob::Token::tokenType_
protected

Definition at line 69 of file Token.h.


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