- Main Page
- Related Pages
- Classes
- Files

- File List
- File Members

# libconfig.h

    00001 /* ----------------------------------------------------------------------------
    00002    libconfig - A library for processing structured configuration files
    00003    Copyright (C) 2005-2008  Mark A Lindner
    00004
    00005    This file is part of libconfig.
    00006
    00007    This library is free software; you can redistribute it and/or
    00008    modify it under the terms of the GNU Lesser General Public License
    00009    as published by the Free Software Foundation; either version 2.1 of
    00010    the License, or (at your option) any later version.
    00011
    00012    This library is distributed in the hope that it will be useful, but
    00013    WITHOUT ANY WARRANTY; without even the implied warranty of
    00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00015    Lesser General Public License for more details.
    00016
    00017    You should have received a copy of the GNU Library General Public
    00018    License along with this library; if not, see
    00019    <http://www.gnu.org/licenses/>.
    00020    ----------------------------------------------------------------------------
    00021 */
    00022
    00023 #ifndef __libconfig_h
    00024 #define __libconfig_h
    00025
    00026 #ifdef __cplusplus
    00027 extern "C" {
    00028 #endif /* __cplusplus */
    00029
    00030 #define LIBCONFIG_API
    00031
    00032 #include <stdio.h>
    00033
    00034 #define CONFIG_TYPE_NONE    0
    00035 #define CONFIG_TYPE_GROUP   1
    00036 #define CONFIG_TYPE_INT     2
    00037 #define CONFIG_TYPE_INT64   3
    00038 #define CONFIG_TYPE_FLOAT   4
    00039 #define CONFIG_TYPE_STRING  5
    00040 #define CONFIG_TYPE_BOOL    6
    00041 #define CONFIG_TYPE_ARRAY   7
    00042 #define CONFIG_TYPE_LIST    8
    00043
    00044 #define CONFIG_FORMAT_DEFAULT  0
    00045 #define CONFIG_FORMAT_HEX      1
    00046
    00047 #define CONFIG_OPTION_AUTOCONVERT 0x01
    00048
    00049 #define CONFIG_TRUE  (1)
    00050 #define CONFIG_FALSE (0)
    00051
    00052 typedef union config_value_t
    00053 {
    00054   long ival;
    00055   long long llval;
    00056   double fval;
    00057   char *sval;
    00058   struct config_list_t *list;
    00059 } config_value_t;
    00060
    00061 typedef struct config_setting_t
    00062 {
    00063   char *name;
    00064   short type;
    00065   short format;
    00066   config_value_t value;
    00067   struct config_setting_t *parent;
    00068   struct config_t *config;
    00069   void *hook;
    00070   unsigned int line;
    00071 } config_setting_t;
    00072
    00073 typedef struct config_list_t
    00074 {
    00075   unsigned int length;
    00076   unsigned int capacity;
    00077   config_setting_t **elements;
    00078 } config_list_t;
    00079
    00080 typedef struct config_t
    00081 {
    00082   config_setting_t *root;
    00083   void (*destructor)(void *);
    00084   int flags;
    00085   const char *error_text;
    00086   int error_line;
    00087 } config_t;
    00088
    00089 extern LIBCONFIG_API int config_read(config_t *config, FILE *stream);
    00090 extern LIBCONFIG_API void config_write(const config_t *config, FILE *stream);
    00091
    00092 extern LIBCONFIG_API void config_set_auto_convert(config_t *config, int flag);
    00093 extern LIBCONFIG_API int config_get_auto_convert(const config_t *config);
    00094
    00095 extern LIBCONFIG_API int config_read_file(config_t *config,
    00096                                           const char *filename);
    00097 extern LIBCONFIG_API int config_write_file(config_t *config,
    00098                                            const char *filename);
    00099
    00100 extern LIBCONFIG_API void config_set_destructor(config_t *config,
    00101                                                 void (*destructor)(void *));
    00102
    00103 extern LIBCONFIG_API void config_init(config_t *config);
    00104 extern LIBCONFIG_API void config_destroy(config_t *config);
    00105
    00106 extern LIBCONFIG_API long config_setting_get_int(
    00107   const config_setting_t *setting);
    00108 extern LIBCONFIG_API long long config_setting_get_int64(
    00109   const config_setting_t *setting);
    00110 extern LIBCONFIG_API double config_setting_get_float(
    00111   const config_setting_t *setting);
    00112 extern LIBCONFIG_API int config_setting_get_bool(
    00113   const config_setting_t *setting);
    00114 extern LIBCONFIG_API const char *config_setting_get_string(
    00115   const config_setting_t *setting);
    00116
    00117 extern LIBCONFIG_API int config_setting_set_int(config_setting_t *setting,
    00118                                                 long value);
    00119 extern LIBCONFIG_API int config_setting_set_int64(config_setting_t *setting,
    00120                                                   long long value);
    00121 extern LIBCONFIG_API int config_setting_set_float(config_setting_t *setting,
    00122                                                   double value);
    00123 extern LIBCONFIG_API int config_setting_set_bool(config_setting_t *setting,
    00124                                                  int value);
    00125 extern LIBCONFIG_API int config_setting_set_string(config_setting_t *setting,
    00126                                                    const char *value);
    00127
    00128 extern LIBCONFIG_API int config_setting_set_format(config_setting_t *setting,
    00129                                                    short format);
    00130 extern LIBCONFIG_API short config_setting_get_format(config_setting_t *setting);
    00131
    00132 extern LIBCONFIG_API long config_setting_get_int_elem(
    00133   const config_setting_t *setting, int idx);
    00134 extern LIBCONFIG_API long long config_setting_get_int64_elem(
    00135   const config_setting_t *setting, int idx);
    00136 extern LIBCONFIG_API double config_setting_get_float_elem(
    00137   const config_setting_t *setting, int idx);
    00138 extern LIBCONFIG_API int config_setting_get_bool_elem(
    00139   const config_setting_t *setting, int idx);
    00140 extern LIBCONFIG_API const char *config_setting_get_string_elem(
    00141   const config_setting_t *setting, int idx);
    00142
    00143 extern LIBCONFIG_API config_setting_t *config_setting_set_int_elem(
    00144   config_setting_t *setting, int idx, long value);
    00145 extern LIBCONFIG_API config_setting_t *config_setting_set_int64_elem(
    00146   config_setting_t *setting, int idx, long long value);
    00147 extern LIBCONFIG_API config_setting_t *config_setting_set_float_elem(
    00148   config_setting_t *setting, int idx, double value);
    00149 extern LIBCONFIG_API config_setting_t *config_setting_set_bool_elem(
    00150   config_setting_t *setting, int idx, int value);
    00151 extern LIBCONFIG_API config_setting_t *config_setting_set_string_elem(
    00152   config_setting_t *setting, int idx, const char *value);
    00153
    00154 #define /* int */ config_setting_type(/* const config_setting_t * */ S) \
    00155   ((S)->type)
    00156
    00157 #define /* int */ config_setting_is_group(/* const config_setting_t * */ S) \
    00158   ((S)->type == CONFIG_TYPE_GROUP)
    00159 #define /* int */ config_setting_is_array(/* const config_setting_t * */ S) \
    00160   ((S)->type == CONFIG_TYPE_ARRAY)
    00161 #define /* int */ config_setting_is_list(/* const config_setting_t * */ S) \
    00162   ((S)->type == CONFIG_TYPE_LIST)
    00163
    00164 #define /* int */ config_setting_is_aggregate( \
    00165   /* const config_setting_t * */ S)                                     \
    00166   (((S)->type == CONFIG_TYPE_GROUP) || ((S)->type == CONFIG_TYPE_LIST)  \
    00167    || ((S)->type == CONFIG_TYPE_ARRAY))
    00168
    00169 #define /* int */ config_setting_is_number(/* const config_setting_t * */ S) \
    00170   (((S)->type == CONFIG_TYPE_INT)                                       \
    00171    || ((S)->type == CONFIG_TYPE_INT64)                                  \
    00172    || ((S)->type == CONFIG_TYPE_FLOAT))
    00173
    00174 #define /* int */ config_setting_is_scalar(/* const config_setting_t * */ S) \
    00175   (((S)->type == CONFIG_TYPE_BOOL) || ((S)->type == CONFIG_TYPE_STRING) \
    00176    || config_setting_is_number(S))
    00177
    00178 #define /* const char * */ config_setting_name( \
    00179   /* const config_setting_t * */ S)             \
    00180   ((S)->name)
    00181
    00182 #define /* config_setting_t * */ config_setting_parent( \
    00183   /* const config_setting_t * */ S)                     \
    00184   ((S)->parent)
    00185
    00186 #define /* int */ config_setting_is_root(       \
    00187   /* const config_setting_t * */ S)             \
    00188   ((S)->parent ? CONFIG_FALSE : CONFIG_TRUE)
    00189
    00190 extern LIBCONFIG_API int config_setting_index(const config_setting_t *setting);
    00191
    00192 extern LIBCONFIG_API int config_setting_length(
    00193   const config_setting_t *setting);
    00194 extern LIBCONFIG_API config_setting_t *config_setting_get_elem(
    00195   const config_setting_t *setting, unsigned int idx);
    00196
    00197 extern LIBCONFIG_API config_setting_t *config_setting_get_member(
    00198   const config_setting_t *setting, const char *name);
    00199
    00200 extern LIBCONFIG_API config_setting_t *config_setting_add(
    00201   config_setting_t *parent, const char *name, int type);
    00202 extern LIBCONFIG_API int config_setting_remove(config_setting_t *parent,
    00203                                                const char *name);
    00204 extern LIBCONFIG_API int config_setting_remove_elem(config_setting_t *parent,
    00205                                                     unsigned int idx);
    00206 extern LIBCONFIG_API void config_setting_set_hook(config_setting_t *setting,
    00207                                                   void *hook);
    00208
    00209 #define config_setting_get_hook(S) ((S)->hook)
    00210
    00211 extern LIBCONFIG_API config_setting_t *config_lookup(const config_t *config,
    00212                                                      const char *path);
    00213
    00214 extern LIBCONFIG_API long config_lookup_int(const config_t *config,
    00215                                             const char *path);
    00216 extern LIBCONFIG_API long long config_lookup_int64(const config_t *config,
    00217                                                    const char *path);
    00218 extern LIBCONFIG_API double config_lookup_float(const config_t *config,
    00219                                                 const char *path);
    00220 extern LIBCONFIG_API int config_lookup_bool(const config_t *config,
    00221                                             const char *path);
    00222 extern LIBCONFIG_API const char *config_lookup_string(const config_t *config,
    00223                                                       const char *path);
    00224
    00225 #define /* config_setting_t * */ config_root_setting( \
    00226   /* const config_t * */ C)                           \
    00227   ((C)->root)
    00228
    00229 #define /* unsigned short */ config_setting_source_line( \
    00230   /* const config_t */ C)                                \
    00231   ((C)->line)
    00232
    00233 #define /* const char * */ config_error_text(/* const config_t * */ C)  \
    00234   ((C)->error_text)
    00235
    00236 #define /* int */ config_error_line(/* const config_t * */ C)   \
    00237   ((C)->error_line)
    00238
    00239 #ifdef __cplusplus
    00240 }
    00241 #endif /* __cplusplus */
    00242
    00243 #endif /* __libconfig_h */