From 14ed2e9b5b2eb39b7221881f83568861f443a254 Mon Sep 17 00:00:00 2001 From: Bill Robertson Date: Sun, 13 Dec 2009 14:44:28 -0500 Subject: [PATCH] Refactor converters. Consistent class names, typedefs, filenames grouped together, replace push method with operator () --- convert_ruby.cpp | 8 ++++++++ ruby_data.h => convert_ruby.h | 16 ++++++++-------- generic_data.cpp => convert_string.cpp | 2 +- generic_data.h => convert_string.h | 4 ++-- convert_v8.cpp | 9 +++++++++ v8_data.h => convert_v8.h | 16 ++++++++-------- converters.h | 14 ++++++++++++++ ruby_data.cpp | 8 -------- v8.cpp | 4 +--- v8_context.cpp | 20 +++++++++----------- v8_data.cpp | 9 --------- v8_object.cpp | 17 +++++++---------- v8_script.cpp | 8 +++----- v8_template.cpp | 15 +++++++-------- 14 files changed, 77 insertions(+), 73 deletions(-) create mode 100644 convert_ruby.cpp rename ruby_data.h => convert_ruby.h (90%) rename generic_data.cpp => convert_string.cpp (84%) rename generic_data.h => convert_string.h (96%) create mode 100644 convert_v8.cpp rename v8_data.h => convert_v8.h (92%) create mode 100644 converters.h delete mode 100644 ruby_data.cpp delete mode 100644 v8_data.cpp diff --git a/convert_ruby.cpp b/convert_ruby.cpp new file mode 100644 index 0000000..2b583de --- /dev/null +++ b/convert_ruby.cpp @@ -0,0 +1,8 @@ +#include "convert_ruby.h" + + +RubyValueDest::RubyValueDest() { +} + +RubyValueDest::~RubyValueDest() { +} diff --git a/ruby_data.h b/convert_ruby.h similarity index 90% rename from ruby_data.h rename to convert_ruby.h index 55e4002..ded0b92 100644 --- a/ruby_data.h +++ b/convert_ruby.h @@ -1,11 +1,11 @@ -#ifndef __ruby_data_h__ -#define __ruby_data_h__ +#ifndef __convert_ruby_h__ +#define __convert_ruby_h__ #include #include -#include #include #include +#include "v8_object.h" /** * A RubyValueSource takes a Destination class and a return @@ -30,7 +30,7 @@ template class RubyValueSource { ~RubyValueSource() {} - RET push(VALUE& value) { + RET operator() (VALUE& value) { switch (TYPE(value)) { case T_FIXNUM: return dest.pushInt(FIX2INT(value)); @@ -60,15 +60,15 @@ private: }; /** - * A RubyDest class receives on of the types defined in + * A RubyValueDest class receives on of the types defined in * data_conversion.txt, and converts it to the appropriate * Ruby VALUE. */ -class RubyDest { +class RubyValueDest { public: - RubyDest(); - ~RubyDest(); + RubyValueDest(); + ~RubyValueDest(); VALUE pushString(const std::string& value) { return rb_str_new2(value.c_str()); diff --git a/generic_data.cpp b/convert_string.cpp similarity index 84% rename from generic_data.cpp rename to convert_string.cpp index aa13fc6..f4a579d 100644 --- a/generic_data.cpp +++ b/convert_string.cpp @@ -1,4 +1,4 @@ -#include "generic_data.h" +#include "convert_string.h" StringDest::StringDest() { } diff --git a/generic_data.h b/convert_string.h similarity index 96% rename from generic_data.h rename to convert_string.h index bca961b..c1b1f82 100644 --- a/generic_data.h +++ b/convert_string.h @@ -1,5 +1,5 @@ -#ifndef __generic_data_h__ -#define __generic_data_h__ +#ifndef __convert_string_h__ +#define __convert_string_h__ #include "v8.h" #include diff --git a/convert_v8.cpp b/convert_v8.cpp new file mode 100644 index 0000000..3c5c3b8 --- /dev/null +++ b/convert_v8.cpp @@ -0,0 +1,9 @@ +#include "convert_v8.h" + +V8LocalDest::V8LocalDest() { + +} + +V8LocalDest::~V8LocalDest() { + +} \ No newline at end of file diff --git a/v8_data.h b/convert_v8.h similarity index 92% rename from v8_data.h rename to convert_v8.h index 28bb31d..e8e636b 100644 --- a/v8_data.h +++ b/convert_v8.h @@ -1,8 +1,8 @@ -#ifndef __v8_data_h__ -#define __v8_data_h__ +#ifndef __convert_v8_h__ +#define __convert_v8_h__ -#include "v8.h" -#include "stdint.h" +#include +#include #include #include @@ -15,7 +15,7 @@ template class V8HandleSource { V8HandleSource() {} ~V8HandleSource() {} - R push(v8::Handle& value) { + R operator() (v8::Handle& value) { if (value->IsUndefined()) { return dest.pushNull(); @@ -70,11 +70,11 @@ template class V8HandleSource { * in data_conversion.txt so it can be used as a template argument * for a conversion source class. */ -class V8HandleDest { +class V8LocalDest { public: - V8HandleDest(); - ~V8HandleDest(); + V8LocalDest(); + ~V8LocalDest(); v8::Local pushString(const std::string& value) { return v8::Local::New(v8::String::New(value.c_str())); diff --git a/converters.h b/converters.h new file mode 100644 index 0000000..a6af218 --- /dev/null +++ b/converters.h @@ -0,0 +1,14 @@ +#ifndef __converters_h__ +#define __converters_h__ + +#include "convert_ruby.h" +#include "convert_string.h" +#include "convert_v8.h" + +typedef RubyValueSource > convert_rb_to_v8_t; +typedef V8HandleSource convert_v8_to_rb_t; + +typedef RubyValueSource convert_rb_to_string_t; +typedef V8HandleSource convert_v8_to_string_t; + +#endif \ No newline at end of file diff --git a/ruby_data.cpp b/ruby_data.cpp deleted file mode 100644 index 2e3e399..0000000 --- a/ruby_data.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "ruby_data.h" - - -RubyDest::RubyDest() { -} - -RubyDest::~RubyDest() { -} diff --git a/v8.cpp b/v8.cpp index f3c2197..44fa674 100644 --- a/v8.cpp +++ b/v8.cpp @@ -1,6 +1,4 @@ -#include "ruby_data.h" -#include "generic_data.h" -#include "v8_data.h" +#include "v8_object.h" #include "v8_context.h" #include "v8_cxt.h" #include "v8_str.h" diff --git a/v8_context.cpp b/v8_context.cpp index 18b6797..06a1cae 100644 --- a/v8_context.cpp +++ b/v8_context.cpp @@ -1,6 +1,4 @@ -#include "ruby_data.h" -#include "v8_data.h" -#include "generic_data.h" +#include "converters.h" #include "v8_context.h" #include @@ -35,12 +33,12 @@ VALUE v8_context_eval(VALUE self, VALUE javascript) { HandleScope handles; RubyValueSource tostring; - const std::string source(tostring.push(javascript)); + const std::string source(tostring(javascript)); Local