xnm.h

Go to the documentation of this file.
00001 /* libxnm
00002  * xnm.h:
00003  *
00004  * Copyright (C) 2007 Dov Grobgeld
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public
00017  * License along with this library; if not, write to the
00018  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019  * Boston, MA 02111-1307, USA.
00020  *
00021  *
00022  * Dov Grobgeld <dov.grobgeld@gmail.com>
00023  * Thu Jan 11 23:44:32 2007
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 /* Forward declarations */
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                                           // output
00231                                           XnmValue **xnm_value);
00232 
00244 int           xnm_value_get_string       (XnmValue *xnm_value,
00245                                           const char *key,
00246                                           // output
00247                                           gchar **string_val);
00248 
00259 int           xnm_value_get_const_string  (XnmValue *xnm_value_tree,
00260                                            const char *key,
00261 
00262                                            /* output */
00263                                            const gchar **const_val_string);
00264 
00275 int           xnm_value_get_int           (XnmValue *xnm_value,
00276                                            const char *key,
00277                                            /* output */
00278                                            int *val_int);
00279 
00280 
00286 int xnm_value_get_bool (XnmValue *xnm_value,
00287                         const char *key,
00288                         /* output */
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                               // output
00431                               const GPtrArray **key_list
00432                               );
00433 
00443 int
00444 xnm_parse_string(const gchar *string,
00445                  // output
00446                  XnmValue **value,
00447                  GError **error
00448                  );
00449 
00460 int
00461 xnm_parse_string_len(const gchar *string,
00462                      int len,
00463                      // output
00464                      XnmValue **value,
00465                      GError **error
00466                      );
00467 
00468 
00478 int
00479 xnm_parse_file(const gchar *filenam,
00480                // output
00481                XnmValue **xnm_value,
00482                GError **error);
00483 
00484 #ifdef  __cplusplus
00485 }
00486 #endif
00487 
00488 #endif

Generated on Thu Dec 25 10:36:27 2008 by  doxygen 1.5.7.1