]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#4288] Removed variants
authorFrancis Dupont <fdupont@isc.org>
Wed, 7 Jan 2026 17:26:55 +0000 (18:26 +0100)
committerFrancis Dupont <fdupont@isc.org>
Wed, 7 Jan 2026 17:26:55 +0000 (18:26 +0100)
src/lib/cc/data.cc
src/lib/cc/data.h
src/lib/cc/tests/data_unittests.cc

index ae261d0405552f96163397fef459c414f2c15f1c..5b9fdb263a54d4a648bf6dd5f377b39fca258ab0 100644 (file)
@@ -54,7 +54,7 @@ operator<<(std::ostream& out, const Element::Position& pos) {
 }
 
 void
-Element::removeEmptyContainersRecursively0(unsigned level) {
+Element::removeEmptyContainersRecursively(unsigned level) {
     if (level <= 0) {
         // Cycles are by definition not empty so no need to throw.
         return;
@@ -87,7 +87,7 @@ Element::removeEmptyContainersRecursively0(unsigned level) {
 
             // Recurse if not empty.
             if (!child->empty()){
-                child->removeEmptyContainersRecursively0(level - 1);
+                child->removeEmptyContainersRecursively(level - 1);
             }
 
             // When returning from recursion, remove if empty.
@@ -662,7 +662,7 @@ fromStringstreamList(std::istream& in, const std::string& file, int& line,
     while (c != EOF && c != ']') {
         if (in.peek() != ']') {
             cur_list_element =
-                Element::fromJSON0(in, file, line, pos, level - 1);
+                Element::fromJSON(in, file, line, pos, level - 1);
             list->add(cur_list_element);
             c = skipTo(in, file, line, pos, ",]", WHITESPACE);
         } else {
@@ -695,7 +695,7 @@ fromStringstreamMap(std::istream& in, const std::string& file, int& line,
             // skip the :
 
             ConstElementPtr value =
-                Element::fromJSON0(in, file, line, pos, level - 1);
+                Element::fromJSON(in, file, line, pos, level - 1);
             map->set(key, value);
 
             c = skipTo(in, file, line, pos, ",}", WHITESPACE);
@@ -784,13 +784,7 @@ Element::fromJSON(std::istream& in, const std::string& file_name, bool preproc)
 
 ElementPtr
 Element::fromJSON(std::istream& in, const std::string& file, int& line,
-                  int& pos) {
-    return (Element::fromJSON0(in, file, line, pos, Element::MAX_NESTING_LEVEL));
-}
-
-ElementPtr
-Element::fromJSON0(std::istream& in, const std::string& file, int& line,
-                   int& pos, unsigned level) {
+                  int& pos, unsigned level) {
     if (level == 0) {
         isc_throw(JSONError, "fromJSON elements nested too deeply");
     }
@@ -898,32 +892,17 @@ Element::fromJSONFile(const std::string& file_name, bool preproc) {
 // to JSON format
 
 void
-IntElement::toJSON(std::ostream& ss) const {
-    IntElement::toJSON0(ss, 1);
-}
-
-void
-IntElement::toJSON0(std::ostream& ss, unsigned) const {
+IntElement::toJSON(std::ostream& ss, unsigned) const {
     ss << intValue();
 }
 
 void
-BigIntElement::toJSON(std::ostream& ss) const {
-    BigIntElement::toJSON0(ss, 1);
-}
-
-void
-BigIntElement::toJSON0(std::ostream& ss, unsigned) const {
+BigIntElement::toJSON(std::ostream& ss, unsigned) const {
     ss << bigIntValue();
 }
 
 void
-DoubleElement::toJSON(std::ostream& ss) const {
-    DoubleElement::toJSON0(ss, 1);
-}
-
-void
-DoubleElement::toJSON0(std::ostream& ss, unsigned) const {
+DoubleElement::toJSON(std::ostream& ss, unsigned) const {
     // The default output for doubles nicely drops off trailing
     // zeros, however this produces strings without decimal points
     // for whole number values.  When reparsed this will create
@@ -939,12 +918,7 @@ DoubleElement::toJSON0(std::ostream& ss, unsigned) const {
 }
 
 void
-BoolElement::toJSON(std::ostream& ss) const {
-    BoolElement::toJSON0(ss, 1);
-}
-
-void
-BoolElement::toJSON0(std::ostream& ss, unsigned) const {
+BoolElement::toJSON(std::ostream& ss, unsigned) const {
     if (boolValue()) {
         ss << "true";
     } else {
@@ -953,22 +927,12 @@ BoolElement::toJSON0(std::ostream& ss, unsigned) const {
 }
 
 void
-NullElement::toJSON(std::ostream& ss) const {
-    NullElement::toJSON0(ss, 1);
-}
-
-void
-    NullElement::toJSON0(std::ostream& ss, unsigned) const {
+NullElement::toJSON(std::ostream& ss, unsigned) const {
     ss << "null";
 }
 
 void
-StringElement::toJSON(std::ostream& ss) const {
-    StringElement::toJSON0(ss, 1);
-}
-
-void
-StringElement::toJSON0(std::ostream& ss, unsigned) const {
+StringElement::toJSON(std::ostream& ss, unsigned) const {
     ss << "\"";
     const std::string& str = stringValue();
     for (size_t i = 0; i < str.size(); ++i) {
@@ -1016,12 +980,7 @@ StringElement::toJSON0(std::ostream& ss, unsigned) const {
 }
 
 void
-ListElement::toJSON(std::ostream& ss) const {
-    ListElement::toJSON0(ss, Element::MAX_NESTING_LEVEL);
-}
-
-void
-ListElement::toJSON0(std::ostream& ss, unsigned level) const {
+ListElement::toJSON(std::ostream& ss, unsigned level) const {
     if (level == 0) {
         isc_throw(BadValue, "toJSON got infinite recursion: "
                   "arguments include cycles");
@@ -1036,18 +995,13 @@ ListElement::toJSON0(std::ostream& ss, unsigned level) const {
         } else {
             first = false;
         }
-        it->toJSON0(ss, level - 1);
+        it->toJSON(ss, level - 1);
     }
     ss << " ]";
 }
 
 void
-MapElement::toJSON(std::ostream& ss) const {
-    MapElement::toJSON0(ss, Element::MAX_NESTING_LEVEL);
-}
-
-void
-MapElement::toJSON0(std::ostream& ss, unsigned level) const {
+MapElement::toJSON(std::ostream& ss, unsigned level) const {
     if (level == 0) {
         isc_throw(BadValue, "toJSON got infinite recursion: "
                   "arguments include cycles");
@@ -1063,7 +1017,7 @@ MapElement::toJSON0(std::ostream& ss, unsigned level) const {
         }
         ss << "\"" << it.first << "\": ";
         if (it.second) {
-            it.second->toJSON0(ss, level - 1);
+            it.second->toJSON(ss, level - 1);
         } else {
             ss << "None";
         }
@@ -1139,7 +1093,7 @@ MapElement::find(const std::string& id, ConstElementPtr& t) const {
 }
 
 bool
-IntElement::equals(const Element& other) const {
+IntElement::equals(const Element& other, unsigned) const {
     // Let's not be very picky with constraining the integer types to be the
     // same. Equality is sometimes checked from high-up in the Element hierarchy.
     // That is a context which, most of the time, does not have information on
@@ -1150,12 +1104,7 @@ IntElement::equals(const Element& other) const {
 }
 
 bool
-IntElement::equals0(const Element& other, unsigned) const {
-    return (IntElement::equals(other));
-}
-
-bool
-BigIntElement::equals(const Element& other) const {
+BigIntElement::equals(const Element& other, unsigned) const {
     // Let's not be very picky with constraining the integer types to be the
     // same. Equality is sometimes checked from high-up in the Element hierarchy.
     // That is a context which, most of the time, does not have information on
@@ -1166,60 +1115,30 @@ BigIntElement::equals(const Element& other) const {
 }
 
 bool
-BigIntElement::equals0(const Element& other, unsigned) const {
-    return (BigIntElement::equals(other));
-}
-
-bool
-DoubleElement::equals(const Element& other) const {
+DoubleElement::equals(const Element& other, unsigned) const {
     return (other.getType() == Element::real) &&
            (fabs(d - other.doubleValue()) < 1e-14);
 }
 
 bool
-DoubleElement::equals0(const Element& other, unsigned) const {
-    return (DoubleElement::equals(other));
-}
-
-bool
-BoolElement::equals(const Element& other) const {
+BoolElement::equals(const Element& other, unsigned) const {
     return (other.getType() == Element::boolean) &&
            (b == other.boolValue());
 }
 
 bool
-BoolElement::equals0(const Element& other, unsigned) const {
-    return (BoolElement::equals(other));
-}
-
-bool
-NullElement::equals(const Element& other) const {
+NullElement::equals(const Element& other, unsigned) const {
     return (other.getType() == Element::null);
 }
 
 bool
-NullElement::equals0(const Element& other, unsigned) const {
-    return (NullElement::equals(other));
-}
-
-bool
-StringElement::equals(const Element& other) const {
+StringElement::equals(const Element& other, unsigned) const {
     return (other.getType() == Element::string) &&
            (s == other.stringValue());
 }
 
 bool
-StringElement::equals0(const Element& other, unsigned) const {
-    return (StringElement::equals(other));
-}
-
-bool
-ListElement::equals(const Element& other) const {
-    return (ListElement::equals0(other, Element::MAX_NESTING_LEVEL));
-}
-
-bool
-ListElement::equals0(const Element& other, unsigned level) const {
+ListElement::equals(const Element& other, unsigned level) const {
     if (level == 0) {
         isc_throw(BadValue, "equals got infinite recursion: "
                   "arguments include cycles");
@@ -1230,7 +1149,7 @@ ListElement::equals0(const Element& other, unsigned level) const {
             return (false);
         }
         for (size_t i = 0; i < s; ++i) {
-            if (!get(i)->equals0(*other.get(i), level - 1)) {
+            if (!get(i)->equals(*other.get(i), level - 1)) {
                 return (false);
             }
         }
@@ -1277,12 +1196,7 @@ ListElement::sort(std::string const& index /* = std::string() */) {
 }
 
 bool
-MapElement::equals(const Element& other) const {
-    return (MapElement::equals0(other, Element::MAX_NESTING_LEVEL));
-}
-
-bool
-MapElement::equals0(const Element& other, unsigned level) const {
+MapElement::equals(const Element& other, unsigned level) const {
     if (level == 0) {
         isc_throw(BadValue, "equals got infinite recursion: "
                   "arguments include cycles");
@@ -1294,7 +1208,7 @@ MapElement::equals0(const Element& other, unsigned level) const {
         for (auto const& kv : mapValue()) {
             auto key = kv.first;
             if (other.contains(key)) {
-                if (!get(key)->equals0(*other.get(key), level - 1)) {
+                if (!get(key)->equals(*other.get(key), level - 1)) {
                     return (false);
                 }
             } else {
@@ -1378,15 +1292,8 @@ merge(ElementPtr element, ConstElementPtr other) {
 
 void
 mergeDiffAdd(ElementPtr& element, ElementPtr& other,
-             HierarchyDescriptor& hierarchy, std::string key, size_t idx) {
-    mergeDiffAdd0(element, other, hierarchy, key, idx,
-                  Element::MAX_NESTING_LEVEL);
-}
-
-void
-mergeDiffAdd0(ElementPtr& element, ElementPtr& other,
-              HierarchyDescriptor& hierarchy, std::string key, size_t idx,
-              unsigned level) {
+             HierarchyDescriptor& hierarchy, std::string key, size_t idx,
+             unsigned level) {
     if (level == 0) {
         isc_throw(BadValue, "mergeDiffAdd got infinite recursion: "
                   "arguments include cycles");
@@ -1412,8 +1319,8 @@ mergeDiffAdd0(ElementPtr& element, ElementPtr& other,
                     // entity.
                     if (f->second.match_(mutable_left, mutable_right)) {
                         found = true;
-                        mergeDiffAdd0(mutable_left, mutable_right, hierarchy,
-                                      key, idx, level - 1);
+                        mergeDiffAdd(mutable_left, mutable_right, hierarchy,
+                                     key, idx, level - 1);
                     }
                 }
                 if (!found) {
@@ -1439,8 +1346,8 @@ mergeDiffAdd0(ElementPtr& element, ElementPtr& other,
                     (value->getType() == Element::map ||
                      value->getType() == Element::list)) {
                     ElementPtr mutable_element = boost::const_pointer_cast<Element>(element->get(current_key));
-                    mergeDiffAdd0(mutable_element, value, hierarchy,
-                                  current_key, idx + 1, level - 1);
+                    mergeDiffAdd(mutable_element, value, hierarchy,
+                                 current_key, idx + 1, level - 1);
                 } else {
                     element->set(current_key, value);
                 }
@@ -1453,15 +1360,8 @@ mergeDiffAdd0(ElementPtr& element, ElementPtr& other,
 
 void
 mergeDiffDel(ElementPtr& element, ElementPtr& other,
-             HierarchyDescriptor& hierarchy, std::string key, size_t idx) {
-    mergeDiffDel0(element, other, hierarchy, key, idx,
-                  Element::MAX_NESTING_LEVEL);
-}
-
-void
-mergeDiffDel0(ElementPtr& element, ElementPtr& other,
-              HierarchyDescriptor& hierarchy, std::string key, size_t idx,
-              unsigned level) {
+             HierarchyDescriptor& hierarchy, std::string key, size_t idx,
+             unsigned level) {
     if (level == 0) {
         isc_throw(BadValue, "mergeDiffDel got infinite recursion: "
                   "arguments include cycles");
@@ -1490,8 +1390,8 @@ mergeDiffDel0(ElementPtr& element, ElementPtr& other,
                             element->remove(iter);
                             removed = true;
                         } else {
-                            mergeDiffDel0(mutable_left, mutable_right,
-                                          hierarchy, key, idx, level - 1);
+                            mergeDiffDel(mutable_left, mutable_right,
+                                         hierarchy, key, idx, level - 1);
                             if (mutable_left->empty()) {
                                 element->remove(iter);
                                 removed = true;
@@ -1522,8 +1422,8 @@ mergeDiffDel0(ElementPtr& element, ElementPtr& other,
                     ElementPtr mutable_element = boost::const_pointer_cast<Element>(element->get(current_key));
                     if (mutable_element->getType() == Element::map ||
                         mutable_element->getType() == Element::list) {
-                        mergeDiffDel0(mutable_element, value, hierarchy,
-                                      current_key, idx + 1, level - 1);
+                        mergeDiffDel(mutable_element, value, hierarchy,
+                                     current_key, idx + 1, level - 1);
                         if (mutable_element->empty()) {
                             element->remove(current_key);
                         }
@@ -1558,15 +1458,7 @@ mergeDiffDel0(ElementPtr& element, ElementPtr& other,
 void
 extend(const std::string& container, const std::string& extension,
        ElementPtr& element, ElementPtr& other, HierarchyDescriptor& hierarchy,
-       std::string key, size_t idx, bool alter) {
-    extend0(container, extension, element, other, hierarchy, key, idx, alter,
-            Element::MAX_NESTING_LEVEL);
-}
-
-void
-extend0(const std::string& container, const std::string& extension,
-        ElementPtr& element, ElementPtr& other, HierarchyDescriptor& hierarchy,
-        std::string key, size_t idx, bool alter, unsigned level) {
+       std::string key, size_t idx, bool alter, unsigned level) {
 
     if (level == 0) {
         isc_throw(BadValue, "extend got infinite recursion: "
@@ -1589,8 +1481,8 @@ extend0(const std::string& container, const std::string& extension,
                         alter = true;
                     }
                     if (f->second.match_(mutable_left, mutable_right)) {
-                        extend0(container, extension, mutable_left, mutable_right,
-                                hierarchy, key, idx, alter, level - 1);
+                        extend(container, extension, mutable_left, mutable_right,
+                               hierarchy, key, idx, alter, level - 1);
                     }
                 }
             }
@@ -1610,8 +1502,8 @@ extend0(const std::string& container, const std::string& extension,
                     if (container == key) {
                         alter = true;
                     }
-                    extend0(container, extension, mutable_element, value,
-                            hierarchy, current_key, idx + 1, alter, level - 1);
+                    extend(container, extension, mutable_element, value,
+                           hierarchy, current_key, idx + 1, alter, level - 1);
                 } else if (alter && current_key == extension) {
                     element->set(current_key, value);
                 }
index 68c68d1107bf73190a763661c411d122891d17fb..d0d2d851066e8b2456c8dcb737124a66f84510d9 100644 (file)
@@ -247,40 +247,21 @@ public:
     /// @brief Test equality.
     ///
     /// @param other The other element to compare with.
-    /// @return true if the other ElementPtr has the same value and the same
-    /// type (or a different and compatible type), false otherwise.
-    /// @throw BadValue when there are more than MAX_NESTING_LEVEL nesting
-    /// levels, e.g. when arguments contain a cycle.
-    virtual bool equals(const Element& other) const = 0;
-
-    /// @brief Test equality.
-    ///
-    /// @note: Variant with nesting depth: to be used only in tests.
-    ///
-    /// @param other The other element to compare with.
     /// @param level The maximum level of recursion.
     /// @return true if the other ElementPtr has the same value and the same
     /// type (or a different and compatible type), false otherwise.
     /// @throw BadValue when nesting depth is more than level.
-    virtual bool equals0(const Element& other, unsigned level) const = 0;
-
-    /// @brief Converts the Element to JSON format and appends it to
-    /// the given output stream.
-    ///
-    /// @param ss The output stream where to append the JSON format.
-    /// @throw BadValue when there are more than MAX_NESTING_LEVEL nesting
-    /// levels, e.g. when arguments contain a cycle.
-    virtual void toJSON(std::ostream& ss) const = 0;
+    virtual bool equals(const Element& other,
+                        unsigned level = MAX_NESTING_LEVEL) const = 0;
 
     /// @brief Converts the Element to JSON format and appends it to
     /// the given output stream.
     ///
-    /// @note: Variant with nesting depth: to be used only in tests.
-    ///
     /// @param ss The output stream where to append the JSON format.
     /// @param level The maximum level of recursion.
     /// @throw BadValue when nesting depth is more than level.
-    virtual void toJSON0(std::ostream& ss, unsigned level) const = 0;
+    virtual void toJSON(std::ostream& ss,
+                        unsigned level = MAX_NESTING_LEVEL) const = 0;
 
     /// @name Type-specific getters
     ///
@@ -695,12 +676,14 @@ public:
     /// track of the current line.
     /// @param pos A reference to the int where the function keeps
     /// track of the current position within the current line.
+    /// @param level The maximum level of recursion.
     /// @return An ElementPtr that contains the element(s) specified
     /// in the given input stream.
     // make this one private?
     /// @throw JSONError
     static ElementPtr fromJSON(std::istream& in, const std::string& file,
-                               int& line, int &pos);
+                               int& line, int &pos,
+                               unsigned level = MAX_NESTING_LEVEL);
 
     /// @brief Creates an Element from the given input stream.
     ///
@@ -711,12 +694,10 @@ public:
     /// track of the current line.
     /// @param pos A reference to the int where the function keeps
     /// track of the current position within the current line.
-    /// @param level The maximum level of recursion.
+
     /// @return An ElementPtr that contains the element(s) specified
     /// in the given input stream.
     /// @throw JSONError
-    static ElementPtr fromJSON0(std::istream& in, const std::string& file,
-                                int& line, int &pos, unsigned level);
 
     /// Reads contents of specified file and interprets it as JSON.
     ///
@@ -791,18 +772,9 @@ public:
 
     /// @brief Remove all empty maps and lists from this Element and its
     /// descendants.
-    void removeEmptyContainersRecursively() {
-        removeEmptyContainersRecursively0(MAX_NESTING_LEVEL);
-    }
-
-protected:
-    /// Converts the Element to JSON format and appends it to
-    /// the given stringstream.
-
-    /// @brief Remove all empty maps and lists from this Element and its
-    /// descendants.
+    ///
     /// @param level nesting level.
-    void removeEmptyContainersRecursively0(unsigned level);
+    void removeEmptyContainersRecursively(unsigned level = MAX_NESTING_LEVEL);
 };
 
 /// Notes: IntElement type is changed to int64_t.
@@ -825,10 +797,10 @@ public:
     bool getValue(int64_t& t) const { t = i; return (true); }
     using Element::setValue;
     bool setValue(long long int v) { i = v; return (true); }
-    void toJSON(std::ostream& ss) const;
-    bool equals(const Element& other) const;
-    void toJSON0(std::ostream& ss, unsigned) const;
-    bool equals0(const Element& other, unsigned) const;
+    void toJSON(std::ostream& ss,
+                unsigned level = MAX_NESTING_LEVEL) const;
+    bool equals(const Element& other,
+                unsigned level = MAX_NESTING_LEVEL) const;
 };
 
 /// @brief Wrapper over int128_t
@@ -862,32 +834,18 @@ public:
     /// stringstream.
     ///
     /// @param ss The output stream where to append the JSON format.
-    void toJSON(std::ostream& ss) const override;
-
-    /// @brief Converts the Element to JSON format and appends it to the given
-    /// stringstream.
-    ///
-    /// @note: Variant with nesting depth: to be used only in tests.
-    /// @param ss The output stream where to append the JSON format.
     /// @param level The maximum level of recursion. Ignored.
-    void toJSON0(std::ostream& ss, unsigned level) const override;
+    void toJSON(std::ostream& ss,
+                unsigned level = MAX_NESTING_LEVEL) const override;
 
     /// @brief Checks whether the other Element is equal.
     ///
     /// @param other The other element to compare with.
-    /// @return true if the other ElementPtr has the same value and the same
-    /// type (or a different and compatible type), false otherwise.
-    bool equals(const Element& other) const override;
-
-    /// @brief Checks whether the other Element is equal.
-    ///
-    /// @note: Variant with nesting depth: to be used only in tests.
-    ///
-    /// @param other The other element to compare with.
     /// @param level The maximum level of recursion. Ignored.
     /// @return true if the other ElementPtr has the same value and the same
     /// type (or a different and compatible type), false otherwise.
-    bool equals0(const Element& other, unsigned level) const override;
+    bool equals(const Element& other,
+                unsigned level = MAX_NESTING_LEVEL) const override;
 
 private:
     /// @brief the underlying stored value
@@ -905,10 +863,10 @@ public:
     bool getValue(double& t) const { t = d; return (true); }
     using Element::setValue;
     bool setValue(const double v) { d = v; return (true); }
-    void toJSON(std::ostream& ss) const;
-    bool equals(const Element& other) const;
-    void toJSON0(std::ostream& ss, unsigned) const;
-    bool equals0(const Element& other, unsigned) const;
+    void toJSON(std::ostream& ss,
+                unsigned level = MAX_NESTING_LEVEL) const;
+    bool equals(const Element& other,
+                unsigned level = MAX_NESTING_LEVEL) const;
 };
 
 class BoolElement : public Element {
@@ -922,20 +880,20 @@ public:
     bool getValue(bool& t) const { t = b; return (true); }
     using Element::setValue;
     bool setValue(const bool v) { b = v; return (true); }
-    void toJSON(std::ostream& ss) const;
-    bool equals(const Element& other) const;
-    void toJSON0(std::ostream& ss, unsigned) const;
-    bool equals0(const Element& other, unsigned) const;
+    void toJSON(std::ostream& ss,
+                unsigned level = MAX_NESTING_LEVEL) const;
+    bool equals(const Element& other,
+                unsigned level = MAX_NESTING_LEVEL) const;
 };
 
 class NullElement : public Element {
 public:
     NullElement(const Position& pos = ZERO_POSITION())
         : Element(null, pos) {}
-    void toJSON(std::ostream& ss) const;
-    bool equals(const Element& other) const;
-    void toJSON0(std::ostream& ss, unsigned) const;
-    bool equals0(const Element& other, unsigned) const;
+    void toJSON(std::ostream& ss,
+                unsigned level = MAX_NESTING_LEVEL) const;
+    bool equals(const Element& other,
+                unsigned level = MAX_NESTING_LEVEL) const;
 };
 
 class StringElement : public Element {
@@ -949,10 +907,10 @@ public:
     bool getValue(std::string& t) const { t = s; return (true); }
     using Element::setValue;
     bool setValue(const std::string& v) { s = v; return (true); }
-    void toJSON(std::ostream& ss) const;
-    bool equals(const Element& other) const;
-    void toJSON0(std::ostream& ss, unsigned) const;
-    bool equals0(const Element& other, unsigned) const;
+    void toJSON(std::ostream& ss,
+                unsigned level = MAX_NESTING_LEVEL) const;
+    bool equals(const Element& other,
+                unsigned level = MAX_NESTING_LEVEL) const;
 };
 
 class ListElement : public Element {
@@ -982,12 +940,12 @@ public:
     void add(ElementPtr e) { l.push_back(e); }
     using Element::remove;
     void remove(int i) { l.erase(l.begin() + i); }
-    void toJSON(std::ostream& ss) const;
-    void toJSON0(std::ostream& ss, unsigned level) const;
+    void toJSON(std::ostream& ss,
+                unsigned level = MAX_NESTING_LEVEL) const;
     size_t size() const { return (l.size()); }
     bool empty() const { return (l.empty()); }
-    bool equals(const Element& other) const;
-    bool equals0(const Element& other, unsigned level) const;
+    bool equals(const Element& other,
+                unsigned level = MAX_NESTING_LEVEL) const;
 
     /// @brief Sorts the elements inside the list.
     ///
@@ -1056,8 +1014,8 @@ public:
     bool contains(const std::string& s) const override {
         return (m.find(s) != m.end());
     }
-    void toJSON(std::ostream& ss) const override;
-    void toJSON0(std::ostream& ss, unsigned level) const override;
+    void toJSON(std::ostream& ss,
+                unsigned level = MAX_NESTING_LEVEL) const override;
 
     // we should name the two finds better...
     // find the element at id; raises TypeError if one of the
@@ -1079,8 +1037,8 @@ public:
         return (m.size());
     }
 
-    bool equals(const Element& other) const override;
-    bool equals0(const Element& other, unsigned level) const override;
+    bool equals(const Element& other,
+                unsigned level = MAX_NESTING_LEVEL) const override;
 
     bool empty() const override { return (m.empty()); }
 };
@@ -1192,27 +1150,11 @@ typedef std::vector<FunctionMap> HierarchyDescriptor;
 /// identification keys.
 /// @param key The container holding the current element.
 /// @param idx The level inside the hierarchy the current element is located.
+/// @param level The maximum level of recursion.
 /// @throw TypeError if elements are not the same Element type.
 void mergeDiffAdd(ElementPtr& element, ElementPtr& other,
                   HierarchyDescriptor& hierarchy, std::string key,
-                  size_t idx = 0);
-
-/// @brief Merges the diff data by adding the missing elements from 'other'
-/// to 'element' (recursively). Both elements must be the same Element type.
-///
-/// @note: Variant with nesting depth: to be used only in tests.
-///
-/// @param element The element to which new data is added.
-/// @param other The element containing the data which needs to be added.
-/// @param hierarchy The hierarchy describing the elements relations and
-/// identification keys.
-/// @param key The container holding the current element.
-/// @param idx The level inside the hierarchy the current element is located.
-/// @param level The maximum level of recursion.
-/// @throw TypeError if elements are not the same Element type.
-void mergeDiffAdd0(ElementPtr& element, ElementPtr& other,
-                   HierarchyDescriptor& hierarchy, std::string key,
-                   size_t idx, unsigned level);
+                  size_t idx = 0, unsigned level = Element::MAX_NESTING_LEVEL);
 
 /// @brief Merges the diff data by removing the data present in 'other' from
 /// 'element' (recursively). Both elements must be the same Element type.
@@ -1231,26 +1173,11 @@ void mergeDiffAdd0(ElementPtr& element, ElementPtr& other,
 /// identification keys.
 /// @param key The container holding the current element.
 /// @param idx The level inside the hierarchy the current element is located.
+/// @param level The maximum level of recursion.
 /// @throw TypeError if elements are not the same Element type.
 void mergeDiffDel(ElementPtr& element, ElementPtr& other,
                   HierarchyDescriptor& hierarchy, std::string key,
-                  size_t idx = 0);
-/// @brief Merges the diff data by removing the data present in 'other' from
-/// 'element' (recursively). Both elements must be the same Element type.
-///
-/// @note: Variant with nesting depth: to be used only in tests.
-///
-/// @param element The element from which new data is removed.
-/// @param other The element containing the data which needs to be removed.
-/// @param hierarchy The hierarchy describing the elements relations and
-/// identification keys.
-/// @param key The container holding the current element.
-/// @param idx The level inside the hierarchy the current element is located.
-/// @param level The maximum level of recursion.
-/// @throw TypeError if elements are not the same Element type.
-void mergeDiffDel0(ElementPtr& element, ElementPtr& other,
-                   HierarchyDescriptor& hierarchy, std::string key,
-                   size_t idx, unsigned level);
+                  size_t idx = 0, unsigned level = Element::MAX_NESTING_LEVEL);
 
 /// @brief Extends data by adding the specified 'extension' elements from
 /// 'other' inside the 'container' element (recursively). Both elements must be
@@ -1267,35 +1194,12 @@ void mergeDiffDel0(ElementPtr& element, ElementPtr& other,
 /// @param idx The level inside the hierarchy the current element is located.
 /// @param alter The flag which indicates if the current element should be
 /// updated.
+/// @param level The maximum level of recursion.
 /// @throw TypeError if elements are not the same Element type.
 void extend(const std::string& container, const std::string& extension,
             ElementPtr& element, ElementPtr& other,
             HierarchyDescriptor& hierarchy, std::string key, size_t idx = 0,
-            bool alter = false);
-
-/// @brief Extends data by adding the specified 'extension' elements from
-/// 'other' inside the 'container' element (recursively). Both elements must be
-/// the same Element type.
-///
-/// @note: Variant with nesting depth: to be used only in tests.
-///
-/// @param container The container holding the data that must be extended.
-/// @param extension The name of the element that contains the data that must be
-/// added (if not already present) in order to extend the initial data.
-/// @param element The element from which new data is added.
-/// @param other The element containing the data which needs to be added.
-/// @param hierarchy The hierarchy describing the elements relations and
-/// identification keys.
-/// @param key The container holding the current element.
-/// @param idx The level inside the hierarchy the current element is located.
-/// @param alter The flag which indicates if the current element should be
-/// updated.
-/// @param level The maximum level of recursion.
-/// @throw TypeError if elements are not the same Element type.
-void extend0(const std::string& container, const std::string& extension,
-             ElementPtr& element, ElementPtr& other,
-             HierarchyDescriptor& hierarchy, std::string key, size_t idx,
-             bool alter, unsigned level);
+            bool alter = false, unsigned level = Element::MAX_NESTING_LEVEL);
 
 /// @brief Copy the data up to a nesting level.
 ///
index 65b3ebb4fe3e36ab05b4bf4d5557730f4a92c3b2..1481b16bd0d0e21b8234b4255579312b9805c3d7 100644 (file)
@@ -1702,7 +1702,7 @@ TEST(Element, mergeDiffAddBadParams) {
         right->set("other", right_other_right);
         ASSERT_FALSE(isc::data::isEquivalent(left, right));
         // Uses 2 levels of nesting so throw with 1 (and pass with 2 or more).
-        EXPECT_THROW(mergeDiffAdd0(left, right, hierarchy, "root", 0, 1),
+        EXPECT_THROW(mergeDiffAdd(left, right, hierarchy, "root", 0, 1),
                      isc::BadValue);
     }
     {
@@ -1753,7 +1753,7 @@ TEST(Element, mergeDiffAddBadParams) {
         right_right->set("other", right_other_right);
         ASSERT_FALSE(isc::data::isEquivalent(left, right));
         // Uses 3 levels of nesting so throw with 2 (and pass with 3 or more).
-        EXPECT_THROW(mergeDiffAdd0(left, right, hierarchy, "root", 0, 2),
+        EXPECT_THROW(mergeDiffAdd(left, right, hierarchy, "root", 0, 2),
                      isc::BadValue);
     }
 }
@@ -1905,7 +1905,7 @@ TEST(Element, mergeDiffAdd) {
         // list element which is updated
         right->set("other", right_other_right);
         ASSERT_FALSE(isc::data::isEquivalent(left, right));
-        ASSERT_NO_THROW(mergeDiffAdd0(left, right, hierarchy, "root", 0, 2));
+        ASSERT_NO_THROW(mergeDiffAdd(left, right, hierarchy, "root", 0, 2));
         std::string expected_str("{ \"elements\": { \"elements\": \"right\", \"id\": 0, \"new-elements\": \"new\", \"other-elements\": \"other\" }, "
                                    "\"left-other-elements\": { \"elements\": \"other-left\", \"id\": 1 }, "
                                    "\"other\": [ \"left-other-left\", \"left-other-left-other\", \"other-other\", \"right-other-right\", \"right-other-right-other\", \"other-other\" ], "
@@ -1961,7 +1961,7 @@ TEST(Element, mergeDiffAdd) {
         // list element which is updated
         right_right->set("other", right_other_right);
         ASSERT_FALSE(isc::data::isEquivalent(left, right));
-        ASSERT_NO_THROW(mergeDiffAdd0(left, right, hierarchy, "root", 0, 3));
+        ASSERT_NO_THROW(mergeDiffAdd(left, right, hierarchy, "root", 0, 3));
         std::string expected_str("[ { \"elements\": \"right\", \"id\": 0, \"new-elements\": \"new\", "
                                      "\"other\": [ \"left-other-left\", \"left-other-left-other\", \"other-other\", \"right-other-right\", \"right-other-right-other\", \"other-other\" ], "
                                      "\"other-elements\": \"other\" }, "
@@ -2072,7 +2072,7 @@ TEST(Element, mergeDiffDelBadParams) {
         right->set("elements-other", right_right);
         ASSERT_FALSE(isc::data::isEquivalent(left, right));
         // Uses 2 levels of nesting so throw with 1 (and pass with 2 or more).
-        EXPECT_THROW(mergeDiffDel0(left, right, hierarchy, "root", 0, 1),
+        EXPECT_THROW(mergeDiffDel(left, right, hierarchy, "root", 0, 1),
                      isc::BadValue);
     }
     {
@@ -2137,7 +2137,7 @@ TEST(Element, mergeDiffDelBadParams) {
         right->add(right_right);
         ASSERT_FALSE(isc::data::isEquivalent(left, right));
         // Uses 3 levels of nesting so throw with 2 (and pass with 3 or more).
-        EXPECT_THROW(mergeDiffDel0(left, right, hierarchy, "root", 0, 2),
+        EXPECT_THROW(mergeDiffDel(left, right, hierarchy, "root", 0, 2),
                      isc::BadValue);
     }
 }
@@ -2286,7 +2286,7 @@ TEST(Element, mergeDiffDel) {
         // the key can not be removed
         right->set("elements-other", right_right);
         ASSERT_FALSE(isc::data::isEquivalent(left, right));
-        ASSERT_NO_THROW(mergeDiffDel0(left, right, hierarchy, "root", 0, 2));
+        ASSERT_NO_THROW(mergeDiffDel(left, right, hierarchy, "root", 0, 2));
         std::string expected_str("{ \"elements\": { \"id\": 0, \"other-elements\": \"other\" }, "
                                    "\"elements-other\": { \"elements\": \"new-left\", \"id\": 3, \"other-elements\": \"new-other\" }, "
                                    "\"left-other-elements\": { \"elements\": \"other-left\", \"id\": 1 }, "
@@ -2356,7 +2356,7 @@ TEST(Element, mergeDiffDel) {
         // the key can not be removed
         right->add(right_right);
         ASSERT_FALSE(isc::data::isEquivalent(left, right));
-        ASSERT_NO_THROW(mergeDiffDel0(left, right, hierarchy, "root", 0, 3));
+        ASSERT_NO_THROW(mergeDiffDel(left, right, hierarchy, "root", 0, 3));
         std::string expected_str("[ { \"id\": 0, \"other\": [ \"left-other-left\", \"left-other-left-other\" ], \"other-elements\": \"other\" }, "
                                    "{ \"elements\": \"other-left\", \"id\": 1 } ]");
         ElementPtr expected = Element::fromJSON(expected_str);
@@ -2425,8 +2425,8 @@ TEST(Element, extendBadParam) {
         right->set("elements", right_right);
         ASSERT_FALSE(isc::data::isEquivalent(left, right));
         // Uses 2 levels of nesting so throw with 1 (and pass with 2 or more).
-        EXPECT_THROW(extend0("root", "new-elements", left, right, hierarchy,
-                             "root", 0, false, 1), isc::BadValue);
+        EXPECT_THROW(extend("root", "new-elements", left, right, hierarchy,
+                            "root", 0, false, 1), isc::BadValue);
     }
     {
         SCOPED_TRACE("nested list");
@@ -2451,8 +2451,8 @@ TEST(Element, extendBadParam) {
         right->add(right_right);
         ASSERT_FALSE(isc::data::isEquivalent(left, right));
         // Uses 2 levels of nesting so throw with 1 (and pass with 2 or more).
-        EXPECT_THROW(extend0("root", "new-elements", left, right, hierarchy,
-                             "root", 0, false, 1), isc::BadValue);
+        EXPECT_THROW(extend("root", "new-elements", left, right, hierarchy,
+                            "root", 0, false, 1), isc::BadValue);
     }
 }
 
@@ -2519,8 +2519,8 @@ TEST(Element, extend) {
         // map element which is used for extension
         right->set("elements", right_right);
         ASSERT_FALSE(isc::data::isEquivalent(left, right));
-        ASSERT_NO_THROW(extend0("root", "new-elements", left, right, hierarchy,
-                                "root", 0, false, 2));
+        ASSERT_NO_THROW(extend("root", "new-elements", left, right, hierarchy,
+                               "root", 0, false, 2));
         std::string expected_str("{ \"elements\": { \"elements\": \"left\", \"id\": 0, \"new-elements\": \"new\", \"other-elements\": \"other\" } }");
         ElementPtr expected = Element::fromJSON(expected_str);
         EXPECT_TRUE(isc::data::isEquivalent(left, expected))
@@ -2548,8 +2548,8 @@ TEST(Element, extend) {
         // map element which is used for extension
         right->add(right_right);
         ASSERT_FALSE(isc::data::isEquivalent(left, right));
-        ASSERT_NO_THROW(extend0("root", "new-elements", left, right, hierarchy,
-                                "root", 0, false, 2));
+        ASSERT_NO_THROW(extend("root", "new-elements", left, right, hierarchy,
+                               "root", 0, false, 2));
         std::string expected_str("[ { \"elements\": \"left\", \"id\": 0, \"new-elements\": \"new\", \"other-elements\": \"other\" } ]");
         ElementPtr expected = Element::fromJSON(expected_str);
         EXPECT_TRUE(isc::data::isEquivalent(left, expected))
@@ -2802,7 +2802,7 @@ TEST(Element, nestedListFromJSON) {
         try {
             int l = 1;
             int p = 1;
-            ElementPtr list = Element::fromJSON0(ss, "sss", l, p, max_level);
+            ElementPtr list = Element::fromJSON(ss, "sss", l, p, max_level);
             EXPECT_TRUE(isEquivalent(list, expected));
         } catch (const JSONError&) {
             EXPECT_EQ(max_level, level);
@@ -2833,7 +2833,7 @@ TEST(Element, nestedMapFromJSON) {
         try {
             int l = 1;
             int p = 1;
-            ElementPtr map = Element::fromJSON0(ss, "sss", l, p, max_level);
+            ElementPtr map = Element::fromJSON(ss, "sss", l, p, max_level);
             EXPECT_TRUE(isEquivalent(map, expected));
         } catch (const JSONError&) {
             EXPECT_EQ(max_level, level);