/usr/include/mapnik/feature.hpp is in libmapnik-dev 3.0.9+ds-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | /*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2015 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
*
*****************************************************************************/
#ifndef MAPNIK_FEATURE_HPP
#define MAPNIK_FEATURE_HPP
// mapnik
#include <mapnik/config.hpp>
#include <mapnik/value_types.hpp>
#include <mapnik/value.hpp>
#include <mapnik/box2d.hpp>
#include <mapnik/geometry.hpp>
#include <mapnik/geometry_envelope.hpp>
//
#include <mapnik/feature_kv_iterator.hpp>
#include <mapnik/util/noncopyable.hpp>
// stl
#include <memory>
#include <vector>
#include <map>
#include <ostream> // for basic_ostream, operator<<, etc
#include <sstream> // for basic_stringstream
#include <stdexcept> // for out_of_range
#include <iostream>
namespace mapnik {
class raster;
class feature_impl;
using raster_ptr = std::shared_ptr<raster>;
template <typename T>
class context : private util::noncopyable
{
friend class feature_impl;
public:
using map_type = T;
using value_type = typename map_type::value_type;
using key_type = typename map_type::key_type;
using size_type = typename map_type::size_type;
using difference_type = typename map_type::difference_type;
using iterator = typename map_type::iterator;
using const_iterator = typename map_type::const_iterator;
context()
: mapping_() {}
inline size_type push(key_type const& name)
{
size_type index = mapping_.size();
mapping_.emplace(name, index);
return index;
}
inline void add(key_type const& name, size_type index)
{
mapping_.emplace(name, index);
}
inline size_type size() const { return mapping_.size(); }
inline const_iterator begin() const { return mapping_.begin();}
inline const_iterator end() const { return mapping_.end();}
private:
map_type mapping_;
};
using context_type = context<std::map<std::string,std::size_t> >;
using context_ptr = std::shared_ptr<context_type>;
static const value default_feature_value;
class MAPNIK_DECL feature_impl : private util::noncopyable
{
friend class feature_kv_iterator;
public:
using value_type = mapnik::value;
using cont_type = std::vector<value_type>;
using iterator = feature_kv_iterator;
feature_impl(context_ptr const& ctx, mapnik::value_integer id)
: id_(id),
ctx_(ctx),
data_(ctx_->mapping_.size()),
geom_(geometry::geometry_empty()),
raster_() {}
inline mapnik::value_integer id() const { return id_;}
inline void set_id(mapnik::value_integer id) { id_ = id;}
template <typename T>
inline void put(context_type::key_type const& key, T const& val)
{
put(key, value(val));
}
template <typename T>
inline void put_new(context_type::key_type const& key, T const& val)
{
put_new(key, value(val));
}
inline void put(context_type::key_type const& key, value && val)
{
context_type::map_type::const_iterator itr = ctx_->mapping_.find(key);
if (itr != ctx_->mapping_.end()
&& itr->second < data_.size())
{
data_[itr->second] = std::move(val);
}
else
{
throw std::out_of_range(std::string("Key does not exist: '") + key + "'");
}
}
inline void put_new(context_type::key_type const& key, value && val)
{
context_type::map_type::const_iterator itr = ctx_->mapping_.find(key);
if (itr != ctx_->mapping_.end()
&& itr->second < data_.size())
{
data_[itr->second] = std::move(val);
}
else
{
cont_type::size_type index = ctx_->push(key);
if (index == data_.size())
data_.push_back(std::move(val));
}
}
inline bool has_key(context_type::key_type const& key) const
{
return (ctx_->mapping_.find(key) != ctx_->mapping_.end());
}
inline value_type const& get(context_type::key_type const& key) const
{
context_type::map_type::const_iterator itr = ctx_->mapping_.find(key);
if (itr != ctx_->mapping_.end())
return get(itr->second);
else
return default_feature_value;
}
inline value_type const& get(std::size_t index) const
{
if (index < data_.size())
return data_[index];
return default_feature_value;
}
inline std::size_t size() const
{
return data_.size();
}
inline cont_type const& get_data() const
{
return data_;
}
inline void set_data(cont_type const& data)
{
data_ = data;
}
inline context_ptr context() const
{
return ctx_;
}
inline void set_geometry(geometry::geometry<double> && geom)
{
geom_ = std::move(geom);
}
inline void set_geometry_copy(geometry::geometry<double> const& geom)
{
geom_ = geom;
}
inline geometry::geometry<double> const& get_geometry() const
{
return geom_;
}
inline box2d<double> envelope() const
{
return mapnik::geometry::envelope(geom_);
}
inline raster_ptr const& get_raster() const
{
return raster_;
}
inline void set_raster(raster_ptr const& raster)
{
raster_ = raster;
}
inline feature_kv_iterator begin() const
{
return feature_kv_iterator(*this,true);
}
inline feature_kv_iterator end() const
{
return feature_kv_iterator(*this);
}
std::string to_string() const
{
std::stringstream ss;
ss << "Feature ( id=" << id_ << std::endl;
for (auto const& kv : ctx_->mapping_)
{
std::size_t index = kv.second;
if (index < data_.size())
{
if (data_[kv.second] == mapnik::value_null())
{
ss << " " << kv.first << ":null" << std::endl;
}
else
{
ss << " " << kv.first << ":" << data_[kv.second] << std::endl;
}
}
}
ss << ")" << std::endl;
return ss.str();
}
private:
mapnik::value_integer id_;
context_ptr ctx_;
cont_type data_;
geometry::geometry<double> geom_;
raster_ptr raster_;
};
inline std::ostream& operator<< (std::ostream & out,feature_impl const& f)
{
out << f.to_string();
return out;
}
using feature_ptr = std::shared_ptr<feature_impl>;
}
#endif // MAPNIK_FEATURE_HPP
|