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-2018 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_std.h>
21 #include <aerospike/as_util.h>
22 #include <aerospike/as_val.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /******************************************************************************
29  * MACROS
30  ******************************************************************************/
31 
32 #define pair_new(a,b) as_pair_new((as_val *) a, (as_val *) b)
33 
34 /******************************************************************************
35  * TYPES
36  ******************************************************************************/
37 
38 /**
39  * A Pair of values: (_1,_2)
40  * @ingroup aerospike_t
41  */
42 typedef struct as_pair_s {
43 
44  /**
45  * @private
46  * as_pair is a subtype of as_val.
47  * You can cast as_pair to as_val.
48  */
49  as_val _;
50 
51  /**
52  * The first value of the pair.
53  */
54  as_val * _1;
55 
56  /**
57  * The second value of the pair.
58  */
59  as_val * _2;
60 
61 } as_pair;
62 
63 /******************************************************************************
64  * INSTANCE FUNCTIONS
65  ******************************************************************************/
66 
67 /**
68  * Create and initializes a new heap allocated `as_pair`.
69  *
70  * @param _1 The first value.
71  * @param _2 The second value.
72  *
73  * @return On success, the new pair. Otherwise NULL.
74  *
75  * @relatesalso as_pair
76  */
78 
79 /**
80  * Initializes a stack allocated `as_pair`.
81  *
82  * @param pair The pair to initialize.
83  * @param _1 The first value.
84  * @param _2 The second value.
85  *
86  * @return On success, the new pair. Otherwise NULL.
87  *
88  * @relatesalso as_pair
89  */
90 AS_EXTERN as_pair * as_pair_init(as_pair * pair, as_val * _1, as_val * _2);
91 
92 /**
93  * Destroy the `as_pair` and release associated resources.
94  *
95  * @relatesalso as_pair
96  */
97 static inline void as_pair_destroy(as_pair * pair)
98 {
99  as_val_destroy((as_val *) pair);
100 }
101 
102 /******************************************************************************
103  * VALUE FUNCTIONS
104  ******************************************************************************/
105 
106 /**
107  * Get the first value of the pair
108  *
109  * @relatesalso as_pair
110  */
111 static inline as_val * as_pair_1(as_pair * pair)
112 {
113  return pair ? pair->_1 : NULL;
114 }
115 
116 /**
117  * Get the second value of the pair
118  */
119 static inline as_val * as_pair_2(as_pair * pair)
120 {
121  return pair ? pair->_2 : NULL;
122 }
123 
124 /******************************************************************************
125  * CONVERSION FUNCTIONS
126  *****************************************************************************/
127 
128 /**
129  * Convert to an as_val.
130  *
131  * @relatesalso as_pair
132  */
133 static inline as_val * as_pair_toval(const as_pair * pair)
134 {
135  return (as_val *) pair;
136 }
137 
138 /**
139  * Convert from an as_val.
140  *
141  * @relatesalso as_pair
142  */
143 static inline as_pair * as_pair_fromval(const as_val * v)
144 {
145  return as_util_fromval(v, AS_PAIR, as_pair);
146 }
147 
148 /******************************************************************************
149  * as_val FUNCTIONS
150  *****************************************************************************/
151 
152 /**
153  * @private
154  * Internal helper function for destroying an as_val.
155  */
157 
158 /**
159  * @private
160  * Internal helper function for getting the hashcode of an as_val.
161  */
162 AS_EXTERN uint32_t as_pair_val_hashcode(const as_val *);
163 
164 /**
165  * @private
166  * Internal helper function for getting the string representation of an as_val.
167  */
168 AS_EXTERN char * as_pair_val_tostring(const as_val *);
169 
170 #ifdef __cplusplus
171 } // end extern "C"
172 #endif
static as_val * as_pair_1(as_pair *pair)
Definition: as_pair.h:111
static as_val * as_pair_toval(const as_pair *pair)
Definition: as_pair.h:133
AS_EXTERN as_pair * as_pair_init(as_pair *pair, as_val *_1, as_val *_2)
#define as_util_fromval(object, type_id, type)
Definition: as_util.h:43
AS_EXTERN uint32_t as_pair_val_hashcode(const as_val *)
static as_pair * as_pair_fromval(const as_val *v)
Definition: as_pair.h:143
Definition: as_val.h:61
static void as_pair_destroy(as_pair *pair)
Definition: as_pair.h:97
#define AS_EXTERN
Definition: as_std.h:25
AS_EXTERN as_pair * as_pair_new(as_val *_1, as_val *_2)
static as_val * as_pair_2(as_pair *pair)
Definition: as_pair.h:119
Definition: as_val.h:44
AS_EXTERN char * as_pair_val_tostring(const as_val *)
#define as_val_destroy(__v)
Definition: as_val.h:114
AS_EXTERN void as_pair_val_destroy(as_val *)