config.h
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
33 #ifndef _CONFIG_H
34 #define _CONFIG_H
35 
36 #include <stdio.h>
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 typedef struct _Config Config;
43 
44 /* Parses a file and returns a handle to the contents. The file should
45  * already be opened and passed in as f. filename is used merely for
46  * printing error messages if the need should arise. */
47 Config *
48 config_parse_file (FILE * f, char * filename);
49 
50 /* Parses the default DGC configuration file (config/master.cfg) and
51  * returns a handle to it. If the environment variable DGC_CONFIG_PATH
52  * is set, that path is used instead. */
53 Config *
55 
63 int config_get_default_src (char *buf, int buflen);
64 
65 /* Frees a configuration handle */
66 void
67 config_free (Config * conf);
68 
69 /* Prints the contents of a parsed configuration file. */
70 int
71 config_print (Config * conf);
72 
76 int config_has_key (Config *conf, const char *key);
77 
78 /* Return number of top-level keys in container named by containerKey.
79  * Return -1 if container key not found.
80  */
81 int
82 config_get_num_subkeys (Config * conf, const char * containerKey);
83 
84 /* Fetch all top-level keys in container named by containerKey.
85  *
86  * Returns a newly allocated, NULL-terminated, array of strings. This array
87  * should be freed by the caller (e.g. with g_strfreev)
88  */
89 char **
90 config_get_subkeys (Config * conf, const char * containerKey);
91 
92 
93 
94 /* These four functions search for a key (i.e. "sick.front.pos") and fetch
95  * the value associated with that key into val, converting it to the specified
96  * type. If the conversion is not possible or the key is not found, an error
97  * is returned. If the key contains an array of multiple values, the first
98  * value is used. Return 0 on success, -1 on failure. */
99 int
100 config_get_int (Config * conf, const char * key, int * val);
101 int
102 config_get_boolean (Config * conf, const char * key, int * val);
103 int
104 config_get_double (Config * conf, const char * key, double * val);
105 int
106 config_get_str (Config * conf, const char * key, char ** val);
107 
108 double config_get_double_or_fail (Config *conf, const char *key);
109 
110 /* These four functions do the same thing as the previous four, except they
111  * return the value associated with the key. In case of error, the default
112  * value def is returned instead. */
113 int
114 config_get_int_or_default (Config * conf, const char * key, int def);
115 int
116 config_get_boolean_or_default (Config * conf, const char * key, int def);
117 double
118 config_get_double_or_default (Config * conf, const char * key, double def);
119 char *
120 config_get_str_or_default (Config * conf, const char * key, char * def);
121 
122 char *config_get_str_or_fail (Config *conf, const char *key);
123 
124 /* These four functions fetch the entire array associated with a key into vals.
125  * vals is an array passed in by the caller of length len elements. The
126  * number of elements actually stored in vals is returned. Also, -1 is
127  * returned on error. */
128 int
129 config_get_int_array (Config * conf, const char * key, int * vals, int len);
130 int
131 config_get_boolean_array (Config * conf, const char * key, int * vals, int len);
132 int
133 config_get_double_array (Config * conf, const char * key, double * vals, int len);
134 int
135 config_get_str_array (Config * conf, const char * key, char ** vals, int len);
136 
141 int config_get_array_len (Config *conf, const char * key);
142 
143 /* Allocates and returns a NULL-terminated array of strings. */
144 char **
145 config_get_str_array_alloc (Config * conf, const char * key);
146 
147 void config_str_array_free ( char **data);
148 
149 /* Creates a new config struct */
150 Config *
151 config_alloc( void );
152 
153 
154 /* These four functions search for a key, or create it if it does not exist.
155  * They then store a single value associated with that key.
156  * Return 0 on success, -1 on failure. */
157 int
158 config_set_int (Config * conf,
159  const char * key,
160  int val);
161 int
162 config_set_boolean (Config * conf,
163  const char * key,
164  int val);
165 int
166 config_set_double (Config * conf,
167  const char * key,
168  double val);
169 int
170 config_set_str (Config * conf,
171  const char * key,
172  char * val);
173 
174 /* These four functions search for a key, or create it if it does not exist.
175  * They store the entire input array contained in vals to that key.
176  * vals is an array passed in by the caller of length len elements. The
177  * Return 0 on success, -1 on failure. */
178 int
180  const char * key,
181  int * vals,
182  int len);
183 int
185  const char * key,
186  int * vals,
187  int len);
188 int
190  const char * key,
191  double * vals,
192  int len);
193 int
195  const char * key,
196  char ** vals,
197  int len);
198 
199 
200 #ifdef __cplusplus
201 }
202 #endif
203 
204 #endif
205 
208 /*Previous 3 lines appended automatically on Sun Feb 5 19:40:15 WET 2012 */
int config_get_array_len(Config *conf, const char *key)
Definition: config.cpp:963
int config_set_int_array(Config *conf, const char *key, int *vals, int len)
Definition: config.cpp:1117
int config_get_num_subkeys(Config *conf, const char *containerKey)
Definition: config.cpp:726
double config_get_double_or_default(Config *conf, const char *key, double def)
Definition: config.cpp:854
Config * config_parse_file(FILE *f, char *filename)
Definition: config.cpp:576
int config_print(Config *conf)
Definition: config.cpp:556
int config_get_boolean_array(Config *conf, const char *key, int *vals, int len)
Definition: config.cpp:897
Config * config_parse_default(void)
Definition: config.cpp:603
char * config_get_str_or_fail(Config *conf, const char *key)
Definition: config.cpp:822
void config_free(Config *conf)
Definition: config.cpp:639
char * config_get_str_or_default(Config *conf, const char *key, char *def)
Definition: config.cpp:864
Config * config_alloc(void)
Definition: config.cpp:1001
int config_set_int(Config *conf, const char *key, int val)
Definition: config.cpp:1076
int config_get_int_array(Config *conf, const char *key, int *vals, int len)
Definition: config.cpp:874
int config_get_default_src(char *buf, int buflen)
Definition: config.cpp:629
int config_set_double_array(Config *conf, const char *key, double *vals, int len)
Definition: config.cpp:1179
int config_set_str(Config *conf, const char *key, char *val)
Definition: config.cpp:1104
int config_set_double(Config *conf, const char *key, double val)
Definition: config.cpp:1094
int config_has_key(Config *conf, const char *key)
Definition: config.cpp:720
char ** config_get_str_array_alloc(Config *conf, const char *key)
Definition: config.cpp:973
int config_get_int_or_default(Config *conf, const char *key, int def)
Definition: config.cpp:834
int config_get_double(Config *conf, const char *key, double *val)
Definition: config.cpp:790
int config_get_boolean_or_default(Config *conf, const char *key, int def)
Definition: config.cpp:844
char ** config_get_subkeys(Config *conf, const char *containerKey)
Definition: config.cpp:744
int config_get_int(Config *conf, const char *key, int *val)
Definition: config.cpp:770
int config_get_double_array(Config *conf, const char *key, double *vals, int len)
Definition: config.cpp:920
int config_get_str(Config *conf, const char *key, char **val)
Definition: config.cpp:812
double config_get_double_or_fail(Config *conf, const char *key)
Definition: config.cpp:799
int config_set_str_array(Config *conf, const char *key, char **vals, int len)
Definition: config.cpp:1209
int config_set_boolean(Config *conf, const char *key, int val)
Definition: config.cpp:1086
int config_get_boolean(Config *conf, const char *key, int *val)
Definition: config.cpp:780
void config_str_array_free(char **data)
Definition: config.cpp:991
int config_get_str_array(Config *conf, const char *key, char **vals, int len)
Definition: config.cpp:943
int config_set_boolean_array(Config *conf, const char *key, int *vals, int len)
Definition: config.cpp:1147


mit_darpa_logs_player
Author(s): Miguel Oliveira
autogenerated on Mon Mar 2 2015 01:32:15