All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
target/Linux-x86_64/include/aerospike/as_pair.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2008-2013 by Aerospike.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to
6  * deal in the Software without restriction, including without limitation the
7  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8  * sell copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20  * IN THE SOFTWARE.
21  *****************************************************************************/
22 
23 #pragma once
24 
25 #include <aerospike/as_util.h>
26 #include <aerospike/as_val.h>
27 
28 #include <stdint.h>
29 
30 /******************************************************************************
31  * MACROS
32  ******************************************************************************/
33 
34 #define pair_new(a,b) as_pair_new((as_val *) a, (as_val *) b)
35 
36 /******************************************************************************
37  * TYPES
38  ******************************************************************************/
39 
40 /**
41  * A Pair of values: (_1,_2)
42  * @ingroup aerospike_t
43  */
44 typedef struct as_pair_s {
45 
46  /**
47  * @private
48  * as_pair is a subtype of as_val.
49  * You can cast as_pair to as_val.
50  */
51  as_val _;
52 
53  /**
54  * The first value of the pair.
55  */
56  as_val * _1;
57 
58  /**
59  * The second value of the pair.
60  */
61  as_val * _2;
62 
63 } as_pair;
64 
65 /******************************************************************************
66  * INSTANCE FUNCTIONS
67  ******************************************************************************/
68 
69 /**
70  * Create and initializes a new heap allocated `as_pair`.
71  *
72  * @param _1 The first value.
73  * @param _2 The second value.
74  *
75  * @return On success, the new pair. Otherwise NULL.
76  *
77  * @relatesalso as_pair
78  */
79 as_pair * as_pair_new(as_val * _1, as_val * _2);
80 
81 /**
82  * Initializes a stack allocated `as_pair`.
83  *
84  * @param pair The pair to initialize.
85  * @param _1 The first value.
86  * @param _2 The second value.
87  *
88  * @return On success, the new pair. Otherwise NULL.
89  *
90  * @relatesalso as_pair
91  */
92 as_pair * as_pair_init(as_pair * pair, as_val * _1, as_val * _2);
93 
94 /**
95  * Destroy the `as_pair` and release associated resources.
96  *
97  * @relatesalso as_pair
98  */
99 static inline void as_pair_destroy(as_pair * pair)
100 {
101  as_val_destroy((as_val *) pair);
102 }
103 
104 /******************************************************************************
105  * VALUE FUNCTIONS
106  ******************************************************************************/
107 
108 /**
109  * Get the first value of the pair
110  *
111  * @relatesalso as_pair
112  */
113 static inline as_val * as_pair_1(as_pair * pair)
114 {
115  return pair ? pair->_1 : NULL;
116 }
117 
118 /**
119  * Get the second value of the pair
120  */
121 static inline as_val * as_pair_2(as_pair * pair)
122 {
123  return pair ? pair->_2 : NULL;
124 }
125 
126 /******************************************************************************
127  * CONVERSION FUNCTIONS
128  *****************************************************************************/
129 
130 /**
131  * Convert to an as_val.
132  *
133  * @relatesalso as_pair
134  */
135 static inline as_val * as_pair_toval(const as_pair * pair)
136 {
137  return (as_val *) pair;
138 }
139 
140 /**
141  * Convert from an as_val.
142  *
143  * @relatesalso as_pair
144  */
145 static inline as_pair * as_pair_fromval(const as_val * v)
146 {
147  return as_util_fromval(v, AS_PAIR, as_pair);
148 }
149 
150 /******************************************************************************
151  * as_val FUNCTIONS
152  *****************************************************************************/
153 
154 /**
155  * @private
156  * Internal helper function for destroying an as_val.
157  */
159 
160 /**
161  * @private
162  * Internal helper function for getting the hashcode of an as_val.
163  */
164 uint32_t as_pair_val_hashcode(const as_val *);
165 
166 /**
167  * @private
168  * Internal helper function for getting the string representation of an as_val.
169  */
170 char * as_pair_val_tostring(const as_val *);