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