#include <glib.h>
Go to the source code of this file.
Data Structures | |
struct | XnmValue |
Enumerations | |
enum | { XNM_ERROR = 0, XNM_ERROR_SYNTAX_ERROR = 1, XNM_ERROR_KEY_NOT_FOUND = 2 } |
enum | XnmValueType { XNM_UNKNOWN, XNM_TABLE, XNM_ARRAY, XNM_STRING, XNM_BINARY } |
enum | XnmValueGetType { XNM_GET_UINT8, XNM_GET_UINT16, XNM_GET_UINT, XNM_GET_UINT32, XNM_GET_INT8, XNM_GET_INT16, XNM_GET_INT, XNM_GET_INT32, XNM_GET_INT64, XNM_GET_FLOAT, XNM_GET_DOUBLE, XNM_GET_STRING, XNM_GET_BOOL } |
Functions | |
XnmValue * | xnm_value_new_string (const gchar *s) |
XnmValue * | xnm_value_new_table () |
XnmValue * | xnm_value_new_array () |
XnmValue * | xnm_value_new_binary (const gchar *buf, size_t size) |
void | xnm_value_ref (XnmValue *xnm_value) |
void | xnm_value_unref (XnmValue *xnm_value) |
gchar * | xnm_value_export_to_string (XnmValue *xnm_value) |
int | xnm_value_get (XnmValue *xnm_value_tree, const char *key, XnmValue **xnm_value) |
int | xnm_value_get_string (XnmValue *xnm_value, const char *key, gchar **string_val) |
int | xnm_value_get_const_string (XnmValue *xnm_value_tree, const char *key, const gchar **const_val_string) |
int | xnm_value_get_int (XnmValue *xnm_value, const char *key, int *val_int) |
int | xnm_value_get_bool (XnmValue *xnm_value, const char *key, gboolean *val_bool) |
int | xnm_value_array_push_value (XnmValue *xnm_value_array, XnmValue *value) |
int | xnm_value_array_push_string (XnmValue *xnm_value_array, const gchar *string) |
int | xnm_value_array_push_int (XnmValue *xnm_value_array, int value_int) |
int | xnm_value_array_push_printf (XnmValue *xnm_value_array, const gchar *format,...) |
int | xnm_value_table_set_key_value (XnmValue *xnm_value_tree, const gchar *key, XnmValue *xnm_value) |
int | xnm_value_table_set_key_value_string (XnmValue *xnm_value_parent, const gchar *key, const gchar *string) |
int | xnm_value_set_key_value_printf (XnmValue *xnm_value_parent, const gchar *key, const gchar *format,...) |
int | xnm_value_get_array_length (XnmValue *xnm_value, const char *key) |
int | xnm_value_get_values (XnmValue *xnm_value,...) |
int | xnm_value_get_table_key_list (XnmValue *xnm_value, const char *key, const GPtrArray **key_list) |
int | xnm_parse_string (const gchar *string, XnmValue **value, GError **error) |
int | xnm_parse_string_len (const gchar *string, int len, XnmValue **value, GError **error) |
int | xnm_parse_file (const gchar *filenam, XnmValue **xnm_value, GError **error) |
Values are accessed by their keys which is a slash separated path description from the root to a value. Tables are dereferenced by the key name, and arrays by the array index enclosed in square brackets.
Given a xnm structure that looks like:
gaim => { gtk=> { browsers=> { place=>F command=>"xterm -e lynx %s" browser=>firefox new_window=>F } plugins => [ '/usr/lib/gaim/gaimrc.so' '/usr/lib/gaim/ssl-nss.so' '/usr/lib/gaim/ssl.so' ] } pos => [ {x=>0 y=>0} {x=>100 y=0} {x=>100 y=>50 } ] }
Here are a couple of valid keys
Most commands are made to ignore undefined keys.
libxnm provides several methods for extracting values from an xnm tree that all start with xnm_get .
anonymous enum |
Error definitions
enum XnmValueGetType |
Values used when retrieving. Note that binary values may not be extracted this way, as they need to have the length of them returned as well.
enum XnmValueType |
The possible types of a XnmValue.
int xnm_parse_file | ( | const gchar * | filenam, | |
XnmValue ** | xnm_value, | |||
GError ** | error | |||
) |
Read a file and parse it.
filenam | ||
xnm_value | ||
error |
int xnm_parse_string | ( | const gchar * | string, | |
XnmValue ** | value, | |||
GError ** | error | |||
) |
Parse a string in XNM syntax.
string | A string in xnm format |
value | A newly allocated XnmValue if the parsing was successful. | |
error | Error if parsing failed. |
int xnm_parse_string_len | ( | const gchar * | string, | |
int | len, | |||
XnmValue ** | value, | |||
GError ** | error | |||
) |
Parse a string in asf format with a given len.
string | ||
len | ||
value | ||
error |
int xnm_value_array_push_int | ( | XnmValue * | xnm_value_array, | |
int | value_int | |||
) |
Push an integer value into an xnm value of type array.
xnm_value_array | ||
value_int |
int xnm_value_array_push_printf | ( | XnmValue * | xnm_value_array, | |
const gchar * | format, | |||
... | ||||
) |
Formatted addition to an array. Use e.g. for doubles.
xnm_value_array | ||
format |
int xnm_value_array_push_string | ( | XnmValue * | xnm_value_array, | |
const gchar * | string | |||
) |
Push a string into an xnm value of type array.
xnm_value_array | ||
string |
gchar* xnm_value_export_to_string | ( | XnmValue * | xnm_value | ) |
Allocate a new string containing a serialized representation of xnm_value.
xnm_value |
Retrieve an xnm value from an xnm_value_tree. If the key is not found then the value is not assigned. If the key is found then xnm_value is assigned the corresponding string.
Note that xnm_value_get does *not* dereference xnm_value before overwriting it with a new value.
The returned xnm_value points into the xnm_value_tree with an increased reference count.
xnm_value_tree | ||
key | ||
xnm_value |
int xnm_value_get_array_length | ( | XnmValue * | xnm_value, | |
const char * | key | |||
) |
Retrive the length of a XnmValue array.
xnm_value | ||
key |
int xnm_value_get_bool | ( | XnmValue * | xnm_value, | |
const char * | key, | |||
gboolean * | val_bool | |||
) |
Retrieve a boolean value from an xnm_value. The boolean value is considered true if it starts with 't','T','y','Y', or 1. Everything else is false.
int xnm_value_get_const_string | ( | XnmValue * | xnm_value_tree, | |
const char * | key, | |||
const gchar ** | const_val_string | |||
) |
This value retrieves a const pointer to the string within the xnm_value_tree.
xnm_value_tree | ||
key |
const_val_string |
int xnm_value_get_int | ( | XnmValue * | xnm_value, | |
const char * | key, | |||
int * | val_int | |||
) |
This value retrieves a value from an xnm_value and turns it into an integer with atoi().
xnm_value | ||
key |
val_int |
int xnm_value_get_string | ( | XnmValue * | xnm_value, | |
const char * | key, | |||
gchar ** | string_val | |||
) |
This value retrieves a string from an xnm_value_tree. If the key is found then string_value is freed, and the string is copied into string_val. Otherwise, string_val is left untouched.
xnm_value | ||
key | ||
string_val |
int xnm_value_get_table_key_list | ( | XnmValue * | xnm_value, | |
const char * | key, | |||
const GPtrArray ** | key_list | |||
) |
Get a list of all keys of a table.
xnm_value | ||
key | ||
key_list |
int xnm_value_get_values | ( | XnmValue * | xnm_value, | |
... | ||||
) |
Get a list of values in one call. This function is very convenient for extracting multiple values in one call. It takes as argument a NULL terminated vararg list, where each value extraction is controlled by three arguments:
xnm_value |
XnmValue* xnm_value_new_binary | ( | const gchar * | buf, | |
size_t | size | |||
) |
Allocate a new XnmValue with the type binary and initiate it with the data in buf.
XnmValue* xnm_value_new_string | ( | const gchar * | s | ) |
void xnm_value_ref | ( | XnmValue * | xnm_value | ) |
Increase the reference count of xnm_value.
xnm_value |
int xnm_value_set_key_value_printf | ( | XnmValue * | xnm_value_parent, | |
const gchar * | key, | |||
const gchar * | format, | |||
... | ||||
) |
Set a key value which is formatted with printf.
xnm_value_parent | ||
key | ||
format |
int xnm_value_table_set_key_value | ( | XnmValue * | xnm_value_tree, | |
const gchar * | key, | |||
XnmValue * | xnm_value | |||
) |
Add a xnm_value to a xnm table. This function increases the reference count of the xnm_value.
Note! This function does not yet support hierarchical keys. To set an a key that is not a direct parent of xnm_value_tree, the leaf xnm_value table must first be retrieved, and this function then called on that value.
xnm_value_tree | ||
key | ||
xnm_value |
int xnm_value_table_set_key_value_string | ( | XnmValue * | xnm_value_parent, | |
const gchar * | key, | |||
const gchar * | string | |||
) |
Convenience function for setting a string key value. If the key already exists in xnm_value_parent, then it is freed and replaced by the new svalue.
xnm_value_parent | ||
key | ||
string |
void xnm_value_unref | ( | XnmValue * | xnm_value | ) |
Decrease the reference count on an xnm_value. If the reference count goes down to 0, the value is destroyed.
xnm_value |