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

A node in the tree structure representing the data to export / import. More...

Public Member Functions

 Node () noexcept
 
 Node (const Node &other) noexcept
 
 Node (Node &&other) noexcept
 
NODE_NATURE getNodeNature () const
 
NODE_VALUE_TYPE getNodeValueType () const
 
bool isValueTypeNumber () const
 
bool hasChild (nkMemory::StringView key, NODE_VALUE_TYPE valueType)
 
bool hasChild (nkMemory::StringView key, NODE_NATURE nature)
 
nkMemory::StringView getValueAsString () const
 
int getValueAsInt () const
 
unsigned int getValueAsUint () const
 
long long getValueAsLong () const
 
unsigned long long getValueAsUlong () const
 
float getValueAsFloat () const
 
double getValueAsDouble () const
 
bool getValueAsBool () const
 
unsigned int getMemberCount () const
 
nkMemory::StringView getMemberKey (unsigned int index) const
 
NodegetMemberValue (unsigned int index) const
 
NodegetMemberValue (nkMemory::StringView key) const
 
NodegetMemberValue (nkMemory::StringView key, NODE_VALUE_TYPE valueType) const
 
NodegetMemberValue (nkMemory::StringView key, NODE_NATURE nodeNature) const
 
unsigned int getArraySize () const
 
NodegetArrayElement (unsigned int index) const
 
NodegetArrayElement (unsigned int index, NODE_VALUE_TYPE valueType) const
 
NodegetArrayElement (unsigned int index, NODE_NATURE nodeNature) const
 
void * getUserData () const
 
void setAsString (nkMemory::StringView value)
 
void setAsInt (int value)
 
void setAsUint (unsigned int value)
 
void setAsLong (long long value)
 
void setAsUlong (unsigned long long value)
 
void setAsFloat (float value)
 
void setAsDouble (double value)
 
void setAsBool (bool value)
 
NodeaddMember (nkMemory::StringView key)
 
void deleteMember (nkMemory::StringView key)
 
NodeaddElement ()
 
void setUserData (void *value)
 
Nodeoperator= (const Node &other)
 
Nodeoperator= (Node &&other)
 

Detailed Description

A node in the tree structure representing the data to export / import.

Constructor & Destructor Documentation

◆ Node() [1/3]

nkExport::Node::Node ( )
noexcept

Default constructor.

◆ Node() [2/3]

nkExport::Node::Node ( const Node other)
noexcept

Copy constructor.

Parameters
otherThe node to copy from.

◆ Node() [3/3]

nkExport::Node::Node ( Node &&  other)
noexcept

Move constructor.

Parameters
otherThe node to move.

Member Function Documentation

◆ getNodeNature()

NODE_NATURE nkExport::Node::getNodeNature ( ) const
Returns
The nature of the node. The nature of the node describes the kind of data you can expect to be able to retrieve from it.

◆ getNodeValueType()

NODE_VALUE_TYPE nkExport::Node::getNodeValueType ( ) const
Returns
The value type of the value this node holds. This describes precisely what the value inside the node is, to call the right accessor.

◆ isValueTypeNumber()

bool nkExport::Node::isValueTypeNumber ( ) const
Returns
Whether the node has any kind of number value type inside (int, uint, long, ulong, float, double).

◆ hasChild() [1/2]

bool nkExport::Node::hasChild ( nkMemory::StringView  key,
NODE_VALUE_TYPE  valueType 
)
Parameters
keyThe key of the child to check for.
valueTypeThe value type the child should have.
Returns
Whether a child member of the given value type is available (true) or not (false).

◆ hasChild() [2/2]

bool nkExport::Node::hasChild ( nkMemory::StringView  key,
NODE_NATURE  nature 
)
Parameters
keyThe key of the child to check for.
natureThe nature the child should have.
Returns
Whether a child member of the given nature is available (true) or not (false).

◆ getValueAsString()

nkMemory::StringView nkExport::Node::getValueAsString ( ) const
Returns
The value cast as a string.
Remarks
Beware that the value is retained via an union internally. If called while holding a different type, this will most likely end in a crash.

◆ getValueAsInt()

int nkExport::Node::getValueAsInt ( ) const
Returns
The value cast as an int.
Remarks
Beware that the value is retained via an union internally. If called while holding a different type, this will most likely return garbage.

◆ getValueAsUint()

unsigned int nkExport::Node::getValueAsUint ( ) const
Returns
The value cast as an unsigned int.
Remarks
Beware that the value is retained via an union internally. If called while holding a different type, this will most likely return garbage.

◆ getValueAsLong()

long long nkExport::Node::getValueAsLong ( ) const
Returns
The value cast as a long (8 bytes).
Remarks
Beware that the value is retained via an union internally. If called while holding a different type, this will most likely return garbage.

◆ getValueAsUlong()

unsigned long long nkExport::Node::getValueAsUlong ( ) const
Returns
The value cast as an unsigned long (8 bytes).
Remarks
Beware that the value is retained via an union internally. If called while holding a different type, this will most likely return garbage.

◆ getValueAsFloat()

float nkExport::Node::getValueAsFloat ( ) const
Returns
The value cast as a float.
Remarks
Beware that the value is retained via an union internally. If called while holding a different type, this will most likely return garbage.

◆ getValueAsDouble()

double nkExport::Node::getValueAsDouble ( ) const
Returns
The value cast as a double.
Remarks
Beware that the value is retained via an union internally. If called while holding a different type, this will most likely return garbage.

◆ getValueAsBool()

bool nkExport::Node::getValueAsBool ( ) const
Returns
The value cast as a bool.
Remarks
Beware that the value is retained via an union internally. If called while holding a different type, this will most likely return garbage.

◆ getMemberCount()

unsigned int nkExport::Node::getMemberCount ( ) const
Returns
The number of members the node has.

◆ getMemberKey()

nkMemory::StringView nkExport::Node::getMemberKey ( unsigned int  index) const

Allows to retrieve a key of a member, like if they were indexable. Can be used to inspect an unknown structure, for instance.

Parameters
indexThe index of the member key to retrieve. For instance, if a node has 5 members, it would be possible to index them from 0 to 4.
Returns
The key of the member at index requested. If index is out of bounds, an empty string.

◆ getMemberValue() [1/4]

Node* nkExport::Node::getMemberValue ( unsigned int  index) const

Allows to retrieve a member, like if they were indexable. See nkExport::Node::getMemberKey for more details.

Parameters
indexThe index of the member to retrieve.
Returns
The member at requested index. If index is out of bounds, nullptr.

◆ getMemberValue() [2/4]

Node* nkExport::Node::getMemberValue ( nkMemory::StringView  key) const

Allows to get a member directly from its key.

Parameters
keyThe key identifying the wanted member.
Returns
The member at requested key. If none is existing, nullptr.
Remarks
It is possible to address a member using its path within the tree. Member chaining and array indexing are supported. Example of such path : "o.array[0].type".

◆ getMemberValue() [3/4]

Node* nkExport::Node::getMemberValue ( nkMemory::StringView  key,
NODE_VALUE_TYPE  valueType 
) const

Allows to get a member directly from its key, with a constraint on its value type.

Parameters
keyThe key identifying the wanted member.
valueTypeThe value type the member should have.
Returns
The member at requested key. If none is existing or if the value type constraint is not satisfied, nullptr.
Remarks
It is possible to address a member using its path within the tree. Member chaining and array indexing are supported. Example of such path : "o.array[0].type".

◆ getMemberValue() [4/4]

Node* nkExport::Node::getMemberValue ( nkMemory::StringView  key,
NODE_NATURE  nodeNature 
) const

Allows to get a member directly from its key, with a constraint on its nature.

Parameters
keyThe key identifying the wanted member.
nodeNatureThe nature the member should have.
Returns
The member at requested key. If none is existing or if the nature constraint is not satisfied, nullptr.
Remarks
It is possible to address a member using its path within the tree. Member chaining and array indexing are supported. Example of such path : "o.array[0].type".

◆ getArraySize()

unsigned int nkExport::Node::getArraySize ( ) const
Returns
The size of the array represented by the node.

◆ getArrayElement() [1/3]

Node* nkExport::Node::getArrayElement ( unsigned int  index) const
Parameters
indexThe index at which to index the array.
Returns
The attached element. If index is out of bounds, nullptr.

◆ getArrayElement() [2/3]

Node* nkExport::Node::getArrayElement ( unsigned int  index,
NODE_VALUE_TYPE  valueType 
) const
Parameters
indexThe index at which to index the array.
valueTypeThe value type the element should have.
Returns
The attached element. If index is out of bounds or if the value type constraint is not satisfied, nullptr.

◆ getArrayElement() [3/3]

Node* nkExport::Node::getArrayElement ( unsigned int  index,
NODE_NATURE  nodeNature 
) const
Parameters
indexThe index at which to index the array.
nodeNatureThe nature the element should have.
Returns
The attached element. If index is out of bounds or if the nature constraint is not satisfied, nullptr.

◆ getUserData()

void* nkExport::Node::getUserData ( ) const
Returns
The user data attached to the node.

◆ setAsString()

void nkExport::Node::setAsString ( nkMemory::StringView  value)

Converts the node to hold a string.

Parameters
valueThe string to attach to this node.

◆ setAsInt()

void nkExport::Node::setAsInt ( int  value)

Converts the node to hold an int.

Parameters
valueThe int to attach to this node.

◆ setAsUint()

void nkExport::Node::setAsUint ( unsigned int  value)

Converts the node to hold an unsigned int.

Parameters
valueThe unsigned int to attach to this node.

◆ setAsLong()

void nkExport::Node::setAsLong ( long long  value)

Converts the node to hold a long (8 bytes).

Parameters
valueThe long to attach to this node.

◆ setAsUlong()

void nkExport::Node::setAsUlong ( unsigned long long  value)

Converts the node to hold an unsigned long (8 bytes).

Parameters
valueThe unsigned long to attach to this node.

◆ setAsFloat()

void nkExport::Node::setAsFloat ( float  value)

Converts the node to hold a float.

Parameters
valueThe float to attach to this node.

◆ setAsDouble()

void nkExport::Node::setAsDouble ( double  value)

Converts the node to hold a double.

Parameters
valueThe double to attach to this node.

◆ setAsBool()

void nkExport::Node::setAsBool ( bool  value)

Converts the node to hold a boolean.

Parameters
valueThe bool to attach to this node.

◆ addMember()

Node* nkExport::Node::addMember ( nkMemory::StringView  key)

Converts the node as an object to hold child members.

Parameters
keyThe key of the member to add.
Returns
The child member, empty.
Remarks
The node is responsible for freeing the child member. You don't need to free the returned pointer after use.

◆ deleteMember()

void nkExport::Node::deleteMember ( nkMemory::StringView  key)

Allows to erase a member from the node.

Parameters
keyThe key of the member to delete.
Remarks
This will also free the memory of the child node, if existing.

◆ addElement()

Node* nkExport::Node::addElement ( )

Converts the node into an array to index children.

Returns
A new child, empty.
Remarks
The node is responsible for freeing the child. You don't need to free the returned pointer after use.

◆ setUserData()

void nkExport::Node::setUserData ( void *  value)

Allows to attach user data to the node. This data is ignored by the component, and can be used by the client application if any information needs to be communicated by this mean.

Parameters
valueThe data to attach to this node.

◆ operator=() [1/2]

Node& nkExport::Node::operator= ( const Node other)

Copy assignment operator.

Parameters
otherThe node to copy from.
Returns
The updated instance of the calling object.

◆ operator=() [2/2]

Node& nkExport::Node::operator= ( Node &&  other)

Move assignment operator.

Parameters
otherThe node to move.
Returns
The updated instance of the calling object.

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