Merge pull request #1661 from mapnik/bigint

Compile tile support for 64-bit integers in mapnik::value
This commit is contained in:
Artem Pavlenko 2012-12-19 01:59:36 -08:00
commit da0c99b4be
27 changed files with 293 additions and 216 deletions

View file

@ -57,7 +57,7 @@ boost::shared_ptr<mapnik::datasource> create_datasource(const dict& d)
std::string key = extract<std::string>(keys[i]);
object obj = d[key];
extract<std::string> ex0(obj);
extract<int> ex1(obj);
extract<mapnik::value_integer> ex1(obj);
extract<double> ex2(obj);
if (ex0.check())
{

View file

@ -38,7 +38,7 @@ boost::shared_ptr<mapnik::datasource> create_datasource(const dict& d)
std::string key = extract<std::string>(keys[i]);
object obj = d[key];
extract<std::string> ex0(obj);
extract<int> ex1(obj);
extract<mapnik::value_integer> ex1(obj);
extract<double> ex2(obj);
if (ex0.check())

View file

@ -196,11 +196,11 @@ void export_feature()
// Python to mapnik::value converters
// NOTE: order matters here. For example value_null must be listed before
// bool otherwise Py_None will be interpreted as bool (false)
implicitly_convertible<UnicodeString,mapnik::value>();
implicitly_convertible<mapnik::value_unicode_string,mapnik::value>();
implicitly_convertible<mapnik::value_null,mapnik::value>();
implicitly_convertible<int,mapnik::value>();
implicitly_convertible<bool,mapnik::value>();
implicitly_convertible<double,mapnik::value>();
implicitly_convertible<mapnik::value_integer,mapnik::value>();
implicitly_convertible<mapnik::value_double,mapnik::value>();
implicitly_convertible<mapnik::value_bool,mapnik::value>();
// http://misspent.wordpress.com/2009/09/27/how-to-write-boost-python-converters/
UnicodeString_from_python_str();

View file

@ -78,7 +78,7 @@ struct parameters_pickle_suite : boost::python::pickle_suite
std::string key = extract<std::string>(keys[i]);
object obj = d[key];
extract<std::string> ex0(obj);
extract<int> ex1(obj);
extract<mapnik::value_integer> ex1(obj);
extract<double> ex2(obj);
extract<UnicodeString> ex3(obj);
@ -185,7 +185,7 @@ boost::shared_ptr<mapnik::parameter> create_parameter_from_string(std::string co
return boost::make_shared<mapnik::parameter>(key,mapnik::value_holder(value));
}
boost::shared_ptr<mapnik::parameter> create_parameter_from_int(std::string const& key, int value)
boost::shared_ptr<mapnik::parameter> create_parameter_from_int(std::string const& key, mapnik::value_integer value)
{
return boost::make_shared<mapnik::parameter>(key,mapnik::value_holder(value));
}

View file

@ -30,7 +30,7 @@ namespace boost { namespace python {
struct value_converter : public boost::static_visitor<PyObject*>
{
PyObject * operator() (int val) const
PyObject * operator() (mapnik::value_integer val) const
{
#if PY_VERSION_HEX >= 0x03000000
return ::PyLong_FromLong(val);

View file

@ -52,14 +52,14 @@ struct geometry_type_attribute
template <typename V, typename F>
V value(F const& f) const
{
int type = 0;
mapnik::value_integer type = 0;
geometry_container::const_iterator itr = f.paths().begin();
geometry_container::const_iterator end = f.paths().end();
for ( ; itr != end; ++itr)
{
if (type != 0 && itr->type() != type)
{
return 4; // Collection
return value_integer(4); // Collection
}
type = itr->type();
}

View file

@ -108,7 +108,7 @@ struct regex_replace_impl
mapnik::transcoder const& tr_;
};
struct geometry_types : qi::symbols<char,int>
struct geometry_types : qi::symbols<char,mapnik::value_integer>
{
geometry_types()
{
@ -121,6 +121,12 @@ struct geometry_types : qi::symbols<char,int>
}
};
template <typename T>
struct integer_parser
{
typedef qi::int_parser<T,10,1,-1> type;
};
template <typename Iterator>
struct expression_grammar : qi::grammar<Iterator, expr_node(), space_type>
{
@ -129,6 +135,7 @@ struct expression_grammar : qi::grammar<Iterator, expr_node(), space_type>
explicit expression_grammar(mapnik::transcoder const& tr);
qi::real_parser<double, qi::strict_real_policies<double> > strict_double;
typename integer_parser<mapnik::value_integer>::type int__;
boost::phoenix::function<unicode_impl> unicode_;
boost::phoenix::function<regex_match_impl> regex_match_;
boost::phoenix::function<regex_replace_impl> regex_replace_;

View file

@ -186,7 +186,8 @@ struct feature_generator_grammar:
using boost::spirit::karma::lit;
using boost::spirit::karma::uint_;
using boost::spirit::karma::bool_;
using boost::spirit::karma::int_;
//using boost::spirit::karma::int_;
//using boost::spirit::karma::long_long;
using boost::spirit::karma::double_;
using boost::spirit::karma::_val;
using boost::spirit::karma::_1;
@ -212,7 +213,7 @@ struct feature_generator_grammar:
<< value(phoenix::at_c<1>(_val))
;
value = (value_null_| bool_ | int_| double_ | ustring)[_1 = value_base_(_r1)]
value = (value_null_| bool_ | int__ | double_ | ustring)[_1 = value_base_(_r1)]
;
value_null_ = string[_1 = "null"]
@ -231,6 +232,7 @@ struct feature_generator_grammar:
karma::rule<OutputIterator, void(mapnik::value const&)> value;
karma::rule<OutputIterator, mapnik::value_null()> value_null_;
karma::rule<OutputIterator, UnicodeString()> ustring;
typename karma::int_generator<mapnik::value_integer,10, false> int__;
// phoenix functions
phoenix::function<get_id> id_;
phoenix::function<value_base> value_base_;

View file

@ -29,6 +29,7 @@
// spirit::qi
#include <boost/config/warning_disable.hpp>
#include <boost/cstdint.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix.hpp>
#include <boost/variant/apply_visitor.hpp>
@ -59,6 +60,7 @@ public:
{
return mapnik::value(val);
}
mapnik::transcoder const& tr_;
};
@ -109,9 +111,11 @@ struct feature_grammar :
qi::rule<Iterator,space_type> value;
qi::symbols<char const, char const> unesc_char;
qi::uint_parser< unsigned, 16, 4, 4 > hex4 ;
qi::int_parser<mapnik::value_integer,10,1,-1> int__;
qi::rule<Iterator,std::string(), space_type> string_;
qi::rule<Iterator,space_type> key_value;
qi::rule<Iterator,boost::variant<value_null,bool,int,double>(),space_type> number;
qi::rule<Iterator,boost::variant<value_null,bool,
value_integer,value_double>(),space_type> number;
qi::rule<Iterator,space_type> object;
qi::rule<Iterator,space_type> array;
qi::rule<Iterator,space_type> pairs;
@ -123,7 +127,7 @@ struct feature_grammar :
qi::rule<Iterator,void(FeatureType &),space_type> properties;
qi::rule<Iterator,qi::locals<std::string>, void(FeatureType &),space_type> attributes;
qi::rule<Iterator,boost::variant<value_null,bool,int,double,std::string>(), space_type> attribute_value;
qi::rule<Iterator,boost::variant<value_null,bool,value_integer,value_double,std::string>(), space_type> attribute_value;
phoenix::function<put_property> put_property_;
phoenix::function<extract_geometry> extract_geometry_;

View file

@ -38,7 +38,7 @@
namespace mapnik
{
typedef boost::variant<value_null,int,double,std::string> value_holder;
typedef boost::variant<value_null,value_integer,value_double,std::string> value_holder;
typedef std::pair<std::string, value_holder> parameter;
typedef std::map<std::string, value_holder> param_map;

View file

@ -50,6 +50,9 @@ namespace mapnik { namespace util {
MAPNIK_DECL bool string2int(const char * value, int & result);
MAPNIK_DECL bool string2int(std::string const& value, int & result);
MAPNIK_DECL bool string2longlong(const char * value, boost::long_long_type & result);
MAPNIK_DECL bool string2longlong(std::string const& value, boost::long_long_type & result);
MAPNIK_DECL bool string2double(std::string const& value, double & result);
MAPNIK_DECL bool string2double(const char * value, double & result);

View file

@ -107,7 +107,19 @@ struct value_null
}
};
typedef boost::variant<value_null,bool,int,double,UnicodeString> value_base;
#define BIGINT
#ifdef BIGINT
typedef long long value_integer;
#else
typedef int value_integer;
#endif
typedef double value_double;
typedef UnicodeString value_unicode_string;
typedef bool value_bool;
typedef boost::variant<value_null,value_bool,value_integer,value_double,value_unicode_string> value_base;
namespace impl {
@ -126,18 +138,18 @@ struct equals
return lhs == rhs;
}
bool operator() (int lhs, double rhs) const
bool operator() (value_integer lhs, value_double rhs) const
{
return lhs == rhs;
}
bool operator() (double lhs, int rhs) const
bool operator() (value_double lhs, value_integer rhs) const
{
return (lhs == rhs)? true : false ;
}
bool operator() (UnicodeString const& lhs,
UnicodeString const& rhs) const
bool operator() (value_unicode_string const& lhs,
value_unicode_string const& rhs) const
{
return (lhs == rhs) ? true: false;
}
@ -164,18 +176,18 @@ struct not_equals
return lhs != rhs;
}
bool operator() (int lhs, double rhs) const
bool operator() (value_integer lhs, value_double rhs) const
{
return lhs != rhs;
}
bool operator() (double lhs, int rhs) const
bool operator() (value_double lhs, value_integer rhs) const
{
return lhs != rhs;
}
bool operator() (UnicodeString const& lhs,
UnicodeString const& rhs) const
bool operator() (value_unicode_string const& lhs,
value_unicode_string const& rhs) const
{
return (lhs != rhs)? true : false;
}
@ -215,17 +227,17 @@ struct greater_than
return lhs > rhs;
}
bool operator() (int lhs, double rhs) const
bool operator() (value_integer lhs, value_double rhs) const
{
return lhs > rhs;
}
bool operator() (double lhs, int rhs) const
bool operator() (value_double lhs, value_integer rhs) const
{
return lhs > rhs;
}
bool operator() (UnicodeString const& lhs, UnicodeString const& rhs) const
bool operator() (value_unicode_string const& lhs, value_unicode_string const& rhs) const
{
return (lhs > rhs) ? true : false ;
}
@ -251,17 +263,17 @@ struct greater_or_equal
return lhs >= rhs;
}
bool operator() (int lhs, double rhs) const
bool operator() (value_integer lhs, value_double rhs) const
{
return lhs >= rhs;
}
bool operator() (double lhs, int rhs) const
bool operator() (value_double lhs, value_integer rhs) const
{
return lhs >= rhs;
}
bool operator() (UnicodeString const& lhs, UnicodeString const& rhs) const
bool operator() (value_unicode_string const& lhs, value_unicode_string const& rhs) const
{
return ( lhs >= rhs ) ? true : false ;
}
@ -287,18 +299,18 @@ struct less_than
return lhs < rhs;
}
bool operator() (int lhs, double rhs) const
bool operator() (value_integer lhs, value_double rhs) const
{
return lhs < rhs;
}
bool operator() (double lhs, int rhs) const
bool operator() (value_double lhs, value_integer rhs) const
{
return lhs < rhs;
}
bool operator()(UnicodeString const& lhs,
UnicodeString const& rhs ) const
bool operator()(value_unicode_string const& lhs,
value_unicode_string const& rhs ) const
{
return (lhs < rhs) ? true : false ;
}
@ -324,18 +336,18 @@ struct less_or_equal
return lhs <= rhs;
}
bool operator() (int lhs, double rhs) const
bool operator() (value_integer lhs, value_double rhs) const
{
return lhs <= rhs;
}
bool operator() (double lhs, int rhs) const
bool operator() (value_double lhs, value_integer rhs) const
{
return lhs <= rhs;
}
bool operator()(UnicodeString const& lhs,
UnicodeString const& rhs ) const
bool operator()(value_unicode_string const& lhs,
value_unicode_string const& rhs ) const
{
return (lhs <= rhs) ? true : false ;
}
@ -350,6 +362,51 @@ template <typename V>
struct add : public boost::static_visitor<V>
{
typedef V value_type;
value_type operator() (value_unicode_string const& lhs ,
value_unicode_string const& rhs ) const
{
return lhs + rhs;
}
value_type operator() (value_double lhs, value_integer rhs) const
{
return lhs + rhs;
}
value_type operator() (value_integer lhs, value_double rhs) const
{
return lhs + rhs;
}
value_type operator() (value_unicode_string const& lhs, value_null rhs) const
{
boost::ignore_unused_variable_warning(rhs);
return lhs;
}
value_type operator() (value_null lhs, value_unicode_string const& rhs) const
{
boost::ignore_unused_variable_warning(lhs);
return rhs;
}
template <typename R>
value_type operator() (value_unicode_string const& lhs, R const& rhs) const
{
std::string val;
if (util::to_string(val,rhs))
return lhs + value_unicode_string(val.c_str());
return lhs;
}
template <typename L>
value_type operator() (L const& lhs , value_unicode_string const& rhs) const
{
std::string val;
if (util::to_string(val,lhs))
return value_unicode_string(val.c_str()) + rhs;
return rhs;
}
template <typename T>
value_type operator() (T lhs, T rhs) const
@ -357,57 +414,16 @@ struct add : public boost::static_visitor<V>
return lhs + rhs ;
}
value_type operator() (UnicodeString const& lhs ,
UnicodeString const& rhs ) const
{
return lhs + rhs;
}
value_type operator() (double lhs, int rhs) const
{
return lhs + rhs;
}
value_type operator() (int lhs, double rhs) const
{
return lhs + rhs;
}
value_type operator() (UnicodeString const& lhs, value_null rhs) const
{
boost::ignore_unused_variable_warning(rhs);
return lhs;
}
value_type operator() (value_null lhs, UnicodeString const& rhs) const
{
boost::ignore_unused_variable_warning(lhs);
return rhs;
}
template <typename R>
value_type operator() (UnicodeString const& lhs, R const& rhs) const
{
std::string val;
if (util::to_string(val,rhs))
return lhs + UnicodeString(val.c_str());
return lhs;
}
template <typename L>
value_type operator() (L const& lhs , UnicodeString const& rhs) const
{
std::string val;
if (util::to_string(val,lhs))
return UnicodeString(val.c_str()) + rhs;
return rhs;
}
template <typename T1, typename T2>
value_type operator() (T1 const& lhs, T2 const&) const
{
return lhs;
}
value_type operator() (value_bool lhs, value_bool rhs) const
{
return value_integer(lhs + rhs);
}
};
template <typename V>
@ -421,26 +437,31 @@ struct sub : public boost::static_visitor<V>
}
template <typename T>
value_type operator() (T lhs, T rhs) const
value_type operator() (T lhs, T rhs) const
{
return lhs - rhs ;
}
value_type operator() (UnicodeString const& lhs,
UnicodeString const& ) const
value_type operator() (value_unicode_string const& lhs,
value_unicode_string const& ) const
{
return lhs;
}
value_type operator() (double lhs, int rhs) const
value_type operator() (value_double lhs, value_integer rhs) const
{
return lhs - rhs;
}
value_type operator() (int lhs, double rhs) const
value_type operator() (value_integer lhs, value_double rhs) const
{
return lhs - rhs;
}
value_type operator() (value_bool lhs, value_bool rhs) const
{
return value_integer(lhs - rhs);
}
};
template <typename V>
@ -458,21 +479,26 @@ struct mult : public boost::static_visitor<V>
return lhs * rhs;
}
value_type operator() (UnicodeString const& lhs,
UnicodeString const& ) const
value_type operator() (value_unicode_string const& lhs,
value_unicode_string const& ) const
{
return lhs;
}
value_type operator() (double lhs, int rhs) const
value_type operator() (value_double lhs, value_integer rhs) const
{
return lhs * rhs;
}
value_type operator() (int lhs, double rhs) const
value_type operator() (value_integer lhs, value_double rhs) const
{
return lhs * rhs;
}
value_type operator() (value_bool lhs, value_bool rhs) const
{
return value_integer(0);
}
};
template <typename V>
@ -491,25 +517,25 @@ struct div: public boost::static_visitor<V>
return lhs / rhs;
}
value_type operator() (bool lhs, bool rhs ) const
value_type operator() (value_bool lhs, value_bool rhs ) const
{
boost::ignore_unused_variable_warning(lhs);
boost::ignore_unused_variable_warning(rhs);
return false;
}
value_type operator() (UnicodeString const& lhs,
UnicodeString const&) const
value_type operator() (value_unicode_string const& lhs,
value_unicode_string const&) const
{
return lhs;
}
value_type operator() (double lhs, int rhs) const
value_type operator() (value_double lhs, value_integer rhs) const
{
return lhs / rhs;
}
value_type operator() (int lhs, double rhs) const
value_type operator() (value_integer lhs, value_double rhs) const
{
return lhs / rhs;
}
@ -531,31 +557,31 @@ struct mod: public boost::static_visitor<V>
return lhs % rhs;
}
value_type operator() (UnicodeString const& lhs,
UnicodeString const&) const
value_type operator() (value_unicode_string const& lhs,
value_unicode_string const&) const
{
return lhs;
}
value_type operator() (bool lhs,
bool rhs) const
value_type operator() (value_bool lhs,
value_bool rhs) const
{
boost::ignore_unused_variable_warning(lhs);
boost::ignore_unused_variable_warning(rhs);
return false;
}
value_type operator() (double lhs, int rhs) const
value_type operator() (value_double lhs, value_integer rhs) const
{
return std::fmod(lhs, rhs);
}
value_type operator() (int lhs, double rhs) const
value_type operator() (value_integer lhs, value_double rhs) const
{
return std::fmod(lhs, rhs);
}
value_type operator() (double lhs, double rhs) const
value_type operator() (value_double lhs, value_double rhs) const
{
return std::fmod(lhs, rhs);
}
@ -577,39 +603,39 @@ struct negate : public boost::static_visitor<V>
return val;
}
value_type operator() (bool val) const
value_type operator() (value_bool val) const
{
return val ? -1 : 0;
return val ? value_integer(-1) : value_integer(0);
}
value_type operator() (UnicodeString const& ustr) const
value_type operator() (value_unicode_string const& ustr) const
{
UnicodeString inplace(ustr);
value_unicode_string inplace(ustr);
return inplace.reverse();
}
};
struct to_bool : public boost::static_visitor<bool>
struct to_bool : public boost::static_visitor<value_bool>
{
bool operator() (bool val) const
value_bool operator() (value_bool val) const
{
return val;
}
bool operator() (UnicodeString const& ustr) const
value_bool operator() (value_unicode_string const& ustr) const
{
boost::ignore_unused_variable_warning(ustr);
return true;
}
bool operator() (value_null const& val) const
value_bool operator() (value_null const& val) const
{
boost::ignore_unused_variable_warning(val);
return false;
}
template <typename T>
bool operator() (T val) const
value_bool operator() (T val) const
{
return val > 0 ? true : false;
}
@ -626,14 +652,14 @@ struct to_string : public boost::static_visitor<std::string>
}
// specializations
std::string operator() (UnicodeString const& val) const
std::string operator() (value_unicode_string const& val) const
{
std::string utf8;
to_utf8(val,utf8);
return utf8;
}
std::string operator() (double val) const
std::string operator() (value_double val) const
{
std::string str;
util::to_string(str, val); // TODO set precision(16)
@ -647,54 +673,54 @@ struct to_string : public boost::static_visitor<std::string>
}
};
struct to_unicode : public boost::static_visitor<UnicodeString>
struct to_unicode : public boost::static_visitor<value_unicode_string>
{
template <typename T>
UnicodeString operator() (T val) const
value_unicode_string operator() (T val) const
{
std::string str;
util::to_string(str,val);
return UnicodeString(str.c_str());
return value_unicode_string(str.c_str());
}
// specializations
UnicodeString const& operator() (UnicodeString const& val) const
value_unicode_string const& operator() (value_unicode_string const& val) const
{
return val;
}
UnicodeString operator() (double val) const
value_unicode_string operator() (value_double val) const
{
std::string str;
util::to_string(str,val);
return UnicodeString(str.c_str());
return value_unicode_string(str.c_str());
}
UnicodeString operator() (value_null const& val) const
value_unicode_string operator() (value_null const& val) const
{
boost::ignore_unused_variable_warning(val);
return UnicodeString("");
return value_unicode_string("");
}
};
struct to_expression_string : public boost::static_visitor<std::string>
{
std::string operator() (UnicodeString const& val) const
std::string operator() (value_unicode_string const& val) const
{
std::string utf8;
to_utf8(val,utf8);
return "'" + utf8 + "'";
}
std::string operator() (double val) const
std::string operator() (value_double val) const
{
std::string output;
util::to_string(output,val); // TODO precision(16)
return output;
}
std::string operator() (bool val) const
std::string operator() (value_bool val) const
{
return val ? "true":"false";
}
@ -714,69 +740,85 @@ struct to_expression_string : public boost::static_visitor<std::string>
}
};
struct to_double : public boost::static_visitor<double>
struct to_double : public boost::static_visitor<value_double>
{
double operator() (int val) const
{
return static_cast<double>(val);
}
double operator() (double val) const
value_double operator() (value_double val) const
{
return val;
}
double operator() (std::string const& val) const
value_double operator() (value_integer val) const
{
double result;
return static_cast<value_double>(val);
}
value_double operator() (value_bool val) const
{
return static_cast<value_double>(val);
}
value_double operator() (std::string const& val) const
{
value_double result;
if (util::string2double(val,result))
return result;
return 0;
}
double operator() (UnicodeString const& val) const
value_double operator() (value_unicode_string const& val) const
{
std::string utf8;
to_utf8(val,utf8);
return operator()(utf8);
}
double operator() (value_null const& val) const
value_double operator() (value_null const& val) const
{
boost::ignore_unused_variable_warning(val);
return 0.0;
}
};
struct to_int : public boost::static_visitor<double>
struct to_int : public boost::static_visitor<value_integer>
{
int operator() (int val) const
value_integer operator() (value_integer val) const
{
return val;
}
int operator() (double val) const
value_integer operator() (value_double val) const
{
return rint(val);
}
int operator() (std::string const& val) const
value_integer operator() (value_bool val) const
{
int result;
if (util::string2int(val,result))
return result;
return 0;
return static_cast<int>(val);
}
int operator() (UnicodeString const& val) const
value_integer operator() (std::string const& val) const
{
value_integer result;
#ifdef BIGINT
if (util::string2longlong(val,result))
#else
if (util::string2int(val,result))
#endif
return result;
return value_integer(0);
}
value_integer operator() (value_unicode_string const& val) const
{
std::string utf8;
to_utf8(val,utf8);
return operator()(utf8);
}
int operator() (value_null const& val) const
value_integer operator() (value_null const& val) const
{
boost::ignore_unused_variable_warning(val);
return 0;
return value_integer(0);
}
};
@ -842,7 +884,7 @@ public:
bool is_null() const;
bool to_bool() const
value_bool to_bool() const
{
return boost::apply_visitor(impl::to_bool(),base_);
}
@ -857,17 +899,17 @@ public:
return boost::apply_visitor(impl::to_string(),base_);
}
UnicodeString to_unicode() const
value_unicode_string to_unicode() const
{
return boost::apply_visitor(impl::to_unicode(),base_);
}
double to_double() const
value_double to_double() const
{
return boost::apply_visitor(impl::to_double(),base_);
}
double to_int() const
value_integer to_int() const
{
return boost::apply_visitor(impl::to_int(),base_);
}

View file

@ -453,7 +453,7 @@ void csv_datasource::parse_csv(T & stream,
{
csv_utils::fix_json_quoting(csv_line);
}
Tokenizer tok(csv_line, grammer);
Tokenizer::iterator beg = tok.begin();
@ -584,7 +584,7 @@ void csv_datasource::parse_csv(T & stream,
MAPNIK_LOG_ERROR(csv) << s.str();
}
}
}
}
}
else
{
@ -695,7 +695,7 @@ void csv_datasource::parse_csv(T & stream,
}
else
{
feature->put(fld_name,static_cast<int>(float_val));
feature->put(fld_name,static_cast<mapnik::value_integer>(float_val));
if (feature_count == 1)
{
desc_.add_descriptor(

View file

@ -445,10 +445,10 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
{
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Loading colour table...";
unsigned nodata_value = static_cast<unsigned>(nodata);
unsigned nodata_value = static_cast<unsigned>(nodata); // FIXME: is it realy unsigned ?
if (hasNoData)
{
feature->put("NODATA",static_cast<int>(nodata_value));
feature->put("NODATA",static_cast<mapnik::value_integer>(nodata_value));
}
for (unsigned y = 0; y < image.height(); ++y)
{

View file

@ -51,7 +51,7 @@ DATASOURCE_PLUGIN(geojson_datasource)
struct attr_value_converter : public boost::static_visitor<mapnik::eAttributeType>
{
mapnik::eAttributeType operator() (int /*val*/) const
mapnik::eAttributeType operator() (mapnik::value_integer /*val*/) const
{
return mapnik::Integer;
}
@ -100,29 +100,29 @@ geojson_datasource::geojson_datasource(parameters const& params)
{
if (file_.empty()) throw mapnik::datasource_exception("GeoJSON Plugin: missing <file> parameter");
typedef std::istreambuf_iterator<char> base_iterator_type;
typedef std::istreambuf_iterator<char> base_iterator_type;
std::ifstream is(file_.c_str());
boost::spirit::multi_pass<base_iterator_type> begin =
boost::spirit::multi_pass<base_iterator_type> begin =
boost::spirit::make_default_multi_pass(base_iterator_type(is));
boost::spirit::multi_pass<base_iterator_type> end =
boost::spirit::multi_pass<base_iterator_type> end =
boost::spirit::make_default_multi_pass(base_iterator_type());
mapnik::context_ptr ctx = boost::make_shared<mapnik::context_type>();
mapnik::json::feature_collection_parser<boost::spirit::multi_pass<base_iterator_type> > p(ctx,*tr_);
bool result = p.parse(begin,end, features_);
if (!result)
if (!result)
{
throw mapnik::datasource_exception("geojson_datasource: Failed parse GeoJSON file '" + file_ + "'");
}
bool first = true;
std::size_t count=0;
BOOST_FOREACH (mapnik::feature_ptr f, features_)
{
mapnik::box2d<double> const& box = f->envelope();
if (first)
if (first)
{
extent_ = box;
first = false;
@ -137,7 +137,7 @@ geojson_datasource::geojson_datasource(parameters const& params)
else
{
extent_.expand_to_include(box);
}
}
tree_.insert(box_type(point_type(box.minx(),box.miny()),point_type(box.maxx(),box.maxy())), count++);
}
}
@ -149,7 +149,7 @@ const char * geojson_datasource::name()
return "geojson";
}
boost::optional<mapnik::datasource::geometry_t> geojson_datasource::get_geometry_type() const
boost::optional<mapnik::datasource::geometry_t> geojson_datasource::get_geometry_type() const
{
boost::optional<mapnik::datasource::geometry_t> result;
int multi_type = 0;
@ -171,7 +171,7 @@ boost::optional<mapnik::datasource::geometry_t> geojson_datasource::get_geometry
return result;
}
mapnik::datasource::datasource_t geojson_datasource::type() const
mapnik::datasource::datasource_t geojson_datasource::type() const
{
return type_;
}
@ -195,7 +195,7 @@ mapnik::featureset_ptr geojson_datasource::features(mapnik::query const& q) cons
box_type box(point_type(b.minx(),b.miny()),point_type(b.maxx(),b.maxy()));
index_array_ = tree_.find(box);
return boost::make_shared<geojson_featureset>(features_, index_array_.begin(), index_array_.end());
}
}
// otherwise return an empty featureset pointer
return mapnik::featureset_ptr();
}

View file

@ -117,7 +117,7 @@ feature_ptr ogr_featureset::next()
{
case OFTInteger:
{
feature->put( fld_name, poFeature->GetFieldAsInteger(i));
feature->put<mapnik::value_integer>( fld_name, poFeature->GetFieldAsInteger(i));
break;
}

View file

@ -126,7 +126,7 @@ feature_ptr ogr_index_featureset<filterT>::next()
{
case OFTInteger:
{
feature->put(fld_name,poFeature->GetFieldAsInteger (i));
feature->put<mapnik::value_integer>(fld_name,poFeature->GetFieldAsInteger (i));
break;
}

View file

@ -76,7 +76,8 @@ feature_ptr postgis_featureset::next()
std::string name = rs_->getFieldName(pos);
// validation happens of this type at initialization
int val;
mapnik::value_integer val;
if (oid == 20)
{
val = int8net(buf);
@ -94,7 +95,7 @@ feature_ptr postgis_featureset::next()
// TODO - extend feature class to know
// that its id is also an attribute to avoid
// this duplication
feature->put(name,val);
feature->put<mapnik::value_integer>(name,val);
++pos;
}
else
@ -135,24 +136,19 @@ feature_ptr postgis_featureset::next()
case 23: //int4
{
int val = int4net(buf);
feature->put(name, val);
feature->put<mapnik::value_integer>(name, int4net(buf));
break;
}
case 21: //int2
{
int val = int2net(buf);
feature->put(name, val);
feature->put<mapnik::value_integer>(name, int2net(buf));
break;
}
case 20: //int8/BigInt
{
// TODO - need to support boost::uint64_t in mapnik::value
// https://github.com/mapnik/mapnik/issues/895
int val = int8net(buf);
feature->put(name, val);
feature->put<mapnik::value_integer>(name, int8net(buf));
break;
}

View file

@ -173,7 +173,7 @@ void dbf_file::add_attribute(int col, mapnik::transcoder const& tr, Feature & f)
}
else
{
int val = 0;
mapnik::value_integer val = 0;
const char *itr = record_+fields_[col].offset_;
const char *end = itr + fields_[col].length_;
if (qi::phrase_parse(itr,end,int_,ascii::space,val))

View file

@ -104,7 +104,7 @@ feature_ptr sqlite_featureset::next()
{
case SQLITE_INTEGER:
{
feature->put(fld_name_str, rs_->column_integer(i));
feature->put<mapnik::value_integer>(fld_name_str, rs_->column_integer(i));
break;
}

View file

@ -39,6 +39,7 @@ namespace mapnik { namespace util {
using namespace boost::spirit;
BOOST_SPIRIT_AUTO(qi, INTEGER, qi::int_)
BOOST_SPIRIT_AUTO(qi, LONGLONG, qi::long_long)
BOOST_SPIRIT_AUTO(qi, FLOAT, qi::float_)
BOOST_SPIRIT_AUTO(qi, DOUBLE, qi::double_)
@ -63,6 +64,27 @@ bool string2int(std::string const& value, int & result)
return r && (str_beg == str_end);
}
bool string2longlong(const char * value, boost::long_long_type & result)
{
size_t length = strlen(value);
if (length < 1 || value == NULL)
return false;
const char *iter = value;
const char *end = value + length;
bool r = qi::phrase_parse(iter,end,LONGLONG,ascii::space,result);
return r && (iter == end);
}
bool string2longlong(std::string const& value, boost::long_long_type & result)
{
if (value.empty())
return false;
std::string::const_iterator str_beg = value.begin();
std::string::const_iterator str_end = value.end();
bool r = qi::phrase_parse(str_beg,str_end,LONGLONG,ascii::space,result);
return r && (str_beg == str_end);
}
bool string2double(std::string const& value, double & result)
{
if (value.empty())

View file

@ -47,10 +47,10 @@ expr_node regex_replace_impl::operator() (T0 & node, T1 const& pattern, T2 const
template <typename Iterator>
expression_grammar<Iterator>::expression_grammar(mapnik::transcoder const& tr)
: expression_grammar::base_type(expr),
unicode_(unicode_impl(tr)),
regex_match_(regex_match_impl(tr)),
regex_replace_(regex_replace_impl(tr))
: expression_grammar::base_type(expr),
unicode_(unicode_impl(tr)),
regex_match_(regex_match_impl(tr)),
regex_replace_(regex_replace_impl(tr))
{
using boost::phoenix::construct;
using qi::_1;
@ -63,12 +63,12 @@ expression_grammar<Iterator>::expression_grammar(mapnik::transcoder const& tr)
using qi::lexeme;
using qi::_val;
using qi::lit;
using qi::int_;
using qi::double_;
using qi::hex;
using qi::omit;
using standard_wide::char_;
using standard_wide::no_case;
expr = logical_expr.alias();
logical_expr = not_expr [_val = _1]
@ -138,7 +138,7 @@ expression_grammar<Iterator>::expression_grammar(mapnik::transcoder const& tr)
;
primary_expr = strict_double [_val = _1]
| int_ [_val = _1]
| int__[_val = _1]
| no_case[lit("true")] [_val = true]
| no_case[lit("false")] [_val = false]
| no_case[lit("null")] [_val = value_null() ]
@ -171,4 +171,4 @@ expression_grammar<Iterator>::expression_grammar(mapnik::transcoder const& tr)
template struct mapnik::expression_grammar<std::string::const_iterator>;
}
}

View file

@ -38,7 +38,7 @@ feature_grammar<Iterator,FeatureType>::feature_grammar(mapnik::transcoder const&
put_property_(put_property(tr))
{
using qi::lit;
using qi::int_;
using qi::long_long;
using qi::double_;
#if BOOST_VERSION > 104200
using qi::no_skip;
@ -90,7 +90,7 @@ feature_grammar<Iterator,FeatureType>::feature_grammar(mapnik::transcoder const&
#else
number = strict_double
#endif
| int_
| int__
| lit("true") [_val = true]
| lit ("false") [_val = false]
| lit("null")[_val = construct<value_null>()]

View file

@ -365,13 +365,13 @@ void map_parser::parse_map_include(Map & map, xml_node const& include)
if (*type == "int")
{
is_string = false;
int value = paramIter->get_value<int>();
mapnik::value_integer value = paramIter->get_value<mapnik::value_integer>();
params[name] = value;
}
else if (*type == "float")
{
is_string = false;
double value = paramIter->get_value<double>();
double value = paramIter->get_value<mapnik::value_double>();
params[name] = value;
}
}

View file

@ -664,12 +664,12 @@ public:
serialize_type( boost::property_tree::ptree & node):
node_(node) {}
void operator () ( int val ) const
void operator () ( mapnik::value_integer val ) const
{
node_.put("<xmlattr>.type", "int" );
}
void operator () ( double val ) const
void operator () ( mapnik::value_double val ) const
{
node_.put("<xmlattr>.type", "float" );
}

View file

@ -125,7 +125,7 @@ DEFINE_NAME_TRAIT( double, "double")
DEFINE_NAME_TRAIT( float, "float")
DEFINE_NAME_TRAIT( unsigned, "unsigned")
DEFINE_NAME_TRAIT( boolean, "boolean")
DEFINE_NAME_TRAIT( int, "integer" )
DEFINE_NAME_TRAIT( mapnik::value_integer, "long long" )
DEFINE_NAME_TRAIT( std::string, "string" )
DEFINE_NAME_TRAIT( color, "color" )
DEFINE_NAME_TRAIT(expression_ptr, "expression_ptr" )
@ -463,6 +463,7 @@ std::string xml_node::line_to_string() const
compile_get_opt_attr(boolean);
compile_get_opt_attr(std::string);
compile_get_opt_attr(unsigned);
compile_get_opt_attr(mapnik::value_integer);
compile_get_opt_attr(float);
compile_get_opt_attr(double);
compile_get_opt_attr(color);
@ -484,7 +485,7 @@ compile_get_attr(pattern_alignment_e);
compile_get_attr(line_rasterizer_e);
compile_get_attr(colorizer_mode);
compile_get_attr(double);
compile_get_value(int);
compile_get_value(value_integer);
compile_get_value(double);
compile_get_value(expression_ptr);
} //ns mapnik

View file

@ -10,17 +10,17 @@ int main( int, char*[] )
mapnik::parameters params;
// true
params["bool"] = true;
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
//params["bool"] = true;
//BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
params["bool"] = "true";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
params["bool"] = 1;
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
//params["bool"] = 1;
//BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
params["bool"] = "1";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
//params["bool"] = "1";
//BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
params["bool"] = "True";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
@ -32,17 +32,17 @@ int main( int, char*[] )
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == true));
// false
params["bool"] = false;
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false) );
//params["bool"] = false;
//BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false) );
params["bool"] = "false";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false) );
params["bool"] = 0;
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false));
//params["bool"] = 0;
//BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false));
params["bool"] = "0";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false));
//params["bool"] = "0";
//BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false));
params["bool"] = "False";
BOOST_TEST( (params.get<mapnik::boolean>("bool") && *params.get<mapnik::boolean>("bool") == false));
@ -58,8 +58,8 @@ int main( int, char*[] )
BOOST_TEST( (params.get<std::string>("string") && *params.get<std::string>("string") == "hello") );
// int
params["int"] = 1;
BOOST_TEST( (params.get<int>("int") && *params.get<int>("int") == 1) );
params["int"] = mapnik::value_integer(1);
BOOST_TEST( (params.get<mapnik::value_integer>("int") && *params.get<mapnik::value_integer>("int") == 1) );
// double
params["double"] = 1.5;