Kea 3.1.5
isc::data::ListElement Class Reference

#include <data.h>

+ Inheritance diagram for isc::data::ListElement:

Public Member Functions

 ListElement (const Position &pos=ZERO_POSITION())
 
void add (ElementPtr e)
 Adds an ElementPtr to the list.
 
bool empty () const
 Return true if there are no elements in the list.
 
bool equals (const Element &other, unsigned level=MAX_NESTING_LEVEL) const
 Test equality.
 
virtual ConstElementPtr get (const std::string &name) const
 Returns the ElementPtr at the given key.
 
ConstElementPtr get (int i) const
 Returns the ElementPtr at the given index.
 
ElementPtr getNonConst (int i) const
 returns element as non-const pointer.
 
virtual bool getValue (bool &t) const
 Get the boolean value.
 
virtual bool getValue (double &t) const
 Get the double value.
 
virtual bool getValue (int64_t &t) const
 Get the integer value.
 
virtual bool getValue (std::map< std::string, ConstElementPtr > &t) const
 Get the map value.
 
virtual bool getValue (std::string &t) const
 Get the string value.
 
bool getValue (std::vector< ElementPtr > &t) const
 Get the list value.
 
const std::vector< ElementPtr > & listValue () const
 Return the list value.
 
virtual void remove (const std::string &name)
 Remove the ElementPtr at the given key.
 
void remove (int i)
 Removes the element at the given position.
 
virtual void set (const std::string &name, ConstElementPtr element)
 Sets the ElementPtr at the given key.
 
void set (size_t i, ElementPtr e)
 Sets the ElementPtr at the given index.
 
virtual bool setValue (const bool t)
 Set the boolean value.
 
virtual bool setValue (const double v)
 Set the double value.
 
bool setValue (const int i)
 Set the integer value (int overload).
 
virtual bool setValue (const isc::util::int128_t &v)
 Set the big integer value.
 
bool setValue (const long int i)
 Set the integer value (long int overload).
 
virtual bool setValue (const long long int v)
 Set the integer value.
 
virtual bool setValue (const std::map< std::string, ConstElementPtr > &v)
 Set the map value.
 
virtual bool setValue (const std::string &v)
 Set the string value.
 
bool setValue (const std::vector< ElementPtr > &v)
 Set the list value.
 
size_t size () const
 Returns the number of elements in the list.
 
void sort (std::string const &index=std::string())
 Sorts the elements inside the list.
 
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.
 
- Public Member Functions inherited from isc::data::Element
virtual ~Element ()
 
const PositiongetPosition () const
 Returns position where the data element's value starts in a configuration string.
 
types getType () const
 
std::string str () const
 Returns a string representing the Element and all its child elements.
 
std::string toWire () const
 Returns the wireformat for the Element and all its child elements.
 
void toWire (std::ostream &out) const
 Appends the wireformat for the Element to the stream.
 
virtual int64_t intValue () const
 Return the integer value.
 
virtual isc::util::int128_t bigIntValue () const
 Return the big integer value.
 
virtual double doubleValue () const
 Return the double value.
 
virtual bool boolValue () const
 Return the boolean value.
 
virtual std::string stringValue () const
 Return the string value.
 
virtual const std::map< std::string, ConstElementPtr > & mapValue () const
 Return the map value.
 
bool setValue (const long int i)
 Set the integer value (long int overload).
 
bool setValue (const int i)
 Set the integer value (int overload).
 
virtual bool contains (const std::string &name) const
 Checks if there is data at the given key.
 
virtual ConstElementPtr find (const std::string &identifier) const
 Recursively finds any data at the given identifier.
 
virtual bool find (const std::string &identifier, ConstElementPtr &t) const
 See Element::find()
 
void removeEmptyContainersRecursively (unsigned level=MAX_NESTING_LEVEL)
 Remove all empty maps and lists from this Element and its descendants.
 

Additional Inherited Members

- Public Types inherited from isc::data::Element
enum  types : uint16_t {
  integer = 0 , real = 1 , boolean = 2 , null = 3 ,
  string = 4 , bigint = 5 , list = 6 , map = 7 ,
  any = 8
}
 The types that an Element can hold. More...
 
- Static Public Member Functions inherited from isc::data::Element
static const PositionZERO_POSITION ()
 Returns Position object with line_ and pos_ set to 0, and with an empty file name.
 
static ElementPtr create (const Position &pos=ZERO_POSITION())
 Create a NullElement.
 
static ElementPtr create (const long long int i, const Position &pos=ZERO_POSITION())
 Create an IntElement.
 
static ElementPtr create (const int i, const Position &pos=ZERO_POSITION())
 Create an IntElement (int overload).
 
static ElementPtr create (const long int i, const Position &pos=ZERO_POSITION())
 Create an IntElement (long int overload).
 
static ElementPtr create (const uint32_t i, const Position &pos=ZERO_POSITION())
 Create an IntElement (int32_t overload).
 
static ElementPtr create (const isc::util::int128_t &i, const Position &pos=ZERO_POSITION())
 Create a BigIntElement.
 
static ElementPtr create (const double d, const Position &pos=ZERO_POSITION())
 Create a DoubleElement.
 
static ElementPtr create (const bool b, const Position &pos=ZERO_POSITION())
 Create a BoolElement.
 
static ElementPtr create (const std::string &s, const Position &pos=ZERO_POSITION())
 Create a StringElement.
 
static ElementPtr create (const char *s, const Position &pos=ZERO_POSITION())
 Create a StringElement (char* overload).
 
static ElementPtr createList (const Position &pos=ZERO_POSITION())
 Creates an empty ListElement type ElementPtr.
 
static ElementPtr createMap (const Position &pos=ZERO_POSITION())
 Creates an empty MapElement type ElementPtr.
 
static ElementPtr fromJSON (const std::string &in, bool preproc=false)
 These functions will parse the given string (JSON) representation of a compound element.
 
static ElementPtr fromJSON (std::istream &in, bool preproc=false)
 Creates an Element from the given input stream containing JSON formatted data.
 
static ElementPtr fromJSON (std::istream &in, const std::string &file_name, bool preproc=false)
 Creates an Element from the given input stream containing JSON formatted data.
 
static ElementPtr fromJSON (std::istream &in, const std::string &file, int &line, int &pos, unsigned level=MAX_NESTING_LEVEL)
 Creates an Element from the given input stream, where we keep track of the location in the stream for error reporting.
 
static ElementPtr fromJSONFile (const std::string &file_name, bool preproc=false)
 Reads contents of specified file and interprets it as JSON.
 
static std::string typeToName (Element::types type)
 Returns the name of the given type as a string.
 
static Element::types nameToType (const std::string &type_name)
 Converts the string to the corresponding type Throws a TypeError if the name is unknown.
 
static void preprocess (std::istream &in, std::stringstream &out)
 input text preprocessor.
 
static ElementPtr fromWire (std::stringstream &in, int length)
 These function parse the wireformat at the given stringstream (of the given length).
 
static ElementPtr fromWire (const std::string &s)
 Creates an Element from the wire format in the given string.
 
- Static Public Attributes inherited from isc::data::Element
static constexpr unsigned MAX_NESTING_LEVEL = 100U
 Maximum nesting level of Element objects.
 
- Protected Member Functions inherited from isc::data::Element
 Element (types t, const Position &pos=ZERO_POSITION())
 Constructor.
 

Detailed Description

Definition at line 902 of file data.h.

Constructor & Destructor Documentation

◆ ListElement()

isc::data::ListElement::ListElement ( const Position & pos = ZERO_POSITION())
inline

Definition at line 906 of file data.h.

References isc::data::Element::Element(), and isc::data::Element::list.

+ Here is the call graph for this function:

Member Function Documentation

◆ add()

void isc::data::ListElement::add ( ElementPtr element)
inlinevirtual

Adds an ElementPtr to the list.

Parameters
elementThe ElementPtr to add

Reimplemented from isc::data::Element.

Definition at line 926 of file data.h.

◆ empty()

bool isc::data::ListElement::empty ( ) const
inlinevirtual

Return true if there are no elements in the list.

Reimplemented from isc::data::Element.

Definition at line 932 of file data.h.

◆ equals()

bool isc::data::ListElement::equals ( const Element & other,
unsigned level = MAX_NESTING_LEVEL ) const
virtual

Test equality.

Parameters
otherThe other element to compare with.
levelThe maximum level of recursion.
Returns
true if the other ElementPtr has the same value and the same type (or a different and compatible type), false otherwise.
Exceptions
BadValuewhen nesting depth is more than level.

Implements isc::data::Element.

Definition at line 1141 of file data.cc.

References isc::data::Element::Element(), isc::data::Element::equals(), isc::data::Element::get(), isc::data::Element::getType(), isc_throw, isc::data::Element::list, and isc::data::Element::size().

+ Here is the call graph for this function:

◆ get() [1/2]

ConstElementPtr isc::data::Element::get ( const std::string & name) const
virtual

Returns the ElementPtr at the given key.

Parameters
nameThe key of the Element to return
Returns
The ElementPtr at the given key, or null if not present

Reimplemented from isc::data::Element.

Definition at line 479 of file data.cc.

◆ get() [2/2]

ConstElementPtr isc::data::ListElement::get ( int i) const
inlinevirtual

Returns the ElementPtr at the given index.

If the index is out of bounds, this function throws an std::out_of_range exception.

Parameters
iThe position of the ElementPtr to return
Returns
specified element pointer.

Reimplemented from isc::data::Element.

Definition at line 920 of file data.h.

◆ getNonConst()

ElementPtr isc::data::ListElement::getNonConst ( int i) const
inlinevirtual

returns element as non-const pointer.

Parameters
iThe position of the ElementPtr to retrieve.
Returns
specified element pointer.

Reimplemented from isc::data::Element.

Definition at line 921 of file data.h.

◆ getValue() [1/6]

bool isc::data::Element::getValue ( bool & t) const
virtual

Get the boolean value.

Parameters
tThe reference to the boolean.
Returns
false.

Reimplemented from isc::data::Element.

Definition at line 337 of file data.cc.

◆ getValue() [2/6]

bool isc::data::Element::getValue ( double & t) const
virtual

Get the double value.

Parameters
tThe reference to the double.
Returns
false.

Reimplemented from isc::data::Element.

Definition at line 331 of file data.cc.

◆ getValue() [3/6]

bool isc::data::Element::getValue ( int64_t & t) const
virtual

Get the integer value.

Parameters
tThe reference to the integer.
Returns
false.

Reimplemented from isc::data::Element.

Definition at line 325 of file data.cc.

◆ getValue() [4/6]

bool isc::data::Element::getValue ( std::map< std::string, ConstElementPtr > & t) const
virtual

Get the map value.

Parameters
tThe reference to the map.
Returns
false.

Reimplemented from isc::data::Element.

Definition at line 355 of file data.cc.

◆ getValue() [5/6]

bool isc::data::Element::getValue ( std::string & t) const
virtual

Get the string value.

Parameters
tThe reference to the string.
Returns
false.

Reimplemented from isc::data::Element.

Definition at line 343 of file data.cc.

◆ getValue() [6/6]

bool isc::data::ListElement::getValue ( std::vector< ElementPtr > & t) const
inlinevirtual

Get the list value.

Parameters
tThe reference to the list.
Returns
false.

Reimplemented from isc::data::Element.

Definition at line 910 of file data.h.

◆ listValue()

const std::vector< ElementPtr > & isc::data::ListElement::listValue ( ) const
inlinevirtual

Return the list value.

Reimplemented from isc::data::Element.

Definition at line 908 of file data.h.

◆ remove() [1/2]

void isc::data::Element::remove ( const std::string & name)
virtual

Remove the ElementPtr at the given key.

Parameters
nameThe key of the Element to remove

Reimplemented from isc::data::Element.

Definition at line 488 of file data.cc.

◆ remove() [2/2]

void isc::data::ListElement::remove ( int i)
inlinevirtual

Removes the element at the given position.

If the index is out of nothing happens.

Parameters
iThe index of the element to remove.

Reimplemented from isc::data::Element.

Definition at line 928 of file data.h.

◆ set() [1/2]

void isc::data::Element::set ( const std::string & name,
ConstElementPtr element )
virtual

Sets the ElementPtr at the given key.

Parameters
nameThe key of the Element to set
elementThe ElementPtr to set at the given key.

Reimplemented from isc::data::Element.

Definition at line 484 of file data.cc.

◆ set() [2/2]

void isc::data::ListElement::set ( size_t i,
ElementPtr element )
inlinevirtual

Sets the ElementPtr at the given index.

If the index is out of bounds, this function throws an std::out_of_range exception.

Parameters
iThe position of the ElementPtr to set
elementThe ElementPtr to set at the position

Reimplemented from isc::data::Element.

Definition at line 923 of file data.h.

◆ setValue() [1/9]

bool isc::data::Element::setValue ( const bool t)
virtual

Set the boolean value.

Parameters
tThe new boolean value.
Returns
False.

Reimplemented from isc::data::Element.

Definition at line 390 of file data.cc.

◆ setValue() [2/9]

bool isc::data::Element::setValue ( const double v)
virtual

Set the double value.

Parameters
vThe new double value.
Returns
False.

Reimplemented from isc::data::Element.

Definition at line 384 of file data.cc.

◆ setValue() [3/9]

bool isc::data::Element::setValue ( const int i)
inline

Set the integer value (int overload).

Parameters
iThe new integer value.
Returns
True (and set the value) when the Element type is integer, false otherwise.

Definition at line 424 of file data.h.

◆ setValue() [4/9]

bool isc::data::Element::setValue ( const isc::util::int128_t & v)
virtual

Set the big integer value.

Parameters
vThe new big integer value.
Returns
False.

Reimplemented from isc::data::Element.

Definition at line 378 of file data.cc.

◆ setValue() [5/9]

bool isc::data::Element::setValue ( const long int i)
inline

Set the integer value (long int overload).

Parameters
iThe new integer value.
Returns
True (and set the value) when the Element type is integer, false otherwise.

Definition at line 415 of file data.h.

◆ setValue() [6/9]

bool isc::data::Element::setValue ( const long long int v)
virtual

Set the integer value.

Parameters
vThe new integer value.
Returns
False.

Reimplemented from isc::data::Element.

Definition at line 372 of file data.cc.

◆ setValue() [7/9]

bool isc::data::Element::setValue ( const std::map< std::string, ConstElementPtr > & v)
virtual

Set the map value.

Parameters
vThe new map value.
Returns
False.

Reimplemented from isc::data::Element.

Definition at line 408 of file data.cc.

◆ setValue() [8/9]

bool isc::data::Element::setValue ( const std::string & v)
virtual

Set the string value.

Parameters
vThe new string value.
Returns
False.

Reimplemented from isc::data::Element.

Definition at line 396 of file data.cc.

◆ setValue() [9/9]

bool isc::data::ListElement::setValue ( const std::vector< ElementPtr > & v)
inlinevirtual

Set the list value.

Parameters
vThe new list value.
Returns
False.

Reimplemented from isc::data::Element.

Definition at line 915 of file data.h.

◆ size()

size_t isc::data::ListElement::size ( ) const
inlinevirtual

Returns the number of elements in the list.

Reimplemented from isc::data::Element.

Definition at line 931 of file data.h.

◆ sort()

void isc::data::ListElement::sort ( std::string const & index = std::string())

Sorts the elements inside the list.

The list must contain elements of the same type. Call with the key by which you want to sort when the list contains maps. Nested lists are not supported. Call without a parameter when sorting any other type.

Parameters
indexthe key by which you want to sort when the list contains maps

Definition at line 1163 of file data.cc.

References isc_throw, isc::data::Element::list, and isc::data::Element::map.

◆ toJSON()

void isc::data::ListElement::toJSON ( std::ostream & ss,
unsigned level = MAX_NESTING_LEVEL ) const
virtual

Converts the Element to JSON format and appends it to the given output stream.

Parameters
ssThe output stream where to append the JSON format.
levelThe maximum level of recursion.
Exceptions
BadValuewhen nesting depth is more than level.

Implements isc::data::Element.

Definition at line 983 of file data.cc.

References isc_throw, and isc::data::Element::listValue().

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: