/
feature_layer_desc.hpp
188 lines (166 loc) · 5.04 KB
/
feature_layer_desc.hpp
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
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2006 Artem Pavlenko
*
* This library 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.
*
* This library 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 this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
//$Id$
#ifndef FEATURE_LAYER_DESC_HPP
#define FEATURE_LAYER_DESC_HPP
#include <string>
#include <vector>
#include <iostream>
namespace mapnik
{
using std::string;
using std::vector;
using std::clog;
enum {
Integer=1,
Float =2,
Double =3,
String =4,
Geometry=5,
Object=6
};
class attribute_descriptor
{
public:
attribute_descriptor(string const& name,unsigned type,
bool primary_key=false,
int size=-1,
int precision=-1)
: name_(name),
type_(type),
primary_key_(primary_key),
size_(size),
precision_(precision) {}
attribute_descriptor(attribute_descriptor const& other)
: name_(other.name_),
type_(other.type_),
primary_key_(other.primary_key_),
size_(other.size_),
precision_(other.precision_) {}
attribute_descriptor& operator=(attribute_descriptor const& other)
{
if (this == &other)
return *this;
name_=other.name_;
type_=other.type_;
primary_key_=other.primary_key_;
size_=other.size_;
precision_=other.precision_;
return *this;
}
string const& get_name() const
{
return name_;
}
unsigned get_type() const
{
return type_;
}
bool is_primary_key() const
{
return primary_key_;
}
int get_size() const
{
return size_;
}
int get_precision() const
{
return precision_;
}
private:
string name_;
int type_;
bool primary_key_;
int size_;
int precision_;
};
template <typename charT,typename traits>
inline std::basic_ostream<charT,traits>&
operator << (std::basic_ostream<charT,traits>& out,
attribute_descriptor const& ad)
{
out << "name=" << ad.get_name() << "\n";
out << "type=" << ad.get_type() << "\n";
out << "size=" << ad.get_size() << "\n";
return out;
}
class layer_descriptor
{
public:
layer_descriptor(string const& name,string const& encoding)
: name_(name),
encoding_(encoding) {}
layer_descriptor(layer_descriptor const& other)
: name_(other.name_),
encoding_(other.encoding_),
desc_ar_(other.desc_ar_) {}
void set_name(string const& name)
{
name_=name;
}
string const& get_name() const
{
return name_;
}
void set_encoding(std::string const& encoding)
{
encoding_=encoding;
}
std::string const& get_encoding() const
{
return encoding_;
}
void add_descriptor(attribute_descriptor const& desc)
{
desc_ar_.push_back(desc);
}
vector<attribute_descriptor> const& get_descriptors() const
{
return desc_ar_;
}
vector<attribute_descriptor>& get_descriptors()
{
return desc_ar_;
}
private:
string name_;
string encoding_;
vector<attribute_descriptor> desc_ar_;
};
template <typename charT,typename traits>
inline std::basic_ostream<charT,traits>&
operator << (std::basic_ostream<charT,traits>& out,
layer_descriptor const& ld)
{
out << "name=" << ld.get_name() << "\n";
out << "encoding=" << ld.get_encoding() << "\n";
vector<attribute_descriptor> const& desc_ar=ld.get_descriptors();
vector<attribute_descriptor>::const_iterator pos=desc_ar.begin();
while (pos != desc_ar.end())
{
out << *pos++ << "\n";
}
return out;
}
}
#endif //FEATURE_LAYER_DESC_HPP