STRUCTS_TYPE_ID(3)

NAME
structs_type_id - structs types for identifiers

LIBRARY
PDEL Library (libpdel, -lpdel)

SYNOPSIS
#include <sys/types.h>
#include <pdel/structs/structs.h>
#include <pdel/structs/type/id.h>
STRUCTS_ID_TYPE(idlist, vsize);

DESCRIPTION
The STRUCTS_ID_TYPE() macro defines a structs(3) type (i.e., a struct structs_type) for describing an enumeration or identifier list.

The data structure represented is an integral value that may take one of a fixed set of values. The possible values are defined by the idlist argument, which is a pointer to an array of struct structs_id:

    struct structs_id {
        const char  *id;        /* string representation */
        u_int32_t   value;      /* integer representation */
        u_int       imatch;     /* case-insensitive matching allowed */
    };

The id points to a unique string representing the value; imatch, determines whether the parsing of the ASCII representation is case-insensitive. value is the actual integer value. The first element in the array used as the default value. The array is terminated with an entry having id equal to NULL.

vsize is the size of the integral type used to store the value, which must be 1, 2, or 4.

SEE ALSO
libpdel(3), structs(3), structs_type(3)

EXAMPLES

    /* Set of possible colors */
    enum color {
    	RED,
    	GREEN,
    	BLUE,
    };
    /* The current color */
    static enum color current_color;
    /* Structs type describing something of type "enum color" */
    static const struct structs_id color_list[] = {
    	{ "red", RED },
    	{ "green", GREEN },
    	{ "blue", BLUE },
    	{ NULL, 0 }
    };
    static const struct structs_type color_type
    	= STRUCTS_ID_TYPE(color_list, sizeof(enum color));

HISTORY
The PDEL library was developed at Packet Design, LLC. http://www.packetdesign.com/

AUTHORS
Archie Cobbs <archie@freebsd.org>