#include "reflex/ruby/style_length.h" #include #include "defs.h" using namespace Rucy; RUCY_DEFINE_VALUE_FROM_TO(Reflex::StyleLength2) #define THIS to(self) #define CHECK RUCY_CHECK_OBJ(Reflex::StyleLength2, 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_width(VALUE self, VALUE width) { CHECK; THIS->set_width(to(width)); } static VALUE get_width(VALUE self) { CHECK; return value(THIS->width()); } static VALUE set_height(VALUE self, VALUE height) { CHECK; THIS->set_height(to(height)); } static VALUE get_height(VALUE self) { CHECK; return value(THIS->height()); } 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 cStyleLength2; void Init_style_length2 () { Module mReflex = rb_define_module("Reflex"); cStyleLength2 = rb_define_class_under(mReflex, "StyleLength2", rb_cObject); rb_define_alloc_func(cStyleLength2, alloc); rb_define_private_method(cStyleLength2, "initialize_copy", RUBY_METHOD_FUNC(initialize_copy), 1); rb_define_method(cStyleLength2, "width=", RUBY_METHOD_FUNC(set_width), 1); rb_define_method(cStyleLength2, "width", RUBY_METHOD_FUNC(get_width), 0); rb_define_method(cStyleLength2, "height=", RUBY_METHOD_FUNC(set_height), 1); rb_define_method(cStyleLength2, "height", RUBY_METHOD_FUNC(get_height), 0); cStyleLength2.define_method("[]=", set_at); cStyleLength2.define_method("[]", get_at); } namespace Rucy { template <> Reflex::StyleLength2 value_to (Value value, bool convert) { if (convert && value.is_array()) { Value* a = value.as_array(); switch (value.size()) { case 1: return Reflex::StyleLength2( to(a[0])); case 2: return Reflex::StyleLength2( to(a[0]), to(a[1])); default: argument_error(__FILE__, __LINE__); } } return value_to(value, convert); } }// Rucy namespace Reflex { Class style_length2_class () { return cStyleLength2; } }// Reflex