MACSio  0.9
Multi-purpose, Application-Centric, Scalable I/O Proxy App
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages

Support for enumerated types. More...

Functions

struct json_objectjson_object_new_enum (void)
 Create a new, empty enumeration object. More...
 
void json_object_enum_add (struct json_object *jso, char const *name, int64_t val, json_bool selected)
 Add a name/value pair to an enumeration. More...
 
int json_object_enum_length (struct json_object *jso)
 Get the length (or size) of an enumeration. More...
 
char const * json_object_enum_get_idx_name (struct json_object *jso, int idx)
 Get the name of a specific name/value pair in the enumeration. More...
 
char const * json_object_enum_get_name (struct json_object *jso, int64_t val)
 Get name of value in an enumeration. More...
 
int64_t json_object_enum_get_idx_val (struct json_object *jso, int idx)
 Get the value of a specific name/value pair in the enumeration. More...
 
int64_t json_object_enum_get_val (struct json_object *jso, char const *name)
 Get value of name in an enumeration. More...
 
int64_t json_object_enum_get_choice_val (struct json_object *jso)
 Get chosen value of an enumeration. More...
 
char const * json_object_enum_get_choice_name (struct json_object *jso)
 Get chosen name of an enumeration. More...
 

Detailed Description

Support for enumerated types.

Enumerations are an extension of JSON-C. The are not really relevant to MACSio but were implemented as part of a hack-a-thon.

A challenge with enumerations is that they kinda sorta involve two different kinds of information. One is a list of possible values (e.g. the available enumerations). The other is an instance of a JSON object of that enumeration type and its associated value (e.g. one of the available enumerations). Here, these two different sources of information wind up being combined into a single JSON object. This single object maintains both a list of the available enumeration values and the currently selected choice.

Function Documentation

struct json_object* json_object_new_enum ( void  )

Create a new, empty enumeration object.

The enumeration's choice (e.g. selected value) is uninitialized.

Definition at line 1305 of file json_object.c.

void json_object_enum_add ( struct json_object jso,
char const *  name,
int64_t  val,
json_bool  selected 
)

Add a name/value pair to an enumeration.

Caller can also choose to indicate that the given name/value pair should be the currently selected value for the enumeration by passing JSON_C_TRUE for selected argument. Alternatively, caller can use either json_object_set_enum_choice_val() or json_object_set_enum_choice_name() to adjust the current value for an enumeration.

Parameters
[in]jsoThe JSON enumeration object to update
[in]nameThe symbolic name of the new enumeration choice
[in]valThe numerical value of the new enumeration choice.
[in]selectedMake this value is the currently selected value of the enumeration

Definition at line 1327 of file json_object.c.

int json_object_enum_length ( struct json_object jso)

Get the length (or size) of an enumeration.

Returns
The number of available name/value pairs in the enumeration. If jso is either null or does not reference a JSON-C object which is an enumeration, -1 is returned.

Definition at line 1362 of file json_object.c.

char const* json_object_enum_get_idx_name ( struct json_object jso,
int  idx 
)

Get the name of a specific name/value pair in the enumeration.

Enumeration name/value pairs are indexed starting from zero.

Returns
The name of the ith name/value pair in the enumeration. If jso is either null or does not reference a JSON-C object which is an enumeration, null is returned.

Definition at line 1377 of file json_object.c.

char const* json_object_enum_get_name ( struct json_object jso,
int64_t  val 
)

Get name of value in an enumeration.

Returns
The name of the name/value pair whose value matches the given value. If jso is either null or does not reference a JSON-C object which is an enumeration, null is returned.

Definition at line 1398 of file json_object.c.

int64_t json_object_enum_get_idx_val ( struct json_object jso,
int  idx 
)

Get the value of a specific name/value pair in the enumeration.

Enumeration name/value pairs are indexed starting from zero.

Returns
The value of the ith name/value pair in the enumeration. If jso is either null or does not reference a JSON-C object which is an enumeration, -1 is returned.

Definition at line 1420 of file json_object.c.

int64_t json_object_enum_get_val ( struct json_object jso,
char const *  name 
)

Get value of name in an enumeration.

Returns
The value of the name/value pair whose name matches the given name. If jso is either null or does not reference a JSON-C object which is an enumeration, -1 is returned.

Definition at line 1441 of file json_object.c.

int64_t json_object_enum_get_choice_val ( struct json_object jso)

Get chosen value of an enumeration.

Returns
The value of the selected choice of the enumeration If jso is either null or does not reference a JSON-C object which is an enumeration, -1 is returned.

Definition at line 1460 of file json_object.c.

char const* json_object_enum_get_choice_name ( struct json_object jso)

Get chosen name of an enumeration.

Returns
The name of the selected choice of the enumeration If jso is either null or does not reference a JSON-C object which is an enumeration, null is returned.

Definition at line 1473 of file json_object.c.