Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 0ab34bc2a8c6c70c80558f36e15f60280a1ec0f4 @elliotlaster elliotlaster committed Jul 7, 2011
@@ -0,0 +1,35 @@
+# -*- ruby -*-
+
+require 'autotest/restart'
+
+# Autotest.add_hook :initialize do |at|
+# at.extra_files << "../some/external/dependency.rb"
+#
+# at.libs << ":../some/external"
+#
+# at.add_exception 'vendor'
+#
+# at.add_mapping(/dependency.rb/) do |f, _|
+# at.files_matching(/test_.*rb$/)
+# end
+#
+# %w(TestA TestB).each do |klass|
+# at.extra_class_map[klass] = "test/test_misc.rb"
+# end
+# end
+
+# Autotest.add_hook :run_command do |at|
+# system "rake build"
+# end
+
+# require 'autotest/restart'
+
+Autotest.add_hook :initialize do |at|
+ at.add_mapping(/.*\.c/) do |f, _|
+ at.files_matching(/test_.*rb$/)
+ end
+end
+
+Autotest.add_hook :run_command do |at|
+ system "rake compile"
+end
@@ -0,0 +1 @@
+tmp
@@ -0,0 +1,6 @@
+=== 1.0.0 / 2011-07-06
+
+* 1 major enhancement
+
+ * Birthday!
+
@@ -0,0 +1,8 @@
+.autotest
+History.txt
+Manifest.txt
+README.txt
+Rakefile
+bin/ruby_mapnik
+lib/ruby_mapnik.rb
+test/test_ruby_mapnik.rb
@@ -0,0 +1,57 @@
+= ruby_mapnik
+
+* FIX (url)
+
+== DESCRIPTION:
+
+FIX (describe your package)
+
+== FEATURES/PROBLEMS:
+
+* FIX (list of features or problems)
+
+== SYNOPSIS:
+
+ FIX (code sample of usage)
+
+== REQUIREMENTS:
+
+* FIX (list of requirements)
+
+== INSTALL:
+
+* FIX (sudo gem install, anything else)
+
+== DEVELOPERS:
+
+After checking out the source, run:
+
+ $ rake newb
+
+This task will install any missing dependencies, run the tests/specs,
+and generate the RDoc.
+
+== LICENSE:
+
+(The MIT License)
+
+Copyright (c) 2011 FIX
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,28 @@
+require 'rubygems'
+require 'hoe'
+require "rake/extensiontask"
+# Hoe.plugin :compiler
+# Hoe.plugin :compiler
+# Hoe.plugin :gem_prelude_sucks
+# Hoe.plugin :gem_prelude_sucks
+# Hoe.plugin :inline
+# Hoe.plugin :inline
+# Hoe.plugin :racc
+# Hoe.plugin :racc
+# Hoe.plugin :rubyforge
+# Hoe.plugin :rubyforge
+
+Hoe.spec 'ruby_mapnik' do
+ developer('Elliot Laster', 'elliotlaster@gmail.com')
+ # self.readme_file = 'README.rdoc'
+ # self.history_file = 'CHANGELOG.rdoc'
+ # self.extra_rdoc_files = FileList['*.rdoc']
+ self.extra_dev_deps << ['rake-compiler', '>= 0']
+ self.spec_extras = { :extensions => ["ext/ruby_mapnik/extconf.rb"] }
+
+ Rake::ExtensionTask.new('ruby_mapnik', spec) do |ext|
+ ext.lib_dir = File.join('lib', 'ruby_mapnik')
+ end
+end
+
+Rake::Task[:test].prerequisites << :compile
@@ -0,0 +1,9 @@
+#include "_mapnik.h"
+
+void register_mapnik(){
+ Rice::Module rb_mapnik = Rice::define_module("Mapnik");
+
+ register_color(rb_mapnik);
+ register_coord(rb_mapnik);
+ register_datasource(rb_mapnik);
+}
@@ -0,0 +1,23 @@
+#ifndef mapnik_HPP
+#define mapnik_HPP
+
+ // Rice
+#include <rice/Enum.hpp>
+#include <rice/Object.hpp>
+#include <rice/Data_Type.hpp>
+#include <rice/Data_Object.hpp>
+#include <rice/Allocation_Strategies.hpp>
+#include <rice/Module.hpp>
+#include <rice/Enum.hpp>
+
+// // Mapnik
+// #include <mapnik2/map.hpp>
+
+// Ruby Mapnik
+#include <_mapnik_color.rb.h>
+#include <_mapnik_coord.rb.h>
+#include <_mapnik_datasource.rb.h>
+
+void register_mapnik();
+
+#endif
@@ -0,0 +1,21 @@
+#include "_mapnik_color.rb.h"
+
+void register_color(Rice::Module rb_mapnik){
+ Rice::Data_Type< mapnik::color > rb_ccolor = Rice::define_class_under< mapnik::color >(rb_mapnik, "Color");
+ rb_ccolor.define_constructor(Rice::Constructor< mapnik::color, int, int, int, int >());
+
+ rb_ccolor.define_method("red", &mapnik::color::red);
+ rb_ccolor.define_method("green", &mapnik::color::green);
+ rb_ccolor.define_method("blue", &mapnik::color::blue);
+ rb_ccolor.define_method("alpha", &mapnik::color::alpha);
+
+ rb_ccolor.define_method("red=", &mapnik::color::set_red, (Rice::Arg("value")));
+ rb_ccolor.define_method("green=", &mapnik::color::set_green, (Rice::Arg("value")));
+ rb_ccolor.define_method("blue=", &mapnik::color::set_blue, (Rice::Arg("value")));
+ rb_ccolor.define_method("alpha=", &mapnik::color::set_alpha, (Rice::Arg("value")));
+
+// These symbols are not found on my installation. Moving on...
+ rb_ccolor.define_method("to_hex", &mapnik::color::to_hex_string);
+ rb_ccolor.define_method("to_s", &mapnik::color::to_string);
+
+}
@@ -0,0 +1,13 @@
+#ifndef PIKA2_MAPNIK_COLOR
+#define PIKA2_MAPNIK_COLOR
+ // Rice
+#include <rice/Data_Type.hpp>
+#include <rice/Constructor.hpp>
+#include <rice/Class.hpp>
+
+ // Mapnik
+#include <mapnik2/color.hpp>
+
+void register_color(Rice::Module rb_mapnik);
+
+#endif
@@ -0,0 +1,48 @@
+#include "_mapnik_coord.rb.h"
+
+void wrap_mapnik_coord_double__2__x_set(mapnik::coord2d* self, double val) {
+ self->x = val;
+}
+double wrap_mapnik_coord_double__2__x_get(mapnik::coord2d* self) {
+ return self->x;
+}
+void wrap_mapnik_coord_double__2__y_set(mapnik::coord2d* self, double val) {
+ self->y = val;
+}
+double wrap_mapnik_coord_double__2__y_get(mapnik::coord2d* self) {
+ return self->y;
+}
+
+mapnik::coord2d wrap_mapnik_coord_double__2__times_equals(mapnik::coord2d self, float value){
+ return self *= value;
+}
+
+mapnik::coord2d wrap_mapnik_coord_double__2__addition(mapnik::coord2d self, float value){
+ return self += value;
+}
+
+mapnik::coord2d wrap_mapnik_coord_double__2__subtraction(mapnik::coord2d self, float value){
+ return self -= value;
+}
+
+mapnik::coord2d wrap_mapnik_coord_double__2__division(mapnik::coord2d self, float value){
+ return self /= value;
+}
+
+bool wrap_mapnik_coord_double__2__equality(mapnik::coord2d self, mapnik::coord2d rhs){
+ return self == rhs;
+}
+
+void register_coord(Rice::Module rb_mmapnik) {
+ Rice::Data_Type< mapnik::coord2d > rb_ccoord2d = Rice::define_class_under< mapnik::coord2d >(rb_mmapnik, "Coord2d");
+ rb_ccoord2d.define_constructor(Rice::Constructor< mapnik::coord2d,double,double >());
+ rb_ccoord2d.define_method("x=", &wrap_mapnik_coord_double__2__x_set);
+ rb_ccoord2d.define_method("x", &wrap_mapnik_coord_double__2__x_get);
+ rb_ccoord2d.define_method("y=", &wrap_mapnik_coord_double__2__y_set);
+ rb_ccoord2d.define_method("y", &wrap_mapnik_coord_double__2__y_get);
+ rb_ccoord2d.define_method("*", &wrap_mapnik_coord_double__2__times_equals, (Rice::Arg("value")));
+ rb_ccoord2d.define_method("==", &wrap_mapnik_coord_double__2__equality, (Rice::Arg("rhs")));
+ rb_ccoord2d.define_method("+", &wrap_mapnik_coord_double__2__addition, (Rice::Arg("value")));
+ rb_ccoord2d.define_method("-", &wrap_mapnik_coord_double__2__subtraction, (Rice::Arg("value")));
+ rb_ccoord2d.define_method("/", &wrap_mapnik_coord_double__2__division, (Rice::Arg("value")));
+}
@@ -0,0 +1,13 @@
+#ifndef PIKA2_MAPNIK_COORD
+#define PIKA2_MAPNIK_COORD
+// Rice
+#include <rice/Data_Type.hpp>
+#include <rice/Constructor.hpp>
+#include <rice/Class.hpp>
+
+// Mapnik
+#include <mapnik2/coord.hpp>
+
+void register_coord(Rice::Module rb_mapnik);
+
+#endif
@@ -0,0 +1,43 @@
+#include "_mapnik_datasource.rb.h"
+
+std::string name(mapnik::datasource* self){
+ mapnik::layer_descriptor ld = self->get_descriptor();
+ return ld.get_name();
+}
+
+boost::shared_ptr<mapnik::datasource> create(Rice::Object params){
+ bool bind=true;
+ Rice::Hash options = (Rice::Hash) params;
+ mapnik::parameters datasource_params;
+
+ Rice::Hash::iterator it = options.begin();
+ Rice::Hash::iterator end = options.end();
+ for(; it != end; ++it) {
+ Rice::String keyString = (Rice::String) it->key;
+ Rice::Object value = it->value;
+ switch (value.rb_type()) {
+ case T_STRING:
+ datasource_params[keyString.str()] = ((Rice::String) value).str();
+ break;
+ case T_FLOAT:
+ datasource_params[keyString.str()] = NUM2DBL(value.value());
+ break;
+ case T_FIXNUM:
+ datasource_params[keyString.str()] = (int)NUM2INT(value.value());
+ break;
+ }
+ }
+
+ return mapnik::datasource_cache::create(datasource_params, bind);
+}
+
+void register_datasource(Rice::Module rb_mapnik){
+ Rice::Data_Type< mapnik::datasource > rb_cdatasource = Rice::define_class_under< mapnik::datasource >(rb_mapnik, "Datasource");
+
+ rb_cdatasource.define_method("envelope", &mapnik::datasource::envelope);
+ rb_cdatasource.define_method("descriptor", &mapnik::datasource::get_descriptor);
+ rb_cdatasource.define_method("name", &name);
+
+ rb_cdatasource.define_singleton_method("create", &create, (Rice::Arg("params")));
+ // TODO: more
+}
@@ -0,0 +1,17 @@
+#ifndef PIKA2_MAPNIK_DATASOURCE
+#define PIKA2_MAPNIK_DATASOURCE
+ // Rice
+#include <rice/Data_Type.hpp>
+#include <rice/Constructor.hpp>
+#include <rice/Class.hpp>
+#include <rice/Hash.hpp>
+#include <rice/Array.hpp>
+
+ // Mapnik
+#include <mapnik2/datasource.hpp>
+#include <mapnik2/datasource_cache.hpp>
+#include <mapnik2/feature_layer_desc.hpp>
+
+void register_datasource(Rice::Module rb_mapnik);
+
+#endif
Oops, something went wrong.

0 comments on commit 0ab34bc

Please sign in to comment.