nvs_util - EPOCH Named Variable Set Utilities

The NVS_UTIL package provides a C language implementation of EPOCH's C++ nvarset (named variable set) class. A named variable set is essentially an associative array of named variables.

An empty set of named variables is created as follows:

    #include  "nvs_util.h"			-- Named variable sets.
    NVarSet  set ;
    nvsCreate (&set) ;

Named variables are then added to the set using nvsAdd():

    nvsAdd (set, nvrNew ("THIS", NvrFloating, 123.45)) ;
    nvsAdd (set, nvrNew ("THAT", NvrInteger, 6789)) ;

The variables in a set can be retrieved by index:

    int  i ;
    NamedVariable  variable ;
    for (i = 0 ;  i < nvsCount (set) ;  i++) {
        variable = nvsGet (set, i) ;
        printf ("%s = %s\n", nvrName (variable), nvrString (variable)) ;

or by name:

    variable = nvsFind (set, "THAT") ;		-- Prints "THAT = 6789".
    printf ("%s = %s\n", nvrName (variable), nvrString (variable)) ;

Individual variables can be deleted from a set:

    variable = nvsDelete (set, "THIS") ;

Although the variable is removed from the set, the variable itself is not destroyed. In contrast, deleting the entire set in one fell swoop:

    nvsDestroy (set) ;

automatically destroys the remaining variables via calls to nvrDestroy().

Public Procedures

nvsAdd() - adds a named variable to a set.
nvsCount() - returns the number of named variables in a set.
nvsCreate() - creates an empty named variable set.
nvsDelete() - deletes a named variable from a set.
nvsDestroy() - destroys a set.
nvsFind() - retrieves a variable by name from a set.
nvsGet() - retrieves a variable by index from a set.

Source Files


Alex Measday  /  E-mail