API Documentation
Public Member Functions | List of all members
nkExport::TreeReader Class Referencefinal

Utility class providing an easier way to parse trees. More...

Public Member Functions

 TreeReader () noexcept
 
 TreeReader (const TreeReader &)=delete
 
 TreeReader (TreeReader &&other) noexcept
 
void addBool (bool &target, nkMemory::StringView path)
 
void addInt (int &target, nkMemory::StringView path)
 
void addUint (unsigned int &target, nkMemory::StringView path)
 
void addFloat (float &target, nkMemory::StringView path)
 
void addString (nkMemory::String &target, nkMemory::StringView path)
 
template<typename T >
void addVector (nkMemory::BufferCast< T > &target, std::function< T(nkExport::Node *)> entryFiller, nkMemory::StringView path)
 
template<typename T >
void addVector (std::vector< T > &target, std::function< T(nkExport::Node *)> entryFiller, nkMemory::StringView path)
 
template<typename T = std::string>
void addString (std::string &target, nkMemory::StringView path)
 
void fill (nkExport::Node *tree)
 
TreeReaderoperator= (const TreeReader &)=delete
 
TreeReaderoperator= (TreeReader &&) noexcept
 

Detailed Description

Utility class providing an easier way to parse trees.

The typical use when directly working on a node can look like :

nkExport::Node* child = parent->getMemberValue("a.result") ;

if (child && child->isValueTypeNumber())
  target = child->getValueAsInt() ;

nkExport::Node* secondChild = ...
...

Using this utility, the code can be simplified to :

nkExport::TreeReader reader ;
reader.addInt(target, "a.result") ;
reader.addString(secondTarget, "a.reason") ;
reader.fill(parent) ;

Note that like for a Node, the path can directly index objects and arrays.

Constructor & Destructor Documentation

◆ TreeReader() [1/3]

nkExport::TreeReader::TreeReader ( )
noexcept

Default constructor.

◆ TreeReader() [2/3]

nkExport::TreeReader::TreeReader ( const TreeReader )
delete

Copy constructor.

◆ TreeReader() [3/3]

nkExport::TreeReader::TreeReader ( TreeReader &&  other)
noexcept

Move constructor.

Parameters
otherThe other instance to move from.

Member Function Documentation

◆ addBool()

void nkExport::TreeReader::addBool ( bool &  target,
nkMemory::StringView  path 
)

Adds an boolean as a target.

Parameters
targetThe target boolean to fill.
pathThe member path in the tree.
Remarks
The member path needs to point to a boolean.

◆ addInt()

void nkExport::TreeReader::addInt ( int &  target,
nkMemory::StringView  path 
)

Adds an int as a target.

Parameters
targetThe target int to fill.
pathThe member path in the tree.
Remarks
The member path needs to point to a number.

◆ addUint()

void nkExport::TreeReader::addUint ( unsigned int &  target,
nkMemory::StringView  path 
)

Adds an unsigned int as a target.

Parameters
targetThe target unsigned int to fill.
pathThe member path in the tree.
Remarks
The member path needs to point to a number.

◆ addFloat()

void nkExport::TreeReader::addFloat ( float &  target,
nkMemory::StringView  path 
)

Adds a float as a target.

Parameters
targetThe target float to fill.
pathThe member path in the tree.
Remarks
The member path needs to point to a number.

◆ addString() [1/2]

void nkExport::TreeReader::addString ( nkMemory::String target,
nkMemory::StringView  path 
)

Adds a string as a target.

Parameters
targetThe target string to fill.
pathThe member path in the tree.
Remarks
The member path needs to point to a string.

◆ addVector() [1/2]

template<typename T >
void nkExport::TreeReader::addVector ( nkMemory::BufferCast< T > &  target,
std::function< T(nkExport::Node *)>  entryFiller,
nkMemory::StringView  path 
)

Adds a vector as target. The provided buffer will be filled one entry at a time from given member path.

Parameters
targetThe target buffer to fill.
entryFillerThe callback used to populate the entries which need to be filled.
pathThe member path in the tree.
Remarks
The member path needs to point to an array. For each entry available in the member array, the callback will be called to create and set it up, before appending it in the buffer.

◆ addVector() [2/2]

template<typename T >
void nkExport::TreeReader::addVector ( std::vector< T > &  target,
std::function< T(nkExport::Node *)>  entryFiller,
nkMemory::StringView  path 
)

Adds a vector as target, std template version. The provided vector will be filled one entry at a time from given member path.

Parameters
targetThe target vector to fill.
entryFillerThe callback used to populate the entries which need to be filled.
pathThe member path in the tree.
Remarks
The member path needs to point to an array. For each entry available in the member array, the callback will be called to create and set it up, before appending it in the vector.

◆ addString() [2/2]

template<typename T = std::string>
void nkExport::TreeReader::addString ( std::string &  target,
nkMemory::StringView  path 
)

Adds a string as a target, std template version.

Parameters
targetThe target string to fill.
pathThe member path in the tree.
Remarks
The member path needs to point to a string.

◆ fill()

void nkExport::TreeReader::fill ( nkExport::Node tree)

Fills the set targets using the provided tree.

Parameters
treeThe tree to fill the targets from.

◆ operator=() [1/2]

TreeReader& nkExport::TreeReader::operator= ( const TreeReader )
delete

Copy assignment operator.

◆ operator=() [2/2]

TreeReader& nkExport::TreeReader::operator= ( TreeReader &&  )
noexcept

Move assignment operator.


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