All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
as_pair.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008-2015 Aerospike, Inc.
3  *
4  * Portions may be licensed to Aerospike, Inc. under one or more contributor
5  * license agreements.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
8  * use this file except in compliance with the License. You may obtain a copy of
9  * the License at http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14  * License for the specific language governing permissions and limitations under
15  * the License.
16  */
17 
18 #pragma once
19 
20 #include <aerospike/as_util.h>
21 #include <aerospike/as_val.h>
22 
23 #include <stdint.h>
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 /******************************************************************************
30  * MACROS
31  ******************************************************************************/
32 
33 #define pair_new(a,b) as_pair_new((as_val *) a, (as_val *) b)
34 
35 /******************************************************************************
36  * TYPES
37  ******************************************************************************/
38 
39 /**
40  * A Pair of values: (_1,_2)
41  * @ingroup aerospike_t
42  */
43 typedef struct as_pair_s {
44 
45  /**
46  * @private
47  * as_pair is a subtype of as_val.
48  * You can cast as_pair to as_val.
49  */
51 
52  /**
53  * The first value of the pair.
54  */
56 
57  /**
58  * The second value of the pair.
59  */
61 
62 } as_pair;
63 
64 /******************************************************************************
65  * INSTANCE FUNCTIONS
66  ******************************************************************************/
67 
68 /**
69  * Create and initializes a new heap allocated `as_pair`.
70  *
71  * @param _1 The first value.
72  * @param _2 The second value.
73  *
74  * @return On success, the new pair. Otherwise NULL.
75  *
76  * @relatesalso as_pair
77  */
78 as_pair * as_pair_new(as_val * _1, as_val * _2);
79 
80 /**
81  * Initializes a stack allocated `as_pair`.
82  *
83  * @param pair The pair to initialize.
84  * @param _1 The first value.
85  * @param _2 The second value.
86  *
87  * @return On success, the new pair. Otherwise NULL.
88  *
89  * @relatesalso as_pair
90  */
91 as_pair * as_pair_init(as_pair * pair, as_val * _1, as_val * _2);
92 
93 /**
94  * Destroy the `as_pair` and release associated resources.
95  *
96  * @relatesalso as_pair
97  */
98 static inline void as_pair_destroy(as_pair * pair)
99 {
100  as_val_destroy((as_val *) pair);
101 }
102 
103 /******************************************************************************
104  * VALUE FUNCTIONS
105  ******************************************************************************/
106 
107 /**
108  * Get the first value of the pair
109  *
110  * @relatesalso as_pair
111  */
112 static inline as_val * as_pair_1(as_pair * pair)
113 {
114  return pair ? pair->_1 : NULL;
115 }
116 
117 /**
118  * Get the second value of the pair
119  */
120 static inline as_val * as_pair_2(as_pair * pair)
121 {
122  return pair ? pair->_2 : NULL;
123 }
124 
125 /******************************************************************************
126  * CONVERSION FUNCTIONS
127  *****************************************************************************/
128 
129 /**
130  * Convert to an as_val.
131  *
132  * @relatesalso as_pair
133  */
134 static inline as_val * as_pair_toval(const as_pair * pair)
135 {
136  return (as_val *) pair;
137 }
138 
139 /**
140  * Convert from an as_val.
141  *
142  * @relatesalso as_pair
143  */
144 static inline as_pair * as_pair_fromval(const as_val * v)
145 {
146  return as_util_fromval(v, AS_PAIR, as_pair);
147 }
148 
149 /******************************************************************************
150  * as_val FUNCTIONS
151  *****************************************************************************/
152 
153 /**
154  * @private
155  * Internal helper function for destroying an as_val.
156  */
158 
159 /**
160  * @private
161  * Internal helper function for getting the hashcode of an as_val.
162  */
163 uint32_t as_pair_val_hashcode(const as_val *);
164 
165 /**
166  * @private
167  * Internal helper function for getting the string representation of an as_val.
168  */
169 char * as_pair_val_tostring(const as_val *);
170 
171 #ifdef __cplusplus
172 } // end extern "C"
173 #endif
as_pair * as_pair_init(as_pair *pair, as_val *_1, as_val *_2)
static as_val * as_pair_1(as_pair *pair)
Definition: as_pair.h:112
static as_val * as_pair_toval(const as_pair *pair)
Definition: as_pair.h:134
AS_PAIR
Definition: as_val.h:214
uint32_t as_pair_val_hashcode(const as_val *)
#define as_util_fromval(object, type_id, type)
Definition: as_util.h:42
static as_pair * as_pair_fromval(const as_val *v)
Definition: as_pair.h:144
Definition: as_val.h:57
static void as_pair_destroy(as_pair *pair)
Definition: as_pair.h:98
as_pair * as_pair_new(as_val *_1, as_val *_2)
char * as_pair_val_tostring(const as_val *)
as_val * _2
Definition: as_pair.h:60
static as_val * as_pair_2(as_pair *pair)
Definition: as_pair.h:120
as_val * _1
Definition: as_pair.h:55
#define as_val_destroy(__v)
Definition: as_val.h:110
void as_pair_val_destroy(as_val *)
as_val _
Definition: as_pair.h:50