mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-02 06:55:16 +00:00
[#1082] remove MAX_INDEX and use SIZE - 1 instead
This commit is contained in:
@@ -101,6 +101,7 @@ SimpleParser::getInteger(isc::data::ConstElementPtr scope, const std::string& na
|
|||||||
<< ") is not within expected range: (" << min << " - " << max
|
<< ") is not within expected range: (" << min << " - " << max
|
||||||
<< ")");
|
<< ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
return (tmp);
|
return (tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,6 +164,7 @@ SimpleParser::getPosition(const std::string& name, const data::ConstElementPtr p
|
|||||||
if (!elem) {
|
if (!elem) {
|
||||||
return (parent->getPosition());
|
return (parent->getPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
return (elem->getPosition());
|
return (elem->getPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,8 +361,9 @@ SimpleParser::parseIntTriplet(const ConstElementPtr& scope,
|
|||||||
<< min_value << ") and max-" << name << " ("
|
<< min_value << ") and max-" << name << " ("
|
||||||
<< max_value << ")");
|
<< max_value << ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
return (util::Triplet<uint32_t>(min_value, value, max_value));
|
return (util::Triplet<uint32_t>(min_value, value, max_value));
|
||||||
}
|
}
|
||||||
|
|
||||||
}; // end of isc::dhcp namespace
|
} // end of isc::dhcp namespace
|
||||||
}; // end of isc namespace
|
} // end of isc namespace
|
||||||
|
@@ -66,7 +66,7 @@ typedef std::vector<std::string> ParamsList;
|
|||||||
/// they're defined in a single place (the DhcpConfigParser had the defaults
|
/// they're defined in a single place (the DhcpConfigParser had the defaults
|
||||||
/// spread out in multiple files in multiple directories).
|
/// spread out in multiple files in multiple directories).
|
||||||
class SimpleParser {
|
class SimpleParser {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// @brief Checks that all required keywords are present.
|
/// @brief Checks that all required keywords are present.
|
||||||
///
|
///
|
||||||
@@ -333,7 +333,7 @@ public:
|
|||||||
const std::string& name);
|
const std::string& name);
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -81,7 +81,7 @@ struct CfgGlobalsChecks {
|
|||||||
for (auto it = CfgGlobals::nameToIndex.cbegin();
|
for (auto it = CfgGlobals::nameToIndex.cbegin();
|
||||||
it != CfgGlobals::nameToIndex.cend(); ++it) {
|
it != CfgGlobals::nameToIndex.cend(); ++it) {
|
||||||
int idx = it->second;
|
int idx = it->second;
|
||||||
if ((idx < 0) || (idx > CfgGlobals::MAX_INDEX)) {
|
if ((idx < 0) || (idx >= CfgGlobals::SIZE)) {
|
||||||
isc_throw(Unexpected, "invalid index " << idx
|
isc_throw(Unexpected, "invalid index " << idx
|
||||||
<< " for name " << it->first);
|
<< " for name " << it->first);
|
||||||
}
|
}
|
||||||
@@ -93,7 +93,7 @@ struct CfgGlobalsChecks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// No name should be empty.
|
// No name should be empty.
|
||||||
for (int idx = 0; idx <= CfgGlobals::MAX_INDEX; ++idx) {
|
for (int idx = 0; idx < CfgGlobals::SIZE; ++idx) {
|
||||||
if (names[idx].empty()) {
|
if (names[idx].empty()) {
|
||||||
isc_throw(Unexpected, "missing name for " << idx);
|
isc_throw(Unexpected, "missing name for " << idx);
|
||||||
}
|
}
|
||||||
@@ -118,7 +118,7 @@ CfgGlobals::get(const std::string& name) const {
|
|||||||
|
|
||||||
ConstElementPtr
|
ConstElementPtr
|
||||||
CfgGlobals::get(int index) const {
|
CfgGlobals::get(int index) const {
|
||||||
if ((index < 0) || (index > MAX_INDEX)) {
|
if ((index < 0) || (index >= CfgGlobals::SIZE)) {
|
||||||
isc_throw(OutOfRange, "invalid global parameter index " << index);
|
isc_throw(OutOfRange, "invalid global parameter index " << index);
|
||||||
}
|
}
|
||||||
return (values_[index]);
|
return (values_[index]);
|
||||||
@@ -135,7 +135,7 @@ CfgGlobals::set(const std::string& name, ConstElementPtr value) {
|
|||||||
|
|
||||||
void
|
void
|
||||||
CfgGlobals::set(int index, ConstElementPtr value) {
|
CfgGlobals::set(int index, ConstElementPtr value) {
|
||||||
if ((index < 0) || (index > MAX_INDEX)) {
|
if ((index < 0) || (index >= CfgGlobals::SIZE)) {
|
||||||
isc_throw(OutOfRange, "invalid global parameter index " << index);
|
isc_throw(OutOfRange, "invalid global parameter index " << index);
|
||||||
}
|
}
|
||||||
values_[index] = value;
|
values_[index] = value;
|
||||||
@@ -143,7 +143,7 @@ CfgGlobals::set(int index, ConstElementPtr value) {
|
|||||||
|
|
||||||
void
|
void
|
||||||
CfgGlobals::clear() {
|
CfgGlobals::clear() {
|
||||||
for (int idx = 0; idx <= MAX_INDEX; ++idx) {
|
for (int idx = 0; idx < CfgGlobals::SIZE; ++idx) {
|
||||||
if (values_[idx]) {
|
if (values_[idx]) {
|
||||||
values_[idx] = ConstElementPtr();
|
values_[idx] = ConstElementPtr();
|
||||||
}
|
}
|
||||||
|
@@ -84,17 +84,12 @@ public:
|
|||||||
DATA_DIRECTORY,
|
DATA_DIRECTORY,
|
||||||
PREFERRED_LIFETIME,
|
PREFERRED_LIFETIME,
|
||||||
MIN_PREFERRED_LIFETIME,
|
MIN_PREFERRED_LIFETIME,
|
||||||
MAX_PREFERRED_LIFETIME
|
MAX_PREFERRED_LIFETIME,
|
||||||
|
|
||||||
|
// Size sentinel.
|
||||||
|
SIZE
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Last index.
|
|
||||||
///
|
|
||||||
/// @note: please update when a new element is appended to the Index enum.
|
|
||||||
static const int MAX_INDEX = MAX_PREFERRED_LIFETIME;
|
|
||||||
|
|
||||||
/// @brief Size of configured global objects.
|
|
||||||
static const size_t SIZE = MAX_INDEX + 1;
|
|
||||||
|
|
||||||
/// @brief Name to index map.
|
/// @brief Name to index map.
|
||||||
static const std::map<std::string, int> nameToIndex;
|
static const std::map<std::string, int> nameToIndex;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user