UniMRCP  1.7.0
apt_pair.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008-2015 Arsen Chaloyan
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 APT_PAIR_H
18 #define APT_PAIR_H
19 
20 /**
21  * @file apt_pair.h
22  * @brief Generic Name-Value Pair
23  */
24 
25 #include <apr_tables.h>
26 #include "apt_string.h"
27 
29 
30 /** Name-value declaration */
31 typedef struct apt_pair_t apt_pair_t;
32 
33 /** Generic name-value pair definition ("name:value") */
34 struct apt_pair_t {
35  /** The name */
37  /** The value */
39 };
40 
41 /** Dynamic array of name-value pairs */
42 typedef apr_array_header_t apt_pair_arr_t;
43 
44 /** Initialize name-value pair */
45 static APR_INLINE void apt_pair_init(apt_pair_t *pair)
46 {
47  apt_string_reset(&pair->name);
48  apt_string_reset(&pair->value);
49 }
50 
51 /** Copy name-value pair */
52 static APR_INLINE void apt_pair_copy(apt_pair_t *pair, const apt_pair_t *src_pair, apr_pool_t *pool)
53 {
54  apt_string_copy(&pair->name,&src_pair->name,pool);
55  apt_string_copy(&pair->value,&src_pair->value,pool);
56 }
57 
58 /** Create array of name-value pairs */
59 APT_DECLARE(apt_pair_arr_t*) apt_pair_array_create(apr_size_t initial_size, apr_pool_t *pool);
60 /** Copy array of name-value pairs */
61 APT_DECLARE(apt_pair_arr_t*) apt_pair_array_copy(const apt_pair_arr_t *src, apr_pool_t *pool);
62 /** Append name-value pair */
64 /** Find name-value pair by name */
65 APT_DECLARE(const apt_pair_t*) apt_pair_array_find(const apt_pair_arr_t *arr, const apt_str_t *name);
66 /** Get size of pair array */
68 /** Get name-value pair by id */
69 APT_DECLARE(const apt_pair_t*) apt_pair_array_get(const apt_pair_arr_t *arr, int id);
70 
72 
73 #endif /* APT_PAIR_H */
apr_array_header_t apt_pair_arr_t
Definition: apt_pair.h:42
Definition: apt_pair.h:34
#define APT_END_EXTERN_C
Definition: apt.h:38
int apt_bool_t
Definition: apt.h:57
apt_str_t name
Definition: apt_pair.h:36
const apt_pair_t * apt_pair_array_get(const apt_pair_arr_t *arr, int id)
#define APT_BEGIN_EXTERN_C
Definition: apt.h:36
#define APT_DECLARE(type)
Definition: apt.h:53
apt_pair_arr_t * apt_pair_array_copy(const apt_pair_arr_t *src, apr_pool_t *pool)
apt_str_t value
Definition: apt_pair.h:38
const apt_pair_t * apt_pair_array_find(const apt_pair_arr_t *arr, const apt_str_t *name)
Definition: apt_string.h:36
int apt_pair_array_size_get(const apt_pair_arr_t *arr)
apt_pair_arr_t * apt_pair_array_create(apr_size_t initial_size, apr_pool_t *pool)
apt_bool_t apt_pair_array_append(apt_pair_arr_t *arr, const apt_str_t *name, const apt_str_t *value, apr_pool_t *pool)
String Representation.