00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef FEATURE_LAYER_DESC_HPP
00026 #define FEATURE_LAYER_DESC_HPP
00027
00028 #include <string>
00029 #include <vector>
00030 #include <iostream>
00031
00032 namespace mapnik
00033 {
00034
00035 using std::string;
00036 using std::vector;
00037 using std::clog;
00038
00039 enum eAttributeType {
00040 Integer=1,
00041 Float =2,
00042 Double =3,
00043 String =4,
00044 Geometry=5,
00045 Object=6
00046 };
00047
00048 class attribute_descriptor
00049 {
00050 public:
00051 attribute_descriptor(string const& name,unsigned type,
00052 bool primary_key=false,
00053 int size=-1,
00054 int precision=-1)
00055 : name_(name),
00056 type_(type),
00057 primary_key_(primary_key),
00058 size_(size),
00059 precision_(precision) {}
00060
00061 attribute_descriptor(attribute_descriptor const& other)
00062 : name_(other.name_),
00063 type_(other.type_),
00064 primary_key_(other.primary_key_),
00065 size_(other.size_),
00066 precision_(other.precision_) {}
00067
00068 attribute_descriptor& operator=(attribute_descriptor const& other)
00069 {
00070 if (this == &other)
00071 return *this;
00072 name_=other.name_;
00073 type_=other.type_;
00074 primary_key_=other.primary_key_;
00075 size_=other.size_;
00076 precision_=other.precision_;
00077 return *this;
00078 }
00079 string const& get_name() const
00080 {
00081 return name_;
00082 }
00083 unsigned get_type() const
00084 {
00085 return type_;
00086 }
00087 bool is_primary_key() const
00088 {
00089 return primary_key_;
00090 }
00091 int get_size() const
00092 {
00093 return size_;
00094 }
00095
00096 int get_precision() const
00097 {
00098 return precision_;
00099 }
00100 private:
00101 string name_;
00102 int type_;
00103 bool primary_key_;
00104 int size_;
00105 int precision_;
00106 };
00107
00108 template <typename charT,typename traits>
00109 inline std::basic_ostream<charT,traits>&
00110 operator << (std::basic_ostream<charT,traits>& out,
00111 attribute_descriptor const& ad)
00112 {
00113 out << "name=" << ad.get_name() << "\n";
00114 out << "type=" << ad.get_type() << "\n";
00115 out << "size=" << ad.get_size() << "\n";
00116 return out;
00117 }
00118
00119 class layer_descriptor
00120 {
00121 public:
00122 layer_descriptor(string const& name,string const& encoding)
00123 : name_(name),
00124 encoding_(encoding) {}
00125
00126 layer_descriptor(layer_descriptor const& other)
00127 : name_(other.name_),
00128 encoding_(other.encoding_),
00129 desc_ar_(other.desc_ar_) {}
00130
00131 void set_name(string const& name)
00132 {
00133 name_=name;
00134 }
00135
00136 string const& get_name() const
00137 {
00138 return name_;
00139 }
00140
00141 void set_encoding(std::string const& encoding)
00142 {
00143 encoding_=encoding;
00144 }
00145
00146 std::string const& get_encoding() const
00147 {
00148 return encoding_;
00149 }
00150
00151 void add_descriptor(attribute_descriptor const& desc)
00152 {
00153 desc_ar_.push_back(desc);
00154 }
00155
00156 vector<attribute_descriptor> const& get_descriptors() const
00157 {
00158 return desc_ar_;
00159 }
00160 vector<attribute_descriptor>& get_descriptors()
00161 {
00162 return desc_ar_;
00163 }
00164 private:
00165 string name_;
00166 string encoding_;
00167 vector<attribute_descriptor> desc_ar_;
00168 };
00169
00170 template <typename charT,typename traits>
00171 inline std::basic_ostream<charT,traits>&
00172 operator << (std::basic_ostream<charT,traits>& out,
00173 layer_descriptor const& ld)
00174 {
00175 out << "name=" << ld.get_name() << "\n";
00176 out << "encoding=" << ld.get_encoding() << "\n";
00177 vector<attribute_descriptor> const& desc_ar=ld.get_descriptors();
00178 vector<attribute_descriptor>::const_iterator pos=desc_ar.begin();
00179 while (pos != desc_ar.end())
00180 {
00181 out << *pos++ << "\n";
00182
00183 }
00184 return out;
00185 }
00186 }
00187
00188 #endif //FEATURE_LAYER_DESC_HPP