2.2.3.10 PropertyNode


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
PropertyNode Default constructor.


Property

Name Brief Example
pVal Void pointer value of the node. Examples
bVals Vector of char values of the node. Examples
bVals2 Matrix of char values of the node. Examples
dVal Double value of the node. Examples
dVals Vector of double values of the node. Examples
dVals2 Matrix of double values of the node. Examples
fVals Vector of float values of the node. Examples
fVals2 Matrix of float values of the node. Examples
nVal Integer value of the node. Examples
nVal64 64-bit integer value of the node. Examples
nVals Vector of integer values of the node. Examples
nVals2 Matrix of integer values of the node. Examples
oipVal A signed integer type for pointer precision of the node. Examples
pict Save a picture in node. Examples
strVal String value of the node. Examples
strVals Vector of string values of the node. Examples
sVals Vector of short integer values of the node. Examples
sVals2 Matrix of short integer values of the node. Examples