Kea: isc::data::Element Class Reference

| Kea 1.5.0

Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
isc::data::Element Class Referenceabstract

The `Element` class represents a piece of data, used by the command channel and configuration parts. More...

`#include <data.h>`

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

## Classes
struct | Position
| Represents the position of the data element within a configuration string. More...

## Public Types
enum | types { integer, real, boolean, null, string, list, map, any }

## Public Member Functions
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
pure virtuals, every derived class must implement these
virtual bool | equals (const Element &other) const =0
virtual void | toJSON (std::ostream &ss) const =0
| Converts the Element to JSON format and appends it to the given stringstream. More...
Type-specific getters
These functions only work on their corresponding Element type. For all other types, a TypeError is thrown. If you want an exception-safe getter method, use getValue() below
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
virtual const std::map< std::string, ConstElementPtr > & | mapValue () const
Exception-safe getters
The getValue() functions return false if the given reference is of another type than the element contains By default it always returns false; the derived classes override the function for their type, copying their data to the given reference and returning true
virtual bool | getValue (int64_t &t) const
virtual bool | getValue (double &t) const
virtual bool | getValue (bool &t) const
virtual bool | getValue (std::string &t) const
virtual bool | getValue (std::vector< ElementPtr > &t) const
virtual bool | getValue (std::map< std::string, ConstElementPtr > &t) const
Exception-safe setters.
Return false if the Element is not the right type. Set the value and return true if the Elements is of the correct type Notes: Read notes of IntElement definition about the use of long long int, long int and int.
virtual bool | setValue (const long long int v)
bool | setValue (const long int i)
bool | setValue (const int i)
virtual bool | setValue (const double v)
virtual bool | setValue (const bool t)
virtual bool | setValue (const std::string &v)
virtual bool | setValue (const std::vector< ElementPtr > &v)
virtual bool | setValue (const std::map< std::string, ConstElementPtr > &v)
ListElement functions
If the Element on which these functions are called are not an instance of ListElement, a TypeError exception is thrown.
virtual ConstElementPtr | get (const int i) const
| Returns the ElementPtr at the given index. More...
virtual ElementPtr | getNonConst (const int i) const
| returns element as non-const pointer More...
virtual void | set (const size_t i, ElementPtr element)
| Sets the ElementPtr at the given index. More...
virtual void | add (ElementPtr element)
| Adds an ElementPtr to the list. More...
virtual void | remove (const int i)
| Removes the element at the given position. More...
virtual size_t | size () const
| Returns the number of elements in the list. More...
virtual bool | empty () const
| Return true if there are no elements in the list. More...
MapElement functions
If the Element on which these functions are called are not an instance of MapElement, a TypeError exception is thrown.
virtual ConstElementPtr | get (const std::string &name) const
| Returns 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 void | remove (const std::string &name)
| Remove the ElementPtr at the given key. More...
virtual bool | contains (const std::string &name) const
| Checks if there is data at the given key. More...
virtual ConstElementPtr | find (const std::string &identifier) const
| Recursively finds any data at the given identifier. More...
virtual bool | find (const std::string &identifier, ConstElementPtr &t) const
| See `Element::find()` More...

## Static Public Member Functions
static const Position & | ZERO_POSITION ()
| Returns `Position` object with line_ and pos_ set to 0, and with an empty file name. More...
Direct factory functions
These functions simply wrap the given data directly in an Element object, and return a reference to it, in the form of an `ElementPtr`. These factory functions are exception-free (unless there is no memory available, in which case bad_alloc is raised by the underlying system). (Note that that is different from an NullElement, which represents an empty value, and is created with Element::create()) Notes: Read notes of IntElement definition about the use of long long int, long int and int.
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 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...
Compound factory functions
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...
Type name conversion functions
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...
Wire format factory functions
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
| Element (int t, const Position &pos=ZERO_POSITION())
| Constructor. More...

## Detailed Description

The `Element` class represents a piece of data, used by the command channel and configuration parts.

An `Element` can contain simple types (int, real, string, bool and None), and composite types (list and string->element maps)

Elements should in calling functions usually be referenced through an `ElementPtr`, which can be created using the factory functions `Element::create()` and `Element::fromJSON()`

Notes to developers: Element is a base class, implemented by a specific subclass for each type (IntElement, BoolElement, etc). Element does define all functions for all types, and defaults to raising a `TypeError` for functions that are not supported for the type in question.

Definition at line 66 of file data.h.

## Member Enumeration Documentation

## ◆ types

enum isc::data::Element::types

Enumerator
integer |
real |
boolean |
null |
string |
list |
map |
any |

Definition at line 151 of file data.h.

## Constructor & Destructor Documentation

## ◆ Element()

isc::data::Element::Element | ( | int | t,
|  | const Position & | pos = `ZERO_POSITION()`
| ) |  |
| inlineprotected

Constructor.

Parameters

  t | Element type.
  pos | Structure holding position of the value of the data element. It comprises the line number and the position within this line. The values held in this structure are used for error logging purposes.

Definition at line 142 of file data.h.

## ◆ ~Element()

virtual isc::data::Element::~Element | ( |  | ) |
| inlinevirtual

Definition at line 153 of file data.h.

## Member Function Documentation

## ◆ add()

void isc::data::Element::add | ( | ElementPtr | element | ) |
| virtual

Adds an ElementPtr to the list.

Parameters

  element | The ElementPtr to add

Reimplemented in isc::data::ListElement.

Definition at line 145 of file data.cc.

References throwTypeError.

## ◆ boolValue()

virtual bool isc::data::Element::boolValue | ( |  | ) | const
| inlinevirtual

Reimplemented in isc::data::BoolElement.

Definition at line 215 of file data.h.

References throwTypeError.

Referenced by isc::data::BoolElement::equals().

## ◆ contains()

bool isc::data::Element::contains | ( | const std::string & | name | ) | const
| virtual

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 in isc::data::MapElement.

Definition at line 180 of file data.cc.

References throwTypeError.

Referenced by isc::data::MapElement::equals().

## ◆ create() [1/8]

ElementPtr isc::data::Element::create | ( | const bool | b,
|  | const Position & | pos = `ZERO_POSITION()`
| ) |  |
| static

Definition at line 248 of file data.cc.

## ◆ create() [2/8]

ElementPtr isc::data::Element::create | ( | const char * | s,
|  | const Position & | pos = `ZERO_POSITION()`
| ) |  |
| static

Definition at line 258 of file data.cc.

## ◆ create() [3/8]

ElementPtr isc::data::Element::create | ( | const double | d,
|  | const Position & | pos = `ZERO_POSITION()`
| ) |  |
| static

Definition at line 243 of file data.cc.

## ◆ create() [4/8]

ElementPtr isc::data::Element::create | ( | const int | i,
|  | const Position & | pos = `ZERO_POSITION()`
| ) |  |
| static

Definition at line 233 of file data.cc.

## ◆ create() [5/8]

ElementPtr isc::data::Element::create | ( | const long int | i,
|  | const Position & | pos = `ZERO_POSITION()`
| ) |  |
| static

Definition at line 238 of file data.cc.

## ◆ create() [6/8]

ElementPtr isc::data::Element::create | ( | const long long int | i,
|  | const Position & | pos = `ZERO_POSITION()`
| ) |  |
| static

Definition at line 228 of file data.cc.

## ◆ create() [7/8]

ElementPtr isc::data::Element::create | ( | const Position & | pos = `ZERO_POSITION()` | ) |
| static

Definition at line 223 of file data.cc.

Referenced by isc::ha::CommandCreator::createDHCPDisable(), isc::ha::CommandCreator::createLease4GetPage(), isc::ha::CommandCreator::createLease4Update(), isc::ha::CommandCreator::createLease6GetPage(), isc::ha::CommandCreator::createLease6Update(), isc::dhcp::CfgHostsList::externalize(), isc::dhcp::PacketQueue< Pkt6Ptr >::getInfo(), isc::dhcp::PacketQueueRing< Pkt6Ptr >::getInfo(), isc::stats::Observation::getJSON(), isc::dhcp::CfgMACSource::toElement(), isc::dhcp::Cfg4o6::toElement(), isc::dhcp::CfgOptionDef::toElement(), isc::dhcp::SharedNetwork4::toElement(), isc::db::DatabaseConnection::toElement(), isc::dhcp::SharedNetwork6::toElement(), and isc::dhcp::CfgOption::toElement().

## ◆ create() [8/8]

ElementPtr isc::data::Element::create | ( | const std::string & | s,
|  | const Position & | pos = `ZERO_POSITION()`
| ) |  |
| static

Definition at line 253 of file data.cc.

## ◆ createList()

ElementPtr isc::data::Element::createList | ( | const Position & | pos = `ZERO_POSITION()` | ) |
| static

Creates an empty ListElement type ElementPtr.

Parameters

  pos | A structure holding position of the data element value in the configuration string. It is used for error logging purposes.

Definition at line 263 of file data.cc.

Referenced by isc::dhcp::CfgHostsList::add(), isc::dhcp::CfgHostsList::externalize(), isc::dhcp::CfgHostsList::get(), isc::stats::Observation::getJSON(), isc::dhcp::CfgMACSource::toElement(), isc::dhcp::CfgSharedNetworks< SharedNetwork6Ptr, SharedNetwork6Collection >::toElement(), isc::dhcp::CfgOptionDef::toElement(), isc::dhcp::CfgHostDbAccess::toElement(), isc::dhcp::SharedNetwork4::toElement(), isc::process::ConfigControlInfo::toElement(), isc::dhcp::SharedNetwork6::toElement(), and isc::dhcp::CfgOption::toElement().

## ◆ createMap()

ElementPtr isc::data::Element::createMap | ( | const Position & | pos = `ZERO_POSITION()` | ) |
| static

Creates an empty MapElement type ElementPtr.

Parameters

  pos | A structure holding position of the data element value in the configuration string. It is used for error logging purposes.

Definition at line 268 of file data.cc.

Referenced by isc::ha::CommandCreator::createDHCPDisable(), isc::ha::CommandCreator::createLease4GetPage(), isc::ha::CommandCreator::createLease6GetPage(), isc::dhcp::CfgHostsList::externalize(), isc::stats::StatsMgr::get(), isc::stats::StatsMgr::getAll(), isc::dhcp::PacketQueue< Pkt6Ptr >::getInfo(), isc::dhcp::SimpleParser4::setAllDefaults(), isc::dhcp::SimpleParser6::setAllDefaults(), isc::dhcp::Cfg4o6::toElement(), isc::dhcp::CfgOptionDef::toElement(), isc::process::ConfigControlInfo::toElement(), isc::db::DatabaseConnection::toElement(), and isc::dhcp::CfgOption::toElement().

## ◆ doubleValue()

virtual double isc::data::Element::doubleValue | ( |  | ) | const
| inlinevirtual

Reimplemented in isc::data::DoubleElement.

Definition at line 213 of file data.h.

References throwTypeError.

Referenced by isc::data::DoubleElement::equals().

## ◆ empty()

bool isc::data::Element::empty | ( |  | ) | const
| virtual

Return true if there are no elements in the list.

Reimplemented in isc::data::MapElement, and isc::data::ListElement.

Definition at line 160 of file data.cc.

References throwTypeError.

## ◆ equals()

virtual bool isc::data::Element::equals | ( | const Element & | other | ) | const
| pure virtual

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

Implemented in isc::data::MapElement, isc::data::ListElement, isc::data::StringElement, isc::data::NullElement, isc::data::BoolElement, isc::data::DoubleElement, and isc::data::IntElement.

Referenced by isc::data::operator!=(), and isc::data::operator==().

## ◆ find() [1/2]

ConstElementPtr isc::data::Element::find | ( | const std::string & | identifier | ) | const
| virtual

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 in isc::data::MapElement.

Definition at line 185 of file data.cc.

References throwTypeError.

## ◆ find() [2/2]

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

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 in isc::data::MapElement.

Definition at line 190 of file data.cc.

## ◆ fromJSON() [1/4]

ElementPtr isc::data::Element::fromJSON | ( | const std::string & | in,
|  | bool | preproc = `false`
| ) |  |
| static

These functions will parse the given string (JSON) representation of a compound element.

If there is a parse error, an exception of the type isc::data::JSONError is thrown. Creates an Element from the given JSON string

Parameters

  in | The string to parse the element from
  preproc | specified whether preprocessing (e.g. comment removal) should be performed

Returns
  An ElementPtr that contains the element(s) specified in the given string.

Definition at line 750 of file data.cc.

Referenced by isc::dhcp_ddns::NameChangeRequest::fromJSON(), isc::db::MySqlBinding::getJSON(), and user_chk::UserFile::makeUser().

## ◆ fromJSON() [2/4]

ElementPtr isc::data::Element::fromJSON | ( | std::istream & | in,
|  | bool | preproc = `false`
| ) |  |
| static

Creates an Element from the given input stream containing JSON formatted data.

Parameters

  in | The string to parse the element from
  preproc | specified whether preprocessing (e.g. comment removal) should be performed

Exceptions

  JSONError |

Returns
  An ElementPtr that contains the element(s) specified in the given input stream.

Definition at line 654 of file data.cc.

## ◆ fromJSON() [3/4]

ElementPtr isc::data::Element::fromJSON | ( | std::istream & | in,
|  | const std::string & | file,
|  | int & | line,
|  | int & | pos
| ) |  |
| static

Creates an Element from the given input stream, where we keep track of the location in the stream for error reporting.

Parameters

  in | The string to parse the element from.
  file | The input file name.
  line | A reference to the int where the function keeps track of the current line.
  pos | A reference to the int where the function keeps track of the current position within the current line.

Exceptions

  JSONError |

Returns
  An ElementPtr that contains the element(s) specified in the given input stream.

Exceptions

  JSONError |

Definition at line 679 of file data.cc.

References isc_throw.

## ◆ fromJSON() [4/4]

ElementPtr isc::data::Element::fromJSON | ( | std::istream & | in,
|  | const std::string & | file_name,
|  | bool | preproc = `false`
| ) |  |
| static

Creates an Element from the given input stream containing JSON formatted data.

Parameters

  in | The string to parse the element from
  file_name | specified input file name (used in error reporting)
  preproc | specified whether preprocessing (e.g. comment removal) should be performed

Exceptions

  JSONError |

Returns
  An ElementPtr that contains the element(s) specified in the given input stream.

Exceptions

  JSONError |

Definition at line 668 of file data.cc.

## ◆ fromJSONFile()

ElementPtr isc::data::Element::fromJSONFile | ( | const std::string & | file_name,
|  | bool | preproc = `false`
| ) |  |
| static

Reads contents of specified file and interprets it as JSON.

Parameters

  file_name | name of the file to read
  preproc | specified whether preprocessing (e.g. comment removal) should be performed

Returns
  An ElementPtr that contains the element(s) specified if the given file.

Definition at line 769 of file data.cc.

References isc_throw.

## ◆ fromWire() [1/2]

ElementPtr isc::data::Element::fromWire | ( | const std::string & | s | ) |
| static

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.

Parameters

  s | The input string

Returns
  ElementPtr with the data that is parsed.

Definition at line 919 of file data.cc.

## ◆ fromWire() [2/2]

ElementPtr isc::data::Element::fromWire | ( | std::stringstream & | in,
|  | int | length
| ) |  |
| static

These function pparse the wireformat at the given stringstream (of the given length).

If there is a parse error an exception of the type isc::cc::DecodeError is raised. Creates an Element from the wire format in the given stringstream of the given length. Since the wire format is JSON, this is the same as fromJSON, and could be removed.

Parameters

  in | The input stringstream.
  length | The length of the wireformat data in the stream

Returns
  ElementPtr with the data that is parsed.

Definition at line 927 of file data.cc.

## ◆ get() [1/2]

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 in isc::data::ListElement.

Definition at line 130 of file data.cc.

References throwTypeError.

Referenced by isc::data::ListElement::equals(), and isc::data::MapElement::equals().

## ◆ get() [2/2]

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 in isc::data::MapElement.

Definition at line 165 of file data.cc.

References throwTypeError.

## ◆ getNonConst()

ElementPtr isc::data::Element::getNonConst | ( | const int | i | ) | const
| virtual

returns element as non-const pointer

Parameters

  i | The position of the ElementPtr to retrieve

Returns
  specified element pointer

Reimplemented in isc::data::ListElement.

Definition at line 135 of file data.cc.

References throwTypeError.

## ◆ getPosition()

const Position& isc::data::Element::getPosition | ( |  | ) | const
| inline

Returns position where the data element's value starts in a configuration string.

Warning
  The returned reference is valid as long as the object which created it lives.

Definition at line 163 of file data.h.

## ◆ getType()

int isc::data::Element::getType | ( |  | ) | const
| inline

Returns
  the type of this element

Definition at line 156 of file data.h.

Referenced by isc::data::IntElement::equals(), isc::data::DoubleElement::equals(), isc::data::BoolElement::equals(), isc::data::NullElement::equals(), isc::data::StringElement::equals(), isc::data::ListElement::equals(), and isc::data::MapElement::equals().

## ◆ getValue() [1/6]

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

Reimplemented in isc::data::BoolElement.

Definition at line 80 of file data.cc.

## ◆ getValue() [2/6]

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

Reimplemented in isc::data::DoubleElement.

Definition at line 75 of file data.cc.

## ◆ getValue() [3/6]

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

Reimplemented in isc::data::IntElement.

Definition at line 70 of file data.cc.

## ◆ getValue() [4/6]

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

Reimplemented in isc::data::MapElement.

Definition at line 95 of file data.cc.

## ◆ getValue() [5/6]

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

Reimplemented in isc::data::StringElement.

Definition at line 85 of file data.cc.

## ◆ getValue() [6/6]

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

Reimplemented in isc::data::ListElement.

Definition at line 90 of file data.cc.

## ◆ intValue()

virtual int64_t isc::data::Element::intValue | ( |  | ) | const
| inlinevirtual

Reimplemented in isc::data::IntElement.

Definition at line 211 of file data.h.

References throwTypeError.

Referenced by isc::data::IntElement::equals().

## ◆ listValue()

virtual const std::vector<ElementPtr>& isc::data::Element::listValue | ( |  | ) | const
| inlinevirtual

Reimplemented in isc::data::ListElement.

Definition at line 219 of file data.h.

References throwTypeError.

## ◆ mapValue()

virtual const std::map<std::string, ConstElementPtr>& isc::data::Element::mapValue | ( |  | ) | const
| inlinevirtual

Reimplemented in isc::data::MapElement.

Definition at line 223 of file data.h.

References throwTypeError.

Referenced by isc::data::MapElement::equals().

## ◆ nameToType()

Element::types isc::data::Element::nameToType | ( | const std::string & | type_name | ) |
| static

Converts the string to the corresponding type Throws a TypeError if the name is unknown.

Parameters

  type_name | The name to get the type of

Returns
  the corresponding type value

Definition at line 629 of file data.cc.

References isc_throw.

## ◆ preprocess()

void isc::data::Element::preprocess | ( | std::istream & | in,
|  | std::stringstream & | out
| ) |  |
| static

input text preprocessor

This method performs preprocessing of the input stream (which is expected to contain a text version of to be parsed JSON). For now the sole supported operation is bash-style (line starting with #) comment removal, but it will be extended later to cover more cases (C, C++ style comments, file inclusions, maybe macro replacements?).

This method processes the whole input stream. It reads all contents of the input stream, filters the content and returns the result in a different stream.

Parameters

  in | input stream to be preprocessed
  out | output stream (filtered content will be written here)

Definition at line 1367 of file data.cc.

## ◆ remove() [1/2]

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 in isc::data::ListElement.

Definition at line 150 of file data.cc.

References throwTypeError.

## ◆ remove() [2/2]

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 in isc::data::MapElement.

Definition at line 175 of file data.cc.

References throwTypeError.

## ◆ set() [1/2]

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 in isc::data::ListElement.

Definition at line 140 of file data.cc.

References throwTypeError.

## ◆ set() [2/2]

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 in isc::data::MapElement.

Definition at line 170 of file data.cc.

References throwTypeError.

## ◆ setValue() [1/8]

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

Reimplemented in isc::data::BoolElement.

Definition at line 110 of file data.cc.

## ◆ setValue() [2/8]

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

Reimplemented in isc::data::DoubleElement.

Definition at line 105 of file data.cc.

## ◆ setValue() [3/8]

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

Definition at line 258 of file data.h.

References setValue().

Referenced by setValue().

Here is the call graph for this function:

## ◆ setValue() [4/8]

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

Definition at line 257 of file data.h.

References setValue().

Referenced by setValue().

Here is the call graph for this function:

## ◆ setValue() [5/8]

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

Reimplemented in isc::data::IntElement.

Definition at line 100 of file data.cc.

## ◆ setValue() [6/8]

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

Reimplemented in isc::data::MapElement.

Definition at line 125 of file data.cc.

## ◆ setValue() [7/8]

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

Reimplemented in isc::data::StringElement.

Definition at line 115 of file data.cc.

## ◆ setValue() [8/8]

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

Reimplemented in isc::data::ListElement.

Definition at line 120 of file data.cc.

## ◆ size()

size_t isc::data::Element::size | ( |  | ) | const
| virtual

Returns the number of elements in the list.

Reimplemented in isc::data::MapElement, and isc::data::ListElement.

Definition at line 155 of file data.cc.

References throwTypeError.

Referenced by isc::data::ListElement::equals().

## ◆ str()

std::string isc::data::Element::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.

The resulting string will contain the Element in JSON format.

Returns
  std::string containing the string representation

Definition at line 51 of file data.cc.

Referenced by isc::data::operator<<().

## ◆ stringValue()

virtual std::string isc::data::Element::stringValue | ( |  | ) | const
| inlinevirtual

Reimplemented in isc::data::StringElement.

Definition at line 217 of file data.h.

References throwTypeError.

Referenced by isc::data::StringElement::equals().

## ◆ toJSON()

virtual void isc::data::Element::toJSON | ( | std::ostream & | ss | ) | const
| pure virtual

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

Implemented in isc::data::MapElement, isc::data::ListElement, isc::data::StringElement, isc::data::NullElement, isc::data::BoolElement, isc::data::DoubleElement, and isc::data::IntElement.

## ◆ toWire() [1/2]

std::string isc::data::Element::toWire | ( |  | ) | const

Returns the wireformat for the Element and all its child elements.

Returns
  std::string containing the element in wire format

Definition at line 58 of file data.cc.

## ◆ toWire() [2/2]

void isc::data::Element::toWire | ( | std::ostream & | out | ) | const

Definition at line 65 of file data.cc.

## ◆ typeToName()

std::string isc::data::Element::typeToName | ( | Element::types | type | ) |
| static

Returns the name of the given type as a string.

Parameters

  type | The type to return the name of

Returns
  The name of the type, or "unknown" if the type is not known.

Definition at line 605 of file data.cc.

## ◆ ZERO_POSITION()

static const Position& isc::data::Element::ZERO_POSITION | ( |  | ) |
| inlinestatic

Returns `Position` object with line_ and pos_ set to 0, and with an empty file name.

The object containing two zeros is a default for most of the methods creating `Element` objects. The returned value is static so as it is not created everytime the function with the default position argument is called.

Definition at line 120 of file data.h.

Referenced by isc::dhcp::ValueStorage< ValueType >::getPosition().

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

- data.h
- data.cc