Revert previous fix for #89 and add a new improved fix that enhances the

value class to have a proper null type and do comparisions SQL style so
that null is neither equal nor not equal to other things.
This commit is contained in:
Tom Hughes 2008-04-12 15:22:27 +00:00
parent a27bde741e
commit 4483d59797
5 changed files with 259 additions and 178 deletions

View file

@ -47,6 +47,11 @@ namespace boost { namespace python {
{ {
return ::PyUnicode_FromWideChar((wchar_t*)s.getBuffer(),implicit_cast<ssize_t>(s.length())); return ::PyUnicode_FromWideChar((wchar_t*)s.getBuffer(),implicit_cast<ssize_t>(s.length()));
} }
PyObject * operator() (mapnik::value_null const& s) const
{
return NULL;
}
}; };
struct mapnik_value_to_python struct mapnik_value_to_python

View file

@ -120,11 +120,6 @@ namespace mapnik {
return props_.end(); return props_.end();
} }
bool exists(const std::string &k) const
{
return props_.find(k) != props_.end();
}
std::string to_string() const std::string to_string() const
{ {
std::stringstream ss; std::stringstream ss;

View file

@ -39,7 +39,11 @@
namespace mapnik { namespace mapnik {
typedef boost::variant<bool,int,double,UnicodeString> value_base; struct value_null
{
};
typedef boost::variant<value_null,bool,int,double,UnicodeString> value_base;
namespace impl { namespace impl {
struct equals struct equals
@ -72,6 +76,60 @@ namespace mapnik {
{ {
return lhs == rhs; return lhs == rhs;
} }
bool operator() (value_null, value_null) const
{
return false;
}
};
struct not_equals
: public boost::static_visitor<bool>
{
template <typename T, typename U>
bool operator() (const T &, const U &) const
{
return true;
}
template <typename T>
bool operator() (T lhs, T rhs) const
{
return lhs != rhs;
}
bool operator() (int lhs, double rhs) const
{
return lhs != rhs;
}
bool operator() (double lhs, int rhs) const
{
return lhs != rhs;
}
bool operator() (UnicodeString const& lhs,
UnicodeString const& rhs) const
{
return lhs != rhs;
}
bool operator() (value_null, value_null) const
{
return false;
}
template <typename T>
bool operator() (value_null, const T &) const
{
return false;
}
template <typename T>
bool operator() (const T &, value_null) const
{
return false;
}
}; };
struct greater_than struct greater_than
@ -103,6 +161,11 @@ namespace mapnik {
{ {
return lhs > rhs; return lhs > rhs;
} }
bool operator() (value_null, value_null) const
{
return false;
}
}; };
struct greater_or_equal struct greater_or_equal
@ -134,6 +197,11 @@ namespace mapnik {
{ {
return lhs >= rhs; return lhs >= rhs;
} }
bool operator() (value_null, value_null) const
{
return false;
}
}; };
struct less_than struct less_than
@ -166,6 +234,11 @@ namespace mapnik {
{ {
return lhs < rhs; return lhs < rhs;
} }
bool operator() (value_null, value_null) const
{
return false;
}
}; };
struct less_or_equal struct less_or_equal
@ -199,6 +272,11 @@ namespace mapnik {
{ {
return lhs <= rhs; return lhs <= rhs;
} }
bool operator() (value_null, value_null) const
{
return false;
}
}; };
template <typename V> template <typename V>
@ -386,6 +464,11 @@ namespace mapnik {
ss << std::setprecision(16) << val; ss << std::setprecision(16) << val;
return ss.str(); return ss.str();
} }
std::string operator() (value_null const& val) const
{
return "";
}
}; };
struct to_unicode : public boost::static_visitor<UnicodeString> struct to_unicode : public boost::static_visitor<UnicodeString>
@ -411,6 +494,11 @@ namespace mapnik {
out << std::setprecision(16) << val; out << std::setprecision(16) << val;
return UnicodeString(out.str().c_str()); return UnicodeString(out.str().c_str());
} }
UnicodeString operator() (value_null const& val) const
{
return UnicodeString("");
}
}; };
struct to_expression_string : public boost::static_visitor<std::string> struct to_expression_string : public boost::static_visitor<std::string>
@ -455,6 +543,11 @@ namespace mapnik {
ss << std::setprecision(16) << val; ss << std::setprecision(16) << val;
return ss.str(); return ss.str();
} }
std::string operator() (value_null const& val) const
{
return "null";
}
}; };
} }
@ -468,7 +561,7 @@ namespace mapnik {
public: public:
value () value ()
: base_(0) {} : base_(value_null()) {}
template <typename T> value(T _val_) template <typename T> value(T _val_)
: base_(_val_) {} : base_(_val_) {}
@ -480,7 +573,7 @@ namespace mapnik {
bool operator!=(value const& other) const bool operator!=(value const& other) const
{ {
return !(boost::apply_visitor(impl::equals(),base_,other.base_)); return boost::apply_visitor(impl::not_equals(),base_,other.base_);
} }
bool operator>(value const& other) const bool operator>(value const& other) const

View file

@ -456,8 +456,6 @@ namespace mapnik
proj_transform const& prj_trans) proj_transform const& prj_trans)
{ {
typedef coord_transform2<CoordTransform,geometry2d> path_type; typedef coord_transform2<CoordTransform,geometry2d> path_type;
if (feature.exists(sym.get_name()))
{
UnicodeString text = feature[sym.get_name()].to_unicode(); UnicodeString text = feature[sym.get_name()].to_unicode();
boost::shared_ptr<ImageData32> const& data = sym.get_image(); boost::shared_ptr<ImageData32> const& data = sym.get_image();
if (text.length() > 0 && data) if (text.length() > 0 && data)
@ -507,7 +505,6 @@ namespace mapnik
} }
} }
} }
}
template <typename T> template <typename T>
void agg_renderer<T>::process(line_pattern_symbolizer const& sym, void agg_renderer<T>::process(line_pattern_symbolizer const& sym,
@ -669,8 +666,6 @@ namespace mapnik
{ {
typedef coord_transform2<CoordTransform,geometry2d> path_type; typedef coord_transform2<CoordTransform,geometry2d> path_type;
if (feature.exists(sym.get_name()))
{
UnicodeString text = feature[sym.get_name()].to_unicode(); UnicodeString text = feature[sym.get_name()].to_unicode();
if ( text.length() > 0 ) if ( text.length() > 0 )
{ {
@ -725,6 +720,5 @@ namespace mapnik
} }
} }
} }
}
template class agg_renderer<Image32>; template class agg_renderer<Image32>;
} }

View file

@ -750,8 +750,6 @@ namespace mapnik
{ {
typedef coord_transform2<CoordTransform,geometry2d> path_type; typedef coord_transform2<CoordTransform,geometry2d> path_type;
if (feature.exists(sym.get_name()))
{
UnicodeString text = feature[sym.get_name()].to_unicode(); UnicodeString text = feature[sym.get_name()].to_unicode();
boost::shared_ptr<ImageData32> const& data = sym.get_image(); boost::shared_ptr<ImageData32> const& data = sym.get_image();
@ -796,7 +794,6 @@ namespace mapnik
} }
} }
} }
}
template <typename T> template <typename T>
void cairo_renderer<T>::process(line_pattern_symbolizer const& sym, void cairo_renderer<T>::process(line_pattern_symbolizer const& sym,
@ -927,8 +924,6 @@ namespace mapnik
{ {
typedef coord_transform2<CoordTransform,geometry2d> path_type; typedef coord_transform2<CoordTransform,geometry2d> path_type;
if (feature.exists(sym.get_name()))
{
UnicodeString text = feature[sym.get_name()].to_unicode(); UnicodeString text = feature[sym.get_name()].to_unicode();
if (text.length() > 0) if (text.length() > 0)
@ -983,6 +978,5 @@ namespace mapnik
} }
} }
} }
}
template class cairo_renderer<Cairo::Surface>; template class cairo_renderer<Cairo::Surface>;
} }