mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-30 21:45:37 +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
|
||||
<< ")");
|
||||
}
|
||||
|
||||
return (tmp);
|
||||
}
|
||||
|
||||
@@ -163,6 +164,7 @@ SimpleParser::getPosition(const std::string& name, const data::ConstElementPtr p
|
||||
if (!elem) {
|
||||
return (parent->getPosition());
|
||||
}
|
||||
|
||||
return (elem->getPosition());
|
||||
}
|
||||
|
||||
@@ -359,8 +361,9 @@ SimpleParser::parseIntTriplet(const ConstElementPtr& scope,
|
||||
<< min_value << ") and max-" << name << " ("
|
||||
<< max_value << ")");
|
||||
}
|
||||
|
||||
return (util::Triplet<uint32_t>(min_value, value, max_value));
|
||||
}
|
||||
|
||||
}; // end of isc::dhcp namespace
|
||||
}; // end of isc namespace
|
||||
} // end of isc::dhcp 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
|
||||
/// spread out in multiple files in multiple directories).
|
||||
class SimpleParser {
|
||||
public:
|
||||
public:
|
||||
|
||||
/// @brief Checks that all required keywords are present.
|
||||
///
|
||||
@@ -333,7 +333,7 @@ public:
|
||||
const std::string& name);
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -81,7 +81,7 @@ struct CfgGlobalsChecks {
|
||||
for (auto it = CfgGlobals::nameToIndex.cbegin();
|
||||
it != CfgGlobals::nameToIndex.cend(); ++it) {
|
||||
int idx = it->second;
|
||||
if ((idx < 0) || (idx > CfgGlobals::MAX_INDEX)) {
|
||||
if ((idx < 0) || (idx >= CfgGlobals::SIZE)) {
|
||||
isc_throw(Unexpected, "invalid index " << idx
|
||||
<< " for name " << it->first);
|
||||
}
|
||||
@@ -93,7 +93,7 @@ struct CfgGlobalsChecks {
|
||||
}
|
||||
|
||||
// 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()) {
|
||||
isc_throw(Unexpected, "missing name for " << idx);
|
||||
}
|
||||
@@ -118,7 +118,7 @@ CfgGlobals::get(const std::string& name) const {
|
||||
|
||||
ConstElementPtr
|
||||
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);
|
||||
}
|
||||
return (values_[index]);
|
||||
@@ -135,7 +135,7 @@ CfgGlobals::set(const std::string& name, ConstElementPtr value) {
|
||||
|
||||
void
|
||||
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);
|
||||
}
|
||||
values_[index] = value;
|
||||
@@ -143,7 +143,7 @@ CfgGlobals::set(int index, ConstElementPtr value) {
|
||||
|
||||
void
|
||||
CfgGlobals::clear() {
|
||||
for (int idx = 0; idx <= MAX_INDEX; ++idx) {
|
||||
for (int idx = 0; idx < CfgGlobals::SIZE; ++idx) {
|
||||
if (values_[idx]) {
|
||||
values_[idx] = ConstElementPtr();
|
||||
}
|
||||
|
@@ -84,17 +84,12 @@ public:
|
||||
DATA_DIRECTORY,
|
||||
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.
|
||||
static const std::map<std::string, int> nameToIndex;
|
||||
|
||||
|
Reference in New Issue
Block a user