Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

cpp coding style cleanups

  • Loading branch information...
commit 3a029356a5619b55f8f48df5877ecd92a5db49f9 1 parent 0f1386a
@springmeyer springmeyer authored
Showing with 944 additions and 1,072 deletions.
  1. +1 −0  .gitignore
  2. +4 −0 Makefile
  3. +50 −175 src/ds_emitter.hpp
  4. +9 −9 src/js_grid_utils.hpp
  5. +2 −2 src/mapnik_.cpp
  6. +2 −2 src/mapnik_.hpp
  7. +18 −18 src/mapnik_color.cpp
  8. +3 −3 src/mapnik_color.hpp
  9. +24 −24 src/mapnik_datasource.cpp
  10. +2 −2 src/mapnik_datasource.hpp
  11. +9 −9 src/mapnik_expression.cpp
  12. +2 −2 src/mapnik_expression.hpp
  13. +20 −20 src/mapnik_feature.cpp
  14. +2 −2 src/mapnik_feature.hpp
  15. +7 −7 src/mapnik_featureset.cpp
  16. +3 −3 src/mapnik_featureset.hpp
  17. +17 −17 src/mapnik_fonts.hpp
  18. +10 −10 src/mapnik_geometry.cpp
  19. +2 −2 src/mapnik_geometry.hpp
  20. +66 −67 src/mapnik_grid.cpp
  21. +3 −3 src/mapnik_grid.hpp
  22. +54 −55 src/mapnik_grid_view.cpp
  23. +3 −3 src/mapnik_grid_view.hpp
  24. +78 −87 src/mapnik_image.cpp
  25. +3 −3 src/mapnik_image.hpp
  26. +52 −61 src/mapnik_image_view.cpp
  27. +3 −3 src/mapnik_image_view.hpp
  28. +12 −12 src/mapnik_js_datasource.cpp
  29. +2 −2 src/mapnik_js_datasource.hpp
  30. +15 −15 src/mapnik_layer.cpp
  31. +4 −4 src/mapnik_layer.hpp
  32. +180 −187 src/mapnik_map.cpp
  33. +4 −4 src/mapnik_map.hpp
  34. +16 −16 src/mapnik_memory_datasource.cpp
  35. +2 −2 src/mapnik_memory_datasource.hpp
  36. +3 −3 src/mapnik_palette.cpp
  37. +2 −2 src/mapnik_palette.hpp
  38. +2 −2 src/mapnik_plugins.hpp
  39. +106 −106 src/mapnik_projection.cpp
  40. +2 −2 src/mapnik_projection.hpp
  41. +2 −2 src/mapnik_query.cpp
  42. +2 −2 src/mapnik_query.hpp
  43. +16 −16 src/mem_datasource.hpp
  44. +94 −94 src/node_mapnik.cpp
  45. +12 −12 src/utils.hpp
  46. +12 −0 tools/cpp.el
  47. +7 −0 tools/fix_cpp_style.sh
View
1  .gitignore
@@ -9,3 +9,4 @@ test/tmp
lib/_mapnik.node
lib/mapnik_settings.js
node_modules/
+src/*.*~
View
4 Makefile
@@ -44,6 +44,10 @@ endif
fix:
@fixjsstyle lib/*js bin/*js test/*js examples/*/*.js examples/*/*/*.js
+fixc:
+ @tools/fix_cpp_style.sh
+ @rm src/*.*~
+
lint:
@./node_modules/.bin/jshint lib/*js bin/*js test/*js examples/*/*.js examples/*/*/*.js
View
225 src/ds_emitter.hpp
@@ -23,15 +23,15 @@ static void describe_datasource(Local<Object> description, mapnik::datasource_pt
{
// todo collect active attributes in styles
/*
- std::vector<std::string> const& style_names = layer.styles();
- Local<Array> s = Array::New(style_names.size());
- for (unsigned i = 0; i < style_names.size(); ++i)
- {
- s->Set(i, String::New(style_names[i].c_str()) );
- }
- meta->Set(String::NewSymbol("styles"), s );
+ std::vector<std::string> const& style_names = layer.styles();
+ Local<Array> s = Array::New(style_names.size());
+ for (unsigned i = 0; i < style_names.size(); ++i)
+ {
+ s->Set(i, String::New(style_names[i].c_str()) );
+ }
+ meta->Set(String::NewSymbol("styles"), s );
*/
-
+
// type
if (ds->type() == mapnik::datasource::Raster)
{
@@ -41,7 +41,7 @@ static void describe_datasource(Local<Object> description, mapnik::datasource_pt
{
description->Set(String::NewSymbol("type"), String::New("vector"));
}
-
+
// extent
Local<Array> a = Array::New(4);
mapnik::box2d<double> e = ds->envelope();
@@ -50,12 +50,12 @@ static void describe_datasource(Local<Object> description, mapnik::datasource_pt
a->Set(2, Number::New(e.maxx()));
a->Set(3, Number::New(e.maxy()));
description->Set(String::NewSymbol("extent"), a);
-
+
mapnik::layer_descriptor ld = ds->get_descriptor();
-
+
// encoding
description->Set(String::NewSymbol("encoding"), String::New(ld.get_encoding().c_str()));
-
+
// field names and types
Local<Object> fields = Object::New();
std::vector<mapnik::attribute_descriptor> const& desc = ld.get_descriptors();
@@ -77,20 +77,20 @@ static void describe_datasource(Local<Object> description, mapnik::datasource_pt
++itr;
}
description->Set(String::NewSymbol("fields"), fields);
-
+
mapnik::query q(ds->envelope());
mapnik::featureset_ptr fs = ds->features(q);
description->Set(String::NewSymbol("geometry_type"), Undefined());
description->Set(String::NewSymbol("has_features"), False());
-
+
// TODO - need to remove this after this lands:
// https://github.com/mapnik/mapnik/issues/701
if (fs)
{
mapnik::feature_ptr fp = fs->next();
if (fp) {
-
+
description->Set(String::NewSymbol("has_features"), True());
if (fp->num_geometries() > 0)
{
@@ -99,37 +99,37 @@ static void describe_datasource(Local<Object> description, mapnik::datasource_pt
Local<String> js_type = String::New("unknown");
switch (g_type)
{
- case mapnik::Point:
- {
- if (fp->num_geometries() > 1) {
- js_type = String::New("multipoint");
- } else {
- js_type = String::New("point");
- }
- break;
- }
- case mapnik::Polygon:
- {
- if (fp->num_geometries() > 1) {
- js_type = String::New("multipolygon");
- } else {
- js_type = String::New("polygon");
- }
- break;
+ case mapnik::Point:
+ {
+ if (fp->num_geometries() > 1) {
+ js_type = String::New("multipoint");
+ } else {
+ js_type = String::New("point");
}
- case mapnik::LineString:
- {
- if (fp->num_geometries() > 1) {
- js_type = String::New("multilinestring");
- } else {
- js_type = String::New("linestring");
- }
- break;
+ break;
+ }
+ case mapnik::Polygon:
+ {
+ if (fp->num_geometries() > 1) {
+ js_type = String::New("multipolygon");
+ } else {
+ js_type = String::New("polygon");
}
- default:
- {
- break;
+ break;
+ }
+ case mapnik::LineString:
+ {
+ if (fp->num_geometries() > 1) {
+ js_type = String::New("multilinestring");
+ } else {
+ js_type = String::New("linestring");
}
+ break;
+ }
+ default:
+ {
+ break;
+ }
}
description->Set(String::NewSymbol("geometry_type"), js_type);
}
@@ -139,12 +139,12 @@ static void describe_datasource(Local<Object> description, mapnik::datasource_pt
catch (const std::exception & ex)
{
ThrowException(Exception::Error(
- String::New(ex.what())));
+ String::New(ex.what())));
}
catch (...)
{
ThrowException(Exception::Error(
- String::New("unknown exception happened when calling describe_datasource, please file bug")));
+ String::New("unknown exception happened when calling describe_datasource, please file bug")));
}
}
@@ -154,12 +154,7 @@ static void datasource_features(Local<Array> a, mapnik::datasource_ptr ds, unsig
try
{
- #if MAPNIK_VERSION >= 800
mapnik::query q(ds->envelope());
- #else
- mapnik::query q(ds->envelope(),1.0,1.0);
- #endif
-
mapnik::layer_descriptor ld = ds->get_descriptor();
std::vector<mapnik::attribute_descriptor> const& desc = ld.get_descriptors();
std::vector<mapnik::attribute_descriptor>::const_iterator itr = desc.begin();
@@ -169,7 +164,7 @@ static void datasource_features(Local<Array> a, mapnik::datasource_ptr ds, unsig
q.add_property_name(itr->get_name());
++itr;
}
-
+
mapnik::featureset_ptr fs = ds->features(q);
if (fs)
{
@@ -188,10 +183,10 @@ static void datasource_features(Local<Array> a, mapnik::datasource_ptr ds, unsig
// not a mapnik::value_holder
boost::apply_visitor( serializer, boost::get<1>(*itr).base() );
}
-
+
// add feature id
feat->Set(String::NewSymbol("__id__"), Integer::New(fp->id()));
-
+
a->Set(idx, feat);
}
++idx;
@@ -201,136 +196,16 @@ static void datasource_features(Local<Array> a, mapnik::datasource_ptr ds, unsig
catch (const std::exception & ex)
{
ThrowException(Exception::Error(
- String::New(ex.what())));
+ String::New(ex.what())));
}
catch (...)
{
ThrowException(Exception::Error(
- String::New("unknown exception happened when calling datasource_features, please file bug")));
+ String::New("unknown exception happened when calling datasource_features, please file bug")));
}
}
-/*
-// start, limit
-static void datasource_stats(Local<Object> stats, mapnik::datasource_ptr ds, unsigned first, unsigned last)
-{
- // TODO
- // for strings, collect first 15 unique
- // allow options to specific which fields
-
-#if MAPNIK_VERSION >= 800
- mapnik::query q(ds->envelope());
-#else
- mapnik::query q(ds->envelope(),1.0,1.0);
-#endif
-
- mapnik::layer_descriptor ld = ds->get_descriptor();
- std::vector<mapnik::attribute_descriptor> const& desc = ld.get_descriptors();
- Local<Object> fields = Object::New();
- std::vector<mapnik::attribute_descriptor>::const_iterator itr = desc.begin();
- std::vector<mapnik::attribute_descriptor>::const_iterator end = desc.end();
- unsigned int size = 0;
- typedef std::vector<mapnik::value> vals;
- std::map<std::string, vals > values;
- //Local<Object> values = Object::New();
- while (itr != end)
- {
- q.add_property_name(itr->get_name());
- Local<Object> field_hash = Object::New();
- int field_type = itr->get_type();
- std::string type("");
- if (field_type == 1) type = "Number";
- else if (field_type == 2) type = "Number";
- else if (field_type == 3) type = "Number";
- else if (field_type == 4) type = "String";
- else if (field_type == 5) type = "Geometry";
- else if (field_type == 6) type = "Mapnik Object";
- field_hash->Set(String::NewSymbol("type"),String::New(type.c_str()));
- fields->Set(String::NewSymbol(itr->get_name().c_str()),field_hash);
- //values->Set(String::NewSymbol(itr->get_name().c_str()),Local<Array>::New());
- ++itr;
- ++size;
- }
- stats->Set(String::NewSymbol("fields"), fields);
-
- // todo - ability to get mapnik features without also parseing geometries
- mapnik::featureset_ptr fs = ds->features(q);
- unsigned idx = 0;
- if (fs)
- {
- mapnik::feature_ptr fp;
- typedef std::map<std::string,mapnik::value> properties;
- properties min_prop;
- properties max_prop;
- first = true;
- while ((fp = fs->next()))
- {
- ++idx;
- properties const& fprops = fp->props();
- properties::const_iterator it;
- properties::const_iterator end;
- if (first){
- first = false;
- it = fprops.begin();
- end = fprops.end();
- for (; it != end; ++it)
- {
- min_prop[it->first] = it->second;
- max_prop[it->first] = it->second;
- vals& v = values[it->first];
- if(std::find(v.begin(), v.end(), it->second) == v.end()) {
- v.push_back(it->second);
- }
- }
- }
- else
- {
- it = fprops.begin();
- end = fprops.end();
- for (; it != end; ++it)
- {
- vals& v = values[it->first];
- if(std::find(v.begin(), v.end(), it->second) == v.end()) {
- v.push_back(it->second);
- if (it->second > max_prop[it->first])
- max_prop[it->first] = it->second;
-
- if (it->second < min_prop[it->first])
- min_prop[it->first] = it->second;
- }
- }
- }
- }
-
- Local<Array> names = fields->GetPropertyNames();
- uint32_t i = 0;
- uint32_t a_length = names->Length();
- while (i < a_length) {
- Local<Value> name = names->Get(i)->ToString();
- Local<Object> hash = fields->Get(name)->ToObject();
- std::string key = TOSTR(name);
- node_mapnik::params_to_object serializer_min(hash, "min");
- boost::apply_visitor( serializer_min, min_prop[key].base() );
- node_mapnik::params_to_object serializer_max(hash, "max");
- boost::apply_visitor( serializer_max, max_prop[key].base() );
- vals& v = values[key];
- unsigned int num_vals = v.size();
- Local<Array> a = Array::New(num_vals);
- for (unsigned j = 0; j < num_vals; ++j)
- {
- a->Set(j, boost::apply_visitor(value_converter(),v[j].base()) );
- }
- hash->Set(String::NewSymbol("values"),a);
- i++;
- }
-
- }
-
- stats->Set(String::NewSymbol("count"), Number::New(idx));
-}
-*/
-
}
#endif
View
18 src/js_grid_utils.hpp
@@ -15,9 +15,9 @@ using namespace node;
namespace node_mapnik {
template <typename T, typename ArrayType>
-static void grid2utf(T const& grid_type,
- ArrayType const& l,
- std::vector<typename T::lookup_type>& key_order)
+static void grid2utf(T const& grid_type,
+ ArrayType const& l,
+ std::vector<typename T::lookup_type>& key_order)
{
typename T::data_type const& data = grid_type.data();
typename T::feature_key_type const& feature_keys = grid_type.get_feature_keys();
@@ -67,10 +67,10 @@ static void grid2utf(T const& grid_type,
// requires mapnik >= r2957
template <typename T, typename ArrayType>
-static void grid2utf(T const& grid_type,
- ArrayType const& l,
- std::vector<typename T::lookup_type>& key_order,
- unsigned int resolution)
+static void grid2utf(T const& grid_type,
+ ArrayType const& l,
+ std::vector<typename T::lookup_type>& key_order,
+ unsigned int resolution)
{
typename T::feature_key_type const& feature_keys = grid_type.get_feature_keys();
typename T::key_type keys;
@@ -120,8 +120,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();
std::set<std::string> const& attributes = grid_type.property_names();
View
4 src/mapnik_.cpp
@@ -17,8 +17,8 @@ void •::Initialize(Handle<Object> target) {
}
•::•(std::string const& name) :
- ObjectWrap(),
- this_(boost::make_shared<mapnik::•>(name)) {}
+ObjectWrap(),
+ this_(boost::make_shared<mapnik::•>(name)) {}
•::~•()
{
View
4 src/mapnik_.hpp
@@ -17,7 +17,7 @@ using namespace node;
typedef boost::shared_ptr<mapnik::•> •_ptr;
class •: public node::ObjectWrap {
- public:
+public:
static Persistent<FunctionTemplate> constructor;
static void Initialize(Handle<Object> target);
static Handle<Value> New(const Arguments &args);
@@ -25,7 +25,7 @@ class •: public node::ObjectWrap {
•(std::string const& name);
•(std::string const& name, std::string const& srs);
- private:
+private:
~•();
•_ptr this_;
};
View
36 src/mapnik_color.cpp
@@ -25,14 +25,14 @@ void Color::Initialize(Handle<Object> target) {
ATTR(constructor, "g", get_prop, set_prop);
ATTR(constructor, "b", get_prop, set_prop);
ATTR(constructor, "a", get_prop, set_prop);
-
+
target->Set(String::NewSymbol("Color"),constructor->GetFunction());
}
Color::Color() :
- ObjectWrap(),
- this_() {}
+ ObjectWrap(),
+ this_() {}
Color::~Color()
{
@@ -57,20 +57,20 @@ Handle<Value> Color::New(const Arguments& args)
color_ptr c_p;
try
{
-
+
if (args.Length() == 1 && args[0]->IsString()){
-
+
c_p = boost::make_shared<mapnik::color>(TOSTR(args[0]));
-
+
} else if (args.Length() == 3) {
int r = args[0]->IntegerValue();
int g = args[1]->IntegerValue();
int b = args[2]->IntegerValue();
c_p = boost::make_shared<mapnik::color>(r,g,b);
-
+
} else if (args.Length() == 4) {
-
+
int r = args[0]->IntegerValue();
int g = args[1]->IntegerValue();
int b = args[2]->IntegerValue();
@@ -78,9 +78,9 @@ Handle<Value> Color::New(const Arguments& args)
c_p = boost::make_shared<mapnik::color>(r,g,b,a);
} else {
return ThrowException(Exception::Error(
- String::New("invalid arguments: colors can be created from a string, integer r,g,b values, or integer r,g,b,a values")));
+ String::New("invalid arguments: colors can be created from a string, integer r,g,b values, or integer r,g,b,a values")));
+
-
}
// todo allow int,int,int and int,int,int,int contructor
@@ -88,12 +88,12 @@ Handle<Value> Color::New(const Arguments& args)
catch (const std::exception & ex)
{
return ThrowException(Exception::Error(
- String::New(ex.what())));
+ String::New(ex.what())));
}
catch (...)
{
return ThrowException(Exception::Error(
- String::New("unknown exception happened, please file bug")));
+ String::New("unknown exception happened, please file bug")));
}
if (c_p)
@@ -106,7 +106,7 @@ Handle<Value> Color::New(const Arguments& args)
else
{
return ThrowException(Exception::Error(
- String::New("unknown exception happened, please file bug")));
+ String::New("unknown exception happened, please file bug")));
}
return Undefined();
@@ -123,7 +123,7 @@ Handle<Value> Color::New(mapnik::color const& color) {
Handle<Value> Color::get_prop(Local<String> property,
- const AccessorInfo& info)
+ const AccessorInfo& info)
{
HandleScope scope;
Color* c = ObjectWrap::Unwrap<Color>(info.This());
@@ -135,20 +135,20 @@ Handle<Value> Color::get_prop(Local<String> property,
else if (a == "g")
return scope.Close(Integer::New(c->get()->green()));
else if (a == "b")
- return scope.Close(Integer::New(c->get()->blue()));
+ return scope.Close(Integer::New(c->get()->blue()));
return Undefined();
}
void Color::set_prop(Local<String> property,
- Local<Value> value,
- const AccessorInfo& info)
+ Local<Value> value,
+ const AccessorInfo& info)
{
HandleScope scope;
Color* c = ObjectWrap::Unwrap<Color>(info.This());
std::string a = TOSTR(property);
if (!value->IsNumber())
ThrowException(Exception::TypeError(
- String::New("color channel value must be an integer")));
+ String::New("color channel value must be an integer")));
if (a == "a") {
c->get()->set_alpha(value->IntegerValue());
} else if (a == "r") {
View
6 src/mapnik_color.hpp
@@ -17,7 +17,7 @@ using namespace node;
typedef boost::shared_ptr<mapnik::color> color_ptr;
class Color: public node::ObjectWrap {
- public:
+public:
static Persistent<FunctionTemplate> constructor;
static void Initialize(Handle<Object> target);
static Handle<Value> New(const Arguments &args);
@@ -26,14 +26,14 @@ class Color: public node::ObjectWrap {
static Handle<Value> hex(const Arguments &args);
static Handle<Value> get_prop(Local<String> property,
- const AccessorInfo& info);
+ const AccessorInfo& info);
static void set_prop(Local<String> property,
Local<Value> value,
const AccessorInfo& info);
Color();
inline color_ptr get() { return this_; }
- private:
+private:
~Color();
color_ptr this_;
};
View
48 src/mapnik_datasource.cpp
@@ -29,8 +29,8 @@ void Datasource::Initialize(Handle<Object> target) {
}
Datasource::Datasource() :
- ObjectWrap(),
- datasource_() {}
+ ObjectWrap(),
+ datasource_() {}
Datasource::~Datasource()
{
@@ -52,26 +52,26 @@ Handle<Value> Datasource::New(const Arguments& args)
if (d->datasource_->type() == mapnik::datasource::Raster)
{
args.This()->Set(String::NewSymbol("type"),
- String::NewSymbol("raster"),
- static_cast<v8::PropertyAttribute>(v8::ReadOnly|v8::DontDelete));
+ String::NewSymbol("raster"),
+ static_cast<v8::PropertyAttribute>(v8::ReadOnly|v8::DontDelete));
}
else
{
args.This()->Set(String::NewSymbol("type"),
- String::NewSymbol("vector"),
- static_cast<v8::PropertyAttribute>(v8::ReadOnly|v8::DontDelete));
+ String::NewSymbol("vector"),
+ static_cast<v8::PropertyAttribute>(v8::ReadOnly|v8::DontDelete));
}
d->Wrap(args.This());
return args.This();
}
if (!args.Length() == 1){
return ThrowException(Exception::TypeError(
- String::New("accepts only one argument, an object of key:value datasource options")));
+ String::New("accepts only one argument, an object of key:value datasource options")));
}
if (!args[0]->IsObject())
return ThrowException(Exception::TypeError(
- String::New("Must provide an object, eg {type: 'shape', file : 'world.shp'}")));
+ String::New("Must provide an object, eg {type: 'shape', file : 'world.shp'}")));
Local<Object> options = args[0]->ToObject();
@@ -82,8 +82,8 @@ Handle<Value> Datasource::New(const Arguments& args)
{
Local<Value> bind_opt = options->Get(String::New("bind"));
if (!bind_opt->IsBoolean())
- return ThrowException(Exception::TypeError(
- String::New("'bind' must be a Boolean")));
+ return ThrowException(Exception::TypeError(
+ String::New("'bind' must be a Boolean")));
bind = bind_opt->BooleanValue();
}
@@ -108,26 +108,26 @@ Handle<Value> Datasource::New(const Arguments& args)
catch (const std::exception & ex)
{
return ThrowException(Exception::Error(
- String::New(ex.what())));
+ String::New(ex.what())));
}
catch (...)
{
return ThrowException(Exception::Error(
- String::New("unknown exception happened, please file bug")));
+ String::New("unknown exception happened, please file bug")));
}
if (ds)
{
if (ds->type() == mapnik::datasource::Raster)
{
args.This()->Set(String::NewSymbol("type"),
- String::NewSymbol("raster"),
- static_cast<v8::PropertyAttribute>(v8::ReadOnly|v8::DontDelete));
+ String::NewSymbol("raster"),
+ static_cast<v8::PropertyAttribute>(v8::ReadOnly|v8::DontDelete));
}
else
{
args.This()->Set(String::NewSymbol("type"),
- String::NewSymbol("vector"),
- static_cast<v8::PropertyAttribute>(v8::ReadOnly|v8::DontDelete));
+ String::NewSymbol("vector"),
+ static_cast<v8::PropertyAttribute>(v8::ReadOnly|v8::DontDelete));
}
Datasource* d = new Datasource();
d->Wrap(args.This());
@@ -173,12 +173,12 @@ Handle<Value> Datasource::describe(const Arguments& args)
catch (const std::exception & ex )
{
return ThrowException(Exception::Error(
- String::New(ex.what())));
+ String::New(ex.what())));
}
catch (...)
{
return ThrowException(Exception::Error(
- String::New("unknown exception happened describing datasource, please file bug")));
+ String::New("unknown exception happened describing datasource, please file bug")));
}
return scope.Close(description);
@@ -196,7 +196,7 @@ Handle<Value> Datasource::features(const Arguments& args)
{
if (!args[0]->IsNumber() || !args[1]->IsNumber())
return ThrowException(Exception::Error(
- String::New("Index of 'first' and 'last' feature must be an integer")));
+ String::New("Index of 'first' and 'last' feature must be an integer")));
first = args[0]->IntegerValue();
last = args[1]->IntegerValue();
}
@@ -212,12 +212,12 @@ Handle<Value> Datasource::features(const Arguments& args)
catch (const std::exception & ex )
{
return ThrowException(Exception::Error(
- String::New(ex.what())));
+ String::New(ex.what())));
}
catch (...)
{
return ThrowException(Exception::Error(
- String::New("unknown exception happened slicing datasource, please file bug")));
+ String::New("unknown exception happened slicing datasource, please file bug")));
}
return scope.Close(a);
@@ -243,18 +243,18 @@ Handle<Value> Datasource::featureset(const Arguments& args)
q.add_property_name(itr->get_name());
++itr;
}
-
+
fs = ds->datasource_->features(q);
}
catch (const std::exception & ex)
{
return ThrowException(Exception::Error(
- String::New(ex.what())));
+ String::New(ex.what())));
}
catch (...)
{
return ThrowException(Exception::Error(
- String::New("unknown exception happened getting featureset, please file bug")));
+ String::New("unknown exception happened getting featureset, please file bug")));
}
if (fs)
View
4 src/mapnik_datasource.hpp
@@ -11,7 +11,7 @@ using namespace v8;
using namespace node;
class Datasource: public node::ObjectWrap {
- public:
+public:
static Persistent<FunctionTemplate> constructor;
static void Initialize(Handle<Object> target);
static Handle<Value> New(const Arguments &args);
@@ -25,7 +25,7 @@ class Datasource: public node::ObjectWrap {
Datasource();
inline mapnik::datasource_ptr get() { return datasource_; }
- private:
+private:
~Datasource();
mapnik::datasource_ptr datasource_;
};
View
18 src/mapnik_expression.cpp
@@ -22,8 +22,8 @@ void Expression::Initialize(Handle<Object> target) {
}
Expression::Expression() :
- ObjectWrap(),
- this_() {}
+ ObjectWrap(),
+ this_() {}
Expression::~Expression()
{
@@ -50,21 +50,21 @@ Handle<Value> Expression::New(const Arguments& args)
{
if (args.Length() == 1 && args[0]->IsString()){
e_ptr = mapnik::parse_expression(TOSTR(args[0]),"utf8");
-
+
} else {
return ThrowException(Exception::Error(
- String::New("invalid arguments: accepts a single argument of string type")));
+ String::New("invalid arguments: accepts a single argument of string type")));
}
}
catch (const std::exception & ex)
{
return ThrowException(Exception::Error(
- String::New(ex.what())));
+ String::New(ex.what())));
}
catch (...)
{
return ThrowException(Exception::Error(
- String::New("unknown exception happened, please file bug")));
+ String::New("unknown exception happened, please file bug")));
}
if (e_ptr)
@@ -77,7 +77,7 @@ Handle<Value> Expression::New(const Arguments& args)
else
{
return ThrowException(Exception::Error(
- String::New("unknown exception happened, please file bug")));
+ String::New("unknown exception happened, please file bug")));
}
return Undefined();
@@ -97,7 +97,7 @@ Handle<Value> Expression::evaluate(const Arguments& args)
if (!args.Length() > 0) {
return ThrowException(Exception::Error(
- String::New("requires a mapnik.Feature as an argument")));
+ String::New("requires a mapnik.Feature as an argument")));
}
Local<Object> obj = args[0]->ToObject();
@@ -114,4 +114,4 @@ Handle<Value> Expression::evaluate(const Arguments& args)
Expression* e = ObjectWrap::Unwrap<Expression>(args.This());
mapnik::value value_obj = boost::apply_visitor(mapnik::evaluate<mapnik::Feature,mapnik::value>(*(f->get())),*(e->get()));
return scope.Close(boost::apply_visitor(node_mapnik::value_converter(),value_obj.base()));
-}
+}
View
4 src/mapnik_expression.hpp
@@ -19,7 +19,7 @@ using namespace v8;
using namespace node;
class Expression: public node::ObjectWrap {
- public:
+public:
static Persistent<FunctionTemplate> constructor;
static void Initialize(Handle<Object> target);
static Handle<Value> New(const Arguments &args);
@@ -29,7 +29,7 @@ class Expression: public node::ObjectWrap {
Expression();
inline mapnik::expression_ptr get() { return this_; }
- private:
+private:
~Expression();
mapnik::expression_ptr this_;
};
View
40 src/mapnik_feature.cpp
@@ -22,7 +22,7 @@ void Feature::Initialize(Handle<Object> target) {
constructor = Persistent<FunctionTemplate>::New(FunctionTemplate::New(Feature::New));
constructor->InstanceTemplate()->SetInternalFieldCount(1);
constructor->SetClassName(String::NewSymbol("Feature"));
-
+
NODE_SET_PROTOTYPE_METHOD(constructor, "id", id);
NODE_SET_PROTOTYPE_METHOD(constructor, "extent", extent);
NODE_SET_PROTOTYPE_METHOD(constructor, "attributes", attributes);
@@ -35,16 +35,16 @@ void Feature::Initialize(Handle<Object> target) {
}
Feature::Feature(mapnik::feature_ptr f) :
- ObjectWrap(),
- this_(f) {}
+ ObjectWrap(),
+ this_(f) {}
Feature::Feature(int id) :
- ObjectWrap(),
- this_() {
+ ObjectWrap(),
+ this_() {
// TODO - accept/require context object to reused
ctx_ = boost::make_shared<mapnik::context_type>();
this_ = mapnik::feature_factory::create(ctx_,id);
- }
+}
Feature::~Feature()
{
@@ -67,12 +67,12 @@ Handle<Value> Feature::New(const Arguments& args)
}
// TODO - expose mapnik.Context
-
+
if (args.Length() > 1 || args.Length() < 1 || !args[0]->IsNumber()) {
return ThrowException(Exception::TypeError(
- String::New("requires one argument: an integer feature id")));
+ String::New("requires one argument: an integer feature id")));
}
-
+
Feature* f = new Feature(args[0]->IntegerValue());
f->Wrap(args.This());
return args.This();
@@ -108,7 +108,7 @@ Handle<Value> Feature::extent(const Arguments& args)
a->Set(1, Number::New(e.miny()));
a->Set(2, Number::New(e.maxx()));
a->Set(3, Number::New(e.maxy()));
-
+
return scope.Close(a);
}
@@ -117,7 +117,7 @@ Handle<Value> Feature::attributes(const Arguments& args)
HandleScope scope;
Feature* fp = ObjectWrap::Unwrap<Feature>(args.This());
-
+
Local<Object> feat = Object::New();
mapnik::feature_ptr feature = fp->get();
@@ -128,7 +128,7 @@ Handle<Value> Feature::attributes(const Arguments& args)
node_mapnik::params_to_object serializer( feat , boost::get<0>(*itr));
boost::apply_visitor( serializer, boost::get<1>(*itr).base() );
}
-
+
return scope.Close(feat);
}
@@ -154,7 +154,7 @@ Handle<Value> Feature::addGeometry(const Arguments& args)
Local<Object> obj = value->ToObject();
if (Geometry::constructor->HasInstance(obj)) {
Geometry* g = ObjectWrap::Unwrap<Geometry>(obj);
-
+
try
{
std::auto_ptr<mapnik::geometry_type> geom_ptr = g->get();
@@ -163,17 +163,17 @@ Handle<Value> Feature::addGeometry(const Arguments& args)
geom_ptr.release();
} else {
return ThrowException(Exception::Error(
- String::New("empty geometry!")));
+ String::New("empty geometry!")));
}
}
catch (const std::exception & ex )
{
return ThrowException(Exception::Error(
- String::New(ex.what())));
+ String::New(ex.what())));
}
catch (...) {
return ThrowException(Exception::Error(
- String::New("Unknown exception happended - please report bug")));
+ String::New("Unknown exception happended - please report bug")));
}
}
}
@@ -225,11 +225,11 @@ Handle<Value> Feature::addAttributes(const Arguments& args)
catch (const std::exception & ex )
{
return ThrowException(Exception::Error(
- String::New(ex.what())));
+ String::New(ex.what())));
}
catch (...) {
return ThrowException(Exception::Error(
- String::New("Unknown exception happended - please report bug")));
+ String::New("Unknown exception happended - please report bug")));
}
}
}
@@ -256,11 +256,11 @@ Handle<Value> Feature::toJSON(const Arguments& args)
if (!generator.generate(json,*(fp->get())))
{
return ThrowException(Exception::Error(
- String::New("Failed to generate GeoJSON")));
+ String::New("Failed to generate GeoJSON")));
}
#else
return ThrowException(Exception::Error(
- String::New("GeoJSON output requires at least boost 1.47 ")));
+ String::New("GeoJSON output requires at least boost 1.47 ")));
#endif
return scope.Close(String::New(json.c_str()));
View
4 src/mapnik_feature.hpp
@@ -17,7 +17,7 @@ using namespace node;
class Feature: public node::ObjectWrap {
- public:
+public:
static Persistent<FunctionTemplate> constructor;
static void Initialize(Handle<Object> target);
static Handle<Value> New(const Arguments &args);
@@ -38,7 +38,7 @@ class Feature: public node::ObjectWrap {
Feature(int id);
inline mapnik::feature_ptr get() { return this_; }
- private:
+private:
~Feature();
mapnik::feature_ptr this_;
mapnik::context_ptr ctx_;
View
14 src/mapnik_featureset.cpp
@@ -18,8 +18,8 @@ void Featureset::Initialize(Handle<Object> target) {
}
Featureset::Featureset() :
- ObjectWrap(),
- this_() {}
+ ObjectWrap(),
+ this_() {}
Featureset::~Featureset()
{
@@ -42,30 +42,30 @@ Handle<Value> Featureset::New(const Arguments& args)
}
return ThrowException(Exception::TypeError(
- String::New("Sorry a Featureset cannot currently be created, only accessed via an existing datasource")));
+ String::New("Sorry a Featureset cannot currently be created, only accessed via an existing datasource")));
}
Handle<Value> Featureset::next(const Arguments& args)
{
HandleScope scope;
-
+
Featureset* fs = ObjectWrap::Unwrap<Featureset>(args.This());
if (fs->this_) {
mapnik::feature_ptr fp;
try
{
- fp = fs->this_->next();
+ fp = fs->this_->next();
}
catch (const std::exception & ex)
{
return ThrowException(Exception::Error(
- String::New(ex.what())));
+ String::New(ex.what())));
}
catch (...)
{
return ThrowException(Exception::Error(
- String::New("unknown exception happened when accessing a feature with next(), please file bug")));
+ String::New("unknown exception happened when accessing a feature with next(), please file bug")));
}
if (fp) {
return scope.Close(Feature::New(fp));
View
6 src/mapnik_featureset.hpp
@@ -12,16 +12,16 @@ using namespace node;
typedef mapnik::featureset_ptr fs_ptr;
class Featureset: public node::ObjectWrap {
- public:
+public:
static Persistent<FunctionTemplate> constructor;
static void Initialize(Handle<Object> target);
static Handle<Value> New(const Arguments &args);
static Handle<Value> New(mapnik::featureset_ptr fs_ptr);
static Handle<Value> next(const Arguments &args);
-
+
Featureset();
- private:
+private:
~Featureset();
fs_ptr this_;
};
View
34 src/mapnik_fonts.hpp
@@ -24,31 +24,31 @@ namespace node_mapnik {
static inline Handle<Value> register_fonts(const Arguments& args)
{
HandleScope scope;
-
+
try
{
if (!args.Length() >= 1 || !args[0]->IsString())
- return ThrowException(Exception::TypeError(
- String::New("first argument must be a path to a directory of fonts")));
-
+ return ThrowException(Exception::TypeError(
+ String::New("first argument must be a path to a directory of fonts")));
+
bool found = false;
-
+
std::vector<std::string> const names_before = mapnik::freetype_engine::face_names();
-
+
// option hash
if (args.Length() == 2){
- if (!args[1]->IsObject())
- return ThrowException(Exception::TypeError(
- String::New("second argument is optional, but if provided must be an object, eg. { recurse:Boolean }")));
-
+ if (!args[1]->IsObject())
+ return ThrowException(Exception::TypeError(
+ String::New("second argument is optional, but if provided must be an object, eg. { recurse:Boolean }")));
+
Local<Object> options = args[1]->ToObject();
if (options->Has(String::New("recurse")))
{
Local<Value> recurse_opt = options->Get(String::New("recurse"));
if (!recurse_opt->IsBoolean())
- return ThrowException(Exception::TypeError(
- String::New("'recurse' must be a Boolean")));
-
+ return ThrowException(Exception::TypeError(
+ String::New("'recurse' must be a Boolean")));
+
bool recurse = recurse_opt->BooleanValue();
std::string const& path = TOSTR(args[0]);
found = mapnik::freetype_engine::register_fonts(path,recurse);
@@ -59,17 +59,17 @@ static inline Handle<Value> register_fonts(const Arguments& args)
std::string const& path = TOSTR(args[0]);
found = mapnik::freetype_engine::register_fonts(path);
}
-
+
std::vector<std::string> const& names_after = mapnik::freetype_engine::face_names();
if (names_after.size() == names_before.size())
found = false;
-
- return scope.Close(Boolean::New(found));
+
+ return scope.Close(Boolean::New(found));
}
catch (const std::exception & ex)
{
return ThrowException(Exception::Error(
- String::New(ex.what())));
+ String::New(ex.what())));
}
}
View
20 src/mapnik_geometry.cpp
@@ -19,20 +19,20 @@ void Geometry::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(constructor, "extent", extent);
NODE_SET_PROTOTYPE_METHOD(constructor, "type", type);
-
+
NODE_MAPNIK_DEFINE_CONSTANT(constructor->GetFunction(),
"Point",mapnik::Point)
- NODE_MAPNIK_DEFINE_CONSTANT(constructor->GetFunction(),
- "LineString",mapnik::LineString)
- NODE_MAPNIK_DEFINE_CONSTANT(constructor->GetFunction(),
- "Polygon",mapnik::Polygon)
+ NODE_MAPNIK_DEFINE_CONSTANT(constructor->GetFunction(),
+ "LineString",mapnik::LineString)
+ NODE_MAPNIK_DEFINE_CONSTANT(constructor->GetFunction(),
+ "Polygon",mapnik::Polygon)
- target->Set(String::NewSymbol("Geometry"),constructor->GetFunction());
+ target->Set(String::NewSymbol("Geometry"),constructor->GetFunction());
}
Geometry::Geometry() :
- ObjectWrap(),
- this_() {}
+ ObjectWrap(),
+ this_() {}
Geometry::~Geometry()
{
@@ -56,7 +56,7 @@ Handle<Value> Geometry::New(const Arguments& args)
else
{
return ThrowException(Exception::Error(
- String::New("a mapnik.Geometry cannot be created directly - rather you should create mapnik.Path objects which can contain one or more geometries")));
+ String::New("a mapnik.Geometry cannot be created directly - rather you should create mapnik.Path objects which can contain one or more geometries")));
}
return args.This();
}
@@ -73,7 +73,7 @@ Handle<Value> Geometry::extent(const Arguments& args)
a->Set(1, Number::New(e.miny()));
a->Set(2, Number::New(e.maxx()));
a->Set(3, Number::New(e.maxy()));
-
+
return scope.Close(a);
}
View
4 src/mapnik_geometry.hpp
@@ -17,7 +17,7 @@ using namespace node;
typedef std::auto_ptr<mapnik::geometry_type> geometry_ptr;
class Geometry: public node::ObjectWrap {
- public:
+public:
static Persistent<FunctionTemplate> constructor;
static void Initialize(Handle<Object> target);
static Handle<Value> New(const Arguments &args);
@@ -28,7 +28,7 @@ class Geometry: public node::ObjectWrap {
Geometry();
inline geometry_ptr get() { return this_; }
- private:
+private:
~Geometry();
geometry_ptr this_;
};
View
133 src/mapnik_grid.cpp
@@ -1,7 +1,6 @@
// node
#include <node_buffer.h>
-#include <node_version.h>
// mapnik
#include <mapnik/image_data.hpp>
@@ -43,16 +42,16 @@ void Grid::Initialize(Handle<Object> target) {
}
Grid::Grid(unsigned int width, unsigned int height, std::string const& key, unsigned int resolution) :
- ObjectWrap(),
- this_(boost::make_shared<mapnik::grid>(width,height,key,resolution)) {
- V8::AdjustAmountOfExternalAllocatedMemory(width * height);
- }
+ ObjectWrap(),
+ this_(boost::make_shared<mapnik::grid>(width,height,key,resolution)) {
+ V8::AdjustAmountOfExternalAllocatedMemory(width * height);
+}
Grid::Grid(grid_ptr this_) :
- ObjectWrap(),
- this_(this_) {
- V8::AdjustAmountOfExternalAllocatedMemory(this_->width() * this_->height());
- }
+ ObjectWrap(),
+ this_(this_) {
+ V8::AdjustAmountOfExternalAllocatedMemory(this_->width() * this_->height());
+ }
Grid::~Grid()
{
@@ -79,38 +78,38 @@ Handle<Value> Grid::New(const Arguments& args)
{
if (!args[0]->IsNumber() || !args[1]->IsNumber())
return ThrowException(Exception::TypeError(
- String::New("Grid 'width' and 'height' must be a integers")));
-
+ String::New("Grid 'width' and 'height' must be a integers")));
+
// defaults
std::string key("__id__");
unsigned int resolution = 1;
-
+
if (args.Length() >= 3) {
if (!args[2]->IsObject())
- return ThrowException(Exception::TypeError(
- String::New("optional third arg must be an options object")));
+ return ThrowException(Exception::TypeError(
+ String::New("optional third arg must be an options object")));
Local<Object> options = args[2]->ToObject();
-
+
if (options->Has(String::New("key"))) {
Local<Value> bind_opt = options->Get(String::New("key"));
if (!bind_opt->IsString())
- return ThrowException(Exception::TypeError(
- String::New("optional arg 'key' must be an string")));
-
+ return ThrowException(Exception::TypeError(
+ String::New("optional arg 'key' must be an string")));
+
key = TOSTR(bind_opt);
}
// TODO - remove, deprecated
if (options->Has(String::New("resolution"))) {
Local<Value> bind_opt = options->Get(String::New("resolution"));
if (!bind_opt->IsNumber())
- return ThrowException(Exception::TypeError(
- String::New("optional arg 'resolution' must be an string")));
-
+ return ThrowException(Exception::TypeError(
+ String::New("optional arg 'resolution' must be an string")));
+
resolution = bind_opt->IntegerValue();
}
}
-
+
Grid* g = new Grid(args[0]->IntegerValue(),args[1]->IntegerValue(),key,resolution);
g->Wrap(args.This());
return args.This();
@@ -118,7 +117,7 @@ Handle<Value> Grid::New(const Arguments& args)
else
{
return ThrowException(Exception::Error(
- String::New("please provide Grid width and height")));
+ String::New("please provide Grid width and height")));
}
return Undefined();
}
@@ -148,7 +147,7 @@ Handle<Value> Grid::height(const Arguments& args)
}
Handle<Value> Grid::get_prop(Local<String> property,
- const AccessorInfo& info)
+ const AccessorInfo& info)
{
HandleScope scope;
Grid* g = ObjectWrap::Unwrap<Grid>(info.Holder());
@@ -159,8 +158,8 @@ Handle<Value> Grid::get_prop(Local<String> property,
}
void Grid::set_prop(Local<String> property,
- Local<Value> value,
- const AccessorInfo& info)
+ Local<Value> value,
+ const AccessorInfo& info)
{
HandleScope scope;
Grid* g = ObjectWrap::Unwrap<Grid>(info.Holder());
@@ -168,7 +167,7 @@ void Grid::set_prop(Local<String> property,
if (a == "key") {
if (!value->IsNumber())
ThrowException(Exception::TypeError(
- String::New("width must be an integer")));
+ String::New("width must be an integer")));
g->get()->set_key(TOSTR(value));
}
}
@@ -200,7 +199,7 @@ Handle<Value> Grid::view(const Arguments& args)
if ( (!args.Length() == 4) || (!args[0]->IsNumber() && !args[1]->IsNumber() && !args[2]->IsNumber() && !args[3]->IsNumber() ))
return ThrowException(Exception::TypeError(
- String::New("requires 4 integer arguments: x, y, width, height")));
+ String::New("requires 4 integer arguments: x, y, width, height")));
unsigned x = args[0]->IntegerValue();
unsigned y = args[1]->IntegerValue();
@@ -217,25 +216,25 @@ Handle<Value> Grid::encodeSync(const Arguments& args) // format, resolution
HandleScope scope;
Grid* g = ObjectWrap::Unwrap<Grid>(args.This());
-
+
// defaults
std::string format("utf");
unsigned int resolution = 4;
bool add_features = true;
-
+
// accept custom format
if (args.Length() >= 1){
if (!args[0]->IsString())
- return ThrowException(Exception::TypeError(
- String::New("first arg, 'format' must be a string")));
+ return ThrowException(Exception::TypeError(
+ String::New("first arg, 'format' must be a string")));
format = TOSTR(args[0]);
}
-
+
// options hash
if (args.Length() >= 2) {
if (!args[1]->IsObject())
- return ThrowException(Exception::TypeError(
- String::New("optional second arg must be an options object")));
+ return ThrowException(Exception::TypeError(
+ String::New("optional second arg must be an options object")));
Local<Object> options = args[1]->ToObject();
@@ -243,9 +242,9 @@ Handle<Value> Grid::encodeSync(const Arguments& args) // format, resolution
{
Local<Value> bind_opt = options->Get(String::New("resolution"));
if (!bind_opt->IsNumber())
- return ThrowException(Exception::TypeError(
- String::New("'resolution' must be an Integer")));
-
+ return ThrowException(Exception::TypeError(
+ String::New("'resolution' must be an Integer")));
+
resolution = bind_opt->IntegerValue();
}
@@ -253,19 +252,19 @@ Handle<Value> Grid::encodeSync(const Arguments& args) // format, resolution
{
Local<Value> bind_opt = options->Get(String::New("features"));
if (!bind_opt->IsBoolean())
- return ThrowException(Exception::TypeError(
- String::New("'features' must be an Boolean")));
-
+ return ThrowException(Exception::TypeError(
+ String::New("'features' must be an Boolean")));
+
add_features = bind_opt->BooleanValue();
}
}
-
+
try {
-
+
Local<Array> grid_array = Array::New();
std::vector<mapnik::grid::lookup_type> key_order;
node_mapnik::grid2utf<mapnik::grid>(*g->get(),grid_array,key_order,resolution);
-
+
// convert key order to proper javascript array
Local<Array> keys_a = Array::New(key_order.size());
std::vector<std::string>::iterator it;
@@ -274,28 +273,28 @@ Handle<Value> Grid::encodeSync(const Arguments& args) // format, resolution
{
keys_a->Set(i, String::New((*it).c_str()));
}
-
+
// gather feature data
Local<Object> feature_data = Object::New();
if (add_features) {
node_mapnik::write_features<mapnik::grid>(*g->get(),
- feature_data,
- key_order
- );
+ feature_data,
+ key_order
+ );
}
-
+
// Create the return hash.
Local<Object> json = Object::New();
json->Set(String::NewSymbol("grid"), grid_array);
json->Set(String::NewSymbol("keys"), keys_a);
json->Set(String::NewSymbol("data"), feature_data);
return json;
-
+
}
catch (std::exception & ex)
{
return ThrowException(Exception::Error(
- String::New(ex.what())));
+ String::New(ex.what())));
}
}
@@ -326,16 +325,16 @@ Handle<Value> Grid::encode(const Arguments& args) // format, resolution
// accept custom format
if (args.Length() >= 1){
if (!args[0]->IsString())
- return ThrowException(Exception::TypeError(
- String::New("first arg, 'format' must be a string")));
+ return ThrowException(Exception::TypeError(
+ String::New("first arg, 'format' must be a string")));
format = TOSTR(args[0]);
}
// options hash
if (args.Length() >= 2) {
if (!args[1]->IsObject())
- return ThrowException(Exception::TypeError(
- String::New("optional second arg must be an options object")));
+ return ThrowException(Exception::TypeError(
+ String::New("optional second arg must be an options object")));
Local<Object> options = args[1]->ToObject();
@@ -343,8 +342,8 @@ Handle<Value> Grid::encode(const Arguments& args) // format, resolution
{
Local<Value> bind_opt = options->Get(String::New("resolution"));
if (!bind_opt->IsNumber())
- return ThrowException(Exception::TypeError(
- String::New("'resolution' must be an Integer")));
+ return ThrowException(Exception::TypeError(
+ String::New("'resolution' must be an Integer")));
resolution = bind_opt->IntegerValue();
}
@@ -353,8 +352,8 @@ Handle<Value> Grid::encode(const Arguments& args) // format, resolution
{
Local<Value> bind_opt = options->Get(String::New("features"));
if (!bind_opt->IsBoolean())
- return ThrowException(Exception::TypeError(
- String::New("'features' must be an Boolean")));
+ return ThrowException(Exception::TypeError(
+ String::New("'features' must be an Boolean")));
add_features = bind_opt->BooleanValue();
}
@@ -363,9 +362,9 @@ Handle<Value> Grid::encode(const Arguments& args) // format, resolution
// ensure callback is a function
if (!args[args.Length()-1]->IsFunction())
return ThrowException(Exception::TypeError(
- String::New("last argument must be a callback function")));
+ String::New("last argument must be a callback function")));
Local<Function> callback = Local<Function>::Cast(args[args.Length()-1]);
-
+
encode_grid_baton_t *closure = new encode_grid_baton_t();
closure->request.data = closure;
closure->g = g;
@@ -415,7 +414,7 @@ void Grid::EIO_AfterEncode(uv_work_t* req)
Local<Value> argv[1] = { Exception::Error(String::New(closure->error_name.c_str())) };
closure->cb->Call(Context::GetCurrent()->Global(), 1, argv);
} else {
-
+
// convert key order to proper javascript array
Local<Array> keys_a = Array::New(closure->key_order.size());
std::vector<std::string>::iterator it;
@@ -424,14 +423,14 @@ void Grid::EIO_AfterEncode(uv_work_t* req)
{
keys_a->Set(i, String::New((*it).c_str()));
}
-
+
// gather feature data
Local<Object> feature_data = Object::New();
if (closure->add_features) {
node_mapnik::write_features<mapnik::grid>(*closure->g->get(),
- feature_data,
- closure->key_order
- );
+ feature_data,
+ closure->key_order
+ );
}
// Create the return hash.
@@ -445,7 +444,7 @@ void Grid::EIO_AfterEncode(uv_work_t* req)
}
if (try_catch.HasCaught()) {
- FatalException(try_catch);
+ FatalException(try_catch);
}
uv_unref(uv_default_loop());
View
6 src/mapnik_grid.hpp
@@ -13,7 +13,7 @@ using namespace node;
typedef boost::shared_ptr<mapnik::grid> grid_ptr;
class Grid: public node::ObjectWrap {
- public:
+public:
static Persistent<FunctionTemplate> constructor;
static void Initialize(Handle<Object> target);
static Handle<Value> New(const Arguments &args);
@@ -30,7 +30,7 @@ class Grid: public node::ObjectWrap {
static Handle<Value> painted(const Arguments &args);
static Handle<Value> get_prop(Local<String> property,
- const AccessorInfo& info);
+ const AccessorInfo& info);
static void set_prop(Local<String> property,
Local<Value> value,
const AccessorInfo& info);
@@ -41,7 +41,7 @@ class Grid: public node::ObjectWrap {
Grid(grid_ptr this_);
inline grid_ptr get() { return this_; }
- private:
+private:
~Grid();
grid_ptr this_;
};
View
109 src/mapnik_grid_view.cpp
@@ -1,7 +1,6 @@
// node
#include <node_buffer.h>
-#include <node_version.h>
// mapnik
#include <mapnik/grid/grid_view.hpp>
@@ -38,8 +37,8 @@ void GridView::Initialize(Handle<Object> target) {
GridView::GridView(grid_view_ptr gp) :
- ObjectWrap(),
- this_(gp) {}
+ ObjectWrap(),
+ this_(gp) {}
GridView::~GridView()
{
@@ -66,10 +65,10 @@ Handle<Value> GridView::New(const Arguments& args)
}
Handle<Value> GridView::New(boost::shared_ptr<mapnik::grid> grid_ptr,
- unsigned x,
- unsigned y,
- unsigned w,
- unsigned h
+ unsigned x,
+ unsigned y,
+ unsigned w,
+ unsigned h
)
{
HandleScope scope;
@@ -130,16 +129,16 @@ Handle<Value> GridView::getPixel(const Arguments& args)
if (args.Length() >= 2) {
if (!args[0]->IsNumber())
- return ThrowException(Exception::TypeError(
- String::New("first arg, 'x' must be an integer")));
+ return ThrowException(Exception::TypeError(
+ String::New("first arg, 'x' must be an integer")));
if (!args[1]->IsNumber())
- return ThrowException(Exception::TypeError(
- String::New("second arg, 'y' must be an integer")));
+ return ThrowException(Exception::TypeError(
+ String::New("second arg, 'y' must be an integer")));
x = args[0]->IntegerValue();
y = args[1]->IntegerValue();
} else {
- return ThrowException(Exception::TypeError(
- String::New("must supply x,y to query pixel color")));
+ return ThrowException(Exception::TypeError(
+ String::New("must supply x,y to query pixel color")));
}
GridView* g = ObjectWrap::Unwrap<GridView>(args.This());
@@ -158,25 +157,25 @@ Handle<Value> GridView::encodeSync(const Arguments& args)
HandleScope scope;
GridView* g = ObjectWrap::Unwrap<GridView>(args.This());
-
+
// defaults
std::string format("utf");
unsigned int resolution = 4;
bool add_features = true;
-
+
// accept custom format
if (args.Length() >= 1){
if (!args[0]->IsString())
- return ThrowException(Exception::TypeError(
- String::New("first arg, 'format' must be a string")));
+ return ThrowException(Exception::TypeError(
+ String::New("first arg, 'format' must be a string")));
format = TOSTR(args[0]);
}
-
+
// options hash
if (args.Length() >= 2) {
if (!args[1]->IsObject())
- return ThrowException(Exception::TypeError(
- String::New("optional second arg must be an options object")));
+ return ThrowException(Exception::TypeError(
+ String::New("optional second arg must be an options object")));
Local<Object> options = args[1]->ToObject();
@@ -184,9 +183,9 @@ Handle<Value> GridView::encodeSync(const Arguments& args)
{
Local<Value> bind_opt = options->Get(String::New("resolution"));
if (!bind_opt->IsNumber())
- return ThrowException(Exception::TypeError(
- String::New("'resolution' must be an Integer")));
-
+ return ThrowException(Exception::TypeError(
+ String::New("'resolution' must be an Integer")));
+
resolution = bind_opt->IntegerValue();
}
@@ -194,19 +193,19 @@ Handle<Value> GridView::encodeSync(const Arguments& args)
{
Local<Value> bind_opt = options->Get(String::New("features"));
if (!bind_opt->IsBoolean())
- return ThrowException(Exception::TypeError(
- String::New("'features' must be an Boolean")));
-
+ return ThrowException(Exception::TypeError(
+ String::New("'features' must be an Boolean")));
+
add_features = bind_opt->BooleanValue();
}
}
-
+
try {
-
+
Local<Array> grid_array = Array::New();
std::vector<mapnik::grid_view::lookup_type> key_order;
node_mapnik::grid2utf<mapnik::grid_view>(*g->get(),grid_array,key_order,resolution);
-
+
// convert key order to proper javascript array
Local<Array> keys_a = Array::New(key_order.size());
std::vector<std::string>::iterator it;
@@ -215,28 +214,28 @@ Handle<Value> GridView::encodeSync(const Arguments& args)
{
keys_a->Set(i, String::New((*it).c_str()));
}
-
+
// gather feature data
Local<Object> feature_data = Object::New();
if (add_features) {
node_mapnik::write_features<mapnik::grid_view>(*g->get(),
- feature_data,
- key_order
- );
+ feature_data,
+ key_order
+ );
}
-
+
// Create the return hash.
Local<Object> json = Object::New();
json->Set(String::NewSymbol("grid"), grid_array);
json->Set(String::NewSymbol("keys"), keys_a);
json->Set(String::NewSymbol("data"), feature_data);
return json;
-
+
}
catch (std::exception & ex)
{
return ThrowException(Exception::Error(
- String::New(ex.what())));
+ String::New(ex.what())));
}
}
@@ -269,16 +268,16 @@ Handle<Value> GridView::encode(const Arguments& args)
// accept custom format
if (args.Length() >= 1){
if (!args[0]->IsString())
- return ThrowException(Exception::TypeError(
- String::New("first arg, 'format' must be a string")));
+ return ThrowException(Exception::TypeError(
+ String::New("first arg, 'format' must be a string")));
format = TOSTR(args[0]);
}
// options hash
if (args.Length() >= 2) {
if (!args[1]->IsObject())
- return ThrowException(Exception::TypeError(
- String::New("optional second arg must be an options object")));
+ return ThrowException(Exception::TypeError(
+ String::New("optional second arg must be an options object")));
Local<Object> options = args[1]->ToObject();
@@ -286,8 +285,8 @@ Handle<Value> GridView::encode(const Arguments& args)
{
Local<Value> bind_opt = options->Get(String::New("resolution"));
if (!bind_opt->IsNumber())
- return ThrowException(Exception::TypeError(
- String::New("'resolution' must be an Integer")));
+ return ThrowException(Exception::TypeError(
+ String::New("'resolution' must be an Integer")));
resolution = bind_opt->IntegerValue();
}
@@ -296,8 +295,8 @@ Handle<Value> GridView::encode(const Arguments& args)
{
Local<Value> bind_opt = options->Get(String::New("features"));
if (!bind_opt->IsBoolean())
- return ThrowException(Exception::TypeError(
- String::New("'features' must be an Boolean")));
+ return ThrowException(Exception::TypeError(
+ String::New("'features' must be an Boolean")));
add_features = bind_opt->BooleanValue();
}
@@ -306,9 +305,9 @@ Handle<Value> GridView::encode(const Arguments& args)
// ensure callback is a function
if (!args[args.Length()-1]->IsFunction())
return ThrowException(Exception::TypeError(
- String::New("last argument must be a callback function")));
+ String::New("last argument must be a callback function")));
Local<Function> callback = Local<Function>::Cast(args[args.Length()-1]);
-
+
encode_grid_view_baton_t *closure = new encode_grid_view_baton_t();
closure->request.data = closure;
closure->g = g;
@@ -331,9 +330,9 @@ void GridView::EIO_Encode(uv_work_t* req)
{
// TODO - write features and clear here as well?
node_mapnik::grid2utf<mapnik::grid_view>(*closure->g->get(),
- closure->array,
- closure->key_order,
- closure->resolution);
+ closure->array,
+ closure->key_order,
+ closure->resolution);
}
catch (std::exception & ex)
{
@@ -359,7 +358,7 @@ void GridView::EIO_AfterEncode(uv_work_t* req)
Local<Value> argv[1] = { Exception::Error(String::New(closure->error_name.c_str())) };
closure->cb->Call(Context::GetCurrent()->Global(), 1, argv);
} else {
-
+
// convert key order to proper javascript array
Local<Array> keys_a = Array::New(closure->key_order.size());
std::vector<std::string>::iterator it;
@@ -368,14 +367,14 @@ void GridView::EIO_AfterEncode(uv_work_t* req)
{
keys_a->Set(i, String::New((*it).c_str()));
}
-
+
// gather feature data
Local<Object> feature_data = Object::New();
if (closure->add_features) {
node_mapnik::write_features<mapnik::grid_view>(*closure->g->get(),
- feature_data,
- closure->key_order
- );
+ feature_data,
+ closure->key_order
+ );
}
// Create the return hash.
@@ -389,7 +388,7 @@ void GridView::EIO_AfterEncode(uv_work_t* req)
}
if (try_catch.HasCaught()) {
- FatalException(try_catch);
+ FatalException(try_catch);
}
uv_unref(uv_default_loop());
View
6 src/mapnik_grid_view.hpp
@@ -14,12 +14,12 @@ using namespace node;
typedef boost::shared_ptr<mapnik::grid_view> grid_view_ptr;
class GridView: public node::ObjectWrap {
- public:
+public:
static Persistent<FunctionTemplate> constructor;
static void Initialize(Handle<Object> target);
static Handle<Value> New(const Arguments &args);
static Handle<Value> New(boost::shared_ptr<mapnik::grid> grid_ptr,
- unsigned x,unsigned y, unsigned w, unsigned h);
+ unsigned x,unsigned y, unsigned w, unsigned h);
static Handle<Value> encodeSync(const Arguments &args);
static Handle<Value> encode(const Arguments &args);
@@ -34,7 +34,7 @@ class GridView: public node::ObjectWrap {
GridView(grid_view_ptr gp);
inline grid_view_ptr get() { return this_; }
- private:
+private:
~GridView();
grid_view_ptr this_;
};
View
165 src/mapnik_image.cpp
@@ -1,7 +1,6 @@
// node
#include <node_buffer.h>
-#include <node_version.h>
// mapnik
#include <mapnik/image_util.hpp>
@@ -47,23 +46,23 @@ void Image::Initialize(Handle<Object> target) {
// This *must* go after the ATTR setting
NODE_SET_METHOD(constructor->GetFunction(),
- "open",
- Image::open);
+ "open",
+ Image::open);
target->Set(String::NewSymbol("Image"),constructor->GetFunction());
}
Image::Image(unsigned int width, unsigned int height) :
- ObjectWrap(),
- this_(boost::make_shared<mapnik::image_32>(width,height)) {
- V8::AdjustAmountOfExternalAllocatedMemory(4 * width * height);
- }
+ ObjectWrap(),
+ this_(boost::make_shared<mapnik::image_32>(width,height)) {
+ V8::AdjustAmountOfExternalAllocatedMemory(4 * width * height);
+}
Image::Image(image_ptr this_) :
- ObjectWrap(),
- this_(this_) {
- V8::AdjustAmountOfExternalAllocatedMemory(4 * this_->width() * this_->height());
- }
+ ObjectWrap(),
+ this_(this_) {
+ V8::AdjustAmountOfExternalAllocatedMemory(4 * this_->width() * this_->height());
+ }
Image::~Image()
{
@@ -90,7 +89,7 @@ Handle<Value> Image::New(const Arguments& args)
{
if (!args[0]->IsNumber() || !args[1]->IsNumber())
return ThrowException(Exception::Error(
- String::New("Image 'width' and 'height' must be a integers")));
+ String::New("Image 'width' and 'height' must be a integers")));
Image* im = new Image(args[0]->IntegerValue(),args[1]->IntegerValue());
im->Wrap(args.This());
return args.This();
@@ -98,13 +97,13 @@ Handle<Value> Image::New(const Arguments& args)
else
{
return ThrowException(Exception::Error(
- String::New("please provide Image width and height")));
+ String::New("please provide Image width and height")));
}
return Undefined();
}
Handle<Value> Image::get_prop(Local<String> property,
- const AccessorInfo& info)
+ const AccessorInfo& info)
{
HandleScope scope;
Image* im = ObjectWrap::Unwrap<Image>(info.Holder());
@@ -120,8 +119,8 @@ Handle<Value> Image::get_prop(Local<String> property,
}
void Image::set_prop(Local<String> property,
- Local<Value> value,
- const AccessorInfo& info)
+ Local<Value> value,
+ const AccessorInfo& info)
{
HandleScope scope;
Image* im = ObjectWrap::Unwrap<Image>(info.Holder());
@@ -129,8 +128,8 @@ void Image::set_prop(Local<String> property,
if (a == "background") {
if (!value->IsObject())
ThrowException(Exception::TypeError(
- String::New("mapnik.Color expected")));
-
+ String::New("mapnik.Color expected")));
+
Local<Object> obj = value->ToObject();
if (obj->IsNull() || obj->IsUndefined() || !Color::constructor->HasInstance(obj))
ThrowException(Exception::TypeError(String::New("mapnik.Color expected")));
@@ -148,13 +147,13 @@ Handle<Value> Image::setGrayScaleToAlpha(const Arguments& args)
im->this_->set_grayscale_to_alpha();
} else {
if (!args[0]->IsObject())
- return ThrowException(Exception::TypeError(
- String::New("optional second arg must be a mapnik.Color")));
+ return ThrowException(Exception::TypeError(
+ String::New("optional second arg must be a mapnik.Color")));
Local<Object> obj = args[0]->ToObject();
if (obj->IsNull() || obj->IsUndefined() || !Color::constructor->HasInstance(obj))
- return ThrowException(Exception::TypeError(String::New("mapnik.Color expected as second arg")));
+ return ThrowException(Exception::TypeError(String::New("mapnik.Color expected as second arg")));
Color * color = ObjectWrap::Unwrap<Color>(obj);
@@ -174,9 +173,9 @@ Handle<Value> Image::setGrayScaleToAlpha(const Arguments& args)
unsigned a = (int)((r * .3) + (g * .59) + (b * .11));
row_from[x] = (a << 24) |
- (color->get()->blue() << 16) |
- (color->get()->green() << 8) |
- (color->get()->red()) ;
+ (color->get()->blue() << 16) |
+ (color->get()->green() << 8) |
+ (color->get()->red()) ;
}
}
}
@@ -211,12 +210,12 @@ Handle<Value> Image::height(const Arguments& args)
Handle<Value> Image::open(const Arguments& args)
{
HandleScope scope;
-
+
if (!args[0]->IsString()) {
- return ThrowException(Exception::TypeError(String::New(
- "Argument must be a string")));
+ return ThrowException(Exception::TypeError(String::New(
+ "Argument must be a string")));
}
-
+
try {
std::string filename = TOSTR(args[0]);
boost::optional<std::string> type = mapnik::type_from_filename(filename);
@@ -233,15 +232,15 @@ Handle<Value> Image::open(const Arguments& args)
return scope.Close(obj);
}
return ThrowException(Exception::TypeError(String::New(
- ("Failed to load: " + filename).c_str())));
+ ("Failed to load: " + filename).c_str())));
}
return ThrowException(Exception::TypeError(String::New(
- ("Unsupported image format:" + filename).c_str())));
+ ("Unsupported image format:" + filename).c_str())));
}
catch (std::exception & ex)
{
return ThrowException(Exception::Error(
- String::New(ex.what())));
+ String::New(ex.what())));
}