void SetNodeUserField_bn ( node_bn*  node,   const char*  name,   const void*  data,   int  length,   int  kind )

This associates user-defined data with node on a field-by-field basis using attribute-value pairs. When the net is written to file, this data will be saved in the file with it, and will be available when the net is read back from file.

For name pass the name of the field to be set. Field names may be any ascii C string which meets the requirements of an IDname (max 30 chars, alphanumeric, underscores okay). The number of different field names is only limited by available memory.

For data pass a pointer to the data to associate, and for length pass the number of bytes of data to save. When you later retrieve the data with GetNodeUserField_bn that function will return the same length, and a pointer to a byte-for-byte copy of the same data.

Pass 0 for kind. It is only for future expansion.

If you have already set a field with the same name, Netica will overwrite that. To remove a field, call this function passing NULL for data.

The data may be of any type, but if you wish your Bayes net files to be portable across different operating systems, or if people or other programs may directly read your Bayes net files, it is best for the data to be an ascii string. Netica Application can also read and set user fields if they are ascii strings (use the multi-purpose selector at the bottom of the node properties dialog box of version 2.00 or later). Some helpful functions to set user fields to integers, real numbers and strings are: SetNodeUserInt, SetNodeUserNumber and SetNodeUserString, which are provided in NeticaEx.c, and in the examples below. See GetNodeUserField_bn for the matching functions that do retrieval.

SetNodeUserField_bn will just copy the data from the location pointed to by data, and will never modify it or try to free that memory.

All memory management for the internal representation of user-defined fields is managed by Netica. They are duplicated when nodes are duplicated, and freed when they are freed.

If you wish to associate user data with a node, and not have that data saved to file, use SetNodeUserData_bn instead.

Version:

Versions 2.00 and later have this function.

See also:

GetNodeUserField_bn    Retrieve it, by its name
GetNodeNthUserField_bn    Iterate through the user fields of this node
SetNodeUserData_bn    To attach completely user-managed data (not saved to file)
SetNetUserField_bn    Attach field-by-field data to the whole net

Example:

The following function is available in NeticaEx.c:
// To set a user field to an ascii string // #include <string.h> void SetNodeUserString (node_bn* node, const char* fieldname, const char* str){ SetNodeUserField_bn (node, fieldname, str, strlen (str), 0); }
Example 2:
The following function is available in NeticaEx.c:
// To set a user field to an integer // #include <string.h> #include <stdio.h> void SetNodeUserInt (node_bn* node, const char* fieldname, int num){ char buf[22]; sprintf (buf, "%d", (int)num); SetNodeUserField_bn (node, fieldname, buf, strlen (buf), 0); }
Example 3:
The following function is available in NeticaEx.c:
// To set a user field to a real number // #include <string.h> #include <stdio.h> void SetNodeUserNumber (node_bn* node, const char* fieldname, double num){ char buf[65]; sprintf (buf, "%g", (double)num); SetNodeUserField_bn (node, fieldname, buf, strlen (buf), 0); }