BRL-CAD
bu_structparse Struct Reference

#include <parse.h>

Data Fields

const char sp_fmt [4]
 
size_t sp_count
 
const char * sp_name
 
size_t sp_offset
 
void(* sp_hook )(const struct bu_structparse *, const char *, void *, const char *, void *)
 
const char * sp_desc
 
void * sp_default
 

Detailed Description

The "bu_structparse" struct describes one element of a structure. Collections of these are combined to describe entire structures (or at least those portions for which parse/print/import/export support is desired.

Provides a convenient way of describing a C data structure, and reading and writing it in both human-readable ASCII and efficient binary forms.

For example:

struct data_structure {
char a_char;
char str[32];
short a_short;
int a_int;
fastf_t a_fastf_t;
double a_double;
}
struct data_structure default = { 'c', "the default string", 32767, 1, 1.0, 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_fastf_t", bu_offsetof(data_structure, a_fastf_t), BU_STRUCTPARSE_FUNC_NULL, "A variable-precision fasf_t floating point value", (void*)&default.a_fastf_t},
{"%g", 1, "a_double", bu_offsetof(data_structure, a_double), BU_STRUCTPARSE_FUNC_NULL, "A double-precision fasf_t floating point value", (void*)&default.a_double},
{ "", 0, (char *)NULL, 0, BU_STRUCTPARSE_FUNC_NULL, (char *)NULL, (void *)NULL}
};
#define bu_offsetof(_t, _m)
Definition: parse.h:66
#define bu_offsetofarray(_t, _a, _d, _i)
Definition: parse.h:67
#define BU_STRUCTPARSE_FUNC_NULL
Definition: parse.h:155
double fastf_t
fastest 64-bit (or larger) floating point type
Definition: vmath.h:330

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 139 of file parse.h.

Field Documentation

◆ sp_fmt

const char sp_fmt[4]

"%i" or "%f", etc.

Definition at line 140 of file parse.h.

◆ sp_count

size_t sp_count

number of elements

Definition at line 141 of file parse.h.

◆ sp_name

const char* sp_name

Element's symbolic name

Definition at line 142 of file parse.h.

◆ sp_offset

size_t sp_offset

Byte offset in struct

Definition at line 143 of file parse.h.

◆ sp_hook

void(* sp_hook) (const struct bu_structparse *, const char *, void *, const char *, void *)

Optional hooked function, or indir ptr

Definition at line 144 of file parse.h.

◆ sp_desc

const char* sp_desc

description of element

Definition at line 149 of file parse.h.

◆ sp_default

void* sp_default

ptr to default value

Definition at line 150 of file parse.h.


The documentation for this struct was generated from the following file: