The following examples illustrates how to construct a simple leaf data node. There are multiple ways to construct leaf nodes depending on what information you have before the construction and what data type is the node.

The most common and generic API function to construct the data node that does not required to know the type of the node is demonstrated below. However, you have to find the object template prior the construction:


    ... 

    obj_template_t *leafobj =
    obj_find_child(parentobj,
          modname,
          objname);
    if (!leafobj) {
        /* report an error or do not try to generate the leaf */
        return ERR_NCX_DEF_NOT_FOUND;
    }

    /* construct a leaf val_vale tree regardless of its type */ 
    val_value_t *any_type_leaf = 
         val_make_simval_obj(leafobj, 
                             (const xmlChar *)"8", 
                              &res);
    ...


The most beneficial part of this API function is that you do NOT have to investigate the type of the node before the construction. 

However, If you know the type of the node and want to construct the value based on the type, the following example demonstrates how to accomplish this goal.

In this example we are constructing “string” type data node:


    ... 

    /* construct a sting type leaf */ 
    val_value_t *string_leaf = 
        agt_make_leaf(parentobj, 
                      leafname, 
                      (const xmlChar *)"example value", 
                       &res);
   ...


In the example code above, if the PARENTOBJ is a leaf or leaf-list then it will be used directly instead of checking for a child node.

In order to construct data node with integer types, the following API function can be used:


    ... 

    /* construct a uint32 type leaf */ 
    val_value_t *string_leaf = 
        agt_make_uint_leaf(parentobj, 
                           leafname, 
                           (uint32)32, 
                           &res);

    /* construct a uint32 type leaf */ 
    val_value_t *value = 
        agt_make_int_leaf(parentobj, 
                          leafname, 
                          (int32)32, 
                           &res);

    /* construct a uint64 type leaf */ 
    val_value_t *value = 
        agt_make_uint64_leaf(parentobj, 
                             leafname, 
                             (uint64)64, 
                              &res);

    /* construct a int64 type leaf */ 
    val_value_t *value = 
        agt_make_int64_leaf(parentobj, 
                          leafname, 
                          (int64)64, 
                           &res);

   ...


In order to construct data node with boolean type, the following API function can be used. The BOOLVAL value is getting set to TRUE if the value of this node should be TRUE:


    ... 

    /* construct a boolean type leaf */ 
    val_value_t *string_leaf = 
        agt_make_boolean_leaf(parentobj, 
                              modname,
                              leafname, 
                              boolval, 
                              &res);

   ...


In order to construct data node with empty type, the following API function can be used. The BOOLVAL value is ignored by this API function:


    ... 

    /* construct a boolean type leaf */ 
    val_value_t *string_leaf = 
        agt_make_empty_leaf(parentobj, 
                            modname,
                            leafname, 
                            boolval, 
                            &res);

   ...