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