Kea 3.0.3-git
data.h
Go to the documentation of this file.
1// Copyright (C) 2010-2026 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 {
25namespace data {
26
27class Element;
28// todo: describe the rationale behind ElementPtr?
29typedef boost::shared_ptr<Element> ElementPtr;
30typedef boost::shared_ptr<const Element> ConstElementPtr;
31
37class TypeError : public isc::Exception {
38public:
39 TypeError(const char* file, size_t line, const char* what) :
40 isc::Exception(file, line, what) {}
41};
42
47// i'd like to use Exception here but we need one that is derived from
48// runtime_error (as this one is directly based on external data, and
49// i want to add some values to any static data string that is provided)
50class JSONError : public isc::Exception {
51public:
52 JSONError(const char* file, size_t line, const char* what) :
53 isc::Exception(file, line, what) {}
54};
55
73class Element {
74public:
86 static constexpr unsigned MAX_NESTING_LEVEL = 100U;
87
107 struct Position {
108 std::string file_;
109 uint32_t line_;
110 uint32_t pos_;
111
113 Position() : file_(""), line_(0), pos_(0) {
114 }
115
121 Position(const std::string& file, const uint32_t line,
122 const uint32_t pos)
123 : file_(file), line_(line), pos_(pos) {
124 }
125
129 std::string str() const;
130 };
131
139 static const Position& ZERO_POSITION() {
140 static Position position("", 0, 0);
141 return (position);
142 }
143
152 enum types : int {
154 real = 1,
155 boolean = 2,
156 null = 3,
157 string = 4,
159 list = 6,
160 map = 7,
161 any = 8,
162 };
163
164private:
165 // technically the type could be omitted; is it useful?
166 // should we remove it or replace it with a pure virtual
167 // function getType?
168 types type_;
169
171 Position position_;
172
173protected:
174
182 : type_(t), position_(pos) {
183 }
184
185
186public:
187 // Base class; make destructor virtual.
188 virtual ~Element() {}
189
191 types getType() const {
192 return (type_);
193 }
194
201 const Position& getPosition() const {
202 return (position_);
203 }
204
215 std::string str() const;
216
223 std::string toWire() const;
224
228 void toWire(std::ostream& out) const;
229
234#define throwTypeError(error) \
235 { \
236 std::string msg_ = error; \
237 if ((position_.file_ != "") || \
238 (position_.line_ != 0) || \
239 (position_.pos_ != 0)) { \
240 msg_ += " in (" + position_.str() + ")"; \
241 } \
242 isc_throw(TypeError, msg_); \
243 }
244
246
254 virtual bool equals(const Element& other,
255 unsigned level = MAX_NESTING_LEVEL) const = 0;
256
263 virtual void toJSON(std::ostream& ss,
264 unsigned level = MAX_NESTING_LEVEL) const = 0;
265
273
274
275 virtual int64_t intValue() const {
276 throwTypeError("intValue() called on non-integer Element");
277 }
278
281 throwTypeError("bigIntValue() called on non-big-integer Element");
282 }
283
285 virtual double doubleValue() const {
286 throwTypeError("doubleValue() called on non-double Element");
287 }
288
290 virtual bool boolValue() const {
291 throwTypeError("boolValue() called on non-Bool Element");
292 }
293
295 virtual std::string stringValue() const {
296 throwTypeError("stringValue() called on non-string Element");
297 }
298
300 virtual const std::vector<ElementPtr>& listValue() const {
301 // replace with real exception or empty vector?
302 throwTypeError("listValue() called on non-list Element");
303 }
304
306 virtual const std::map<std::string, ConstElementPtr>& mapValue() const {
307 // replace with real exception or empty map?
308 throwTypeError("mapValue() called on non-map Element");
309 }
310
311
320
321
325 virtual bool getValue(int64_t& t) const;
326
331 virtual bool getValue(double& t) const;
332
337 virtual bool getValue(bool& t) const;
338
343 virtual bool getValue(std::string& t) const;
344
349 virtual bool getValue(std::vector<ElementPtr>& t) const;
350
355 virtual bool getValue(std::map<std::string, ConstElementPtr>& t) const;
357
367
368
372 virtual bool setValue(const long long int v);
373
378 virtual bool setValue(const isc::util::int128_t& v);
379
384 virtual bool setValue(const double v);
385
390 virtual bool setValue(const bool t);
391
396 virtual bool setValue(const std::string& v);
397
402 virtual bool setValue(const std::vector<ElementPtr>& v);
403
408 virtual bool setValue(const std::map<std::string, ConstElementPtr>& v);
409
415 bool setValue(const long int i) {
416 return (setValue(static_cast<long long int>(i)));
417 }
418
424 bool setValue(const int i) {
425 return (setValue(static_cast<long long int>(i)));
426 }
427
428
429 // Other functions for specific subtypes.
430
435
436
440 virtual ConstElementPtr get(const int i) const;
441
446 virtual ElementPtr getNonConst(const int i) const;
447
452 virtual void set(const size_t i, ElementPtr element);
453
456 virtual void add(ElementPtr element);
457
461 virtual void remove(const int i);
462
464 virtual size_t size() const;
465
467 virtual bool empty() const;
469
470
475
476
479 virtual ConstElementPtr get(const std::string& name) const;
480
484 virtual void set(const std::string& name, ConstElementPtr element);
485
488 virtual void remove(const std::string& name);
489
493 virtual bool contains(const std::string& name) const;
494
508 virtual ConstElementPtr find(const std::string& identifier) const;
509
514 virtual bool find(const std::string& identifier, ConstElementPtr& t) const;
516
518
519 // TODO: should we move all factory functions to a different class
520 // so as not to burden the Element base with too many functions?
521 // and/or perhaps even to a separate header?
522
535
536
540 static ElementPtr create(const Position& pos = ZERO_POSITION());
541
547 static ElementPtr create(const long long int i,
548 const Position& pos = ZERO_POSITION());
549
555 static ElementPtr create(const int i,
556 const Position& pos = ZERO_POSITION());
557
563 static ElementPtr create(const long int i,
564 const Position& pos = ZERO_POSITION());
565
571 static ElementPtr create(const uint32_t i,
572 const Position& pos = ZERO_POSITION());
573
579 static ElementPtr create(const isc::util::int128_t& i,
580 const Position& pos = ZERO_POSITION());
581
587 static ElementPtr create(const double d,
588 const Position& pos = ZERO_POSITION());
589
595 static ElementPtr create(const bool b,
596 const Position& pos = ZERO_POSITION());
597
603 static ElementPtr create(const std::string& s,
604 const Position& pos = ZERO_POSITION());
605
606 // need both std:string and char *, since c++ will match
607 // bool before std::string when you pass it a char *
608
614 static ElementPtr create(const char *s,
615 const Position& pos = ZERO_POSITION());
616
621 static ElementPtr createList(const Position& pos = ZERO_POSITION());
622
627 static ElementPtr createMap(const Position& pos = ZERO_POSITION());
629
631
635
637
643 static ElementPtr fromJSON(const std::string& in, bool preproc = false);
644
654 static ElementPtr fromJSON(std::istream& in, bool preproc = false);
655
667 static ElementPtr fromJSON(std::istream& in, const std::string& file_name,
668 bool preproc = false);
669
682 // make this one private?
684 static ElementPtr fromJSON(std::istream& in, const std::string& file,
685 int& line, int &pos,
686 unsigned level = MAX_NESTING_LEVEL);
687
695 static ElementPtr fromJSONFile(const std::string& file_name,
696 bool preproc = false);
698
700
706 static std::string typeToName(Element::types type);
707
713 static Element::types nameToType(const std::string& type_name);
714
729 static void preprocess(std::istream& in, std::stringstream& out);
730
732
736
738
747 static ElementPtr fromWire(std::stringstream& in, int length);
748
756 static ElementPtr fromWire(const std::string& s);
758
764};
765
776class IntElement : public Element {
777 int64_t i;
778public:
779 IntElement(int64_t v, const Position& pos = ZERO_POSITION())
780 : Element(integer, pos), i(v) { }
781 int64_t intValue() const { return (i); }
782 using Element::getValue;
783 bool getValue(int64_t& t) const { t = i; return (true); }
784 using Element::setValue;
785 bool setValue(long long int v) { i = v; return (true); }
786 void toJSON(std::ostream& ss,
787 unsigned level = MAX_NESTING_LEVEL) const;
788 bool equals(const Element& other,
789 unsigned level = MAX_NESTING_LEVEL) const;
790};
791
793class BigIntElement : public Element {
794 using int128_t = isc::util::int128_t;
795 using Element::getValue;
796 using Element::setValue;
797
798public:
800 BigIntElement(const int128_t& v, const Position& pos = ZERO_POSITION())
801 : Element(bigint, pos), i_(v) {
802 }
803
807 int128_t bigIntValue() const override {
808 return (i_);
809 }
810
814 bool setValue(const int128_t& v) override {
815 i_ = v;
816 return (true);
817 }
818
824 void toJSON(std::ostream& ss,
825 unsigned level = MAX_NESTING_LEVEL) const override;
826
833 bool equals(const Element& other,
834 unsigned level = MAX_NESTING_LEVEL) const override;
835
836private:
838 int128_t i_;
839};
840
841class DoubleElement : public Element {
842 double d;
843
844public:
845 DoubleElement(double v, const Position& pos = ZERO_POSITION())
846 : Element(real, pos), d(v) {}
847 double doubleValue() const { return (d); }
848 using Element::getValue;
849 bool getValue(double& t) const { t = d; return (true); }
850 using Element::setValue;
851 bool setValue(const double v) { d = v; return (true); }
852 void toJSON(std::ostream& ss,
853 unsigned level = MAX_NESTING_LEVEL) const;
854 bool equals(const Element& other,
855 unsigned level = MAX_NESTING_LEVEL) const;
856};
857
858class BoolElement : public Element {
859 bool b;
860
861public:
862 BoolElement(const bool v, const Position& pos = ZERO_POSITION())
863 : Element(boolean, pos), b(v) {}
864 bool boolValue() const { return (b); }
865 using Element::getValue;
866 bool getValue(bool& t) const { t = b; return (true); }
867 using Element::setValue;
868 bool setValue(const bool v) { b = v; return (true); }
869 void toJSON(std::ostream& ss,
870 unsigned level = MAX_NESTING_LEVEL) const;
871 bool equals(const Element& other,
872 unsigned level = MAX_NESTING_LEVEL) const;
873};
874
875class NullElement : public Element {
876public:
878 : Element(null, pos) {}
879 void toJSON(std::ostream& ss,
880 unsigned level = MAX_NESTING_LEVEL) const;
881 bool equals(const Element& other,
882 unsigned level = MAX_NESTING_LEVEL) const;
883};
884
885class StringElement : public Element {
886 std::string s;
887
888public:
889 StringElement(std::string v, const Position& pos = ZERO_POSITION())
890 : Element(string, pos), s(v) {}
891 std::string stringValue() const { return (s); }
892 using Element::getValue;
893 bool getValue(std::string& t) const { t = s; return (true); }
894 using Element::setValue;
895 bool setValue(const std::string& v) { s = v; return (true); }
896 void toJSON(std::ostream& ss,
897 unsigned level = MAX_NESTING_LEVEL) const;
898 bool equals(const Element& other,
899 unsigned level = MAX_NESTING_LEVEL) const;
900};
901
902class ListElement : public Element {
903 std::vector<ElementPtr> l;
904
905public:
907 : Element(list, pos) {}
908 const std::vector<ElementPtr>& listValue() const { return (l); }
909 using Element::getValue;
910 bool getValue(std::vector<ElementPtr>& t) const {
911 t = l;
912 return (true);
913 }
914 using Element::setValue;
915 bool setValue(const std::vector<ElementPtr>& v) {
916 l = v;
917 return (true);
918 }
919 using Element::get;
920 ConstElementPtr get(int i) const { return (l.at(i)); }
921 ElementPtr getNonConst(int i) const { return (l.at(i)); }
922 using Element::set;
923 void set(size_t i, ElementPtr e) {
924 l.at(i) = e;
925 }
926 void add(ElementPtr e) { l.push_back(e); }
927 using Element::remove;
928 void remove(int i) { l.erase(l.begin() + i); }
929 void toJSON(std::ostream& ss,
930 unsigned level = MAX_NESTING_LEVEL) const;
931 size_t size() const { return (l.size()); }
932 bool empty() const { return (l.empty()); }
933 bool equals(const Element& other,
934 unsigned level = MAX_NESTING_LEVEL) const;
935
945 void sort(std::string const& index = std::string());
946};
947
948class MapElement : public Element {
949 std::map<std::string, ConstElementPtr> m;
950
951public:
952 MapElement(const Position& pos = ZERO_POSITION()) : Element(map, pos) {}
953 // @todo should we have direct iterators instead of exposing the std::map
954 // here?
955 const std::map<std::string, ConstElementPtr>& mapValue() const override {
956 return (m);
957 }
958 using Element::getValue;
959 bool getValue(std::map<std::string, ConstElementPtr>& t) const override {
960 t = m;
961 return (true);
962 }
963 using Element::setValue;
964 bool setValue(const std::map<std::string, ConstElementPtr>& v) override {
965 m = v;
966 return (true);
967 }
968 using Element::get;
969 ConstElementPtr get(const std::string& s) const override {
970 auto found = m.find(s);
971 return (found != m.end() ? found->second : ConstElementPtr());
972 }
973
980 ConstElementPtr get(int const i) const override {
981 auto it(m.begin());
982 std::advance(it, i);
983 return create(it->first);
984 }
985
986 using Element::set;
987 void set(const std::string& key, ConstElementPtr value) override;
988 using Element::remove;
989 void remove(const std::string& s) override { m.erase(s); }
990
994 void remove(int const i) override {
995 auto it(m.begin());
996 std::advance(it, i);
997 m.erase(it);
998 }
999
1000 bool contains(const std::string& s) const override {
1001 return (m.find(s) != m.end());
1002 }
1003 void toJSON(std::ostream& ss,
1004 unsigned level = MAX_NESTING_LEVEL) const override;
1005
1006 // we should name the two finds better...
1007 // find the element at id; raises TypeError if one of the
1008 // elements at path except the one we're looking for is not a
1009 // mapelement.
1010 // returns an empty element if the item could not be found
1011 ConstElementPtr find(const std::string& id) const override;
1012
1013 // find the Element at 'id', and store the element pointer in t
1014 // returns true if found, or false if not found (either because
1015 // it doesn't exist or one of the elements in the path is not
1016 // a MapElement)
1017 bool find(const std::string& id, ConstElementPtr& t) const override;
1018
1022 size_t size() const override {
1023 return (m.size());
1024 }
1025
1026 bool equals(const Element& other,
1027 unsigned level = MAX_NESTING_LEVEL) const override;
1028
1029 bool empty() const override { return (m.empty()); }
1030};
1031
1035bool isNull(ConstElementPtr p);
1036
1049
1059
1061
1073void merge(ElementPtr element, ConstElementPtr other);
1074
1085typedef std::function<bool (ElementPtr&, ElementPtr&)> MatchTestFunc;
1086
1089typedef std::function<bool (ElementPtr&)> NoDataTestFunc;
1090
1092typedef std::function<bool (const std::string&)> IsKeyTestFunc;
1093
1101
1104typedef std::map<std::string, HierarchyTraversalTest> FunctionMap;
1105
1119typedef std::vector<FunctionMap> HierarchyDescriptor;
1120
1141void mergeDiffAdd(ElementPtr& element, ElementPtr& other,
1142 HierarchyDescriptor& hierarchy, std::string key,
1143 size_t idx = 0, unsigned level = Element::MAX_NESTING_LEVEL);
1144
1164void mergeDiffDel(ElementPtr& element, ElementPtr& other,
1165 HierarchyDescriptor& hierarchy, std::string key,
1166 size_t idx = 0, unsigned level = Element::MAX_NESTING_LEVEL);
1167
1185void extend(const std::string& container, const std::string& extension,
1186 ElementPtr& element, ElementPtr& other,
1187 HierarchyDescriptor& hierarchy, std::string key, size_t idx = 0,
1188 bool alter = false, unsigned level = Element::MAX_NESTING_LEVEL);
1189
1203
1214
1219bool IsCircular(ConstElementPtr element);
1220
1227unsigned getNestDepth(ConstElementPtr element,
1228 unsigned max_depth = Element::MAX_NESTING_LEVEL);
1229
1241void prettyPrint(ConstElementPtr element, std::ostream& out,
1242 unsigned indent = 0, unsigned step = 2);
1243
1254std::string prettyPrint(ConstElementPtr element,
1255 unsigned indent = 0, unsigned step = 2);
1256
1267std::ostream& operator<<(std::ostream& out, const Element::Position& pos);
1268
1283std::ostream& operator<<(std::ostream& out, const Element& e);
1284
1290bool operator==(const Element& a, const Element& b);
1291
1297bool operator!=(const Element& a, const Element& b);
1298
1310bool operator<(const Element& a, const Element& b);
1311
1312} // namespace data
1313} // namespace isc
1314
1315#endif // ISC_DATA_H
Element(types t, const Position &pos=ZERO_POSITION())
Constructor.
Definition data.h:181
This is a base class for exceptions thrown from the DNS library module.
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
bool setValue(const int128_t &v) override
Sets the underlying big integer value.
Definition data.h:814
void toJSON(std::ostream &ss, unsigned level=MAX_NESTING_LEVEL) const override
Converts the Element to JSON format and appends it to the given stringstream.
Definition data.cc:900
BigIntElement(const int128_t &v, const Position &pos=ZERO_POSITION())
Constructor.
Definition data.h:800
int128_t bigIntValue() const override
Retrieve the underlying big integer value.
Definition data.h:807
bool equals(const Element &other, unsigned level=MAX_NESTING_LEVEL) const override
Checks whether the other Element is equal.
Definition data.cc:1107
bool getValue(bool &t) const
Get the boolean value.
Definition data.h:866
bool setValue(const bool v)
Set the boolean value.
Definition data.h:868
bool equals(const Element &other, unsigned level=MAX_NESTING_LEVEL) const
Test equality.
Definition data.cc:1124
BoolElement(const bool v, const Position &pos=ZERO_POSITION())
Definition data.h:862
bool boolValue() const
Return the boolean value.
Definition data.h:864
void toJSON(std::ostream &ss, unsigned level=MAX_NESTING_LEVEL) const
Converts the Element to JSON format and appends it to the given output stream.
Definition data.cc:921
void toJSON(std::ostream &ss, unsigned level=MAX_NESTING_LEVEL) const
Converts the Element to JSON format and appends it to the given output stream.
Definition data.cc:905
bool setValue(const double v)
Set the double value.
Definition data.h:851
DoubleElement(double v, const Position &pos=ZERO_POSITION())
Definition data.h:845
bool equals(const Element &other, unsigned level=MAX_NESTING_LEVEL) const
Test equality.
Definition data.cc:1118
double doubleValue() const
Return the double value.
Definition data.h:847
bool getValue(double &t) const
Get the double value.
Definition data.h:849
The Element class represents a piece of data, used by the command channel and configuration parts.
Definition data.h:73
const Position & getPosition() const
Returns position where the data element's value starts in a configuration string.
Definition data.h:201
static ElementPtr create(const Position &pos=ZERO_POSITION())
Create a NullElement.
Definition data.cc:299
virtual bool getValue(int64_t &t) const
Get the integer value.
Definition data.cc:123
static std::string typeToName(Element::types type)
Returns the name of the given type as a string.
Definition data.cc:709
virtual int64_t intValue() const
Return the integer value.
Definition data.h:275
static constexpr unsigned MAX_NESTING_LEVEL
Maximum nesting level of Element objects.
Definition data.h:86
std::string str() const
Returns a string representing the Element and all its child elements.
Definition data.cc:104
virtual std::string stringValue() const
Return the string value.
Definition data.h:295
std::string toWire() const
Returns the wireformat for the Element and all its child elements.
Definition data.cc:111
virtual void toJSON(std::ostream &ss, unsigned level=MAX_NESTING_LEVEL) const =0
Converts the Element to JSON format and appends it to the given output stream.
static ElementPtr fromWire(std::stringstream &in, int length)
These function parse the wireformat at the given stringstream (of the given length).
Definition data.cc:1061
virtual bool setValue(const long long int v)
Set the integer value.
Definition data.cc:153
static ElementPtr fromJSONFile(const std::string &file_name, bool preproc=false)
Reads contents of specified file and interprets it as JSON.
Definition data.cc:878
virtual bool empty() const
Return true if there are no elements in the list.
Definition data.cc:218
virtual void remove(const int i)
Removes the element at the given position.
Definition data.cc:208
virtual bool contains(const std::string &name) const
Checks if there is data at the given key.
Definition data.cc:238
virtual ConstElementPtr find(const std::string &identifier) const
Recursively finds any data at the given identifier.
Definition data.cc:243
virtual size_t size() const
Returns the number of elements in the list.
Definition data.cc:213
Element(types t, const Position &pos=ZERO_POSITION())
Constructor.
Definition data.h:181
static const Position & ZERO_POSITION()
Returns Position object with line_ and pos_ set to 0, and with an empty file name.
Definition data.h:139
virtual const std::map< std::string, ConstElementPtr > & mapValue() const
Return the map value.
Definition data.h:306
virtual void add(ElementPtr element)
Adds an ElementPtr to the list.
Definition data.cc:203
virtual const std::vector< ElementPtr > & listValue() const
Return the list value.
Definition data.h:300
virtual ~Element()
Definition data.h:188
bool setValue(const long int i)
Set the integer value (long int overload).
Definition data.h:415
virtual bool equals(const Element &other, unsigned level=MAX_NESTING_LEVEL) const =0
Test equality.
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:859
virtual ConstElementPtr get(const int i) const
Returns the ElementPtr at the given index.
Definition data.cc:188
types
The types that an Element can hold.
Definition data.h:152
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition data.cc:354
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:735
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
Definition data.cc:349
virtual void set(const size_t i, ElementPtr element)
Sets the ElementPtr at the given index.
Definition data.cc:198
virtual double doubleValue() const
Return the double value.
Definition data.h:285
bool setValue(const int i)
Set the integer value (int overload).
Definition data.h:424
virtual isc::util::int128_t bigIntValue() const
Return the big integer value.
Definition data.h:280
types getType() const
Definition data.h:191
virtual bool boolValue() const
Return the boolean value.
Definition data.h:290
static void preprocess(std::istream &in, std::stringstream &out)
input text preprocessor.
Definition data.cc:1752
virtual ElementPtr getNonConst(const int i) const
returns element as non-const pointer.
Definition data.cc:193
void removeEmptyContainersRecursively(unsigned level=MAX_NESTING_LEVEL)
Remove all empty maps and lists from this Element and its descendants.
Definition data.cc:57
bool setValue(long long int v)
Set the integer value.
Definition data.h:785
IntElement(int64_t v, const Position &pos=ZERO_POSITION())
Definition data.h:779
int64_t intValue() const
Return the integer value.
Definition data.h:781
bool getValue(int64_t &t) const
Get the integer value.
Definition data.h:783
void toJSON(std::ostream &ss, unsigned level=MAX_NESTING_LEVEL) const
Converts the Element to JSON format and appends it to the given output stream.
Definition data.cc:895
bool equals(const Element &other, unsigned level=MAX_NESTING_LEVEL) const
Test equality.
Definition data.cc:1096
JSONError(const char *file, size_t line, const char *what)
Definition data.h:52
void sort(std::string const &index=std::string())
Sorts the elements inside the list.
Definition data.cc:1163
void toJSON(std::ostream &ss, unsigned level=MAX_NESTING_LEVEL) const
Converts the Element to JSON format and appends it to the given output stream.
Definition data.cc:983
bool empty() const
Return true if there are no elements in the list.
Definition data.h:932
const std::vector< ElementPtr > & listValue() const
Return the list value.
Definition data.h:908
void remove(int i)
Removes the element at the given position.
Definition data.h:928
bool getValue(std::vector< ElementPtr > &t) const
Get the list value.
Definition data.h:910
void add(ElementPtr e)
Adds an ElementPtr to the list.
Definition data.h:926
ElementPtr getNonConst(int i) const
returns element as non-const pointer.
Definition data.h:921
void set(size_t i, ElementPtr e)
Sets the ElementPtr at the given index.
Definition data.h:923
size_t size() const
Returns the number of elements in the list.
Definition data.h:931
bool setValue(const std::vector< ElementPtr > &v)
Set the list value.
Definition data.h:915
ListElement(const Position &pos=ZERO_POSITION())
Definition data.h:906
bool equals(const Element &other, unsigned level=MAX_NESTING_LEVEL) const
Test equality.
Definition data.cc:1141
ConstElementPtr get(int i) const
Returns the ElementPtr at the given index.
Definition data.h:920
bool contains(const std::string &s) const override
Checks if there is data at the given key.
Definition data.h:1000
const std::map< std::string, ConstElementPtr > & mapValue() const override
Return the map value.
Definition data.h:955
ConstElementPtr find(const std::string &id) const override
Recursively finds any data at the given identifier.
Definition data.cc:1033
void set(const std::string &key, ConstElementPtr value) override
Sets the ElementPtr at the given key.
Definition data.cc:1077
ConstElementPtr get(const std::string &s) const override
Returns the ElementPtr at the given key.
Definition data.h:969
bool setValue(const std::map< std::string, ConstElementPtr > &v) override
Set the map value.
Definition data.h:964
ConstElementPtr get(int const i) const override
Get the i-th element in the map.
Definition data.h:980
bool equals(const Element &other, unsigned level=MAX_NESTING_LEVEL) const override
Test equality.
Definition data.cc:1199
void toJSON(std::ostream &ss, unsigned level=MAX_NESTING_LEVEL) const override
Converts the Element to JSON format and appends it to the given output stream.
Definition data.cc:1004
bool empty() const override
Return true if there are no elements in the list.
Definition data.h:1029
void remove(int const i) override
Remove the i-th element from the map.
Definition data.h:994
void remove(const std::string &s) override
Remove the ElementPtr at the given key.
Definition data.h:989
bool getValue(std::map< std::string, ConstElementPtr > &t) const override
Get the map value.
Definition data.h:959
MapElement(const Position &pos=ZERO_POSITION())
Definition data.h:952
size_t size() const override
Returns number of stored elements.
Definition data.h:1022
bool equals(const Element &other, unsigned level=MAX_NESTING_LEVEL) const
Test equality.
Definition data.cc:1130
NullElement(const Position &pos=ZERO_POSITION())
Definition data.h:877
void toJSON(std::ostream &ss, unsigned level=MAX_NESTING_LEVEL) const
Converts the Element to JSON format and appends it to the given output stream.
Definition data.cc:930
std::string stringValue() const
Return the string value.
Definition data.h:891
bool equals(const Element &other, unsigned level=MAX_NESTING_LEVEL) const
Test equality.
Definition data.cc:1135
bool setValue(const std::string &v)
Set the string value.
Definition data.h:895
void toJSON(std::ostream &ss, unsigned level=MAX_NESTING_LEVEL) const
Converts the Element to JSON format and appends it to the given output stream.
Definition data.cc:935
bool getValue(std::string &t) const
Get the string value.
Definition data.h:893
StringElement(std::string v, const Position &pos=ZERO_POSITION())
Definition data.h:889
TypeError(const char *file, size_t line, const char *what)
Definition data.h:39
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:30
boost::shared_ptr< Element > ElementPtr
Definition data.h:29
boost::multiprecision::checked_int128_t int128_t
Definition bigints.h:19
#define throwTypeError(error)
Add the position to a TypeError message should be used in place of isc_throw(TypeError,...
Definition data.h:234
bool operator==(const Element &a, const Element &b)
Test equality.
Definition data.cc:268
void extend(const std::string &container, const std::string &extension, ElementPtr &element, ElementPtr &other, HierarchyDescriptor &hierarchy, std::string key, size_t idx, bool alter, unsigned level)
Extends data by adding the specified 'extension' elements from 'other' inside the 'container' element...
Definition data.cc:1459
void removeIdentical(ElementPtr a, ConstElementPtr b)
Remove all values from the first ElementPtr that are equal in the second.
Definition data.cc:1230
void merge(ElementPtr element, ConstElementPtr other)
Merges the data from other into element. (on the first level).
Definition data.cc:1276
std::map< std::string, HierarchyTraversalTest > FunctionMap
Mapping between a container name and functions used to match elements inside the container.
Definition data.h:1104
bool isEquivalent(ConstElementPtr a, ConstElementPtr b)
Compares the data with other using unordered lists.
Definition data.cc:1639
bool operator<(Element const &a, Element const &b)
Test less than.
Definition data.cc:277
bool IsCircular(ConstElementPtr element)
Check if the data is circular.
Definition data.cc:1818
void prettyPrint(ConstElementPtr element, std::ostream &out, unsigned indent, unsigned step)
Pretty prints the data into stream.
Definition data.cc:1740
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:1089
ElementPtr copy(ConstElementPtr from, unsigned level)
Copy the data up to a nesting level.
Definition data.cc:1517
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:30
void mergeDiffAdd(ElementPtr &element, ElementPtr &other, HierarchyDescriptor &hierarchy, std::string key, size_t idx, unsigned level)
Merges the diff data by adding the missing elements from 'other' to 'element' (recursively).
Definition data.cc:1294
unsigned getNestDepth(ConstElementPtr element, unsigned max_depth)
Compute the nesting depth.
Definition data.cc:1823
bool isNull(ConstElementPtr p)
Checks whether the given ElementPtr is a null pointer.
Definition data.cc:1225
std::function< bool(ElementPtr &, ElementPtr &)> MatchTestFunc
Function used to check if two MapElements refer to the same configuration data.
Definition data.h:1085
std::ostream & operator<<(std::ostream &out, const Element::Position &pos)
Insert Element::Position as a string into stream.
Definition data.cc:51
std::function< bool(const std::string &)> IsKeyTestFunc
Function used to check if the key is used for identification.
Definition data.h:1092
void mergeDiffDel(ElementPtr &element, ElementPtr &other, HierarchyDescriptor &hierarchy, std::string key, size_t idx, unsigned level)
Merges the diff data by removing the data present in 'other' from 'element' (recursively).
Definition data.cc:1362
bool operator!=(const Element &a, const Element &b)
Test inequality.
Definition data.cc:272
boost::shared_ptr< Element > ElementPtr
Definition data.h:29
std::vector< FunctionMap > HierarchyDescriptor
Hierarchy descriptor of the containers in a specific Element hierarchy tree.
Definition data.h:1119
boost::multiprecision::checked_int128_t int128_t
Definition bigints.h:19
Defines the logger used by the top-level component of kea-lfc.
Position()
Default constructor.
Definition data.h:113
Represents the position of the data element within a configuration string.
Definition data.h:107
Position(const std::string &file, const uint32_t line, const uint32_t pos)
Constructor.
Definition data.h:121
uint32_t pos_
Position within the line.
Definition data.h:110
std::string str() const
Returns the position in the textual format.
Definition data.cc:44
Position()
Default constructor.
Definition data.h:113
uint32_t line_
Line number.
Definition data.h:109
std::string file_
File name.
Definition data.h:108
Structure holding the test functions used to traverse the element hierarchy.
Definition data.h:1096