|
NAMESTRUCTS_ARRAY_TYPE ,
STRUCTS_FIXEDARRAY_TYPE —
structs types for arrays
LIBRARYPDEL Library (libpdel, -lpdel)SYNOPSIS#include <sys/types.h>
#include
<pdel/structs/structs.h>
#include
<pdel/structs/type/array.h>
int
int
int
int
int
DESCRIPTIONMacrosTheSTRUCTS_ARRAY_TYPE () and
STRUCTS_FIXEDARRAY_TYPE () macros define a
structs(3)
type (i.e., a struct structs_type ) for describing
variable and fixed length arrays, respectively. In both macros,
elem_stype is a pointer to the structs type describing
the array elements, and xml_tag is an XML tag (ASCII
string) used to tag individual array elements when the array is expressed in
XML.
For struct structs_array { u_int length; /* number of elements */ void *elems; /* elements */ }; The length field contains the number of elements in the array. The array itself is pointed to by elems, which must be cast to the appropriate type. mtype is the typed_mem(3) type used to dynamically allocate the array. The elements of the array are subfields whose names are their index in the array. For example, if a subfield of a data structure named “foo.bar” has an array type, then the elements of the array are named “foo.bar.0,” “foo.bar.1,” etc. As a special case, “foo.bar.length” is a read-only virtual subfield of type structs_type_uint(3) that returns the length of the array. This “length” field does not appear in the output of structs_xml_output(3) or structs_traverse(3). To define a structure equivalent to a
FunctionsThe following functions are included to facilitate handling variable length arrays. In all cases, type is the structs(3) type for the data structure pointed to by data, and name indicates the variable length array sub-field of data. If name isNULL or the empty string, then
data itself is the variable length array.
SEE ALSOlibpdel(3), structs(3), structs_type(3), typed_mem(3)EXAMPLES/* Define my variable length array of IP addresses structure */ DEFINE_STRUCTS_ARRAY(ip_array, struct in_addr); /* My variable length array of IP addresses */ static struct ip_array variable_ip_array; /* Structs type describing "variable_ip_array": >= 0 IP addresses */ static const struct structs_type vip_array_type = STRUCTS_ARRAY_TYPE(&structs_type_ip4, "vip_array_memory", "ip"); #define FIXED_ARRAY_LEN 12 /* My fixed length array of IP addresses */ static struct in_addr fixed_ip_array[FIXED_ARRAY_LEN]; /* Structs type describing "fixed_ip_array": 12 IP addresses */ static const struct structs_type vip_array_type = STRUCTS_FIXEDARRAY_TYPE(&structs_type_ip4, sizeof(struct in_addr), FIXED_ARRAY_LEN, "ip"); HISTORYThe PDEL library was developed at Packet Design, LLC.http://www.packetdesign.com/
AUTHORSArchie Cobbs ⟨archie@freebsd.org⟩
Visit the GSP FreeBSD Man Page Interface. |