/
tbox.h
executable file
Β·209 lines (185 loc) Β· 6.52 KB
/
tbox.h
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
/*!The Treasure Box Library
*
* TBox is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* TBox is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with TBox;
* If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
*
* Copyright (C) 2009 - 2015, ruki All rights reserved.
*
* @author ruki
* @file tbox.h
*
*/
#ifndef TB_TBOX_H
#define TB_TBOX_H
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
*/
#include "prefix.h"
#include "zip/zip.h"
#include "xml/xml.h"
#include "asio/asio.h"
#include "libm/libm.h"
#include "libc/libc.h"
#include "math/math.h"
#include "utils/utils.h"
#include "regex/regex.h"
#include "object/object.h"
#include "memory/memory.h"
#include "stream/stream.h"
#include "string/string.h"
#include "network/network.h"
#include "charset/charset.h"
#include "platform/platform.h"
#include "database/database.h"
#include "algorithm/algorithm.h"
#include "container/container.h"
/* //////////////////////////////////////////////////////////////////////////////////////
* extern
*/
__tb_extern_c_enter__
/* //////////////////////////////////////////////////////////////////////////////////////
* macros
*/
// the compile mode
#define TB_MODE_DEBUG (1)
#define TB_MODE_SMALL (2)
#ifdef __tb_debug__
# define __tb_mode_debug__ TB_MODE_DEBUG
#else
# define __tb_mode_debug__ (0)
#endif
#ifdef __tb_small__
# define __tb_mode_small__ TB_MODE_SMALL
#else
# define __tb_mode_small__ (0)
#endif
/*! init tbox
*
* @param priv the platform private data
* pass JavaVM* jvm for android jni
* pass tb_null for other platform
*
* @param allocator the allocator, supports:
*
* - tb_native_allocator()
* uses native memory directly
*
* - tb_static_allocator(data, size)
* uses the a static small buffer and we can check memory error and leaking
*
* - tb_default_allocator(data, size)
* uses the a large pool with the static memory and we can check memory error and leaking
*
* - tb_default_allocator(tb_null, 0)
* uses the a large pool with the native memory and we can check memory error and leaking
*
* - tb_null
* uses tb_default_allocator(tb_null, 0) for large mode
* uses tb_native_allocator() for small mode, need define __tb_small__
*
* @return tb_true or tb_false
*
* @code
*
#include "tbox/tbox.h"
int main(int argc, char** argv)
{
// init tbox
if (!tb_init(tb_null, tb_null)) return 0;
// print info with tag
tb_trace_i("hello tbox");
// print info only for debug
tb_trace_d("hello tbox");
// print error info
tb_trace_e("hello tbox");
// init stream
tb_stream_ref_t stream = tb_stream_init_from_url("http://www.xxxx.com/index.html");
if (stream)
{
// save stream data to file
tb_transfer_done_to_url(stream, "/home/file/index.html", 0, tb_null, tb_null);
// exit stream
tb_stream_exit(stream);
}
// block: save http to file
tb_transfer_done_url("http://www.xxxx.com/index.html", "/home/file/index.html", 0, tb_null, tb_null);
// async: save http to file
tb_transfer_pool_done(tb_transfer_pool(), "http://www.xxxx.com/index0.html", "/home/file/index0.html", 0, 0, tb_null, tb_null);
tb_transfer_pool_done(tb_transfer_pool(), "http://www.xxxx.com/index1.html", "/home/file/index2.html", 0, 0, tb_null, tb_null);
tb_transfer_pool_done(tb_transfer_pool(), "http://www.xxxx.com/index2.html", "/home/file/index3.html", 0, 0, tb_null, tb_null);
tb_transfer_pool_done(tb_transfer_pool(), "http://www.xxxx.com/index3.html", "/home/file/index4.html", 0, 0, tb_null, tb_null);
// ...
// exit tbox
tb_exit();
return 0;
}
* @endcode
*/
#define tb_init(priv, allocator) tb_init_(priv, allocator, (tb_size_t)(__tb_mode_debug__ | __tb_mode_small__), TB_VERSION_BUILD)
/* //////////////////////////////////////////////////////////////////////////////////////
* interfaces
*/
/*! init the tbox library
*
* @param priv the platform private data
* pass JavaVM* jvm for android jni
* pass tb_null for other platform
*
* @param allocator the allocator, supports:
*
* - tb_native_allocator()
* uses native memory directly
*
* - tb_static_allocator(data, size)
* uses the a static small buffer and we can check memory error and leaking
*
* - tb_default_allocator(data, size)
* uses the a large pool with the static memory and we can check memory error and leaking
*
* - tb_default_allocator(tb_null, 0)
* uses the a large pool with the native memory and we can check memory error and leaking
*
* - tb_null
* uses tb_default_allocator(tb_null, 0) for large mode
* uses tb_native_allocator() for small mode, need define __tb_small__
*
* @param mode the compile mode for check __tb_small__ and __tb_debug__
* @param build the build version
*
* @return tb_true or tb_false
*/
tb_bool_t tb_init_(tb_handle_t priv, tb_allocator_ref_t allocator, tb_size_t mode, tb_hize_t build);
/// exit the tbox library
tb_void_t tb_exit(tb_noarg_t);
/*! the state
*
* - TB_STATE_OK
* - TB_STATE_END
* - TB_STATE_EXITING
*
* @return the tbox state
*/
tb_size_t tb_state(tb_noarg_t);
#ifdef TB_CONFIG_INFO_HAVE_VERSION
/*! the tbox version
*
* @return the tbox version
*/
tb_version_t const* tb_version(tb_noarg_t);
#endif
/* //////////////////////////////////////////////////////////////////////////////////////
* extern
*/
__tb_extern_c_leave__
#endif