Xpace
table_c.h
Go to the documentation of this file.
1 
2 /**********************************************************//**
3  **
4  ** @file data/Store/table_c.h
5  **
6  ** Copyright (C) 2012 Xpace, LLC. All rights reserved
7  **
8  ** www.xpace.net
9  **
10  **************************************************************/
11 
12 #ifndef XPACE_TABLE_C_H
13 #define XPACE_TABLE_C_H
14 
15 #include "base/types.h"
16 #include "base/c/types_c.h"
17 #include "base/c/exception_c.h"
18 
19 #ifdef __cplusplus
20 # include "base/datetime.h"
21 # include "data/store/table.h"
22  typedef Xpace::Table* Xpace_Table;
24 #else
25  typedef void* Xpace_Table;
26  typedef void* Xpace_Table_Source;
27 #endif
28 
29 // ================================== CREATE / DESTROY ========
30 
32 {
36 };
37 
38 /// @param config the Table's Configuration
39 /// @param access how the Table will be opened
40 XPACE_C_EXPORT(Xpace_Error) Xpace_Table_create
41  (Xpace_Char16* config,
44 
45 XPACE_C_EXPORT(void) Xpace_Table_destroy
46  (Xpace_Table);
47 
48 // ================================== GET INFO ================
49 
50 XPACE_C_EXPORT(Xpace_Error) Xpace_Table_getConfig
51  (const Xpace_Table,
52  const Xpace_Char16** result);
53 
54 /// @retval true if the table is empty
55 XPACE_C_EXPORT(Xpace_Error) Xpace_Table_isEmpty
56  (const Xpace_Table,
57  bool* result);
58 
59 /// @retval the table's name
60 XPACE_C_EXPORT(Xpace_Error) Xpace_Table_getName
61  (const Xpace_Table,
62  const Xpace_Char16** result);
63 
64 /// Get a column's configuration
65 /// @param col the column number
66 /// @retval the column's Configuration
67 XPACE_C_EXPORT(Xpace_Error) Xpace_Table_getColumnConfig
68  (const Xpace_Table,
70  const Xpace_Char16** result);
71 
72 /// @retval the number of rows in the table
73 XPACE_C_EXPORT(Xpace_Error) Xpace_Table_getRowCount
74  (const Xpace_Table,
75  uint64* result);
76 
77 /// @retval the number of columns in the table
78 XPACE_C_EXPORT(Xpace_Error) Xpace_Table_getColumnCount
79  (const Xpace_Table,
80  uint* result);
81 
82 // ================================== GET DATA ================
83 
84 /// create a read-only cursor into a Table
85 /// @param row start at this row
86 /// @retval the Source
87 XPACE_C_EXPORT(Xpace_Error) Xpace_Table_createSource
88  (Xpace_Table tc,
90  Xpace_Table_Source* result);
91 
92 /// destroy a Table Source
93 XPACE_C_EXPORT(void) Xpace_Table_Source_destroy
95 
96 /// @param row move cursor to this row
97 /// @retval true if successful, false (and don't move) if not
98 XPACE_C_EXPORT(Xpace_Error) Xpace_Table_Source_moveToRow
99  (Xpace_Table_Source,
100  uint64 row,
101  bool* result);
102 
103 /// get the (String) contents of a cell from the current row
104 /// @param column from this column
105 /// @retval the (String) contents of the cell
106 XPACE_C_EXPORT(Xpace_Error) Xpace_Table_Source_getCellStr
107  (const Xpace_Table_Source,
109  const Xpace_Char16** result);
110 
111 /// get the (integer) contents of a cell from the current row
112 /// @param column from this column
113 /// @param ok fillin true if successful
114 /// @retval the (integer) contents of the cell
115 XPACE_C_EXPORT(Xpace_Error) Xpace_Table_Source_getCellInt
116  (const Xpace_Table_Source,
117  uint column,
118  bool* ok,
119  int64* result);
120 
121 /// get the (raw) contents of a cell from the current row
122 /// NB only guarenteed to be valid while the row is current
123 /// @param column from this column
124 /// @retval the (raw) contents of the cell
125 XPACE_C_EXPORT(Xpace_Error) Xpace_Table_Source_getCellBytes
126  (const Xpace_Table_Source,
127  uint column,
128  Xpace_Bytes* result);
129 
130 // ================================== GET TO SINK =============
131 
132 /// Sink callbacks for table data
133 
134 /// Set a column's name and type
135 /// @param name the name of the column
136 /// @param type the type of the column
137 /// @param columnNum a proposed column number
138 /// @retval added true iff actually added
139 /// @return the actual column number to continue, -1 to stop
140 XPACE_C_CALLBACK(int, Xpace_Table_addColumn)
143  uint columnNum,
144  bool* added,
145  void* callerInfo);
146 
147 /// Begin a new row, committing this one (if any)
148 /// @param docNum the new row number
149 /// @return -1 to stop, 0 to return this row, >0 to skip rows
150 XPACE_C_CALLBACK(int64, Xpace_Table_startRow)
151  (uint64 row,
152  void* callerInfo);
153 
154 /// Add a 64-bit int to the row
155 /// @param column
156 /// @param value
157 /// @return true to continue
158 XPACE_C_CALLBACK(bool, Xpace_Table_setInt64)
159  (uint column,
160  int64 value,
161  void* callerInfo);
162 
163 /// Add a double to the row
164 /// @param column
165 /// @param mantissa
166 /// @param decimals
167 /// @returns true to continue
168 XPACE_C_CALLBACK(bool, Xpace_Table_setDecimalFloat)
169  (uint column,
170  int64 mantissa,
171  int decimals,
172  void* callerInfo);
173 
174 /// Add a String8 to the row
175 /// @param column
176 /// @param data the String8's contents - NB valid only as long as the row is current
177 /// @param len the String8's length
178 /// @returns true to continue
179 XPACE_C_CALLBACK(bool, Xpace_Table_setString8)
180  (uint column,
181  const Xpace_Char8* data,
182  size_t len,
183  void* callerInfo);
184 
185 /// Add a String16 to the row
186 /// @param column
187 /// @param data the String16's contents - NB valid only as long as the row is current
188 /// @param len the String16's length
189 /// @return true to continue
190 XPACE_C_CALLBACK(bool, Xpace_Table_setString16)
191  (uint column,
192  const Xpace_Char16* data,
193  size_t len,
194  void* callerInfo);
195 
196 /// Add raw bytes
197 /// @param column
198 /// @param data the bytes - NB valid only as long as the row is current
199 /// @param len the bytes' length
200 /// @return true to continue
201 XPACE_C_CALLBACK(bool, Xpace_Table_setBytes)
202  (uint column,
203  const byte* data,
204  size_t len,
205  void* callerInfo);
206 
207 /// Add DateTime
208 /// @param column
209 /// @param value - NB valid only as long as the row is current
210 /// @return true to continue
211 XPACE_C_CALLBACK(bool, Xpace_Table_setDateTime)
212  (uint column,
213  Xpace_DateTime* value,
214  void* callerInfo);
215 
216 /// We're finished with this sink
217 XPACE_C_CALLBACK(void, Xpace_Table_close)
218  (void* callerInfo);
219 
221 {
222  Xpace_Table_addColumn addColumn;
223  Xpace_Table_startRow startRow;
224  Xpace_Table_setInt64 setInt64;
225  Xpace_Table_setDecimalFloat setDecimalFloat;
226  Xpace_Table_setString8 setString8;
227  Xpace_Table_setString16 setString16;
228  Xpace_Table_setBytes setBytes;
229  Xpace_Table_setDateTime setDateTime;
230  Xpace_Table_close close;
231 };
232 
233 #ifdef __cplusplus
234 
235 // C++ caller for Xpace_Table_Sink - used in several places
236 namespace Xpace
237 {
238  class table_sink : public Table::Sink
239  {
240  public:
241  table_sink
243  void* callerInfo);
244 
245  virtual uint add
246  (const String& name,
247  DerivedDataType type,
248  uint columnNum,
249  bool* added = 0) override;
250 
251  virtual int64 start
252  (uint64 row) override
253  {
254  return start_row(row, caller_info);
255  }
256 
257  virtual bool set
258  (uint column,
259  int64 value) override
260  {
261  return set_int64(column, value, caller_info);
262  }
263 
264  virtual bool set
265  (uint column,
266  const Xpace::DecimalFloat& value) override
267  {
268  return set_decimalFloat(column, value.getMantissa(), value.getDecimals(), caller_info);
269  }
270 
271  virtual bool set
272  (uint column,
273  const Xpace::String8& value) override
274  {
275  return set_string8(column, value.data, value.length, caller_info);
276  }
277 
278  virtual bool set
279  (uint column,
280  const Xpace::String16& value) override
281  {
282  return set_string16(column, value.data, value.length, caller_info);
283  }
284 
285  virtual bool set
286  (uint column,
287  const Xpace::BytesRef& value) override
288  {
289  return set_bytes(column, value.data, value.length, caller_info);
290  }
291 
292  virtual bool set
293  (uint column,
294  const Xpace::DateTime& value) override
295  {
296  Xpace::Date date(value.getDate());
297  Xpace::Time time(value.getTime());
298 
299  Xpace_DateTime dt;
300  dt.year = date.getYear();
301  dt.month = date.getMonth();
302  dt.day = date.getDay();
303  dt.hour = time.getHour();
304  dt.minute = time.getMinute();
305  dt.second = time.getSecond();
306  dt.millisecond = time.getMillisecond();
307  return set_dateTime(column, &dt, caller_info);
308  }
309 
310  virtual void close
311  () override
312  {
313  do_close(caller_info);
314  }
315 
316  private:
317  const Xpace_Table_addColumn add_column;
318  const Xpace_Table_startRow start_row;
319  const Xpace_Table_setInt64 set_int64;
320  const Xpace_Table_setDecimalFloat set_decimalFloat;
321  const Xpace_Table_setString8 set_string8;
322  const Xpace_Table_setString16 set_string16;
323  const Xpace_Table_setBytes set_bytes;
324  const Xpace_Table_setDateTime set_dateTime;
325  const Xpace_Table_close do_close;
326 
327  void *const caller_info;
328  };
329 }
330 
331 #endif
332 
333 /// Get Table data through a callback, starting from and updating the current position
334 /// @param columns ~0-terminated list of columns to get; if 0, get all columns
335 /// @param maxRows the maximum number of rows to get
336 /// @param sink called for each cell
337 /// #param result fillin true iff each call to sink->set() returned true
338 XPACE_C_EXPORT(Xpace_Error) Xpace_Table_Cursor_forEach
339  (Xpace_Table table,
341  uint64 maxRows,
343  void* callerInfo,
344  bool* result);
345 
346 #endif
uint * columns
Definition: table_c.h:340
const Xpace_Char16 Xpace_Data_Type uint bool void * callerInfo
We're finished with this sink.
Definition: table_c.h:141
const Xpace_Char16 Xpace_Data_Type type
Definition: table_c.h:141
unsigned char byte
Definition: types_c.h:41
A low-level data holder.
Definition: types_c.h:82
Xpace_Data_Type
Definition: types_c.h:69
const Xpace_Char16 Xpace_Data_Type uint bool * added
Definition: table_c.h:141
#define XPACE_C_CALLBACK(ret, name)
Definition: types_c.h:37
uint int64 mantissa
Definition: table_c.h:169
Xpace_Table_addColumn addColumn
Definition: table_c.h:222
Xpace_Table_setDecimalFloat setDecimalFloat
Definition: table_c.h:225
uint const Xpace_Char8 size_t len
Definition: table_c.h:180
unsigned int uint
Definition: types_c.h:42
void * Xpace_Table
Definition: table_c.h:25
A low-level const data holder.
Definition: types.h:165
A floatimg-point number with explicit mantissa and decimals TODO: normalize.
Definition: decimalfloat.h:33
const Xpace_Char16 Xpace_Data_Type uint columnNum
Definition: table_c.h:141
Xpace_Table_setString16 setString16
Definition: table_c.h:227
Xpace_Table_setDateTime setDateTime
Definition: table_c.h:229
Copyright (C) 2012 Xpace, LLC.
unsigned long long uint64
Definition: types_c.h:54
Xpace_StoreAccess access
Definition: table_c.h:42
uint int64 int decimals
Definition: table_c.h:169
uint col
Definition: table_c.h:69
uint uint64 maxRows
Definition: table_c.h:340
const Xpace_Char16 * name
Sink callbacks for table data.
Definition: table_c.h:141
uint16 Xpace_Char16
Definition: types_c.h:58
void * Xpace_Table_Source
Definition: table_c.h:26
uint bool * ok
Definition: table_c.h:117
Xpace_Table_close close
Definition: table_c.h:230
Xpace_StoreAccess Xpace_Table * result
Definition: table_c.h:42
Xpace_Table_setString8 setString8
Definition: table_c.h:226
uint int64 value
Definition: table_c.h:159
XPACE_C_EXPORT(Xpace_Error) Xpace_Table_create(Xpace_Char16 *config
Get a column's configuration.
Xpace_Table_startRow startRow
Definition: table_c.h:223
uint column
Add a 64-bit int to the row.
Definition: table_c.h:108
uint64 row
Begin a new row, committing this one (if any)
Definition: table_c.h:89
Xpace_Table_setBytes setBytes
Definition: table_c.h:228
long long int64
Definition: types_c.h:53
uint uint64 Xpace_Table_Sink * sink
Definition: table_c.h:340
Xpace_StoreAccess
Definition: table_c.h:31
uint8 Xpace_Char8
Definition: types_c.h:57
uint const Xpace_Char8 * data
Definition: table_c.h:180
void * Xpace_Error
Definition: exception_c.h:74
Xpace project main namespace
Definition: datetime.h:18
Xpace_Table_setInt64 setInt64
Definition: table_c.h:224

current as of Wed Jun 10 2026 12:00:05