/usr/include/mapnik/params_impl.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 | /*****************************************************************************
*
* 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
*
*****************************************************************************/
// NOTE: This is an implementation header file and is only meant to be included
// from implementation files. It therefore doesn't have an include guard.
// mapnik
#include <mapnik/params.hpp>
#include <mapnik/value_types.hpp>
#include <mapnik/boolean.hpp>
#include <mapnik/util/conversions.hpp>
#pragma GCC diagnostic push
#include <mapnik/warning_ignore.hpp>
#include <boost/optional.hpp>
#include <boost/lexical_cast.hpp>
#pragma GCC diagnostic pop
// stl
#include <string>
#include <sstream>
#include <stdexcept>
namespace mapnik { namespace detail {
template <typename T>
struct extract_value
{
static inline boost::optional<T> do_extract_from_string(std::string const& /*source*/)
{
std::ostringstream s;
s << "No conversion from std::string to " << typeid(T).name();
throw std::runtime_error(s.str());
}
static inline boost::optional<T> do_extract_from_bool(value_bool const& /*source*/)
{
std::ostringstream s;
s << "No conversion from boolean to " << typeid(T).name();
throw std::runtime_error(s.str());
}
};
template <>
struct extract_value<value_bool>
{
static inline boost::optional<value_bool> do_extract_from_string(std::string const& source)
{
bool result;
if (mapnik::util::string2bool(source, result))
return boost::optional<value_bool>(result);
return boost::optional<value_bool>();
}
static inline boost::optional<value_bool> do_extract_from_bool(value_bool const& source)
{
return boost::optional<value_bool>(source);
}
};
template <>
struct extract_value<mapnik::boolean_type>
{
static inline boost::optional<mapnik::boolean_type> do_extract_from_string(std::string const& source)
{
bool result;
if (mapnik::util::string2bool(source, result))
return boost::optional<mapnik::boolean_type>(result);
return boost::optional<mapnik::boolean_type>();
}
static inline boost::optional<mapnik::boolean_type> do_extract_from_bool(value_bool const& source)
{
return boost::optional<mapnik::boolean_type>(source);
}
};
template <>
struct extract_value<mapnik::value_integer>
{
static inline boost::optional<mapnik::value_integer> do_extract_from_string(std::string const& source)
{
mapnik::value_integer result;
if (mapnik::util::string2int(source, result))
return boost::optional<mapnik::value_integer>(result);
return boost::optional<mapnik::value_integer>();
}
static inline boost::optional<mapnik::value_integer> do_extract_from_bool(value_bool const& source)
{
return boost::optional<mapnik::value_integer>(boost::lexical_cast<mapnik::value_integer>(source));
}
};
template <>
struct extract_value<mapnik::value_double>
{
static inline boost::optional<mapnik::value_double> do_extract_from_string(std::string const& source)
{
mapnik::value_double result;
if (mapnik::util::string2double(source, result))
return boost::optional<double>(result);
return boost::optional<double>();
}
static inline boost::optional<mapnik::value_double> do_extract_from_bool(value_bool const& source)
{
return boost::optional<double>(boost::lexical_cast<double>(source));
}
};
template <>
struct extract_value<mapnik::value_null>
{
static inline boost::optional<mapnik::value_null> do_extract_from_string(std::string const&)
{
return boost::optional<mapnik::value_null>(); // FIXME
}
static inline boost::optional<mapnik::value_null> do_extract_from_bool(value_bool const&)
{
return boost::optional<mapnik::value_null>(); // FIXME
}
};
template <>
struct extract_value<std::string>
{
static inline boost::optional<std::string> do_extract_from_string(std::string const& source)
{
return boost::optional<std::string>(source);
}
static inline boost::optional<std::string> do_extract_from_bool(value_bool const& source)
{
if (source) {
return boost::optional<std::string>("true");
}
return boost::optional<std::string>("false");
}
};
template <typename T>
boost::optional<T> param_cast(std::string const& source)
{
return extract_value<T>::do_extract_from_string(source);
}
template <typename T>
boost::optional<T> param_cast(value_bool const& source)
{
return extract_value<T>::do_extract_from_bool(source);
}
} // end namespace detail
template <typename T>
struct value_extractor_visitor
{
value_extractor_visitor(boost::optional<T> & var)
:var_(var) {}
void operator() (std::string const& val) const
{
var_ = detail::param_cast<T>(val);
}
void operator() (value_bool const& val) const
{
var_ = detail::param_cast<T>(val);
}
template <typename T1>
void operator () (T1 const& val) const
{
try
{
var_ = boost::lexical_cast<T>(val);
}
catch (boost::bad_lexical_cast const& )
{
std::ostringstream s;
s << "Failed converting from " << typeid(T1).name()
<< " to " << typeid(T).name();
throw std::runtime_error(s.str());
}
}
boost::optional<T> & var_;
};
namespace params_detail {
template <typename T>
struct converter
{
using value_type = T;
using return_type = boost::optional<value_type>;
static return_type extract(parameters const& params,
std::string const& name,
boost::optional<T> const& default_opt_value)
{
boost::optional<T> result(default_opt_value);
parameters::const_iterator itr = params.find(name);
if (itr != params.end())
{
util::apply_visitor(value_extractor_visitor<T>(result),itr->second);
}
return result;
}
};
} // end namespace params_detail
template <typename T>
boost::optional<T> parameters::get(std::string const& key) const
{
return params_detail::converter<T>::extract(*this,key, boost::none);
}
template <typename T>
boost::optional<T> parameters::get(std::string const& key, T const& default_opt_value) const
{
return params_detail::converter<T>::extract(*this,key,boost::optional<T>(default_opt_value));
}
}
|