Permalink
Browse files

+ simplify logic

+ cleanup c++ usage
  • Loading branch information...
1 parent 6efe571 commit eeb2cccfc17579e999a9bb8382f57d2d179dbb95 @artemp artemp committed Jul 12, 2012
Showing with 22 additions and 38 deletions.
  1. +13 −27 src/js_grid_utils.hpp
  2. +9 −11 src/mapnik_grid_view.cpp
View
@@ -200,23 +200,14 @@ static void write_features(T const& grid_type,
mapnik::feature_impl::iterator end = feature->end();
for ( ;itr!=end; ++itr)
{
- std::string feat_key_name = boost::get<0>(*itr);
- if (feat_key_name == key_name) {
- // drop key unless requested
- if (include_key) {
- found = true;
- feat->Set(String::NewSymbol(key_name.c_str()),
- boost::apply_visitor(node_mapnik::value_converter(),
- boost::get<1>(*itr).base()));
- }
- }
- // TODO - optimize
- else if ( (attributes.find(feat_key_name) != attributes.end()) )
+ std::string const& feat_key_name = boost::get<0>(*itr);
+ if (( feat_key_name == key_name && include_key ) // drop key unless requested
+ || attributes.find(feat_key_name) != attributes.end())
{
found = true;
feat->Set(String::NewSymbol(feat_key_name.c_str()),
- boost::apply_visitor(node_mapnik::value_converter(),
- boost::get<1>(*itr).base()));
+ boost::apply_visitor(node_mapnik::value_converter(),
+ boost::get<1>(*itr).base()));
}
}
@@ -345,8 +336,8 @@ static void grid2utf(T const& grid_type,
template <typename T>
static void write_features(T const& grid_type,
- Local<Object>& feature_data,
- std::vector<typename T::lookup_type> const& key_order)
+ Local<Object>& feature_data,
+ std::vector<typename T::lookup_type> const& key_order)
{
std::string const& key = grid_type.get_key(); // get_key();
std::set<std::string> const& attributes = grid_type.property_names();
@@ -358,35 +349,30 @@ static void write_features(T const& grid_type,
for (; feat_itr != feat_end; ++feat_itr)
{
std::map<std::string,mapnik::value> const& props = feat_itr->second;
- std::map<std::string,mapnik::value>::const_iterator const& itr = props.find(key);
+ std::map<std::string,mapnik::value>::const_iterator itr = props.find(key);
if (itr != props.end())
{
typename T::lookup_type const& join_value = itr->second.to_string();
// only serialize features visible in the grid
- if(std::find(key_order.begin(), key_order.end(), join_value) != key_order.end()) {
+ if(std::find(key_order.begin(), key_order.end(), join_value) != key_order.end())
+ {
Local<Object> feat = Object::New();
std::map<std::string,mapnik::value>::const_iterator it = props.begin();
std::map<std::string,mapnik::value>::const_iterator end = props.end();
bool found = false;
for (; it != end; ++it)
{
std::string const& key_name = it->first;
- if (key_name == key) {
- // drop join_field unless requested
- if (include_key) {
- found = true;
- params_to_object serializer( feat , it->first);
- boost::apply_visitor( serializer, it->second.base() );
- }
- }
- else if ( (attributes.find(key_name) != attributes.end()) )
+ if ((key_name == key && include_key) // drop join_field unless requested
+ || attributes.find(key_name) != attributes.end())
{
found = true;
params_to_object serializer( feat , it->first);
boost::apply_visitor( serializer, it->second.base() );
}
}
+
if (found)
{
feature_data->Set(String::NewSymbol(feat_itr->first.c_str()), feat);
View
@@ -103,8 +103,7 @@ Handle<Value> GridView::isSolid(const Arguments& args)
grid_view_ptr view = g->get();
if (view->width() > 0 && view->height() > 0)
{
- mapnik::grid_view::value_type const* first_row = view->getRow(0);
- mapnik::grid_view::value_type const first_pixel = first_row[0];
+ mapnik::grid_view::value_type first_pixel = view->getRow(0)[0];
for (unsigned y = 0; y < view->height(); ++y)
{
mapnik::grid_view::value_type const * row = view->getRow(y);
@@ -125,8 +124,8 @@ Handle<Value> GridView::getPixel(const Arguments& args)
HandleScope scope;
- unsigned x(0);
- unsigned y(0);
+ unsigned x = 0;
+ unsigned y = 0;
if (args.Length() >= 2) {
if (!args[0]->IsNumber())
@@ -146,8 +145,7 @@ Handle<Value> GridView::getPixel(const Arguments& args)
grid_view_ptr view = g->get();
if (x < view->width() && y < view->height())
{
- mapnik::grid_view::value_type const * row = view->getRow(y);
- mapnik::grid_view::value_type const pixel = row[x];
+ mapnik::grid_view::value_type pixel = view->getRow(y)[x];
return Integer::New(pixel);
}
return Undefined();
@@ -213,7 +211,7 @@ Handle<Value> GridView::encodeSync(const Arguments& args)
Local<Array> keys_a = Array::New(key_order.size());
std::vector<std::string>::iterator it;
unsigned int i;
- for (it = key_order.begin(), i = 0; it < key_order.end(); ++it, ++i)
+ for (it = key_order.begin(), i = 0; it != key_order.end(); ++it, ++i)
{
keys_a->Set(i, String::New((*it).c_str()));
}
@@ -372,7 +370,7 @@ void GridView::EIO_AfterEncode(uv_work_t* req)
Local<Array> keys_a = Array::New(closure->key_order.size());
std::vector<std::string>::iterator it;
unsigned int i;
- for (it = closure->key_order.begin(), i = 0; it < closure->key_order.end(); ++it, ++i)
+ for (it = closure->key_order.begin(), i = 0; it != closure->key_order.end(); ++it, ++i)
{
keys_a->Set(i, String::New((*it).c_str()));
}
@@ -473,7 +471,7 @@ Handle<Value> GridView::encodeSync(const Arguments& args)
Local<Array> keys_a = Array::New(key_order.size());
std::vector<std::string>::iterator it;
unsigned int i;
- for (it = key_order.begin(), i = 0; it < key_order.end(); ++it, ++i)
+ for (it = key_order.begin(), i = 0; it != key_order.end(); ++it, ++i)
{
keys_a->Set(i, String::New((*it).c_str()));
}
@@ -567,7 +565,7 @@ Handle<Value> GridView::encode(const Arguments& args)
Local<Array> keys_a = Array::New(key_order.size());
std::vector<std::string>::iterator it;
unsigned int i;
- for (it = key_order.begin(), i = 0; it < key_order.end(); ++it, ++i)
+ for (it = key_order.begin(), i = 0; it != key_order.end(); ++it, ++i)
{
keys_a->Set(i, String::New((*it).c_str()));
}
@@ -603,4 +601,4 @@ Handle<Value> GridView::encode(const Arguments& args)
return scope.Close(Undefined());
}
-#endif
+#endif

0 comments on commit eeb2ccc

Please sign in to comment.