Kea: isc::data::MapElement Class Reference

| Kea 2.2.0

Public Member Functions | List of all members
isc::data::MapElement Class Reference

`#include <data.h>`

Inheritance diagram for isc::data::MapElement:
[legend]

## Public Member Functions
| MapElement (const Position &pos=ZERO_POSITION())
bool | contains (const std::string &s) const override
| Checks if there is data at the given key. More...
bool | empty () const override
| Return true if there are no elements in the list. More...
bool | equals (const Element &other) const override
ConstElementPtr | find (const std::string &id) const override
| Recursively finds any data at the given identifier. More...
bool | find (const std::string &id, ConstElementPtr &t) const override
| See `Element::find()` More...
virtual ConstElementPtr | get (const int i) const
| Returns the ElementPtr at the given index. More...
virtual ConstElementPtr | get (const std::string &name) const
| Returns the ElementPtr at the given key. More...
ConstElementPtr | get (const std::string &s) const override
| Returns the ElementPtr at the given key. More...
ConstElementPtr | get (int const i) const override
| Get the i-th element in the map. More...
virtual bool | getValue (bool &t) const
virtual bool | getValue (double &t) const
virtual bool | getValue (int64_t &t) const
virtual bool | getValue (std::map< std::string, ConstElementPtr > &t) const
bool | getValue (std::map< std::string, ConstElementPtr > &t) const override
virtual bool | getValue (std::string &t) const
virtual bool | getValue (std::vector< ElementPtr > &t) const
const std::map< std::string, ConstElementPtr > & | mapValue () const override
virtual void | remove (const int i)
| Removes the element at the given position. More...
virtual void | remove (const std::string &name)
| Remove the ElementPtr at the given key. More...
void | remove (const std::string &s) override
| Remove the ElementPtr at the given key. More...
void | remove (int const i) override
| Remove the i-th element from the map. More...
virtual void | set (const size_t i, ElementPtr element)
| Sets the ElementPtr at the given index. More...
void | set (const std::string &key, ConstElementPtr value) override
| Sets the ElementPtr at the given key. More...
virtual void | set (const std::string &name, ConstElementPtr element)
| Sets the ElementPtr at the given key. More...
virtual bool | setValue (const bool t)
virtual bool | setValue (const double v)
bool | setValue (const int i)
bool | setValue (const long int i)
virtual bool | setValue (const long long int v)
virtual bool | setValue (const std::map< std::string, ConstElementPtr > &v)
bool | setValue (const std::map< std::string, ConstElementPtr > &v) override
virtual bool | setValue (const std::string &v)
virtual bool | setValue (const std::vector< ElementPtr > &v)
size_t | size () const override
| Returns number of stored elements. More...
void | toJSON (std::ostream &ss) const override
| Converts the Element to JSON format and appends it to the given stringstream. More...
Public Member Functions inherited from isc::data::Element
virtual | ~Element ()
const Position & | getPosition () const
| Returns position where the data element's value starts in a configuration string. More...
int | getType () const
std::string | str () const
| Returns a string representing the Element and all its child elements; note that this is different from stringValue(), which only returns the single value of a StringElement. More...
std::string | toWire () const
| Returns the wireformat for the Element and all its child elements. More...
void | toWire (std::ostream &out) const
virtual int64_t | intValue () const
virtual double | doubleValue () const
virtual bool | boolValue () const
virtual std::string | stringValue () const
virtual const std::vector< ElementPtr > & | listValue () const
bool | setValue (const long int i)
bool | setValue (const int i)
virtual ElementPtr | getNonConst (const int i) const
| returns element as non-const pointer More...
virtual void | add (ElementPtr element)
| Adds an ElementPtr to the list. More...
void | removeEmptyContainersRecursively ()
| Remove all empty maps and lists from this Element and its descendants. More...

## Additional Inherited Members
Public Types inherited from isc::data::Element
enum | types { integer , real , boolean , null , string , list , map , any }
Static Public Member Functions inherited from isc::data::Element
static const Position & | ZERO_POSITION ()
| Returns `Position` object with line_ and pos_ set to 0, and with an empty file name. More...
static ElementPtr | create (const Position &pos=ZERO_POSITION())
static ElementPtr | create (const long long int i, const Position &pos=ZERO_POSITION())
static ElementPtr | create (const int i, const Position &pos=ZERO_POSITION())
static ElementPtr | create (const long int i, const Position &pos=ZERO_POSITION())
static ElementPtr | create (const uint32_t i, const Position &pos=ZERO_POSITION())
static ElementPtr | create (const double d, const Position &pos=ZERO_POSITION())
static ElementPtr | create (const bool b, const Position &pos=ZERO_POSITION())
static ElementPtr | create (const std::string &s, const Position &pos=ZERO_POSITION())
static ElementPtr | create (const char *s, const Position &pos=ZERO_POSITION())
static ElementPtr | createList (const Position &pos=ZERO_POSITION())
| Creates an empty ListElement type ElementPtr. More...
static ElementPtr | createMap (const Position &pos=ZERO_POSITION())
| Creates an empty MapElement type ElementPtr. More...
static ElementPtr | fromJSON (const std::string &in, bool preproc=false)
| These functions will parse the given string (JSON) representation of a compound element. More...
static ElementPtr | fromJSON (std::istream &in, bool preproc=false)
| Creates an Element from the given input stream containing JSON formatted data. More...
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. More...
static ElementPtr | fromJSON (std::istream &in, const std::string &file, int &line, int &pos)
| Creates an Element from the given input stream, where we keep track of the location in the stream for error reporting. More...
static ElementPtr | fromJSONFile (const std::string &file_name, bool preproc=false)
| Reads contents of specified file and interprets it as JSON. More...
static std::string | typeToName (Element::types type)
| Returns the name of the given type as a string. More...
static Element::types | nameToType (const std::string &type_name)
| Converts the string to the corresponding type Throws a TypeError if the name is unknown. More...
static void | preprocess (std::istream &in, std::stringstream &out)
| input text preprocessor More...
static ElementPtr | fromWire (std::stringstream &in, int length)
| These function pparse the wireformat at the given stringstream (of the given length). More...
static ElementPtr | fromWire (const std::string &s)
| Creates an Element from the wire format in the given string Since the wire format is JSON, this is the same as fromJSON, and could be removed. More...
Protected Member Functions inherited from isc::data::Element
| Element (int t, const Position &pos=ZERO_POSITION())
| Constructor. More...

## Detailed Description

Definition at line 701 of file data.h.

## Constructor & Destructor Documentation

## ◆ MapElement()

isc::data::MapElement::MapElement | ( | const Position & | pos = `ZERO_POSITION()` | ) |
| inline

Definition at line 705 of file data.h.

## Member Function Documentation

## ◆ contains()

bool isc::data::MapElement::contains | ( | const std::string & | name | ) | const
| inlineoverridevirtual

Checks if there is data at the given key.

Parameters

  name | The key of the Element checked for existence

Returns
  true if there is data at the key, false if not.

Reimplemented from isc::data::Element.

Definition at line 753 of file data.h.

## ◆ empty()

bool isc::data::MapElement::empty | ( |  | ) | const
| inlineoverridevirtual

Return true if there are no elements in the list.

Reimplemented from isc::data::Element.

Definition at line 780 of file data.h.

## ◆ equals()

bool isc::data::MapElement::equals | ( | const Element & | other | ) | const
| overridevirtual

Returns
  true if the other ElementPtr has the same type and value

Implements isc::data::Element.

Definition at line 1066 of file data.cc.

References isc::data::Element::contains(), isc::data::Element::equals(), isc::data::Element::get(), isc::data::Element::getType(), isc::data::Element::map, isc::data::Element::mapValue(), and isc::data::Element::size().

Here is the call graph for this function:

## ◆ find() [1/2]

ConstElementPtr isc::data::MapElement::find | ( | const std::string & | identifier | ) | const
| overridevirtual

Recursively finds any data at the given identifier.

The identifier is a /-separated list of names of nested maps, with the last name being the leaf that is returned.

For instance, if you have a MapElement that contains another MapElement at the key "foo", and that second MapElement contains Another Element at key "bar", the identifier for that last element from the first is "foo/bar".

Parameters

  identifier | The identifier of the element to find

Returns
  The ElementPtr at the given identifier. Returns a null ElementPtr if it is not found, which can be checked with Element::is_null(ElementPtr e).

Reimplemented from isc::data::Element.

Definition at line 920 of file data.cc.

References isc::data::Element::get(), and isc::data::Element::size().

Here is the call graph for this function:

## ◆ find() [2/2]

bool isc::data::MapElement::find | ( | const std::string & | identifier,
|  | ConstElementPtr & | t
| ) |  | const
| overridevirtual

See `Element::find()`

Parameters

  identifier | The identifier of the element to find
  t | Reference to store the resulting ElementPtr, if found.

Returns
  true if the element was found, false if not.

Reimplemented from isc::data::Element.

Definition at line 969 of file data.cc.

References isc::data::Element::find().

Here is the call graph for this function:

## ◆ get() [1/4]

ConstElementPtr isc::data::Element::get | ( | const int | i | ) | const
| virtual

Returns the ElementPtr at the given index.

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

Parameters

  i | The position of the ElementPtr to return

Reimplemented from isc::data::Element.

Definition at line 280 of file data.cc.

## ◆ get() [2/4]

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

Returns the ElementPtr at the given key.

Parameters

  name | The 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 319 of file data.cc.

## ◆ get() [3/4]

ConstElementPtr isc::data::MapElement::get | ( | const std::string & | name | ) | const
| inlineoverridevirtual

Returns the ElementPtr at the given key.

Parameters

  name | The 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 722 of file data.h.

## ◆ get() [4/4]

ConstElementPtr isc::data::MapElement::get | ( | int const | i | ) | const
| inlineoverridevirtual

Get the i-th element in the map.

Useful when required to iterate with an index.

Parameters

  i | the position of the element you want to return

Returns
  the element at position i

Reimplemented from isc::data::Element.

Definition at line 733 of file data.h.

References isc::data::Element::create().

Here is the call graph for this function:

## ◆ getValue() [1/7]

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

Reimplemented from isc::data::Element.

Definition at line 244 of file data.cc.

## ◆ getValue() [2/7]

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

Reimplemented from isc::data::Element.

Definition at line 243 of file data.cc.

## ◆ getValue() [3/7]

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

Reimplemented from isc::data::Element.

Definition at line 242 of file data.cc.

## ◆ getValue() [4/7]

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

Reimplemented from isc::data::Element.

Definition at line 247 of file data.cc.

## ◆ getValue() [5/7]

bool isc::data::MapElement::getValue | ( | std::map< std::string, ConstElementPtr > & | t | ) | const
| inlineoverridevirtual

Reimplemented from isc::data::Element.

Definition at line 712 of file data.h.

## ◆ getValue() [6/7]

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

Reimplemented from isc::data::Element.

Definition at line 245 of file data.cc.

## ◆ getValue() [7/7]

bool isc::data::Element::getValue | ( | std::vector< ElementPtr > & | t | ) | const
| virtual

Reimplemented from isc::data::Element.

Definition at line 246 of file data.cc.

## ◆ mapValue()

const std::map< std::string, ConstElementPtr > & isc::data::MapElement::mapValue | ( |  | ) | const
| inlineoverridevirtual

Reimplemented from isc::data::Element.

Definition at line 708 of file data.h.

## ◆ remove() [1/4]

void isc::data::Element::remove | ( | const int | i | ) |
| virtual

Removes the element at the given position.

If the index is out of nothing happens.

Parameters

  i | The index of the element to remove.

Reimplemented from isc::data::Element.

Definition at line 301 of file data.cc.

## ◆ remove() [2/4]

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

Remove the ElementPtr at the given key.

Parameters

  name | The key of the Element to remove

Reimplemented from isc::data::Element.

Definition at line 328 of file data.cc.

## ◆ remove() [3/4]

void isc::data::MapElement::remove | ( | const std::string & | name | ) |
| inlineoverridevirtual

Remove the ElementPtr at the given key.

Parameters

  name | The key of the Element to remove

Reimplemented from isc::data::Element.

Definition at line 742 of file data.h.

## ◆ remove() [4/4]

void isc::data::MapElement::remove | ( | int const | i | ) |
| inlineoverridevirtual

Remove the i-th element from the map.

Parameters

  i | the position of the element you want to remove

Reimplemented from isc::data::Element.

Definition at line 747 of file data.h.

## ◆ set() [1/3]

void isc::data::Element::set | ( | const size_t | i,
|  | ElementPtr | element
| ) |  |
| virtual

Sets the ElementPtr at the given index.

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

Parameters

  i | The position of the ElementPtr to set
  element | The ElementPtr to set at the position

Reimplemented from isc::data::Element.

Definition at line 292 of file data.cc.

## ◆ set() [2/3]

void isc::data::MapElement::set | ( | const std::string & | name,
|  | ConstElementPtr | element
| ) |  |
| overridevirtual

Sets the ElementPtr at the given key.

Parameters

  name | The key of the Element to set
  element | The ElementPtr to set at the given key.

Reimplemented from isc::data::Element.

Definition at line 964 of file data.cc.

## ◆ set() [3/3]

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

Sets the ElementPtr at the given key.

Parameters

  name | The key of the Element to set
  element | The ElementPtr to set at the given key.

Reimplemented from isc::data::Element.

Definition at line 324 of file data.cc.

## ◆ setValue() [1/9]

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

Reimplemented from isc::data::Element.

Definition at line 264 of file data.cc.

## ◆ setValue() [2/9]

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

Reimplemented from isc::data::Element.

Definition at line 263 of file data.cc.

## ◆ setValue() [3/9]

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

Definition at line 262 of file data.h.

## ◆ setValue() [4/9]

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

Definition at line 261 of file data.h.

## ◆ setValue() [5/9]

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

Reimplemented from isc::data::Element.

Definition at line 260 of file data.cc.

## ◆ setValue() [6/9]

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

Reimplemented from isc::data::Element.

Definition at line 267 of file data.cc.

## ◆ setValue() [7/9]

bool isc::data::MapElement::setValue | ( | const std::map< std::string, ConstElementPtr > & | v | ) |
| inlineoverridevirtual

Reimplemented from isc::data::Element.

Definition at line 717 of file data.h.

## ◆ setValue() [8/9]

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

Reimplemented from isc::data::Element.

Definition at line 265 of file data.cc.

## ◆ setValue() [9/9]

bool isc::data::Element::setValue | ( | const std::vector< ElementPtr > & | v | ) |
| virtual

Reimplemented from isc::data::Element.

Definition at line 266 of file data.cc.

## ◆ size()

size_t isc::data::MapElement::size | ( |  | ) | const
| inlineoverridevirtual

Returns number of stored elements.

Returns
  number of elements.

Reimplemented from isc::data::Element.

Definition at line 774 of file data.h.

## ◆ toJSON()

void isc::data::MapElement::toJSON | ( | std::ostream & | ss | ) | const
| overridevirtual

Converts the Element to JSON format and appends it to the given stringstream.

Implements isc::data::Element.

Definition at line 897 of file data.cc.

References isc::data::Element::mapValue().

Here is the call graph for this function:

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

- data.h
- data.cc