knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
Token.h
Go to the documentation of this file.
1 /*
2  * This file is part of KnowRob, please consult
3  * https://github.com/knowrob/knowrob for license details.
4  */
5 
6 #ifndef KNOWROB_TOKEN_H
7 #define KNOWROB_TOKEN_H
8 
9 #include <memory>
10 #include <map>
11 #include <vector>
12 #include <string>
13 #include "knowrob/Printable.h"
14 
15 namespace knowrob {
19  enum class TokenType : uint8_t {
20  // A control token is used to control the evaluation pipeline.
21  CONTROL_TOKEN = 0,
22  // An answer token is the result of a query evaluation.
24  };
25 
29  class Token : public Printable {
30  public:
32 
33  virtual ~Token() = default;
34 
38  TokenType tokenType() const { return tokenType_; }
39 
43  size_t hash() const;
44 
49 
53  bool isControlToken() const { return tokenType() == TokenType::CONTROL_TOKEN; }
54 
58  bool isAnswerToken() const { return tokenType() == TokenType::ANSWER_TOKEN; }
59 
63  bool indicatesEndOfEvaluation() const { return isTerminalToken_; }
64 
65  // Printable interface
66  void write(std::ostream &os) const override { os << stringForm(); }
67 
68  protected:
70  bool isTerminalToken_ = false;
71  };
72 
73  // alias
74  using TokenPtr = std::shared_ptr<const Token>;
75  using TokenMap = std::map<uint32_t, std::vector<TokenPtr>>;
76 }
77 
78 #endif //KNOWROB_TOKEN_H
Token(TokenType tokenType)
Definition: Token.h:31
bool isControlToken() const
Definition: Token.h:53
void write(std::ostream &os) const override
Definition: Token.h:66
virtual ~Token()=default
TokenType tokenType_
Definition: Token.h:69
TokenType tokenType() const
Definition: Token.h:38
size_t hash() const
std::string stringForm() const
bool indicatesEndOfEvaluation() const
Definition: Token.h:63
bool isTerminalToken_
Definition: Token.h:70
std::string stringForm() const
Definition: Token.cpp:29
bool isAnswerToken() const
Definition: Token.h:58
TermRule & string()
Definition: terms.cpp:63
std::shared_ptr< const Token > TokenPtr
Definition: Token.h:74
std::map< uint32_t, std::vector< TokenPtr > > TokenMap
Definition: Token.h:75
TokenType
Definition: Token.h:19