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