sptk2 logo
SPTK Home Page
Public Types | Public Member Functions | Static Public Member Functions | List of all members
sptk::xdoc::Node Class Reference
Inheritance diagram for sptk::xdoc::Node:

Public Types

enum class  Type : uint8_t {
  DocumentRoot , Null , Text , Number ,
  Boolean , Array , Object , CData ,
  Comment , ProcessingInstruction
}
 
using SNode = std::shared_ptr< Node >
 
using Nodes = std::vector< SNode >
 
using Vector = std::vector< SNode >
 
using iterator = Nodes::iterator
 
using const_iterator = Nodes::const_iterator
 

Public Member Functions

 Node (const String &nodeName="", Type type=Type::Null)
 
virtual void clear ()
 
virtual void clearChildren ()
 
String name () const
 
void name (const String &name)
 
Type type () const
 
void type (Type type)
 
SNode & pushNode (const String &name, Type type=Type::Null)
 
SNode & pushValue (const String &name, const Variant &value, Node::Type type=Node::Type::Null)
 Push named property to object. More...
 
SNode & pushValue (const Variant &value, Node::Type type=Node::Type::Null)
 Push value to array. More...
 
Attributesattributes ()
 
const Attributesattributes () const
 
String getString (const String &name="") const
 
String getText (const String &name="") const
 
double getNumber (const String &name="") const
 
bool getBoolean (const String &name="") const
 
const Nodes & nodes (const String &name="") const
 
const VariantgetValue () const
 
template<typename T >
void set (const T &value)
 
template<typename T >
SNode & set (const String &name, const T &value)
 
bool remove (const String &name)
 
bool remove (const SNode &node)
 
SNode & findOrCreate (const String &name)
 
SNode findFirst (const String &name, SearchMode searchMode=SearchMode::Recursive) const
 
SNode & parent ()
 
const SNode & parent () const
 
void load (DataFormat dataFormat, const Buffer &data, bool xmlKeepFormatting=false)
 
void load (DataFormat dataFormat, const String &data, bool xmlKeepFormatting=false)
 
void exportTo (DataFormat dataFormat, Buffer &data, bool formatted) const
 
void exportTo (DataFormat dataFormat, std::ostream &stream, bool formatted) const
 
Node::Vector select (const String &xpath)
 Select a list of sub-nodes matching xpath. More...
 

Static Public Member Functions

static void importJson (const SNode &jsonElement, const sptk::Buffer &jsonStr)
 
static void clone (const SNode &destination, const SNode &source)
 Perform a deep copy of the source to destination. More...
 

Member Function Documentation

◆ clone()

static void sptk::xdoc::Node::clone ( const SNode &  destination,
const SNode &  source 
)
static

Perform a deep copy of the source to destination.

Parameters
destinationDestination node
sourceSource node

◆ importJson()

static void sptk::xdoc::Node::importJson ( const SNode &  jsonElement,
const sptk::Buffer jsonStr 
)
static

Parse JSON text Root element should have JDT_NULL type (empty element) before calling this method.

Parameters
jsonElementOutput node
jsonStrJSON text

◆ pushValue() [1/2]

SNode & sptk::xdoc::Node::pushValue ( const String name,
const Variant value,
Node::Type  type = Node::Type::Null 
)

Push named property to object.

If the value type isn't provided and value isn't null, the type deducted from value.

Parameters
nameProperty name
valueProperty value
typeOptional type
Returns
created node

◆ pushValue() [2/2]

SNode & sptk::xdoc::Node::pushValue ( const Variant value,
Node::Type  type = Node::Type::Null 
)

Push value to array.

If the value type isn't provided and value isn't null, the type deducted from value.

Parameters
valueProperty value
typeOptional type
Returns
created node

◆ select()

Node::Vector sptk::xdoc::Node::select ( const String xpath)

Select a list of sub-nodes matching xpath.

Parameters
xpathXPath
Returns
List of matching sub-nodes

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

Fri Oct 14 2022 09:58:49: SPTK 5.4.1