rapidyaml  0.7.0
parse and emit YAML, and do it fast
c4::yml::NodeInit Struct Reference

convenience class to initialize nodes More...

#include <tree.hpp>

Public Member Functions

 NodeInit ()
 initialize as an empty node More...
 
 NodeInit (NodeType_e t)
 initialize as a typed node More...
 
 NodeInit (NodeScalar const &v)
 initialize as a sequence member More...
 
 NodeInit (NodeScalar const &v, NodeType_e t)
 initialize as a sequence member with explicit type More...
 
 NodeInit (NodeScalar const &k, NodeScalar const &v)
 initialize as a mapping member More...
 
 NodeInit (NodeType_e t, NodeScalar const &k, NodeScalar const &v)
 initialize as a mapping member with explicit type More...
 
 NodeInit (NodeType_e t, NodeScalar const &k)
 initialize as a mapping member with explicit type (eg for SEQ or MAP) More...
 
void clear ()
 
void _add_flags (type_bits more_flags=0)
 
bool _check () const
 

Public Attributes

NodeType type
 
NodeScalar key
 
NodeScalar val
 

Detailed Description

convenience class to initialize nodes

Definition at line 151 of file tree.hpp.

Constructor & Destructor Documentation

◆ NodeInit() [1/7]

c4::yml::NodeInit::NodeInit ( )
inline

initialize as an empty node

Definition at line 161 of file tree.hpp.

161 : type(NOTYPE), key(), val() {}
@ NOTYPE
no node type or style is set
Definition: node_type.hpp:32
NodeType type
Definition: tree.hpp:154
NodeScalar key
Definition: tree.hpp:155
NodeScalar val
Definition: tree.hpp:156

◆ NodeInit() [2/7]

c4::yml::NodeInit::NodeInit ( NodeType_e  t)
inline

initialize as a typed node

Definition at line 163 of file tree.hpp.

163 : type(t), key(), val() {}

◆ NodeInit() [3/7]

c4::yml::NodeInit::NodeInit ( NodeScalar const &  v)
inline

initialize as a sequence member

Definition at line 165 of file tree.hpp.

165 : type(VAL), key(), val(v) { _add_flags(); }
@ VAL
a scalar: has a scalar (ie string) value, possibly empty. must be a leaf node, and cannot be MAP or S...
Definition: node_type.hpp:34
void _add_flags(type_bits more_flags=0)
Definition: tree.hpp:184

◆ NodeInit() [4/7]

c4::yml::NodeInit::NodeInit ( NodeScalar const &  v,
NodeType_e  t 
)
inline

initialize as a sequence member with explicit type

Definition at line 167 of file tree.hpp.

167 : type(t|VAL), key(), val(v) { _add_flags(); }

◆ NodeInit() [5/7]

c4::yml::NodeInit::NodeInit ( NodeScalar const &  k,
NodeScalar const &  v 
)
inline

initialize as a mapping member

Definition at line 169 of file tree.hpp.

169 : type(KEYVAL), key(k), val(v) { _add_flags(); }

◆ NodeInit() [6/7]

c4::yml::NodeInit::NodeInit ( NodeType_e  t,
NodeScalar const &  k,
NodeScalar const &  v 
)
inline

initialize as a mapping member with explicit type

Definition at line 171 of file tree.hpp.

171 : type(t), key(k), val(v) { _add_flags(); }

◆ NodeInit() [7/7]

c4::yml::NodeInit::NodeInit ( NodeType_e  t,
NodeScalar const &  k 
)
inline

initialize as a mapping member with explicit type (eg for SEQ or MAP)

Definition at line 173 of file tree.hpp.

173 : type(t), key(k), val( ) { _add_flags(KEY); }
@ KEY
is member of a map, must have non-empty key
Definition: node_type.hpp:33

References c4::yml::KEY.

Member Function Documentation

◆ clear()

void c4::yml::NodeInit::clear ( )
inline

Definition at line 177 of file tree.hpp.

178  {
179  type.clear();
180  key.clear();
181  val.clear();
182  }
void clear() noexcept
Definition: tree.hpp:133
void clear() noexcept
Definition: node_type.hpp:135

References c4::yml::NodeType::clear(), c4::yml::NodeScalar::clear(), and c4::yml::key().

◆ _add_flags()

void c4::yml::NodeInit::_add_flags ( type_bits  more_flags = 0)
inline

Definition at line 184 of file tree.hpp.

185  {
186  type = (type|more_flags);
187  if( ! key.tag.empty())
188  type = (type|KEYTAG);
189  if( ! val.tag.empty())
190  type = (type|VALTAG);
191  if( ! key.anchor.empty())
192  type = (type|KEYANCH);
193  if( ! val.anchor.empty())
194  type = (type|VALANCH);
195  }
@ VALANCH
the val has an &anchor
Definition: node_type.hpp:42
@ KEYTAG
the key has a tag
Definition: node_type.hpp:43
@ VALTAG
the val has a tag
Definition: node_type.hpp:44
@ KEYANCH
the key has an &anchor
Definition: node_type.hpp:41
csubstr anchor
Definition: tree.hpp:104

References c4::yml::NodeScalar::anchor, c4::yml::key(), c4::yml::KEYANCH, c4::yml::KEYTAG, c4::yml::NodeScalar::tag, c4::yml::VALANCH, and c4::yml::VALTAG.

◆ _check()

bool c4::yml::NodeInit::_check ( ) const
inline

Definition at line 197 of file tree.hpp.

198  {
199  // key cannot be empty
200  RYML_ASSERT(key.scalar.empty() == ((type & KEY) == 0));
201  // key tag cannot be empty
202  RYML_ASSERT(key.tag.empty() == ((type & KEYTAG) == 0));
203  // val may be empty even though VAL is set. But when VAL is not set, val must be empty
204  RYML_ASSERT(((type & VAL) != 0) || val.scalar.empty());
205  // val tag cannot be empty
206  RYML_ASSERT(val.tag.empty() == ((type & VALTAG) == 0));
207  return true;
208  }
csubstr scalar
Definition: tree.hpp:103

References c4::yml::key(), c4::yml::KEY, c4::yml::KEYTAG, c4::yml::NodeScalar::scalar, c4::yml::NodeScalar::tag, c4::yml::VAL, and c4::yml::VALTAG.

Member Data Documentation

◆ type

NodeType c4::yml::NodeInit::type

Definition at line 154 of file tree.hpp.

◆ key

NodeScalar c4::yml::NodeInit::key

Definition at line 155 of file tree.hpp.

◆ val

NodeScalar c4::yml::NodeInit::val

Definition at line 156 of file tree.hpp.


The documentation for this struct was generated from the following file: