Class: OraNumber
- Inherits:
-
Object
- Object
- OraNumber
- Defined in:
- ext/oci8/oci8.c
Class Method Summary collapse
- ._load(str) ⇒ Object
-
.new(*args) ⇒ Object
ruby 1.6.
Instance Method Summary collapse
- #-@ ⇒ Object
- #_dump(*args) ⇒ Object
- #clone ⇒ Object
- #dup ⇒ Object
-
#initialize(*args) ⇒ Object
constructor
begin — OraNumber.new() =end.
- #initialize_copy(rhs) ⇒ Object
-
#to_f ⇒ Object
begin — OraNumber#to_f() =end.
-
#to_i ⇒ Object
begin — OraNumber#to_i() =end.
-
#to_s ⇒ Object
begin — OraNumber#to_s() =end.
Constructor Details
#initialize(*args) ⇒ Object
begin
— OraNumber.new()
end
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'ext/oci8/oranumber.c', line 54
static VALUE ora_number_initialize(int argc, VALUE *argv, VALUE self)
{
ora_vnumber_t *ovn = get_ora_number(self);
volatile VALUE arg;
rb_scan_args(argc, argv, "01", &arg);
ovn->size = 1;
ovn->num.exponent = 0x80;
memset(ovn->num.mantissa, 0, sizeof(ovn->num.mantissa));
if (argc == 1) {
if (TYPE(arg) != T_STRING) {
arg = rb_obj_as_string(arg);
}
if (ora_number_from_str(ovn, RSTRING_ORATEXT(arg), RSTRING_LEN(arg)) != 0) {
rb_raise(rb_eArgError, "could not convert '%s' to OraNumber", RSTRING_PTR(arg));
}
}
return Qnil;
}
|
Class Method Details
._load(str) ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'ext/oci8/oranumber.c', line 173
static VALUE ora_number_s_load(VALUE klass, VALUE str)
{
ora_vnumber_t *ovn;
VALUE obj;
Check_Type(str, T_STRING);
if (RSTRING_LEN(str) != sizeof(ora_vnumber_t)) {
rb_raise(rb_eTypeError, "marshaled OraNumber format differ");
}
obj = ora_number_s_allocate(klass);
ovn = get_ora_number(obj);
memcpy(ovn, RSTRING_PTR(str), sizeof(ora_vnumber_t));
return obj;
}
|
.new(*args) ⇒ Object
ruby 1.6
41 42 43 44 45 46 |
# File 'ext/oci8/oranumber.c', line 41
static VALUE ora_number_s_new(int argc, VALUE *argv, VALUE klass)
{
VALUE obj = ora_number_s_allocate(klass);
rb_obj_call_init(obj, argc, argv);
return obj;
}
|
Instance Method Details
#-@ ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'ext/oci8/oranumber.c', line 137
static VALUE ora_number_uminus(VALUE self)
{
ora_vnumber_t *ovn = get_ora_number(self);
VALUE obj;
int i;
if (ovn->num.exponent == 0x80)
return self;
obj = ora_number_clone(self);
ovn = get_ora_number(obj);
ovn->num.exponent = ~(ovn->num.exponent);
for (i = 0;i < ovn->size - 1;i++)
ovn->num.mantissa[i] = 102 - ovn->num.mantissa[i];
if (Get_Sign(&(ovn->num))) {
if (ovn->size != 21 || ovn->num.mantissa[19] == 0x00) {
ovn->size--;
}
} else {
if (ovn->size != 21) {
ovn->num.mantissa[ovn->size - 1] = 102;
ovn->size++;
}
}
return obj;
}
|
#_dump(*args) ⇒ Object
163 164 165 166 167 168 169 170 171 |
# File 'ext/oci8/oranumber.c', line 163
static VALUE ora_number_dump(int argc, VALUE *argv, VALUE self)
{
ora_vnumber_t *ovn = get_ora_number(self);
unsigned char i;
for (i = ovn->size - 1; i < 20; i++) {
ovn->num.mantissa[i] = 0;
}
return rb_str_new((const char*)ovn, sizeof(ora_vnumber_t));
}
|
#clone ⇒ Object
88 89 90 91 92 |
# File 'ext/oci8/oranumber.c', line 88
static VALUE ora_number_clone(VALUE self)
{
VALUE obj = ora_number_s_allocate(CLASS_OF(self));
return ora_number_initialize_copy(obj, self);
}
|
#dup ⇒ Object
88 89 90 91 92 |
# File 'ext/oci8/oranumber.c', line 88
static VALUE ora_number_clone(VALUE self)
{
VALUE obj = ora_number_s_allocate(CLASS_OF(self));
return ora_number_initialize_copy(obj, self);
}
|
#initialize_copy(rhs) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'ext/oci8/oranumber.c', line 74
static VALUE ora_number_initialize_copy(VALUE lhs, VALUE rhs)
{
ora_vnumber_t *l, *r;
#ifdef HAVE_RB_DEFINE_ALLOC_FUNC
/* ruby 1.8 */
rb_obj_init_copy(lhs, rhs);
#endif
Data_Get_Struct(lhs, ora_vnumber_t, l);
Data_Get_Struct(rhs, ora_vnumber_t, r);
memcpy(l, r, sizeof(ora_vnumber_t));
return lhs;
}
|
#to_f ⇒ Object
begin
— OraNumber#to_f()
end
113 114 115 116 117 118 119 120 |
# File 'ext/oci8/oranumber.c', line 113
static VALUE ora_number_to_f(VALUE self)
{
ora_vnumber_t *ovn = get_ora_number(self);
unsigned char buf[ORA_NUMBER_BUF_SIZE];
ora_number_to_str(buf, NULL, &(ovn->num), ovn->size);
return rb_float_new(rb_cstr_to_dbl(TO_CHARPTR(buf), Qfalse));
}
|
#to_i ⇒ Object
begin
— OraNumber#to_i()
end
99 100 101 102 103 104 105 106 |
# File 'ext/oci8/oranumber.c', line 99
static VALUE ora_number_to_i(VALUE self)
{
ora_vnumber_t *ovn = get_ora_number(self);
unsigned char buf[ORA_NUMBER_BUF_SIZE];
ora_number_to_str(buf, NULL, &(ovn->num), ovn->size);
return rb_cstr2inum(TO_CHARPTR(buf), 10);
}
|
#to_s ⇒ Object
begin
— OraNumber#to_s()
end
127 128 129 130 131 132 133 134 135 |
# File 'ext/oci8/oranumber.c', line 127
static VALUE ora_number_to_s(VALUE self)
{
ora_vnumber_t *ovn = get_ora_number(self);
unsigned char buf[ORA_NUMBER_BUF_SIZE];
size_t len;
ora_number_to_str(buf, &len, &(ovn->num), ovn->size);
return rb_str_new(TO_CHARPTR(buf), len);
}
|