00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00076 #ifndef XNM_H
00077 #define XNM_H
00078
00079 #ifdef __cplusplus
00080 extern "C"
00081 {
00082 #endif
00083
00084 #include <glib.h>
00085
00090 enum {
00091 XNM_ERROR = 0,
00092 XNM_ERROR_SYNTAX_ERROR = 1,
00093 XNM_ERROR_KEY_NOT_FOUND = 2
00094 };
00095
00100 typedef enum {
00101 XNM_UNKNOWN,
00102 XNM_TABLE,
00103 XNM_ARRAY,
00104 XNM_STRING,
00105 XNM_BINARY
00106 } XnmValueType;
00107
00114 typedef enum {
00115 XNM_GET_UINT8,
00116 XNM_GET_UINT16,
00117 XNM_GET_UINT,
00118 XNM_GET_UINT32,
00119 XNM_GET_INT8,
00120 XNM_GET_INT16,
00121 XNM_GET_INT,
00122 XNM_GET_INT32,
00123 XNM_GET_INT64,
00124 XNM_GET_FLOAT,
00125 XNM_GET_DOUBLE,
00126 XNM_GET_STRING,
00127 XNM_GET_BOOL
00128 } XnmValueGetType;
00129
00130
00131 struct xnm_string_struct;
00132 struct xnm_table_struct;
00133 struct xnm_array_struct;
00134 struct xnm_bin_struct;
00135
00140 typedef struct {
00141 int ref_count;
00142 XnmValueType type;
00143
00144 union {
00145 struct xnm_table_struct *table;
00146 struct xnm_array_struct *array;
00147 struct xnm_string_struct *string;
00148 struct xnm_binary_struct *binary;
00149 } value;
00150 } XnmValue;
00151
00160 XnmValue * xnm_value_new_string (const gchar *s);
00161
00168 XnmValue * xnm_value_new_table ();
00169
00175 XnmValue * xnm_value_new_array ();
00176
00177
00183 XnmValue * xnm_value_new_binary (const gchar *buf, size_t size);
00184
00185
00191 void xnm_value_ref (XnmValue *xnm_value);
00192
00199 void xnm_value_unref (XnmValue *xnm_value);
00200
00209 gchar * xnm_value_export_to_string (XnmValue *xnm_value);
00210
00228 int xnm_value_get (XnmValue *xnm_value_tree,
00229 const char *key,
00230
00231 XnmValue **xnm_value);
00232
00244 int xnm_value_get_string (XnmValue *xnm_value,
00245 const char *key,
00246
00247 gchar **string_val);
00248
00259 int xnm_value_get_const_string (XnmValue *xnm_value_tree,
00260 const char *key,
00261
00262
00263 const gchar **const_val_string);
00264
00275 int xnm_value_get_int (XnmValue *xnm_value,
00276 const char *key,
00277
00278 int *val_int);
00279
00280
00286 int xnm_value_get_bool (XnmValue *xnm_value,
00287 const char *key,
00288
00289 gboolean *val_bool);
00290
00296 int xnm_value_array_push_value(XnmValue * xnm_value_array,
00297 XnmValue * value);
00298
00307 int xnm_value_array_push_string(XnmValue * xnm_value_array,
00308 const gchar *string);
00309
00310
00319 int xnm_value_array_push_int(XnmValue * xnm_value_array,
00320 int value_int);
00321
00322
00331 int xnm_value_array_push_printf(XnmValue * xnm_value_array,
00332 const gchar *format,
00333 ...);
00334
00350 int xnm_value_table_set_key_value(XnmValue * xnm_value_tree,
00351 const gchar * key,
00352 XnmValue * xnm_value);
00353
00365 int
00366 xnm_value_table_set_key_value_string(XnmValue *xnm_value_parent,
00367 const gchar *key,
00368 const gchar *string);
00369
00379 int
00380 xnm_value_set_key_value_printf(XnmValue *xnm_value_parent,
00381 const gchar *key,
00382 const gchar *format,
00383 ...
00384 );
00385
00395 int
00396 xnm_value_get_array_length (XnmValue *xnm_value,
00397 const char *key);
00398
00413 int
00414 xnm_value_get_values(XnmValue *xnm_value,
00415 ...);
00416
00417
00427 int
00428 xnm_value_get_table_key_list (XnmValue *xnm_value,
00429 const char *key,
00430
00431 const GPtrArray **key_list
00432 );
00433
00443 int
00444 xnm_parse_string(const gchar *string,
00445
00446 XnmValue **value,
00447 GError **error
00448 );
00449
00460 int
00461 xnm_parse_string_len(const gchar *string,
00462 int len,
00463
00464 XnmValue **value,
00465 GError **error
00466 );
00467
00468
00478 int
00479 xnm_parse_file(const gchar *filenam,
00480
00481 XnmValue **xnm_value,
00482 GError **error);
00483
00484 #ifdef __cplusplus
00485 }
00486 #endif
00487
00488 #endif