#include <bu.h>
Data Fields | |
char | sp_fmt [4] |
"i" or "%f", etc | |
long | sp_count |
number of elements | |
char * | sp_name |
Element's symbolic name. | |
long | sp_offset |
Byte offset in struct. | |
void(* | sp_hook )() |
Optional hooked function, or indir ptr. | |
char * | sp_desc |
description of element | |
void * | sp_default |
ptr to default value |
struct data_structure { char a_char; char str[32]; short a_short; int a_int; double a_double; } struct data_structure data_default = { 'c', "the default string", 32767, 1, 1.0 }; struct data_structure my_values; struct bu_structparse data_sp[] ={ {"%c", 1, "a_char", bu_offsetof(data_structure, a_char), BU_STRUCTPARSE_FUNC_NULL, "a single character", (void*)&default.a_char }, {"%s", 32, "str", bu_offsetofarray(data_structure, str), BU_STRUCTPARSE_FUNC_NULL, "This is a full character string", (void*)default.str }, }, {"%i", 1, "a_short", bu_offsetof(data_structure, a_short), BU_STRUCTPARSE_FUNC_NULL, "A 16bit integer", (void*)&default.a_short }, {"%d", 1, "a_int", bu_offsetof(data_structure, a_int), BU_STRUCTPARSE_FUNC_NULL, "A full integer", (void*)&default.a_int }, {"%f", 1, "a_double", bu_offsetof(data_structure, a_double), BU_STRUCTPARSE_FUNC_NULL, "A double-precision floating point value", (void*)&default.a_double }, { "", 0, (char *)NULL, 0, BU_STRUCTPARSE_FUNC_NULL, (char *)NULL, (void *)NULL } };
To parse a string, call:
bu_struct_parse( vls_string, data_sp, (char *)my_values)
this will parse the vls string and assign values to the members of the structure my_values
A gross hack: To set global variables (or others for that matter) you can store the actual address of the variable in the sp_offset field and pass a null pointer as the last argument to bu_struct_parse(). If you don't understand why this would work, you probably shouldn't use this technique.
Definition at line 1412 of file bu.h.
|
"i" or "%f", etc
Definition at line 1413 of file bu.h. Referenced by bu_struct_export(), bu_struct_import(), bu_struct_print(), bu_structparse_argv(), bu_structparse_get_terse_form(), bu_structprint(), bu_vls_item_print_core(), bu_vls_struct_item(), and bu_vls_struct_print2(). |
|
number of elements
Definition at line 1414 of file bu.h. Referenced by bu_struct_export(), bu_struct_import(), bu_struct_print(), bu_structparse_argv(), bu_structparse_get_terse_form(), bu_structprint(), bu_vls_item_print_core(), bu_vls_struct_item(), and bu_vls_struct_print2(). |
|
Element's symbolic name.
Definition at line 1415 of file bu.h. Referenced by bu_struct_import(), bu_struct_print(), bu_structparse_argv(), bu_structparse_get_terse_form(), bu_structprint(), bu_vls_item_print_core(), bu_vls_name_print(), bu_vls_name_print_nc(), bu_vls_struct_item(), bu_vls_struct_item_named(), bu_vls_struct_print2(), rt_dsp_tclget(), and rt_parsetab_tclget(). |
|
Byte offset in struct.
Definition at line 1416 of file bu.h. Referenced by bu_struct_export(), bu_struct_import(), bu_struct_print(), bu_structparse_argv(), bu_structprint(), bu_vls_item_print_core(), bu_vls_struct_item(), and bu_vls_struct_print2(). |
|
Optional hooked function, or indir ptr.
Referenced by bu_struct_import(). |
|
description of element
|
|
ptr to default value
|