All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
src/include/aerospike/as_bin.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2008-2013 by Aerospike.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to
6  * deal in the Software without restriction, including without limitation the
7  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8  * sell copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20  * IN THE SOFTWARE.
21  *****************************************************************************/
22 
23 #pragma once
24 
25 #include <aerospike/as_integer.h>
26 #include <aerospike/as_string.h>
27 #include <aerospike/as_bytes.h>
28 #include <aerospike/as_list.h>
29 #include <aerospike/as_map.h>
30 #include <aerospike/as_val.h>
31 
32 /******************************************************************************
33  * MACROS
34  *****************************************************************************/
35 
36 /**
37  * Maximum bin name size
38  */
39 #define AS_BIN_NAME_MAX_SIZE 15
40 
41 /**
42  * Maximum bin name length
43  */
44 #define AS_BIN_NAME_MAX_LEN (AS_BIN_NAME_MAX_SIZE - 1)
45 
46 /******************************************************************************
47  * TYPES
48  *****************************************************************************/
49 
50 /**
51  * Bin Name
52  */
54 
55 /**
56  * Bin Value
57  */
58 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  */
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