| OPTION "[" INTEGER "]" DOTTEXT
{
uint16_t numeric_code = convert_option_code($3, @3, ctx);
- TokenPtr opt(new TokenOption(numeric_code));
+ TokenPtr opt(new TokenOption(numeric_code, TokenOption::TEXTUAL));
ctx.expression.push_back(opt);
}
| SUBSTRING "(" string_expr "," start_expr "," length_expr ")"
TokenPtr tstring;
TokenPtr tequal;
- ASSERT_NO_THROW(toption.reset(new TokenOption(100)));
+ ASSERT_NO_THROW(toption.reset(new TokenOption(100, TokenOption::TEXTUAL)));
e_.push_back(toption);
ASSERT_NO_THROW(tstring.reset(new TokenString("hundred4")));
e_.push_back(tstring);
TokenPtr tequal;
// Get the option, i.e., "hundred[46]"
- ASSERT_NO_THROW(toption.reset(new TokenOption(100)));
+ ASSERT_NO_THROW(toption.reset(new TokenOption(100, TokenOption::TEXTUAL)));
e_.push_back(toption);
// Get substring("hundred[46]", 0, 7), i.e., "hundred"
TokenPtr not_found;
// The packets we use have option 100 with a string in them.
- ASSERT_NO_THROW(found.reset(new TokenOption(100)));
- ASSERT_NO_THROW(not_found.reset(new TokenOption(101)));
+ ASSERT_NO_THROW(found.reset(new TokenOption(100, TokenOption::TEXTUAL)));
+ ASSERT_NO_THROW(not_found.reset(new TokenOption(101, TokenOption::TEXTUAL)));
// This should evaluate to the content of the option 100 (i.e. "hundred4")
ASSERT_NO_THROW(found->evaluate(*pkt4_, values_));
TokenPtr not_found;
// The packets we use have option 100 with a string in them.
- ASSERT_NO_THROW(found.reset(new TokenOption(100)));
- ASSERT_NO_THROW(not_found.reset(new TokenOption(101)));
+ ASSERT_NO_THROW(found.reset(new TokenOption(100, TokenOption::TEXTUAL)));
+ ASSERT_NO_THROW(not_found.reset(new TokenOption(101, TokenOption::TEXTUAL)));
// This should evaluate to the content of the option 100 (i.e. "hundred6")
ASSERT_NO_THROW(found->evaluate(*pkt6_, values_));
/// option. If the option is not found, an empty string ("") is returned.
class TokenOption : public Token {
public:
+
+ /// @brief Token representation type.
+ ///
+ /// There are many possible ways in which option can be presented.
+ /// Currently the textual and hexadecimal representations are
+ /// supported. The type of representation is specified in the
+ /// constructor and it affects the value generated by the
+ /// @c TokenOption::evaluate function.
+ enum RepresentationType {
+ TEXTUAL,
+ HEXADECIMAL
+ };
+
/// @brief Constructor that takes an option code as a parameter
/// @param option_code code of the option
///
/// introduce complex dependency of the libkea-eval on libdhcpsrv.
///
/// @param option_code code of the option to be represented.
- TokenOption(uint16_t option_code)
- :option_code_(option_code) {}
+ /// @param rep_type Token representation type.
+ TokenOption(const uint16_t option_code, const RepresentationType& rep_type)
+ : option_code_(option_code), representation_type_(rep_type) {}
/// @brief Evaluates the values of the option
///
}
private:
- uint16_t option_code_; ///< code of the option to be extracted
+ uint16_t option_code_; ///< Code of the option to be extracted
+ RepresentationType representation_type_; ///< Representation type.
};
/// @brief Token that represents equality operator (compares two other tokens)