1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __CUTILS_STR_PARMS_H
18 #define __CUTILS_STR_PARMS_H
19 
20 #include <stdint.h>
21 #include <sys/cdefs.h>
22 
23 __BEGIN_DECLS
24 
25 struct str_parms;
26 
27 struct str_parms *str_parms_create(void);
28 struct str_parms *str_parms_create_str(const char *_string);
29 void str_parms_destroy(struct str_parms *str_parms);
30 
31 void str_parms_del(struct str_parms *str_parms, const char *key);
32 
33 int str_parms_add_str(struct str_parms *str_parms, const char *key,
34                       const char *value);
35 int str_parms_add_int(struct str_parms *str_parms, const char *key, int value);
36 
37 int str_parms_add_float(struct str_parms *str_parms, const char *key,
38                         float value);
39 
40 // Returns non-zero if the str_parms contains the specified key.
41 int str_parms_has_key(struct str_parms *str_parms, const char *key);
42 
43 // Gets value associated with the specified key (if present), placing it in the buffer
44 // pointed to by the out_val parameter.  Returns the length of the returned string value.
45 // If 'key' isn't in the parms, then return -ENOENT (-2) and leave 'out_val' untouched.
46 int str_parms_get_str(struct str_parms *str_parms, const char *key,
47                       char *out_val, int len);
48 int str_parms_get_int(struct str_parms *str_parms, const char *key,
49                       int *out_val);
50 int str_parms_get_float(struct str_parms *str_parms, const char *key,
51                         float *out_val);
52 
53 char *str_parms_to_str(struct str_parms *str_parms);
54 
55 /* debug */
56 void str_parms_dump(struct str_parms *str_parms);
57 
58 __END_DECLS
59 
60 #endif /* __CUTILS_STR_PARMS_H */
61