Kea  1.5.0
eval_context.h
Go to the documentation of this file.
1 // Copyright (C) 2015-2018 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef EVAL_CONTEXT_H
8 #define EVAL_CONTEXT_H
9 #include <string>
10 #include <map>
11 #include <eval/parser.h>
12 #include <eval/eval_context_decl.h>
13 #include <exceptions/exceptions.h>
14 
15 // Tell Flex the lexer's prototype ...
16 #define YY_DECL \
17  isc::eval::EvalParser::symbol_type evallex (EvalContext& driver)
18 
19 // ... and declare it for the parser's sake.
21 
22 namespace isc {
23 namespace eval {
24 
27 public:
28  EvalParseError(const char* file, size_t line, const char* what) :
29  isc::Exception(file, line, what) { };
30 };
31 
32 
35 {
36 public:
37 
39  typedef enum {
43 
45  typedef std::function<bool(const ClientClass&)> CheckDefined;
46 
55  EvalContext(const Option::Universe& option_universe,
56  CheckDefined check_defined = acceptAll);
57 
59  virtual ~EvalContext();
60 
65  static bool acceptAll(const ClientClass& client_class);
66 
69 
74 
76  void scanStringEnd();
77 
83  bool parseString(const std::string& str, ParserType type = PARSER_BOOL);
84 
87  std::string file_;
88 
90  std::string string_;
91 
96  static void error(const isc::eval::location& loc, const std::string& what);
97 
102  static void error(const std::string& what);
103 
107  static void fatal(const std::string& what);
108 
116  uint16_t convertOptionCode(const std::string& option_code,
117  const isc::eval::location& loc);
118 
125  uint16_t convertOptionName(const std::string& option_name,
126  const isc::eval::location& loc);
127 
136  static uint32_t convertUint32(const std::string& number,
137  const isc::eval::location& loc);
138 
145  static uint8_t convertUint8(const std::string& number,
146  const isc::eval::location& loc);
147 
154  static int8_t convertInt8(const std::string& number,
155  const isc::eval::location& loc);
156 
164  int8_t convertNestLevelNumber(const std::string& nest_level,
165  const isc::eval::location& loc);
166 
175  static std::string fromUint32(const uint32_t integer);
176 
181  return (option_universe_);
182  }
183 
188  bool isClientClassDefined(const ClientClass& client_class);
189 
190  private:
192  bool trace_scanning_;
193 
195  bool trace_parsing_;
196 
201  Option::Universe option_universe_;
202 
204  CheckDefined check_defined_;
205 
206 };
207 
208 }; // end of isc::eval namespace
209 }; // end of isc namespace
210 
211 #endif
isc::eval::EvalContext::getUniverse
Option::Universe getUniverse()
Returns the universe (v4 or v6)
Definition: eval_context.h:180
isc::dhcp::Expression
std::vector< TokenPtr > Expression
This is a structure that holds an expression converted to RPN.
Definition: token.h:28
isc::eval::EvalContext::scanStringBegin
void scanStringBegin(ParserType type)
Method called before scanning starts on a string.
isc::eval::EvalContext::CheckDefined
std::function< bool(const ClientClass &)> CheckDefined
Type of the check defined function.
Definition: eval_context.h:45
isc::eval::EvalContext::convertUint8
static uint8_t convertUint8(const std::string &number, const isc::eval::location &loc)
Attempts to convert string to unsigned 8bit integer.
Definition: eval_context.cc:135
isc::eval::EvalContext::convertOptionCode
uint16_t convertOptionCode(const std::string &option_code, const isc::eval::location &loc)
Option code conversion.
Definition: eval_context.cc:69
isc::eval::EvalContext::convertUint32
static uint32_t convertUint32(const std::string &number, const isc::eval::location &loc)
Attempts to convert string to unsigned 32bit integer.
Definition: eval_context.cc:172
isc::eval::EvalContext::expression
isc::dhcp::Expression expression
Parsed expression (output tokens are stored here)
Definition: eval_context.h:68
isc::Exception
This is a base class for exceptions thrown from the DNS library module.
Definition: exceptions/exceptions.h:23
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
isc::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition: exceptions/exceptions.cc:32
isc::eval::EvalParseError
Evaluation error exception raised when trying to parse an exceptions.
Definition: eval_context.h:26
eval_context_decl.h
isc::eval::EvalContext::parseString
bool parseString(const std::string &str, ParserType type=PARSER_BOOL)
Run the parser on the string specified.
Definition: eval_context.cc:38
isc::eval::EvalContext::fromUint32
static std::string fromUint32(const uint32_t integer)
Converts integer to string representation.
Definition: eval_context.cc:190
YY_DECL
#define YY_DECL
Definition: eval_context.h:16
isc::eval::EvalContext::convertInt8
static int8_t convertInt8(const std::string &number, const isc::eval::location &loc)
Attempts to convert string to signed 8bit integer.
Definition: eval_context.cc:153
isc::eval::EvalContext::scanStringEnd
void scanStringEnd()
Method called after the last tokens are scanned from a string.
isc::eval::EvalContext::error
static void error(const isc::eval::location &loc, const std::string &what)
Error handler.
Definition: eval_context.cc:57
isc::eval::EvalContext::string_
std::string string_
The string being parsed.
Definition: eval_context.h:90
isc::eval::EvalContext::isClientClassDefined
bool isClientClassDefined(const ClientClass &client_class)
Check if a client class is already defined.
Definition: eval_context.cc:201
isc::eval::EvalContext::EvalContext
EvalContext(const Option::Universe &option_universe, CheckDefined check_defined=acceptAll)
Default constructor.
Definition: eval_context.cc:21
isc::eval::EvalContext::ParserType
ParserType
Specifies what type of expression the parser is expected to see.
Definition: eval_context.h:39
parser.h
isc::dhcp::ClientClass
std::string ClientClass
Defines a single class name.
Definition: classify.h:37
isc::eval::EvalContext::convertNestLevelNumber
int8_t convertNestLevelNumber(const std::string &nest_level, const isc::eval::location &loc)
Nest level conversion.
Definition: eval_context.cc:118
isc::eval::EvalContext
Evaluation context, an interface to the expression evaluation.
Definition: eval_context.h:35
isc::eval::EvalContext::convertOptionName
uint16_t convertOptionName(const std::string &option_name, const isc::eval::location &loc)
Option name conversion.
Definition: eval_context.cc:94
exceptions.h
isc::eval::EvalContext::fatal
static void fatal(const std::string &what)
Fatal error handler.
Definition: eval_context.cc:206
isc::dhcp::Option::Universe
Universe
defines option universe DHCPv4 or DHCPv6
Definition: option.h:67
isc::eval::EvalContext::acceptAll
static bool acceptAll(const ClientClass &client_class)
Accept all client class names.
Definition: eval_context.cc:33
isc::eval::EvalContext::PARSER_BOOL
@ PARSER_BOOL
expression is expected to evaluate to bool
Definition: eval_context.h:40
isc::eval::EvalParseError::EvalParseError
EvalParseError(const char *file, size_t line, const char *what)
Definition: eval_context.h:28
isc::eval::EvalContext::file_
std::string file_
The name of the file being parsed.
Definition: eval_context.h:87
isc::eval::EvalContext::PARSER_STRING
@ PARSER_STRING
expression is expected to evaluate to string
Definition: eval_context.h:41
isc::eval::EvalContext::~EvalContext
virtual ~EvalContext()
destructor
Definition: eval_context.cc:28