Kea 2.7.6
data.h
Go to the documentation of this file.
1// Copyright (C) 2010-2024 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef ISC_DATA_H
8#define ISC_DATA_H 1
9
10#include <util/bigints.h>
11
12#include <iostream>
13#include <map>
14#include <stdexcept>
15#include <string>
16#include <vector>
17
18#include <boost/shared_ptr.hpp>
19
20#include <stdint.h>
21
23
24namespace isc { namespace data {
25
26class Element;
27// todo: describe the rationale behind ElementPtr?
28typedef boost::shared_ptr<Element> ElementPtr;
29typedef boost::shared_ptr<const Element> ConstElementPtr;
30
36class TypeError : public isc::Exception {
37public:
38 TypeError(const char* file, size_t line, const char* what) :
39 isc::Exception(file, line, what) {}
40};
41
46// i'd like to use Exception here but we need one that is derived from
47// runtime_error (as this one is directly based on external data, and
48// i want to add some values to any static data string that is provided)
49class JSONError : public isc::Exception {
50public:
51 JSONError(const char* file, size_t line, const char* what) :
52 isc::Exception(file, line, what) {}
53};
54
72class Element {
73
74public:
94 struct Position {
95 std::string file_;
96 uint32_t line_;
97 uint32_t pos_;
98
100 Position() : file_(""), line_(0), pos_(0) {
101 }
102
108 Position(const std::string& file, const uint32_t line,
109 const uint32_t pos)
110 : file_(file), line_(line), pos_(pos) {
111 }
112
116 std::string str() const;
117 };
118
126 static const Position& ZERO_POSITION() {
127 static Position position("", 0, 0);
128 return (position);
129 }
130
139 enum types : int {
141 real = 1,
142 boolean = 2,
143 null = 3,
144 string = 4,
146 list = 6,
147 map = 7,
148 any = 8,
149 };
150
151private:
152 // technically the type could be omitted; is it useful?
153 // should we remove it or replace it with a pure virtual
154 // function getType?
155 types type_;
156
158 Position position_;
159
160protected:
161
169 : type_(t), position_(pos) {
170 }
171
172
173public:
174 // base class; make dtor virtual
175 virtual ~Element() {}
176
178 types getType() const { return (type_); }
179
185 const Position& getPosition() const { return (position_); }
186
194 std::string str() const;
195
200 std::string toWire() const;
201 void toWire(std::ostream& out) const;
202
205#define throwTypeError(error) \
206 { \
207 std::string msg_ = error; \
208 if ((position_.file_ != "") || \
209 (position_.line_ != 0) || \
210 (position_.pos_ != 0)) { \
211 msg_ += " in (" + position_.str() + ")"; \
212 } \
213 isc_throw(TypeError, msg_); \
214 }
215
217
220 virtual bool equals(const Element& other) const = 0;
221
224 virtual void toJSON(std::ostream& ss) const = 0;
225
233
234 virtual int64_t intValue() const
235 { throwTypeError("intValue() called on non-integer Element"); }
237 throwTypeError("bigIntValue() called on non-big-integer Element");
238 }
239 virtual double doubleValue() const
240 { throwTypeError("doubleValue() called on non-double Element"); }
241 virtual bool boolValue() const
242 { throwTypeError("boolValue() called on non-Bool Element"); }
243 virtual std::string stringValue() const
244 { throwTypeError("stringValue() called on non-string Element"); }
245 virtual const std::vector<ElementPtr>& listValue() const {
246 // replace with real exception or empty vector?
247 throwTypeError("listValue() called on non-list Element");
248 }
249 virtual const std::map<std::string, ConstElementPtr>& mapValue() const {
250 // replace with real exception or empty map?
251 throwTypeError("mapValue() called on non-map Element");
252 }
254
263
264 virtual bool getValue(int64_t& t) const;
265 virtual bool getValue(double& t) const;
266 virtual bool getValue(bool& t) const;
267 virtual bool getValue(std::string& t) const;
268 virtual bool getValue(std::vector<ElementPtr>& t) const;
269 virtual bool getValue(std::map<std::string, ConstElementPtr>& t) const;
271
281
282 virtual bool setValue(const long long int v);
283 virtual bool setValue(const isc::util::int128_t& v);
284 bool setValue(const long int i) { return (setValue(static_cast<long long int>(i))); }
285 bool setValue(const int i) { return (setValue(static_cast<long long int>(i))); }
286 virtual bool setValue(const double v);
287 virtual bool setValue(const bool t);
288 virtual bool setValue(const std::string& v);
289 virtual bool setValue(const std::vector<ElementPtr>& v);
290 virtual bool setValue(const std::map<std::string, ConstElementPtr>& v);
292
293 // Other functions for specific subtypes
294
299
300
303 virtual ConstElementPtr get(const int i) const;
304
309 virtual ElementPtr getNonConst(const int i) const;
310
315 virtual void set(const size_t i, ElementPtr element);
316
319 virtual void add(ElementPtr element);
320
324 virtual void remove(const int i);
325
327 virtual size_t size() const;
328
330 virtual bool empty() const;
332
333
338
339
342 virtual ConstElementPtr get(const std::string& name) const;
343
347 virtual void set(const std::string& name, ConstElementPtr element);
348
351 virtual void remove(const std::string& name);
352
356 virtual bool contains(const std::string& name) const;
357
371 virtual ConstElementPtr find(const std::string& identifier) const;
372
377 virtual bool find(const std::string& identifier, ConstElementPtr& t) const;
379
381
382 // TODO: should we move all factory functions to a different class
383 // so as not to burden the Element base with too many functions?
384 // and/or perhaps even to a separate header?
385
398
399 static ElementPtr create(const Position& pos = ZERO_POSITION());
400 static ElementPtr create(const long long int i,
401 const Position& pos = ZERO_POSITION());
402 static ElementPtr create(const isc::util::int128_t& i,
403 const Position& pos = ZERO_POSITION());
404 static ElementPtr create(const int i,
405 const Position& pos = ZERO_POSITION());
406 static ElementPtr create(const long int i,
407 const Position& pos = ZERO_POSITION());
408 static ElementPtr create(const uint32_t i,
409 const Position& pos = ZERO_POSITION());
410 static ElementPtr create(const double d,
411 const Position& pos = ZERO_POSITION());
412 static ElementPtr create(const bool b,
413 const Position& pos = ZERO_POSITION());
414 static ElementPtr create(const std::string& s,
415 const Position& pos = ZERO_POSITION());
416 // need both std:string and char *, since c++ will match
417 // bool before std::string when you pass it a char *
418 static ElementPtr create(const char *s,
419 const Position& pos = ZERO_POSITION());
420
425 static ElementPtr createList(const Position& pos = ZERO_POSITION());
426
431 static ElementPtr createMap(const Position& pos = ZERO_POSITION());
433
435
439
441
447 static ElementPtr fromJSON(const std::string& in, bool preproc = false);
448
458 static ElementPtr fromJSON(std::istream& in, bool preproc = false);
459
471 static ElementPtr fromJSON(std::istream& in, const std::string& file_name,
472 bool preproc = false);
473
486 // make this one private?
488 static ElementPtr fromJSON(std::istream& in, const std::string& file,
489 int& line, int &pos);
490
498 static ElementPtr fromJSONFile(const std::string& file_name,
499 bool preproc = false);
501
503
509 static std::string typeToName(Element::types type);
510
516 static Element::types nameToType(const std::string& type_name);
517
532 static void preprocess(std::istream& in, std::stringstream& out);
533
535
539
541
549 static ElementPtr fromWire(std::stringstream& in, int length);
550
557 static ElementPtr fromWire(const std::string& s);
559
563 if (type_ == list || type_ == map) {
564 size_t s(size());
565 for (size_t i = 0; i < s; ++i) {
566 // Get child.
567 ElementPtr child;
568 if (type_ == list) {
569 child = getNonConst(i);
570 } else if (type_ == map) {
571 std::string const key(get(i)->stringValue());
572 // The ElementPtr - ConstElementPtr disparity between
573 // ListElement and MapElement is forcing a const cast here.
574 // It's undefined behavior to modify it after const casting.
575 // The options are limited. I've tried templating, moving
576 // this function from a member function to free-standing and
577 // taking the Element template as argument. I've tried
578 // making it a virtual function with overridden
579 // implementations in ListElement and MapElement. Nothing
580 // works.
581 child = boost::const_pointer_cast<Element>(get(key));
582 }
583
584 // Makes no sense to continue for non-container children.
585 if (child->getType() != list && child->getType() != map) {
586 continue;
587 }
588
589 // Recurse if not empty.
590 if (!child->empty()){
591 child->removeEmptyContainersRecursively();
592 }
593
594 // When returning from recursion, remove if empty.
595 if (child->empty()) {
596 remove(i);
597 --i;
598 --s;
599 }
600 }
601 }
602 }
603};
604
615class IntElement : public Element {
616 int64_t i;
617public:
618 IntElement(int64_t v, const Position& pos = ZERO_POSITION())
619 : Element(integer, pos), i(v) { }
620 int64_t intValue() const { return (i); }
621 using Element::getValue;
622 bool getValue(int64_t& t) const { t = i; return (true); }
623 using Element::setValue;
624 bool setValue(long long int v) { i = v; return (true); }
625 void toJSON(std::ostream& ss) const;
626 bool equals(const Element& other) const;
627};
628
630class BigIntElement : public Element {
631 using int128_t = isc::util::int128_t;
632 using Element::getValue;
633 using Element::setValue;
634
635public:
637 BigIntElement(const int128_t& v, const Position& pos = ZERO_POSITION())
638 : Element(bigint, pos), i_(v) {
639 }
640
644 int128_t bigIntValue() const override {
645 return (i_);
646 }
647
651 bool setValue(const int128_t& v) override {
652 i_ = v;
653 return (true);
654 }
655
658 void toJSON(std::ostream& ss) const override;
659
664 bool equals(const Element& other) const override;
665
666private:
668 int128_t i_;
669};
670
671class DoubleElement : public Element {
672 double d;
673
674public:
675 DoubleElement(double v, const Position& pos = ZERO_POSITION())
676 : Element(real, pos), d(v) {}
677 double doubleValue() const { return (d); }
678 using Element::getValue;
679 bool getValue(double& t) const { t = d; return (true); }
680 using Element::setValue;
681 bool setValue(const double v) { d = v; return (true); }
682 void toJSON(std::ostream& ss) const;
683 bool equals(const Element& other) const;
684};
685
686class BoolElement : public Element {
687 bool b;
688
689public:
690 BoolElement(const bool v, const Position& pos = ZERO_POSITION())
691 : Element(boolean, pos), b(v) {}
692 bool boolValue() const { return (b); }
693 using Element::getValue;
694 bool getValue(bool& t) const { t = b; return (true); }
695 using Element::setValue;
696 bool setValue(const bool v) { b = v; return (true); }
697 void toJSON(std::ostream& ss) const;
698 bool equals(const Element& other) const;
699};
700
701class NullElement : public Element {
702public:
704 : Element(null, pos) {}
705 void toJSON(std::ostream& ss) const;
706 bool equals(const Element& other) const;
707};
708
709class StringElement : public Element {
710 std::string s;
711
712public:
713 StringElement(std::string v, const Position& pos = ZERO_POSITION())
714 : Element(string, pos), s(v) {}
715 std::string stringValue() const { return (s); }
716 using Element::getValue;
717 bool getValue(std::string& t) const { t = s; return (true); }
718 using Element::setValue;
719 bool setValue(const std::string& v) { s = v; return (true); }
720 void toJSON(std::ostream& ss) const;
721 bool equals(const Element& other) const;
722};
723
724class ListElement : public Element {
725 std::vector<ElementPtr> l;
726
727public:
729 : Element(list, pos) {}
730 const std::vector<ElementPtr>& listValue() const { return (l); }
731 using Element::getValue;
732 bool getValue(std::vector<ElementPtr>& t) const {
733 t = l;
734 return (true);
735 }
736 using Element::setValue;
737 bool setValue(const std::vector<ElementPtr>& v) {
738 l = v;
739 return (true);
740 }
741 using Element::get;
742 ConstElementPtr get(int i) const { return (l.at(i)); }
743 ElementPtr getNonConst(int i) const { return (l.at(i)); }
744 using Element::set;
745 void set(size_t i, ElementPtr e) {
746 l.at(i) = e;
747 }
748 void add(ElementPtr e) { l.push_back(e); }
749 using Element::remove;
750 void remove(int i) { l.erase(l.begin() + i); }
751 void toJSON(std::ostream& ss) const;
752 size_t size() const { return (l.size()); }
753 bool empty() const { return (l.empty()); }
754 bool equals(const Element& other) const;
755
765 void sort(std::string const& index = std::string());
766};
767
768class MapElement : public Element {
769 std::map<std::string, ConstElementPtr> m;
770
771public:
772 MapElement(const Position& pos = ZERO_POSITION()) : Element(map, pos) {}
773 // @todo should we have direct iterators instead of exposing the std::map
774 // here?
775 const std::map<std::string, ConstElementPtr>& mapValue() const override {
776 return (m);
777 }
778 using Element::getValue;
779 bool getValue(std::map<std::string, ConstElementPtr>& t) const override {
780 t = m;
781 return (true);
782 }
783 using Element::setValue;
784 bool setValue(const std::map<std::string, ConstElementPtr>& v) override {
785 m = v;
786 return (true);
787 }
788 using Element::get;
789 ConstElementPtr get(const std::string& s) const override {
790 auto found = m.find(s);
791 return (found != m.end() ? found->second : ConstElementPtr());
792 }
793
800 ConstElementPtr get(int const i) const override {
801 auto it(m.begin());
802 std::advance(it, i);
803 return create(it->first);
804 }
805
806 using Element::set;
807 void set(const std::string& key, ConstElementPtr value) override;
808 using Element::remove;
809 void remove(const std::string& s) override { m.erase(s); }
810
814 void remove(int const i) override {
815 auto it(m.begin());
816 std::advance(it, i);
817 m.erase(it);
818 }
819
820 bool contains(const std::string& s) const override {
821 return (m.find(s) != m.end());
822 }
823 void toJSON(std::ostream& ss) const override;
824
825 // we should name the two finds better...
826 // find the element at id; raises TypeError if one of the
827 // elements at path except the one we're looking for is not a
828 // mapelement.
829 // returns an empty element if the item could not be found
830 ConstElementPtr find(const std::string& id) const override;
831
832 // find the Element at 'id', and store the element pointer in t
833 // returns true if found, or false if not found (either because
834 // it doesn't exist or one of the elements in the path is not
835 // a MapElement)
836 bool find(const std::string& id, ConstElementPtr& t) const override;
837
841 size_t size() const override {
842 return (m.size());
843 }
844
845 bool equals(const Element& other) const override;
846
847 bool empty() const override { return (m.empty()); }
848};
849
853bool isNull(ConstElementPtr p);
854
863
870
879void merge(ElementPtr element, ConstElementPtr other);
880
890typedef std::function<bool (ElementPtr&, ElementPtr&)> MatchTestFunc;
891
894typedef std::function<bool (ElementPtr&)> NoDataTestFunc;
895
897typedef std::function<bool (const std::string&)> IsKeyTestFunc;
898
906
909typedef std::map<std::string, HierarchyTraversalTest> FunctionMap;
910
924typedef std::vector<FunctionMap> HierarchyDescriptor;
925
944void mergeDiffAdd(ElementPtr& element, ElementPtr& other,
945 HierarchyDescriptor& hierarchy, std::string key,
946 size_t idx = 0);
947
965void mergeDiffDel(ElementPtr& element, ElementPtr& other,
966 HierarchyDescriptor& hierarchy, std::string key,
967 size_t idx = 0);
968
985void extend(const std::string& container, const std::string& extension,
986 ElementPtr& element, ElementPtr& other,
987 HierarchyDescriptor& hierarchy, std::string key, size_t idx = 0,
988 bool alter = false);
989
1000ElementPtr copy(ConstElementPtr from, int level = 100);
1001
1008
1020void prettyPrint(ConstElementPtr element, std::ostream& out,
1021 unsigned indent = 0, unsigned step = 2);
1022
1033std::string prettyPrint(ConstElementPtr element,
1034 unsigned indent = 0, unsigned step = 2);
1035
1046std::ostream& operator<<(std::ostream& out, const Element::Position& pos);
1047
1062std::ostream& operator<<(std::ostream& out, const Element& e);
1063
1064bool operator==(const Element& a, const Element& b);
1065bool operator!=(const Element& a, const Element& b);
1066bool operator<(const Element& a, const Element& b);
1067
1068} // namespace data
1069} // namespace isc
1070
1071#endif // ISC_DATA_H
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Wrapper over int128_t.
Definition data.h:630
bool setValue(const int128_t &v) override
Sets the underlying big integer value.
Definition data.h:651
BigIntElement(const int128_t &v, const Position &pos=ZERO_POSITION())
Constructor.
Definition data.h:637
int128_t bigIntValue() const override
Retrieve the underlying big integer value.
Definition data.h:644
bool equals(const Element &other) const override
Checks whether the other Element is equal.
Definition data.cc:1038
void toJSON(std::ostream &ss) const override
Converts the Element to JSON format and appends it to the given stringstream.
Definition data.cc:839
bool getValue(bool &t) const
Definition data.h:694
bool setValue(const bool v)
Definition data.h:696
void toJSON(std::ostream &ss) const
Converts the Element to JSON format and appends it to the given stringstream.
Definition data.cc:860
BoolElement(const bool v, const Position &pos=ZERO_POSITION())
Definition data.h:690
bool boolValue() const
Definition data.h:692
bool equals(const Element &other) const
Definition data.cc:1055
bool setValue(const double v)
Definition data.h:681
DoubleElement(double v, const Position &pos=ZERO_POSITION())
Definition data.h:675
bool equals(const Element &other) const
Definition data.cc:1049
double doubleValue() const
Definition data.h:677
bool getValue(double &t) const
Definition data.h:679
void toJSON(std::ostream &ss) const
Converts the Element to JSON format and appends it to the given stringstream.
Definition data.cc:844
The Element class represents a piece of data, used by the command channel and configuration parts.
Definition data.h:72
const Position & getPosition() const
Returns position where the data element's value starts in a configuration string.
Definition data.h:185
static ElementPtr create(const Position &pos=ZERO_POSITION())
Definition data.cc:249
virtual bool equals(const Element &other) const =0
virtual bool getValue(int64_t &t) const
Definition data.cc:73
static std::string typeToName(Element::types type)
Returns the name of the given type as a string.
Definition data.cc:651
virtual int64_t intValue() const
Definition data.h:234
std::string str() const
Returns a string representing the Element and all its child elements; note that this is different fro...
Definition data.cc:54
virtual std::string stringValue() const
Definition data.h:243
std::string toWire() const
Returns the wireformat for the Element and all its child elements.
Definition data.cc:61
static ElementPtr fromWire(std::stringstream &in, int length)
These function pparse the wireformat at the given stringstream (of the given length).
Definition data.cc:992
virtual bool setValue(const long long int v)
Definition data.cc:103
static ElementPtr fromJSONFile(const std::string &file_name, bool preproc=false)
Reads contents of specified file and interprets it as JSON.
Definition data.cc:817
virtual bool empty() const
Return true if there are no elements in the list.
Definition data.cc:168
virtual void remove(const int i)
Removes the element at the given position.
Definition data.cc:158
void removeEmptyContainersRecursively()
Remove all empty maps and lists from this Element and its descendants.
Definition data.h:562
virtual bool contains(const std::string &name) const
Checks if there is data at the given key.
Definition data.cc:188
virtual ConstElementPtr find(const std::string &identifier) const
Recursively finds any data at the given identifier.
Definition data.cc:193
virtual size_t size() const
Returns the number of elements in the list.
Definition data.cc:163
Element(types t, const Position &pos=ZERO_POSITION())
Constructor.
Definition data.h:168
static const Position & ZERO_POSITION()
Returns Position object with line_ and pos_ set to 0, and with an empty file name.
Definition data.h:126
virtual const std::map< std::string, ConstElementPtr > & mapValue() const
Definition data.h:249
virtual void add(ElementPtr element)
Adds an ElementPtr to the list.
Definition data.cc:153
virtual const std::vector< ElementPtr > & listValue() const
Definition data.h:245
virtual ~Element()
Definition data.h:175
bool setValue(const long int i)
Definition data.h:284
static ElementPtr fromJSON(const std::string &in, bool preproc=false)
These functions will parse the given string (JSON) representation of a compound element.
Definition data.cc:798
virtual ConstElementPtr get(const int i) const
Returns the ElementPtr at the given index.
Definition data.cc:138
types
The types that an Element can hold.
Definition data.h:139
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition data.cc:304
static Element::types nameToType(const std::string &type_name)
Converts the string to the corresponding type Throws a TypeError if the name is unknown.
Definition data.cc:677
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
Definition data.cc:299
virtual void toJSON(std::ostream &ss) const =0
Converts the Element to JSON format and appends it to the given stringstream.
virtual void set(const size_t i, ElementPtr element)
Sets the ElementPtr at the given index.
Definition data.cc:148
virtual double doubleValue() const
Definition data.h:239
bool setValue(const int i)
Definition data.h:285
virtual isc::util::int128_t bigIntValue() const
Definition data.h:236
types getType() const
Definition data.h:178
virtual bool boolValue() const
Definition data.h:241
static void preprocess(std::istream &in, std::stringstream &out)
input text preprocessor
Definition data.cc:1641
virtual ElementPtr getNonConst(const int i) const
returns element as non-const pointer
Definition data.cc:143
Notes: IntElement type is changed to int64_t.
Definition data.h:615
bool setValue(long long int v)
Definition data.h:624
IntElement(int64_t v, const Position &pos=ZERO_POSITION())
Definition data.h:618
bool equals(const Element &other) const
Definition data.cc:1027
int64_t intValue() const
Definition data.h:620
void toJSON(std::ostream &ss) const
Converts the Element to JSON format and appends it to the given stringstream.
Definition data.cc:834
bool getValue(int64_t &t) const
Definition data.h:622
A standard Data module exception that is thrown if a parse error is encountered when constructing an ...
Definition data.h:49
JSONError(const char *file, size_t line, const char *what)
Definition data.h:51
void sort(std::string const &index=std::string())
Sorts the elements inside the list.
Definition data.cc:1090
bool empty() const
Return true if there are no elements in the list.
Definition data.h:753
const std::vector< ElementPtr > & listValue() const
Definition data.h:730
void remove(int i)
Removes the element at the given position.
Definition data.h:750
bool getValue(std::vector< ElementPtr > &t) const
Definition data.h:732
void toJSON(std::ostream &ss) const
Converts the Element to JSON format and appends it to the given stringstream.
Definition data.cc:922
void add(ElementPtr e)
Adds an ElementPtr to the list.
Definition data.h:748
ElementPtr getNonConst(int i) const
returns element as non-const pointer
Definition data.h:743
void set(size_t i, ElementPtr e)
Sets the ElementPtr at the given index.
Definition data.h:745
size_t size() const
Returns the number of elements in the list.
Definition data.h:752
bool setValue(const std::vector< ElementPtr > &v)
Definition data.h:737
bool equals(const Element &other) const
Definition data.cc:1072
ListElement(const Position &pos=ZERO_POSITION())
Definition data.h:728
ConstElementPtr get(int i) const
Returns the ElementPtr at the given index.
Definition data.h:742
bool contains(const std::string &s) const override
Checks if there is data at the given key.
Definition data.h:820
const std::map< std::string, ConstElementPtr > & mapValue() const override
Definition data.h:775
ConstElementPtr find(const std::string &id) const override
Recursively finds any data at the given identifier.
Definition data.cc:964
void set(const std::string &key, ConstElementPtr value) override
Sets the ElementPtr at the given key.
Definition data.cc:1008
ConstElementPtr get(const std::string &s) const override
Returns the ElementPtr at the given key.
Definition data.h:789
bool equals(const Element &other) const override
Definition data.cc:1126
bool setValue(const std::map< std::string, ConstElementPtr > &v) override
Definition data.h:784
void toJSON(std::ostream &ss) const override
Converts the Element to JSON format and appends it to the given stringstream.
Definition data.cc:939
ConstElementPtr get(int const i) const override
Get the i-th element in the map.
Definition data.h:800
bool empty() const override
Return true if there are no elements in the list.
Definition data.h:847
void remove(int const i) override
Remove the i-th element from the map.
Definition data.h:814
void remove(const std::string &s) override
Remove the ElementPtr at the given key.
Definition data.h:809
bool getValue(std::map< std::string, ConstElementPtr > &t) const override
Definition data.h:779
MapElement(const Position &pos=ZERO_POSITION())
Definition data.h:772
size_t size() const override
Returns number of stored elements.
Definition data.h:841
bool equals(const Element &other) const
Definition data.cc:1061
void toJSON(std::ostream &ss) const
Converts the Element to JSON format and appends it to the given stringstream.
Definition data.cc:869
NullElement(const Position &pos=ZERO_POSITION())
Definition data.h:703
std::string stringValue() const
Definition data.h:715
bool setValue(const std::string &v)
Definition data.h:719
bool getValue(std::string &t) const
Definition data.h:717
void toJSON(std::ostream &ss) const
Converts the Element to JSON format and appends it to the given stringstream.
Definition data.cc:874
StringElement(std::string v, const Position &pos=ZERO_POSITION())
Definition data.h:713
bool equals(const Element &other) const
Definition data.cc:1066
A standard Data module exception that is thrown if a function is called for an Element that has a wro...
Definition data.h:36
TypeError(const char *file, size_t line, const char *what)
Definition data.h:38
#define throwTypeError(error)
Add the position to a TypeError message should be used in place of isc_throw(TypeError,...
Definition data.h:205
ElementPtr copy(ConstElementPtr from, int level)
Copy the data up to a nesting level.
Definition data.cc:1420
bool operator==(const Element &a, const Element &b)
Definition data.cc:218
void mergeDiffAdd(ElementPtr &element, ElementPtr &other, HierarchyDescriptor &hierarchy, std::string key, size_t idx)
Merges the diff data by adding the missing elements from 'other' to 'element' (recursively).
Definition data.cc:1217
void removeIdentical(ElementPtr a, ConstElementPtr b)
Remove all values from the first ElementPtr that are equal in the second.
Definition data.cc:1153
void merge(ElementPtr element, ConstElementPtr other)
Merges the data from other into element.
Definition data.cc:1199
void mergeDiffDel(ElementPtr &element, ElementPtr &other, HierarchyDescriptor &hierarchy, std::string key, size_t idx)
Merges the diff data by removing the data present in 'other' from 'element' (recursively).
Definition data.cc:1278
std::map< std::string, HierarchyTraversalTest > FunctionMap
Mapping between a container name and functions used to match elements inside the container.
Definition data.h:909
bool operator<(Element const &a, Element const &b)
Definition data.cc:227
bool isEquivalent(ConstElementPtr a, ConstElementPtr b)
Compares the data with other using unordered lists.
Definition data.cc:1542
void prettyPrint(ConstElementPtr element, std::ostream &out, unsigned indent, unsigned step)
Pretty prints the data into stream.
Definition data.cc:1547
std::function< bool(ElementPtr &)> NoDataTestFunc
Function used to check if the data provided for the element contains only information used for identi...
Definition data.h:894
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
void extend(const std::string &container, const std::string &extension, ElementPtr &element, ElementPtr &other, HierarchyDescriptor &hierarchy, std::string key, size_t idx, bool alter)
Extends data by adding the specified 'extension' elements from 'other' inside the 'container' element...
Definition data.cc:1368
bool isNull(ConstElementPtr p)
Checks whether the given ElementPtr is a NULL pointer.
Definition data.cc:1148
std::function< bool(ElementPtr &, ElementPtr &)> MatchTestFunc
Function used to check if two MapElements refer to the same configuration data.
Definition data.h:890
std::ostream & operator<<(std::ostream &out, const Element::Position &pos)
Insert Element::Position as a string into stream.
Definition data.cc:48
std::function< bool(const std::string &)> IsKeyTestFunc
Function used to check if the key is used for identification.
Definition data.h:897
bool operator!=(const Element &a, const Element &b)
Definition data.cc:222
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
std::vector< FunctionMap > HierarchyDescriptor
Hierarchy descriptor of the containers in a specific Element hierarchy tree.
Definition data.h:924
boost::multiprecision::checked_int128_t int128_t
Definition bigints.h:19
Defines the logger used by the top-level component of kea-lfc.
Represents the position of the data element within a configuration string.
Definition data.h:94
Position(const std::string &file, const uint32_t line, const uint32_t pos)
Constructor.
Definition data.h:108
uint32_t pos_
Position within the line.
Definition data.h:97
std::string str() const
Returns the position in the textual format.
Definition data.cc:41
Position()
Default constructor.
Definition data.h:100
uint32_t line_
Line number.
Definition data.h:96
std::string file_
File name.
Definition data.h:95
Structure holding the test functions used to traverse the element hierarchy.
Definition data.h:901