2.2.3.10 PropertyNode


Contents

Name

PropertyNode

Remark

Hierarchy

Examples

Example 1: Scalars and strings

void propnode_scalars_demo()
{
    // A PropertyNode typically lives inside a Tree/TreeNode.
    Tree tr;
    TreeNode tn = tr.AddNode("settings");

    PropertyNode pn;                // create a node
    pn.nVal    = 42;               // int
    pn.dVal    = 3.14159;          // double
    pn.strVal  = "hello";          // string

    // attach PropertyNode to the tree node's "Value" payload
    tn.Value = pn;

    // read back
    PropertyNode got = tn.Value;
    printf("nVal=%d, dVal=%g, strVal=%s\n", got.nVal, got.dVal, got.strVal);
}

Example 2: Vectors

void propnode_vectors_demo()
{
    Tree tr;
    TreeNode tn = tr.AddNode("params");

    PropertyNode pn;
    pn.nVals.SetSize(3); pn.nVals[0] = 1; pn.nVals[1] = 2; pn.nVals[2] = 3;
    pn.dVals = {1.0, 2.5, 7.25};         // doubles
    pn.strVals = {"red","green","blue"}; // strings

    tn.Value = pn;

    // iterate integer vector
    PropertyNode got = tn.Value;
    for (int i = 0; i < got.nVals.GetSize(); i++)
        printf("nVals[%d]=%d\n", i, got.nVals[i]);
}

Example 3: Matrices (2D arrays)

void propnode_matrices_demo()
{
    Tree tr;
    TreeNode tn = tr.AddNode("grid");

    PropertyNode pn;
    pn.dVals2.SetSize(2,3); // 2 rows x 3 cols
    pn.dVals2[0][0] = 10; pn.dVals2[0][1] = 11; pn.dVals2[0][2] = 12;
    pn.dVals2[1][0] = 20; pn.dVals2[1][1] = 21; pn.dVals2[1][2] = 22;

    tn.Value = pn;

    // read back a single element
    double v = ((PropertyNode)tn.Value).dVals2[1][2]; // -> 22
    out_double("grid[1][2] = ", v);
}


Header to Include

origin.h

Reference

Members

Name Brief Example
Default constructor.


Property

Name Brief Example
Void pointer value of the node.
Vector of char values of the node.
Matrix of char values of the node.
Double value of the node.
Vector of double values of the node.
Matrix of double values of the node.
Vector of float values of the node.
Matrix of float values of the node.
Integer value of the node.
64-bit integer value of the node.
Vector of integer values of the node.
Matrix of integer values of the node.
A signed integer type for pointer precision of the node.
Save a picture in node.
String value of the node.
Vector of string values of the node.
Vector of short integer values of the node.
Matrix of short integer values of the node.