- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

# 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 #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
    00031 #if defined(LIBCONFIG_STATIC)
    00032 #define LIBCONFIG_API
    00033 #elif defined(LIBCONFIG_EXPORTS)
    00034 #define LIBCONFIG_API __declspec(dllexport)
    00035 #else /* ! LIBCONFIG_EXPORTS */
    00036 #define LIBCONFIG_API __declspec(dllimport)
    00037 #endif /* LIBCONFIG_STATIC */
    00038 #else /* ! WIN32 */
    00039 #define LIBCONFIG_API
    00040 #endif /* WIN32 */
    00041
    00042 #include <stdio.h>
    00043
    00044 #define CONFIG_TYPE_NONE    0
    00045 #define CONFIG_TYPE_GROUP   1
    00046 #define CONFIG_TYPE_INT     2
    00047 #define CONFIG_TYPE_INT64   3
    00048 #define CONFIG_TYPE_FLOAT   4
    00049 #define CONFIG_TYPE_STRING  5
    00050 #define CONFIG_TYPE_BOOL    6
    00051 #define CONFIG_TYPE_ARRAY   7
    00052 #define CONFIG_TYPE_LIST    8
    00053
    00054 #define CONFIG_FORMAT_DEFAULT  0
    00055 #define CONFIG_FORMAT_HEX      1
    00056
    00057 #define CONFIG_OPTION_AUTOCONVERT 0x01
    00058
    00059 #define CONFIG_TRUE  (1)
    00060 #define CONFIG_FALSE (0)
    00061
    00062 typedef union config_value_t
    00063 {
    00064   long ival;
    00065   long long llval;
    00066   double fval;
    00067   char *sval;
    00068   struct config_list_t *list;
    00069 } config_value_t;
    00070
    00071 typedef struct config_setting_t
    00072 {
    00073   char *name;
    00074   short type;
    00075   short format;
    00076   config_value_t value;
    00077   struct config_setting_t *parent;
    00078   struct config_t *config;
    00079   void *hook;
    00080   unsigned int line;
    00081 } config_setting_t;
    00082
    00083 typedef struct config_list_t
    00084 {
    00085   unsigned int length;
    00086   unsigned int capacity;
    00087   config_setting_t **elements;
    00088 } config_list_t;
    00089
    00090 typedef struct config_t
    00091 {
    00092   config_setting_t *root;
    00093   void (*destructor)(void *);
    00094   int flags;
    00095   const char *error_text;
    00096   int error_line;
    00097 } config_t;
    00098
    00099 extern LIBCONFIG_API int config_read(config_t *config, FILE *stream);
    00100 extern LIBCONFIG_API void config_write(const config_t *config, FILE *stream);
    00101
    00102 extern LIBCONFIG_API void config_set_auto_convert(config_t *config, int flag);
    00103 extern LIBCONFIG_API int config_get_auto_convert(const config_t *config);
    00104
    00105 extern LIBCONFIG_API int config_read_file(config_t *config,
    00106                                           const char *filename);
    00107 extern LIBCONFIG_API int config_write_file(config_t *config,
    00108                                            const char *filename);
    00109
    00110 extern LIBCONFIG_API void config_set_destructor(config_t *config,
    00111                                                 void (*destructor)(void *));
    00112
    00113 extern LIBCONFIG_API void config_init(config_t *config);
    00114 extern LIBCONFIG_API void config_destroy(config_t *config);
    00115
    00116 extern LIBCONFIG_API long config_setting_get_int(
    00117   const config_setting_t *setting);
    00118 extern LIBCONFIG_API long long config_setting_get_int64(
    00119   const config_setting_t *setting);
    00120 extern LIBCONFIG_API double config_setting_get_float(
    00121   const config_setting_t *setting);
    00122 extern LIBCONFIG_API int config_setting_get_bool(
    00123   const config_setting_t *setting);
    00124 extern LIBCONFIG_API const char *config_setting_get_string(
    00125   const config_setting_t *setting);
    00126
    00127 extern LIBCONFIG_API int config_setting_set_int(config_setting_t *setting,
    00128                                                 long value);
    00129 extern LIBCONFIG_API int config_setting_set_int64(config_setting_t *setting,
    00130                                                   long long value);
    00131 extern LIBCONFIG_API int config_setting_set_float(config_setting_t *setting,
    00132                                                   double value);
    00133 extern LIBCONFIG_API int config_setting_set_bool(config_setting_t *setting,
    00134                                                  int value);
    00135 extern LIBCONFIG_API int config_setting_set_string(config_setting_t *setting,
    00136                                                    const char *value);
    00137
    00138 extern LIBCONFIG_API int config_setting_set_format(config_setting_t *setting,
    00139                                                    short format);
    00140 extern LIBCONFIG_API short config_setting_get_format(config_setting_t *setting);
    00141
    00142 extern LIBCONFIG_API long config_setting_get_int_elem(
    00143   const config_setting_t *setting, int idx);
    00144 extern LIBCONFIG_API long long config_setting_get_int64_elem(
    00145   const config_setting_t *setting, int idx);
    00146 extern LIBCONFIG_API double config_setting_get_float_elem(
    00147   const config_setting_t *setting, int idx);
    00148 extern LIBCONFIG_API int config_setting_get_bool_elem(
    00149   const config_setting_t *setting, int idx);
    00150 extern LIBCONFIG_API const char *config_setting_get_string_elem(
    00151   const config_setting_t *setting, int idx);
    00152
    00153 extern LIBCONFIG_API config_setting_t *config_setting_set_int_elem(
    00154   config_setting_t *setting, int idx, long value);
    00155 extern LIBCONFIG_API config_setting_t *config_setting_set_int64_elem(
    00156   config_setting_t *setting, int idx, long long value);
    00157 extern LIBCONFIG_API config_setting_t *config_setting_set_float_elem(
    00158   config_setting_t *setting, int idx, double value);
    00159 extern LIBCONFIG_API config_setting_t *config_setting_set_bool_elem(
    00160   config_setting_t *setting, int idx, int value);
    00161 extern LIBCONFIG_API config_setting_t *config_setting_set_string_elem(
    00162   config_setting_t *setting, int idx, const char *value);
    00163
    00164 #define /* int */ config_setting_type(/* const config_setting_t * */ S) \
    00165   ((S)->type)
    00166
    00167 #define /* int */ config_setting_is_group(/* const config_setting_t * */ S) \
    00168   ((S)->type == CONFIG_TYPE_GROUP)
    00169 #define /* int */ config_setting_is_array(/* const config_setting_t * */ S) \
    00170   ((S)->type == CONFIG_TYPE_ARRAY)
    00171 #define /* int */ config_setting_is_list(/* const config_setting_t * */ S) \
    00172   ((S)->type == CONFIG_TYPE_LIST)
    00173
    00174 #define /* int */ config_setting_is_aggregate( \
    00175   /* const config_setting_t * */ S)                                     \
    00176   (((S)->type == CONFIG_TYPE_GROUP) || ((S)->type == CONFIG_TYPE_LIST)  \
    00177    || ((S)->type == CONFIG_TYPE_ARRAY))
    00178
    00179 #define /* int */ config_setting_is_number(/* const config_setting_t * */ S) \
    00180   (((S)->type == CONFIG_TYPE_INT)                                       \
    00181    || ((S)->type == CONFIG_TYPE_INT64)                                  \
    00182    || ((S)->type == CONFIG_TYPE_FLOAT))
    00183
    00184 #define /* int */ config_setting_is_scalar(/* const config_setting_t * */ S) \
    00185   (((S)->type == CONFIG_TYPE_BOOL) || ((S)->type == CONFIG_TYPE_STRING) \
    00186    || config_setting_is_number(S))
    00187
    00188 #define /* const char * */ config_setting_name( \
    00189   /* const config_setting_t * */ S)             \
    00190   ((S)->name)
    00191
    00192 #define /* config_setting_t * */ config_setting_parent( \
    00193   /* const config_setting_t * */ S)                     \
    00194   ((S)->parent)
    00195
    00196 #define /* int */ config_setting_is_root(       \
    00197   /* const config_setting_t * */ S)             \
    00198   ((S)->parent ? CONFIG_FALSE : CONFIG_TRUE)
    00199
    00200 extern LIBCONFIG_API int config_setting_index(const config_setting_t *setting);
    00201
    00202 extern LIBCONFIG_API int config_setting_length(
    00203   const config_setting_t *setting);
    00204 extern LIBCONFIG_API config_setting_t *config_setting_get_elem(
    00205   const config_setting_t *setting, unsigned int idx);
    00206
    00207 extern LIBCONFIG_API config_setting_t *config_setting_get_member(
    00208   const config_setting_t *setting, const char *name);
    00209
    00210 extern LIBCONFIG_API config_setting_t *config_setting_add(
    00211   config_setting_t *parent, const char *name, int type);
    00212 extern LIBCONFIG_API int config_setting_remove(config_setting_t *parent,
    00213                                                const char *name);
    00214 extern LIBCONFIG_API int config_setting_remove_elem(config_setting_t *parent,
    00215                                                     unsigned int idx);
    00216 extern LIBCONFIG_API void config_setting_set_hook(config_setting_t *setting,
    00217                                                   void *hook);
    00218
    00219 #define config_setting_get_hook(S) ((S)->hook)
    00220
    00221 extern LIBCONFIG_API config_setting_t *config_lookup(const config_t *config,
    00222                                                      const char *path);
    00223
    00224 extern LIBCONFIG_API long config_lookup_int(const config_t *config,
    00225                                             const char *path);
    00226 extern LIBCONFIG_API long long config_lookup_int64(const config_t *config,
    00227                                                    const char *path);
    00228 extern LIBCONFIG_API double config_lookup_float(const config_t *config,
    00229                                                 const char *path);
    00230 extern LIBCONFIG_API int config_lookup_bool(const config_t *config,
    00231                                             const char *path);
    00232 extern LIBCONFIG_API const char *config_lookup_string(const config_t *config,
    00233                                                       const char *path);
    00234
    00235 #define /* config_setting_t * */ config_root_setting( \
    00236   /* const config_t * */ C)                           \
    00237   ((C)->root)
    00238
    00239 #define /* unsigned short */ config_setting_source_line( \
    00240   /* const config_t */ C)                                \
    00241   ((C)->line)
    00242
    00243 #define /* const char * */ config_error_text(/* const config_t * */ C)  \
    00244   ((C)->error_text)
    00245
    00246 #define /* int */ config_error_line(/* const config_t * */ C)   \
    00247   ((C)->error_line)
    00248
    00249 #ifdef __cplusplus
    00250 }
    00251 #endif /* __cplusplus */
    00252
    00253 #endif /* __libconfig_h */