PLaSK library

Loading...
Searching...
No Matches
Public Member Functions | List of all members
plask::XMLWriter::Element Class Reference

Represent single XML element connected with writer. More...

`#include <plask/utils/xml/writer.hpp>`

## Public Member Functions
| Element (XMLWriter &writer, const std::string &name)
| Construct element with given `name`, write to steam opening of element tag.
| Element (XMLWriter &writer, std::string &&name)
| Construct element with given `name`, write to steam opening of element tag.
| Element (Element &parent, const std::string &name)
| Construct element with given `name`, write to steam opening of element tag.
| Element (Element &parent, std::string &&name)
| Construct element with given `name`, write to steam opening of element tag.
| Element (const Element &)=delete
| Disallow to copy element.
Element & | operator= (const Element &)=delete
| Disallow to copy element.
| Element (Element &&to_move)
| Move is allowed.
Element & | operator= (Element &&to_move)
| Move is allowed.
| ~Element ()
| Close element tag.
std::size_t | getLevel () const
Element & | attr (const std::string &attr_name, const std::string &attr_value)
| Append attribute to this element.
template<typename ValueT >
Element & | attr (const std::string &attr_name, const ValueT &attr_value)
| Append attribute to this element.
Element & | writeText (const char *str)
| Append text content to this element.
Element & | writeText (const std::string &str)
| Append text content to this element.
template<class T >
Element & | writeText (const T &value)
| Append text content to this element.
Element & | writeCDATA (const std::string &str)
void | indent ()
| Write spaces to the current indentation level.
template<typename name_t >
Element | addElement (name_t &&name)
| Create sub-element of this.
template<typename name_t >
Element | addTag (name_t &&name)
| Create sub-element of this.
Element & | end ()
| Close this element.
bool | canAppendAttributes () const
| Check if tag attributes still can be appended.
bool | isCurrent () const
| Check if this is current element.
bool | isEnded () const
| Check if this was ended or moved, and can't be used any more.
const std::string & | getName () const
| Get name of this element.
XMLWriter * | getWriter () const
| Get writer used by this.
Element * | getParent () const
| Get parent of this element.

## Detailed Description

Represent single XML element connected with writer.

Constructor put in stream opening tag and destructor closing one.

Definition at line 91 of file writer.hpp.

## Constructor & Destructor Documentation

## ◆ Element() [1/6]

plask::XMLWriter::Element::Element | ( | XMLWriter & | writer,
|  | const std::string & | name
| ) |  |

Construct element with given `name`, write to steam opening of element tag.

Parameters

  writer | XML writer where element should be append
  name | name of elements tag

Definition at line 66 of file writer.cpp.

## ◆ Element() [2/6]

plask::XMLWriter::Element::Element | ( | XMLWriter & | writer,
|  | std::string && | name
| ) |  |

Construct element with given `name`, write to steam opening of element tag.

Parameters

  writer | XML writer where element should be append
  name | name of elements tag

Definition at line 71 of file writer.cpp.

## ◆ Element() [3/6]

plask::XMLWriter::Element::Element | ( | XMLWriter::Element & | parent,
|  | const std::string & | name
| ) |  |

Construct element with given `name`, write to steam opening of element tag.

Parameters

  parent | parent element, must by recently added, not closed one
  name | name of elements tag

Definition at line 76 of file writer.cpp.

## ◆ Element() [4/6]

plask::XMLWriter::Element::Element | ( | XMLWriter::Element & | parent,
|  | std::string && | name
| ) |  |

Construct element with given `name`, write to steam opening of element tag.

Parameters

  parent | parent element, must by recently added, not closed one
  name | name of elements tag

Definition at line 82 of file writer.cpp.

## ◆ Element() [5/6]

plask::XMLWriter::Element::Element | ( | const Element & |  | ) |
| delete

Disallow to copy element.

## ◆ Element() [6/6]

plask::XMLWriter::Element::Element | ( | XMLWriter::Element && | to_move | ) |

Move is allowed.

Definition at line 88 of file writer.cpp.

## ◆ ~Element()

plask::XMLWriter::Element::~Element | ( |  | ) |

Close element tag.

Definition at line 111 of file writer.cpp.

## Member Function Documentation

## ◆ addElement()

template<typename name_t >

Element plask::XMLWriter::Element::addElement | ( | name_t && | name | ) |
| inline

Create sub-element of this.

Returns
  sub-element of this

Definition at line 213 of file writer.hpp.

## ◆ addTag()

template<typename name_t >

Element plask::XMLWriter::Element::addTag | ( | name_t && | name | ) |
| inline

Create sub-element of this.

Returns
  sub-element of this

Definition at line 220 of file writer.hpp.

## ◆ attr() [1/2]

XMLWriter::Element & plask::XMLWriter::Element::attr | ( | const std::string & | attr_name,
|  | const std::string & | attr_value
| ) |  |

Append attribute to this element.

Parameters

  attr_name | name of attribute to append
  attr_value | value of attribute to append

Returns
  *this

Definition at line 122 of file writer.cpp.

## ◆ attr() [2/2]

template<typename ValueT >

Element & plask::XMLWriter::Element::attr | ( | const std::string & | attr_name,
|  | const ValueT & | attr_value
| ) |  |
| inline

Append attribute to this element.

Parameters

  attr_name | name of attribute to append
  attr_value | value of attribute to append, will be change to string using boost::lexical_cast

Returns
  *this

Definition at line 173 of file writer.hpp.

## ◆ canAppendAttributes()

bool plask::XMLWriter::Element::canAppendAttributes | ( |  | ) | const
| inline

Check if tag attributes still can be appended.

Returns
  `true` if attributes can still be append to this element

Definition at line 232 of file writer.hpp.

## ◆ end()

XMLWriter::Element & plask::XMLWriter::Element::end | ( |  | ) |

Close this element.

Returns
  parent of this element or invalid element which can only be delete if this represents the root element

Definition at line 155 of file writer.cpp.

## ◆ getLevel()

std::size_t plask::XMLWriter::Element::getLevel | ( |  | ) | const

Returns
  0 for the root, 1 for a child of the root, and so on

Definition at line 116 of file writer.cpp.

## ◆ getName()

const std::string & plask::XMLWriter::Element::getName | ( |  | ) | const
| inline

Get name of this element.

Returns
  name of this

Definition at line 250 of file writer.hpp.

## ◆ getParent()

Element * plask::XMLWriter::Element::getParent | ( |  | ) | const
| inline

Get parent of this element.

Returns
  parent of this element, `nullptr` if this represent the root

Definition at line 262 of file writer.hpp.

## ◆ getWriter()

XMLWriter * plask::XMLWriter::Element::getWriter | ( |  | ) | const
| inline

Get writer used by this.

Returns
  writer used by this

Definition at line 256 of file writer.hpp.

## ◆ indent()

void plask::XMLWriter::Element::indent | ( |  | ) |

Write spaces to the current indentation level.

Definition at line 149 of file writer.cpp.

## ◆ isCurrent()

bool plask::XMLWriter::Element::isCurrent | ( |  | ) | const
| inline

Check if this is current element.

Returns
  `true` only if this is current element

Definition at line 238 of file writer.hpp.

## ◆ isEnded()

bool plask::XMLWriter::Element::isEnded | ( |  | ) | const
| inline

Check if this was ended or moved, and can't be used any more.

Returns
  `true` only if this was ended or moved

Definition at line 244 of file writer.hpp.

## ◆ operator=() [1/2]

Element & plask::XMLWriter::Element::operator= | ( | const Element & |  | ) |
| delete

Disallow to copy element.

## ◆ operator=() [2/2]

XMLWriter::Element & plask::XMLWriter::Element::operator= | ( | XMLWriter::Element && | to_move | ) |

Move is allowed.

Definition at line 99 of file writer.cpp.

## ◆ writeCDATA()

XMLWriter::Element & plask::XMLWriter::Element::writeCDATA | ( | const std::string & | str | ) |

Definition at line 140 of file writer.cpp.

## ◆ writeText() [1/3]

XMLWriter::Element & plask::XMLWriter::Element::writeText | ( | const char * | str | ) |

Append text content to this element.

Parameters

  str | content to append

Returns
  *this

Definition at line 133 of file writer.cpp.

## ◆ writeText() [2/3]

Element & plask::XMLWriter::Element::writeText | ( | const std::string & | str | ) |
| inline

Append text content to this element.

Parameters

  str | content to append

Returns
  *this

Definition at line 189 of file writer.hpp.

## ◆ writeText() [3/3]

template<class T >

Element & plask::XMLWriter::Element::writeText | ( | const T & | value | ) |
| inline

Append text content to this element.

Parameters

  value | content to append, will be change to string using boost::lexical_cast

Returns
  *this

Definition at line 197 of file writer.hpp.

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

- plask/utils/xml/writer.hpp
- plask/utils/xml/writer.cpp