11 #include <boost/foreach.hpp>
12 #include <boost/lexical_cast.hpp>
27 for (
auto name : required) {
28 if (scope->contains(name)) {
39 for (
auto entry : scope->mapValue()) {
40 if (keywords.count(entry.first) == 0) {
41 if (spurious.empty()) {
42 spurious = entry.first;
47 if ((expected == Element::any) ||
48 (entry.second->getType() == expected)) {
52 << (expected == Element::integer ?
"an " :
"a ")
53 << Element::typeToName(expected));
55 if (!spurious.empty()) {
65 "missing parameter '" << name <<
"' ("
66 << scope->getPosition() <<
")");
68 if (x->getType() != Element::string) {
70 "invalid type specified for parameter '" << name
71 <<
"' (" << x->getPosition() <<
")");
74 return (x->stringValue());
82 "missing parameter '" << name <<
"' ("
83 << scope->getPosition() <<
")");
85 if (x->getType() != Element::integer) {
87 "invalid type specified for parameter '" << name
88 <<
"' (" << x->getPosition() <<
")");
91 return (x->intValue());
96 int64_t min, int64_t max) {
97 int64_t tmp = getInteger(scope, name);
98 if (tmp < min || tmp > max) {
100 "The '" << name <<
"' value (" << tmp
101 <<
") is not within expected range: (" << min <<
" - " << max
113 "missing parameter '" << name <<
"' ("
114 << scope->getPosition() <<
")");
116 if (x->getType() != Element::boolean) {
118 "invalid type specified for parameter '" << name
119 <<
"' (" << x->getPosition() <<
")");
122 return (x->boolValue());
127 const std::string& name) {
128 std::string str = getString(scope, name);
131 }
catch (
const std::exception& e) {
133 <<
"' to address: " << e.
what() <<
"("
134 << getPosition(name, scope) <<
")");
140 const std::string& name) {
144 "missing parameter '" << name <<
"' ("
145 << scope->getPosition() <<
")");
148 if (x->getType() != Element::real) {
150 "invalid type specified for parameter '" << name
151 <<
"' (" << x->getPosition() <<
")");
154 return (x->doubleValue());
161 return (data::Element::ZERO_POSITION());
165 return (parent->getPosition());
168 return (elem->getPosition());
193 switch (def_value.
type_) {
194 case Element::string: {
198 case Element::integer: {
200 int int_value = boost::lexical_cast<int>(def_value.
value_);
203 catch (
const std::exception& ex) {
205 << def_value.
name_ <<
", value is: "
211 case Element::boolean: {
213 if (def_value.
value_ ==
string(
"true")) {
215 }
else if (def_value.
value_ ==
string(
"false")) {
219 "Internal error. Boolean value specified as "
220 << def_value.
value_ <<
", expected true or false");
225 case Element::real: {
226 double dbl_value = boost::lexical_cast<double>(def_value.
value_);
233 "Internal error. Incorrect default value type.");
237 scope->set(def_value.
name_, x);
248 BOOST_FOREACH(
ElementPtr entry, list->listValue()) {
249 cnt += setDefaults(entry, default_values);
258 if ( (parent->getType() != Element::map) ||
259 (child->getType() != Element::map)) {
264 BOOST_FOREACH(
string param, params) {
272 if (child->get(param)) {
279 child->set(param, x);
288 const std::string& name) {
291 bool has_value =
false;
292 uint32_t min_value = 0;
293 bool has_min =
false;
294 uint32_t max_value = 0;
295 bool has_max =
false;
296 if (scope->contains(name)) {
297 value = getInteger(scope, name);
300 if (scope->contains(
"min-" + name)) {
301 min_value = getInteger(scope,
"min-" + name);
304 if (scope->contains(
"max-" + name)) {
305 max_value = getInteger(scope,
"max-" + name);
308 if (!has_value && !has_min && !has_max) {
312 if (!has_min && !has_max) {
316 }
else if (!has_min) {
319 }
else if (!has_max) {
323 }
else if (has_min) {
327 max_value = min_value;
331 << name <<
" but no " << name <<
" (default) in "
332 << scope->getPosition());
336 min_value = max_value;
340 if (min_value > max_value) {
341 if (has_min && has_max) {
343 << min_value <<
") is not less than max-" << name <<
" ("
344 << max_value <<
")");
345 }
else if (has_min) {
348 << min_value <<
") is not less than (default) " << name
349 <<
" (" << value <<
")");
353 <<
" (" << value <<
") is not less than max-" << name
354 <<
" (" << max_value <<
")");
358 if ((value < min_value) || (value > max_value)) {
360 << value <<
") is not between min-" << name <<
" ("
361 << min_value <<
") and max-" << name <<
" ("
362 << max_value <<
")");
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
The IOAddress class represents an IP addresses (version agnostic)
types
The types that an Element can hold.
Notes: IntElement type is changed to int64_t.
To be removed. Please use ConfigError instead.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
std::vector< std::string > SimpleRequiredKeywords
This specifies all required keywords.
std::vector< std::string > ParamsList
This defines a list of all parameters that are derived (or inherited) between contexts.
boost::shared_ptr< const Element > ConstElementPtr
std::vector< SimpleDefault > SimpleDefaults
This specifies all default values in a given scope (e.g. a subnet).
boost::shared_ptr< Element > ElementPtr
std::map< std::string, isc::data::Element::types > SimpleKeywords
This specifies all accepted keywords with their types.
Defines the logger used by the top-level component of kea-lfc.
Represents the position of the data element within a configuration string.
This array defines a single entry of default values.
const isc::data::Element::types type_