libzypp: zypp::xmlout::Node Class Reference

libzypp 17.36.6

Classes | Public Types | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Related Symbols | List of all members
zypp::xmlout::Node Class Reference

RAII writing a nodes start/end tag. More...

`#include <zypp-core/base/Xml.h>`

## Classes
struct | HasContentException
| Exception type thrown if attributes are added to a closed start node. More...
struct | OptionalContentType
| Ctor arg type. More...

## Public Types
using | Attr = NodeAttr

## Public Member Functions
| NON_COPYABLE_BUT_MOVE (Node)
| Node (std::ostream &out_r, std::string name_r, const std::initializer_list< Attr > &attrs_r={})
| Ctor taking nodename and attribute list.
| Node (std::ostream &out_r, std::string name_r, Attr attr_r)
| Convenience ctor for one attribute pair.
| Node (std::ostream &out_r, std::string name_r, OptionalContentType, const std::initializer_list< Attr > &attrs_r={})
| Optional content ctor taking nodename and attribute list.
| Node (std::ostream &out_r, std::string name_r, OptionalContentType, Attr attr_r)
| Optional content Convenience ctor for one attribute pair.
| ~Node ()
| Dtor wrting end tag.
Node & | addAttr (const std::initializer_list< Attr > &attrs_r={})
| Add additional attributes (requires OptionalContentType)
Node & | addAttr (const Attr &attr_r)
std::ostream & | operator* ()
| Return the output stream.

## Static Public Attributes
static constexpr OptionalContentType | optionalContent = OptionalContentType()

## Private Member Functions
void | printStart (const std::initializer_list< Attr > &attrs_r)
void | printAttr (const std::initializer_list< Attr > &attrs_r)
bool | isComment () const

## Private Attributes
std::reference_wrapper< std::ostream > | _out
std::string | _name
bool | _hasContent

## Related Symbols
(Note that these are not member symbols.)
std::ostream & | node (std::ostream &out_r, const std::string &name_r, const std::initializer_list< Node::Attr > &attrs_r={})
| Write a leaf node without PCDATA.

## Detailed Description

RAII writing a nodes start/end tag.

{
Node node( std::cout, "node", { "attr", "val" } ); // <node attr="val">
*node << "write nodes body...."
} // </node>
zypp::xmlout::node
std::ostream & node(std::ostream &out_r, const std::string &name_r, Node::Attr attr_r)
Definition Xml.h:204
zypp::xmlout::Node::node
std::ostream & node(std::ostream &out_r, const std::string &name_r, const std::initializer_list< Node::Attr > &attrs_r={})
Write a leaf node without PCDATA.
Definition Xml.h:198
zypp::xmlout::Node::Node
Node(std::ostream &out_r, std::string name_r, const std::initializer_list< Attr > &attrs_r={})
Ctor taking nodename and attribute list.
Definition Xml.h:93

Note
  If the optionalContent flag is passed to the `ctor`, the start node is kept open, until the first call to operator*. The start node is closed before returning the stream.
  {
  Node node( std::cout, "node", Node::optionalContent, { "attr", "val" } );
  // <node attr="val"
  } // />
  {
  Node node( std::cout, "node", Node::optionalContent, { "attr", "val" } );
  // <node attr="val"
  *node << "write nodes body...." // />write nodes body...
  } // </node>
  zypp::xmlout::Node::optionalContent
  static constexpr OptionalContentType optionalContent
  Definition Xml.h:90
  If the nodename is empty or starts with an `!`, a comment is written.

Definition at line 84 of file Xml.h.

## Member Typedef Documentation

## ◆ Attr

using zypp::xmlout::Node::Attr = NodeAttr

Definition at line 87 of file Xml.h.

## Constructor & Destructor Documentation

## ◆ Node() [1/4]

zypp::xmlout::Node::Node | ( | std::ostream & | out_r,
|  | std::string | name_r,
|  | const std::initializer_list< Attr > & | attrs_r = {} )
| inline

Ctor taking nodename and attribute list.

Definition at line 93 of file Xml.h.

## ◆ Node() [2/4]

zypp::xmlout::Node::Node | ( | std::ostream & | out_r,
|  | std::string | name_r,
|  | Attr | attr_r )
| inline

Convenience ctor for one attribute pair.

Definition at line 98 of file Xml.h.

## ◆ Node() [3/4]

zypp::xmlout::Node::Node | ( | std::ostream & | out_r,
|  | std::string | name_r,
|  | OptionalContentType | ,
|  | const std::initializer_list< Attr > & | attrs_r = {} )
| inline

Optional content ctor taking nodename and attribute list.

Definition at line 103 of file Xml.h.

## ◆ Node() [4/4]

zypp::xmlout::Node::Node | ( | std::ostream & | out_r,
|  | std::string | name_r,
|  | OptionalContentType | ,
|  | Attr | attr_r )
| inline

Optional content Convenience ctor for one attribute pair.

Definition at line 108 of file Xml.h.

## ◆ ~Node()

zypp::xmlout::Node::~Node | ( |  | ) |
| inline

Dtor wrting end tag.

Definition at line 113 of file Xml.h.

## Member Function Documentation

## ◆ NON_COPYABLE_BUT_MOVE()

zypp::xmlout::Node::NON_COPYABLE_BUT_MOVE | ( | Node |  | ) |

## ◆ addAttr() [1/2]

Node & zypp::xmlout::Node::addAttr | ( | const std::initializer_list< Attr > & | attrs_r = {} | ) |
| inline

Add additional attributes (requires OptionalContentType)

Exceptions

  HasContentException | If start node is already closed

Definition at line 132 of file Xml.h.

## ◆ addAttr() [2/2]

Node & zypp::xmlout::Node::addAttr | ( | const Attr & | attr_r | ) |
| inline

Definition at line 141 of file Xml.h.

## ◆ operator*()

std::ostream & zypp::xmlout::Node::operator* | ( |  | ) |
| inline

Return the output stream.

Definition at line 146 of file Xml.h.

## ◆ printStart()

void zypp::xmlout::Node::printStart | ( | const std::initializer_list< Attr > & | attrs_r | ) |
| inlineprivate

Definition at line 160 of file Xml.h.

## ◆ printAttr()

void zypp::xmlout::Node::printAttr | ( | const std::initializer_list< Attr > & | attrs_r | ) |
| inlineprivate

Definition at line 176 of file Xml.h.

## ◆ isComment()

bool zypp::xmlout::Node::isComment | ( |  | ) | const
| inlineprivate

Definition at line 182 of file Xml.h.

## Friends And Related Symbol Documentation

## ◆ node()

std::ostream & node | ( | std::ostream & | out_r,
|  | const std::string & | name_r,
|  | const std::initializer_list< Node::Attr > & | attrs_r = {} )
| related

Write a leaf node without PCDATA.

<node attr="val"/>

Definition at line 198 of file Xml.h.

## Member Data Documentation

## ◆ optionalContent

Node::OptionalContentType zypp::xmlout::Node::optionalContent = OptionalContentType()
| staticconstexpr

Definition at line 90 of file Xml.h.

## ◆ _out

std::reference_wrapper<std::ostream> zypp::xmlout::Node::_out
| private

Definition at line 187 of file Xml.h.

## ◆ _name

std::string zypp::xmlout::Node::_name
| private

Definition at line 188 of file Xml.h.

## ◆ _hasContent

bool zypp::xmlout::Node::_hasContent
| private

Definition at line 189 of file Xml.h.

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

- zypp-core/base/Xml.h
- zypp-core/base/Xml.cc