#include "reflex/ruby/style_length.h" #include #include "defs.h" using namespace Rucy; RUCY_DEFINE_VALUE_FROM_TO(Reflex::StyleLength4) #define THIS to(self) #define CHECK RUCY_CHECK_OBJ(Reflex::StyleLength4, self) static VALUE alloc(VALUE klass) { return new_type(klass); } static VALUE initialize_copy(VALUE self, VALUE obj) { CHECK; *THIS = to(obj).copy(); return self; } static VALUE set_left(VALUE self, VALUE left) { CHECK; THIS->set_left(to(left)); } static VALUE get_left(VALUE self) { CHECK; return value(THIS->left()); } static VALUE set_top(VALUE self, VALUE top) { CHECK; THIS->set_top(to(top)); } static VALUE get_top(VALUE self) { CHECK; return value(THIS->top()); } static VALUE set_right(VALUE self, VALUE right) { CHECK; THIS->set_right(to(right)); } static VALUE get_right(VALUE self) { CHECK; return value(THIS->right()); } static VALUE set_bottom(VALUE self, VALUE bottom) { CHECK; THIS->set_bottom(to(bottom)); } static VALUE get_bottom(VALUE self) { CHECK; return value(THIS->bottom()); } static VALUE set_at(VALUE self, VALUE index, VALUE length) { CHECK; int i = index.as_i(), size = (int) THIS->size(); while (i < 0) i += size; if (i >= size) index_error(__FILE__, __LINE__); (*THIS)[i] = to(length); } static VALUE get_at(VALUE self, VALUE index) { CHECK; int i = index.as_i(), size = (int) THIS->size(); while (i < 0) i += size; if (i >= size) index_error(__FILE__, __LINE__); return value((*THIS)[i]); } static Class cStyleLength4; void Init_style_length4 () { Module mReflex = rb_define_module("Reflex"); cStyleLength4 = rb_define_class_under(mReflex, "StyleLength4", rb_cObject); rb_define_alloc_func(cStyleLength4, alloc); rb_define_private_method(cStyleLength4, "initialize_copy", RUBY_METHOD_FUNC(initialize_copy), 1); rb_define_method(cStyleLength4, "left=", RUBY_METHOD_FUNC(set_left), 1); rb_define_method(cStyleLength4, "left", RUBY_METHOD_FUNC(get_left), 0); rb_define_method(cStyleLength4, "top=", RUBY_METHOD_FUNC(set_top), 1); rb_define_method(cStyleLength4, "top", RUBY_METHOD_FUNC(get_top), 0); rb_define_method(cStyleLength4, "right=", RUBY_METHOD_FUNC(set_right), 1); rb_define_method(cStyleLength4, "right", RUBY_METHOD_FUNC(get_right), 0); rb_define_method(cStyleLength4, "bottom=", RUBY_METHOD_FUNC(set_bottom), 1); rb_define_method(cStyleLength4, "bottom", RUBY_METHOD_FUNC(get_bottom), 0); cStyleLength4.define_method("[]=", set_at); cStyleLength4.define_method("[]", get_at); } namespace Rucy { template <> Reflex::StyleLength4 value_to (Value value, bool convert) { if (convert && value.is_array()) { Value* a = value.as_array(); switch (value.size()) { case 1: return Reflex::StyleLength4( to(a[0])); case 2: return Reflex::StyleLength4( to(a[0]), to(a[1])); case 3: return Reflex::StyleLength4( to(a[0]), to(a[1]), to(a[2])); case 4: return Reflex::StyleLength4( to(a[0]), to(a[1]), to(a[2]), to(a[3])); default: argument_error(__FILE__, __LINE__); } } return value_to(value, convert); } }// Rucy namespace Reflex { Class style_length4_class () { return cStyleLength4; } }// Reflex