forked from nuptzp/utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
table.cpp
464 lines (386 loc) · 11.1 KB
/
table.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
// +build !windows
#include "table.h"
#include "table_v3.h"
#include <string.h>
#define TABLE_CAST(_table) ((table_v3::table_ptr_t)(_table))
#define TABLE_CAST_CONST(_table) ((const table_v3::table_ptr_t)(_table))
table_t table_create( const char * schema, size_t rows, const char * name )
{
return (table_t)(table_v3::table_t::create(schema, rows, name));
}
void table_clean_schema_pool( void )
{
return (void)(table_v3::clean_schema_pool());
}
table_t table_clone( table_t table )
{
return TABLE_CAST(table)->clone();
}
table_t table_assign( table_t table )
{
TABLE_CAST(table)->addref();
return table;
}
void table_destory( table_t table )
{
table_v3::table_ptr_t p = TABLE_CAST(table);
table_v3::table_t::destory(&p);
}
void table_tobuff( table_t table, char * buff)
{
table_v3::table_ptr_t p = TABLE_CAST(table);
table_v3::table_t::to_buff(p, buff);
}
table_t table_frombuff(const char * buff, size_t len )
{
return (table_t)table_v3::table_t::from_buff(buff, len);
}
void table_tobuff_extra( table_t table, char * buff, const char * extra )
{
table_v3::table_ptr_t p = TABLE_CAST(table);
table_v3::table_t::to_buff_extra(p, buff, extra);
}
table_t table_frombuff_extra(const char * buff, size_t len )
{
return (table_t)table_v3::table_t::from_buff_extra(buff, len);
}
size_t table_size_extra(table_t table)
{
return TABLE_CAST(table)->size_extra();
}
void table_row_tobuff(table_t table, size_t row, char * buff)
{
return TABLE_CAST(table)->row_to_buff(row, buff);
}
void table_row_frombuff(table_t table, size_t row, const char * buff, size_t len)
{
return TABLE_CAST(table)->row_from_buff(row, buff, len);
}
size_t table_row_size(table_t table, size_t row)
{
return TABLE_CAST(table)->row_size(row);
}
size_t table_rows( table_t table )
{
return TABLE_CAST(table)->rows();
}
size_t table_cols( table_t table )
{
return TABLE_CAST(table)->cols();
}
size_t table_size( table_t table )
{
return TABLE_CAST(table)->size();
}
size_t table_pod_size( table_t table )
{
return TABLE_CAST(table)->pod_size();
}
size_t table_width( table_t table )
{
return TABLE_CAST(table)->width();
}
const char * table_schema( table_t table )
{
return TABLE_CAST(table)->schema();
}
const char * table_name( table_t table )
{
return TABLE_CAST(table)->name();
}
bool table_is_pod( table_t table )
{
return TABLE_CAST(table)->is_pod();
}
size_t table_append( table_t table )
{
return TABLE_CAST(table)->append();
}
void table_tidy( table_t table )
{
TABLE_CAST(table)->tidy();
}
bool table_is_tidy( table_t table )
{
return TABLE_CAST(table)->is_tidy();
}
size_t table_col_index( table_t table, const char * name )
{
return TABLE_CAST(table)->col_index(name);
}
size_t table_col_offset( table_t table, size_t col )
{
return TABLE_CAST(table)->col_offset(col);
}
int table_col_type( table_t table, size_t col )
{
return TABLE_CAST(table)->col_type(col);
}
size_t table_col_size( table_t table, size_t col )
{
return TABLE_CAST(table)->col_size(col);
}
const char * table_col_name( table_t table, size_t col )
{
return TABLE_CAST(table)->col_name(col);
}
const size_t table_pkcol( table_t table )
{
return TABLE_CAST(table)->pkcol();
}
KEYORDER table_pkorder( table_t table )
{
return TABLE_CAST(table)->pkorder();
}
int table_get_int( table_t table, size_t row, size_t col )
{
return TABLE_CAST(table)->get_int(row, col);
}
short int table_get_short( table_t table, size_t row, size_t col )
{
return (short)(TABLE_CAST(table)->get_int(row, col) & 0x0000ffff);
}
long long table_get_int64( table_t table, size_t row, size_t col )
{
return TABLE_CAST(table)->get_int64(row, col);
}
unsigned int table_get_uint( table_t table, size_t row, size_t col )
{
return TABLE_CAST(table)->get_uint(row, col);
}
unsigned long long table_get_uint64( table_t table, size_t row, size_t col )
{
return TABLE_CAST(table)->get_uint64(row, col);
}
float table_get_float( table_t table, size_t row, size_t col )
{
return TABLE_CAST(table)->get_float(row, col);
}
double table_get_double( table_t table, size_t row, size_t col )
{
return TABLE_CAST(table)->get_double(row, col);
}
const char * table_get_str( table_t table, size_t row, size_t col )
{
return TABLE_CAST(table)->get_str(row, col);
}
const table_t table_get_table( table_t table, size_t row, size_t col )
{
return (table_t)(TABLE_CAST(table)->get_table(row, col));
}
const char * table_get_binary(table_t table, size_t row, size_t col)
{
return TABLE_CAST(table)->get_binary(row, col);
}
const size_t table_get_binary_len(table_t table, size_t row, size_t col)
{
return TABLE_CAST(table)->get_binary_len(row, col);
}
const void * table_get_buff( table_t table, size_t row, size_t col )
{
return TABLE_CAST(table)->get_buff(row, col);
}
const size_t table_get_time_t( table_t table, size_t row, size_t col)
{
return TABLE_CAST(table)->get_time_t(row, col);
}
const long long table_get_time( table_t table, size_t row, size_t col)
{
return TABLE_CAST(table)->get_time(row, col);
}
const long long table_get_pfloat( table_t table, size_t row, size_t col )
{
return TABLE_CAST(table)->get_int64(row, col);//
}
const long long table_get_vfloat( table_t table, size_t row, size_t col )
{
return TABLE_CAST(table)->get_int64(row, col);//
}
void table_set_int( table_t table, size_t row, size_t col, int val )
{
TABLE_CAST(table)->set_int(row, col, val);
}
void table_set_short( table_t table, size_t row, size_t col, short int val )
{
TABLE_CAST(table)->set_int(row, col, val);
}
void table_set_int64( table_t table, size_t row, size_t col, long long val )
{
TABLE_CAST(table)->set_int64(row, col, val);
}
void table_set_uint( table_t table, size_t row, size_t col, unsigned int val )
{
TABLE_CAST(table)->set_uint(row, col, val);
}
void table_set_uint64( table_t table, size_t row, size_t col, unsigned long long val )
{
TABLE_CAST(table)->set_uint64(row, col, val);
}
void table_set_float( table_t table, size_t row, size_t col, float val )
{
TABLE_CAST(table)->set_float(row, col, val);
}
void table_set_double( table_t table, size_t row, size_t col, double val )
{
TABLE_CAST(table)->set_double(row, col, val);
}
void table_set_str_raw( table_t table, size_t row, size_t col, char * val )
{
TABLE_CAST(table)->set_str_raw(row, col, val);
}
void table_set_str( table_t table, size_t row, size_t col, const char * val, bool delold )
{
TABLE_CAST(table)->set_str(row, col, val, delold);
}
void table_set_table_raw( table_t table, size_t row, size_t col, table_t val )
{
TABLE_CAST(table)->set_table_raw(row, col, TABLE_CAST(val));
}
void table_set_table( table_t table, size_t row, size_t col, const table_t val, bool delold )
{
TABLE_CAST(table)->set_table(row, col, TABLE_CAST_CONST(val), delold);
}
//void table_set_binary_raw(table_t table, size_t row, size_t col, size_t len, const char * val);
//{
// TABLE_CAST(table)->set_binary_raw(row, col, len, val);
//}
void table_set_binary(table_t table, size_t row, size_t col, size_t len, const char * val, bool delold)
{
TABLE_CAST(table)->set_binary(row, col, len, val, delold);
}
void table_set_buff( table_t table, size_t row, size_t col, const void * buff, size_t len,size_t offset )
{
TABLE_CAST(table)->set_buff(row, col, buff, len, offset);
}
void table_set_time(table_t table, size_t row, size_t col, size_t sec, int msec)
{
TABLE_CAST(table)->set_time(row, col, sec, msec);
}
bool table_col_isnull(table_t table, size_t row, size_t col)
{
return TABLE_CAST(table)->col_isnull(row, col);
}
void table_col_writenull(table_t table, size_t row, size_t col)
{
TABLE_CAST(table)->col_writenull(row, col);
}
void table_set_pfloat( table_t table, size_t row, size_t col, long long val )
{
TABLE_CAST(table)->set_int64(row, col, val);//同 table_get/set_int64, 设置和返回 int64 即可
}
void table_set_vfloat( table_t table, size_t row, size_t col, long long val )
{
TABLE_CAST(table)->set_int64(row, col, val);//同 table_get/set_int64, 设置和返回 int64 即可
}
void table_fill( table_t table, size_t drow, const table_t other, size_t srow )
{
TABLE_CAST(table)->fill(drow, TABLE_CAST_CONST(other), srow);
}
void table_update( table_t table, const table_t other, const char * keycol )
{
TABLE_CAST(table)->update(TABLE_CAST_CONST(other), keycol);
}
table_t table_select(table_t table, const char * fields, size_t from, size_t count)
{
return (table_t)TABLE_CAST(table)->select(fields, from, count);
}
table_t table_join(table_t table, table_t other, const char * keycol)
{
return (table_t)TABLE_CAST(table)->join( TABLE_CAST_CONST(other), keycol );
}
table_t table_sort(table_t table, field_compare_func comparer, void * userdata)
{
return (table_t)TABLE_CAST(table)->sort( comparer, userdata );
}
table_t table_group(table_t table, const char * key)
{
return (table_t)TABLE_CAST(table)->group( key );
}
table_t table_filter(table_t table, field_compare_func comparer, void * userdata)
{
return (table_t)TABLE_CAST(table)->filter( comparer, userdata );
}
table_t table_move_colsname(table_t table, const char * srcColsName, const char * dstColsName)
{
return (table_t)TABLE_CAST(table)->movecolsname( srcColsName, dstColsName );
}
table_malloc_func gfpMalloc = NULL;
table_free_func gfpFree = NULL;
void table_set_alloctor(table_malloc_func malloc_func, table_free_func free_func)
{
gfpMalloc = malloc_func;
gfpFree = free_func;
}
void table_delete( table_t table, size_t row, size_t num)
{
return TABLE_CAST(table)->remove(row, num);
}
void table_insert( table_t table, size_t row, size_t num)
{
return TABLE_CAST(table)->insert(row, num);
}
bool table_getkv_string(table_t table, const char* key, char* val, size_t val_size)
{
return TABLE_CAST(table)->getkv_string(key, val, val_size);
}
bool table_setkv_string(table_t table, const char* key, const char* val)
{
return TABLE_CAST(table)->setkv_string(key, val);
}
bool table_col_getkv_string(table_t table, size_t col, const char* key, char* val, size_t val_size)
{
return TABLE_CAST(table)->col_getkv_string(col, key, val, val_size);
}
bool table_col_setkv_string(table_t table, size_t col, const char* key, const char* val)
{
return TABLE_CAST(table)->col_setkv_string(col, key, val);
}
bool table_setkv_value(table_t table, int key, int val)
{
return TABLE_CAST(table)->setkv_value(key, val);
}
bool table_getkv_value(table_t table, int key, int * val)
{
return TABLE_CAST(table)->getkv_value(key, val);
}
bool table_col_setkv_value(table_t table, size_t col, int key, int val)
{
return TABLE_CAST(table)->col_setkv_value(col, key, val);
}
bool table_col_getkv_value(table_t table, size_t col, int key, int * val)
{
return TABLE_CAST(table)->col_getkv_value(col, key, val);
}
const size_t table_kv_string_len(table_t table, const char* key)
{
return TABLE_CAST(table)->kv_string_len( key);
}
const size_t table_col_kv_string_len(table_t table, size_t col, const char* key)
{
return TABLE_CAST(table)->col_kv_string_len(col, key);
}
char * table_strnew(size_t bytes){
if(gfpMalloc)
return gfpMalloc(bytes);
else
return new char[bytes];
}
void table_strdel(char * s){
if(gfpFree)
gfpFree(s);
else
{
delete [] s;
}
}
char * table_strdup(const char * s){
if(NULL == s) return NULL;
size_t len = strlen(s);
char * r = table_strnew(len + 1);
memcpy(r, s, len + 1);
return r;
}
char * table_tojson(table_t table)
{
return TABLE_CAST(table)->tojson();
}