forked from therion/therion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
thattr.h
189 lines (137 loc) · 5.39 KB
/
thattr.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
/**
* @file thattr.h
* Generic object attribute structure.
*/
/* Copyright (C) 2007 Stacho Mudrak
*
* $Date: $
* $RCSfile: $
* $Revision: $
*
* --------------------------------------------------------------------
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* --------------------------------------------------------------------
*/
#ifndef thattr_h
#define thattr_h
#include <list>
#include <map>
#include <string>
#include <cstdio>
#include "thmbuffer.h"
#include "thchenc.h"
enum {
THATTR_NA,
THATTR_STRING,
THATTR_DOUBLE,
THATTR_INTEGER,
};
/**
* Single attribute structure.
*/
enum {
THATTRFLAG_NONE = 0,
THATTRFLAG_HIDDEN = 1,
};
struct thattr_attr {
std::string m_val_string; ///< String value.
unsigned long m_flags = THATTRFLAG_NONE; ///< Value flags.
double m_val_double = 0.0; ///< Double value.
long m_val_long = 0; ///< Integer value.
int m_type = 0; ///< Attribute type.
thattr_attr() = default;
bool has_flag(unsigned long flag);
void set_flag(unsigned long flag, bool value);
struct thattr_field * m_field = nullptr; ///< Attribute's field.
struct thattr_obj * m_obj = nullptr; ///< Attribute's object.
};
typedef std::map<size_t, thattr_attr> thattr_id2attr_map;
/**
* Field structure.
*/
struct thattr_field {
std::string m_name; ///< Field name.
size_t m_id; ///< Internal field identifier.
struct thattr * m_parent; ///< Parent attribute class.
int m_type; ///< Generic export type.
bool m_present = false; ///< Whether there is any value present.
long m_mini, ///< Minimum integer value.
m_maxi; ///< Maximum integer value.
double m_mind, ///< Minimum double value.
m_maxd; ///< Maximum double value.
size_t m_maxs; ///< Maximum string length.
int m_xdbf_width, ///< DBF field width.
m_xdbf_decimals, ///< DBF field decimals.
m_xdbf_field; ///< DBF field identifier.
std::string m_xdbf_name; ///< DBF field name.
std::string m_xmp_name; ///< Metapost field name.
// m_xmp_last; ///< Last string value exported for given field.
std::string m_double_format; ///< Double format.
};
typedef std::map<std::string, thattr_field*> thattr_name2field_map;
typedef std::list<thattr_field> thattr_field_list;
/**
* Object structure.
*/
struct thattr_obj {
long m_user_id; ///< User defined ID.
size_t m_id = 0, ///< Internal ID.
m_tree_level; ///< Tree level of object, if table has tree structure.
const char * m_tree_node_id; ///< Tree node id.
class thdataobject * m_data = nullptr; ///< User defined data.
thattr_id2attr_map m_attributes; ///< Map of attributes.
thattr_attr * m_last_attribute; ///< Last attribute set for given object.
struct thattr * m_parent = nullptr; ///< Parent attribute class.
thattr_obj() : m_user_id(-1), m_tree_level(0), m_tree_node_id(""), m_last_attribute(NULL) {}
void set_tree_level(size_t level);
};
typedef std::map<size_t, thattr_obj*> thattr_id2obj_map;
typedef std::map<long, thattr_obj*> thattr_usrid2obj_map;
typedef std::list<thattr_obj> thattr_obj_list;
/**
* Generic object attribute structure.
*/
struct thattr {
size_t m_num_fields, ///< Number of fields.
m_num_objects; ///< Number of objects.
bool m_tree = false; ///< Whether table has a tree structure.
thattr_obj_list m_obj_list; ///< List of objects.
thattr_id2obj_map m_obj_map; ///< ID -> Object map.
thattr_usrid2obj_map m_obj_usrmap; ///< User ID -> Object map.
thattr_field_list m_field_list; ///< List of all fields.
thattr_name2field_map m_field_map; ///< Name -> Field map.
thattr();
thattr_field * insert_field(const char * name);
thattr_field * get_field(const char * name, bool ins = false);
thattr_obj * m_obj_last; ///< Last inserted object.
thattr_obj * insert_object(thdataobject * data, long user_id = -1);
thattr_obj * get_object(); ///< Return last inserted object.
thattr_obj * get_object(long user_id);
void insert_attribute(const char * name, thattr_attr & attr, long user_id = -1);
void insert_attribute(const char * name, const char * value, long user_id = -1);
void insert_attribute(const char * name, double value, long user_id = -1);
void insert_attribute(const char * name, long value, long user_id = -1);
thattr_attr * get_attribute();
void copy_attributes(thattr_obj * object, long user_id = -1);
void analyze_fields();
void export_dbf(const char * fname, int encoding = TT_UTF_8);
void export_txt(const char * fname, int encoding = TT_UTF_8);
void export_html(const char * fname, const char * title, int encoding = TT_UTF_8);
void export_kml(const char * fname, const char * name_field, const char * title);
void export_mp_header(FILE * f);
void export_mp_object_begin(FILE * f, long user_id);
void export_mp_object_end(FILE * f, long user_id);
};
#endif