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
|
/*!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 prefix.h
* @ingroup object
*
*/
#ifndef TB_OBJECT_PREFIX_H
#define TB_OBJECT_PREFIX_H
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
*/
#include "../prefix.h"
#include "../xml/xml.h"
#include "../stream/stream.h"
#include "../container/container.h"
/* //////////////////////////////////////////////////////////////////////////////////////
* types
*/
/// the object type enum
typedef enum __tb_object_type_e
{
TB_OBJECT_TYPE_NONE = 0
, TB_OBJECT_TYPE_DATA = 1
, TB_OBJECT_TYPE_DATE = 2
, TB_OBJECT_TYPE_ARRAY = 3
, TB_OBJECT_TYPE_STRING = 4
, TB_OBJECT_TYPE_NUMBER = 5
, TB_OBJECT_TYPE_BOOLEAN = 6
, TB_OBJECT_TYPE_DICTIONARY = 7
, TB_OBJECT_TYPE_NULL = 8
, TB_OBJECT_TYPE_USER = 9 //!< the user defined type, ...
}tb_object_type_e;
/// the object flag enum
typedef enum __tb_object_flag_e
{
TB_OBJECT_FLAG_NONE = 0
, TB_OBJECT_FLAG_READONLY = 1
, TB_OBJECT_FLAG_SINGLETON = 2
}tb_object_flag_e;
/// the object format enum
typedef enum __tb_object_format_e
{
TB_OBJECT_FORMAT_NONE = 0x0000 //!< none
, TB_OBJECT_FORMAT_BIN = 0x0001 //!< the tbox binary format
, TB_OBJECT_FORMAT_BPLIST = 0x0002 //!< the bplist format for apple
, TB_OBJECT_FORMAT_XPLIST = 0x0003 //!< the xplist format for apple
, TB_OBJECT_FORMAT_XML = 0x0004 //!< the xml format
, TB_OBJECT_FORMAT_JSON = 0x0005 //!< the json format
, TB_OBJECT_FORMAT_MAXN = 0x000f //!< the format maxn
, TB_OBJECT_FORMAT_DEFLATE = 0x0100 //!< deflate?
}tb_object_format_e;
/// the object type
typedef struct __tb_object_t
{
/// the object flag
tb_uint8_t flag;
/// the object type
tb_uint16_t type;
/// the object reference count
tb_size_t refn;
/// the object private data
tb_cpointer_t priv;
/// the copy func
struct __tb_object_t* (*copy)(struct __tb_object_t* object);
/// the clear func
tb_void_t (*clear)(struct __tb_object_t* object);
/// the exit func
tb_void_t (*exit)(struct __tb_object_t* object);
}tb_object_t;
/// the object ref type
typedef tb_object_t* tb_object_ref_t;
/// the object reader type
typedef struct __tb_object_reader_t
{
/// the hooker
tb_hash_map_ref_t hooker;
/// probe format
tb_size_t (*probe)(tb_stream_ref_t stream);
/// read it
tb_object_ref_t (*read)(tb_stream_ref_t stream);
}tb_object_reader_t;
/// the object writer type
typedef struct __tb_object_writer_t
{
/// the hooker
tb_hash_map_ref_t hooker;
/// writ it
tb_long_t (*writ)(tb_stream_ref_t stream, tb_object_ref_t object, tb_bool_t deflate);
}tb_object_writer_t;
#endif
|