All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
as_bin.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 #pragma once
18 
19 #include <aerospike/as_integer.h>
20 #include <aerospike/as_string.h>
21 #include <aerospike/as_geojson.h>
22 #include <aerospike/as_bytes.h>
23 #include <aerospike/as_list.h>
24 #include <aerospike/as_map.h>
25 #include <aerospike/as_val.h>
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 /******************************************************************************
32  * MACROS
33  *****************************************************************************/
34 
35 /**
36  * Maximum bin name size
37  */
38 #define AS_BIN_NAME_MAX_SIZE 15
39 
40 /**
41  * Maximum bin name length
42  */
43 #define AS_BIN_NAME_MAX_LEN (AS_BIN_NAME_MAX_SIZE - 1)
44 
45 /******************************************************************************
46  * TYPES
47  *****************************************************************************/
48 
49 /**
50  * Bin Name
51  */
53 
54 /**
55  * Bin Value
56  */
57 typedef union as_bin_value_s {
65 } as_bin_value;
66 
67 /**
68  * Represents a bin of a record. Each bin is a (name,value) pair.
69  *
70  * Bins of a record should never be directly accessed. The bins should only
71  * be modified via as_record functions. The only time an as_bin is directly
72  * accessible is during iteration via as_record_iterator, but the
73  * as_bin functions should be used to read the values.
74  *
75  * @ingroup client_objects
76  */
77 typedef struct as_bin_s {
78 
79  /**
80  * Bin name.
81  */
82  as_bin_name name;
83 
84  /**
85  * Bin value.
86  */
88 
89  /**
90  * Bin value pointer.
91  * If NULL, then there is no value.
92  * It can point to as_bin.value or a different value.
93  */
95 
96 } as_bin;
97 
98 /**
99  * Sequence of bins.
100  */
101 typedef struct as_bins_s {
102 
103  /**
104  * @private
105  * If true, then as_record_destroy() will free data
106  */
107  bool _free;
108 
109  /**
110  * Number of entries allocated to data.
111  */
112  uint16_t capacity;
113 
114  /**
115  * Number of entries currently holding data.
116  */
117  uint16_t size;
118 
119  /**
120  * Storage for bins
121  */
123 
124 } as_bins;
125 
126 /******************************************************************************
127  * INLINE FUNCTIONS
128  *****************************************************************************/
129 
130 /**
131  * Get the name of the bin.
132  *
133  * ~~~~~~~~~~{.c}
134  * char * name = as_bin_get_name(bin);
135  * ~~~~~~~~~~
136  *
137  * @param bin The bin to get the name of.
138  *
139  * @return The name of the bin.
140  *
141  * @relates as_bin
142  */
143 static inline char * as_bin_get_name(const as_bin * bin) {
144  return (char *) bin->name;
145 }
146 
147 
148 /**
149  * Get the value of the bin.
150  *
151  * ~~~~~~~~~~{.c}
152  * as_bin_value val = as_bin_get_value(bin);
153  * ~~~~~~~~~~
154  *
155  * @param bin The bin to get the value of.
156  *
157  * @return The value of the bin.
158  *
159  * @relates as_bin
160  */
161 static inline as_bin_value * as_bin_get_value(const as_bin * bin) {
162  return bin->valuep;
163 }
164 
165 
166 /**
167  * Get the type for the value of the bin.
168  *
169  * ~~~~~~~~~~{.c}
170  * as_val_t type = as_bin_get_type(bin);
171  * ~~~~~~~~~~
172  *
173  * @param bin The bin to get value's type.
174  *
175  * @return The type of the bin's value
176  *
177  * @relates as_bin
178  */
179 static inline as_val_t as_bin_get_type(const as_bin * bin) {
180  return as_val_type(bin->valuep);
181 }
182 
183 #ifdef __cplusplus
184 } // end extern "C"
185 #endif