Class: Store

Inherits:
DefMethod show all
Defined in:
ext/cumo/narray/gen/narray_def.rb

Overview


Direct Known Subclasses

StoreArray, StoreNum

Instance Attribute Summary

Attributes inherited from ErbPP

#children, #parent

Instance Method Summary collapse

Methods inherited from DefMethod

#c_iter, #c_name, #cumo_id_op, #define_method_args, #init_def, #initialize, #op_map, #singleton

Methods included from DeclMethod

#def_alias, #def_alloc_func, #def_const, #def_method, #def_module_function, #def_singleton_method, #undef_alloc_func, #undef_method, #undef_singleton_method

Methods inherited from ErbPP

#add_child, #description, #find, #find_tmpl, #get, #init_def, #initialize, #load_erb, #method_missing, #method_missing_alias, #result, #run, #set, #upcast_def, #write

Constructor Details

This class inherits a constructor from DefMethod

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ErbPP

Instance Method Details

#c_func(n = nil) ⇒ Object



264
265
266
# File 'ext/cumo/narray/gen/narray_def.rb', line 264

def c_func(n=nil)
  "#{parent.parent.name}_store_#{name}"
end

#condition(klass) ⇒ Object



268
269
270
# File 'ext/cumo/narray/gen/narray_def.rb', line 268

def condition(klass)
  "#{klass}==#{type_var}"
end

#extract_data(ptr, pos, x) ⇒ Object



279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'ext/cumo/narray/gen/narray_def.rb', line 279

def extract_data(ptr, pos, x)
  case type_name
  when "Bit"
    "{BIT_DIGIT b; CUMO_LOAD_BIT(#{ptr},#{pos},b); x = m_from_sint(b);}"
  when "RObject"
    "#{x} = m_num_to_data(*(#{dtype}*)(#{ptr}+#{pos}))"
  when /Complex/
    "{#{dtype} *p = (#{dtype}*)(#{ptr}+#{pos}); #{x} = c_new(CUMO_REAL(*p),CUMO_IMAG(*p));}"
  when /Float/
    "#{x} = m_from_real(*(#{dtype}*)(#{ptr}+#{pos}))"
  when /UInt64/
    "#{x} = m_from_uint64(*(#{dtype}*)(#{ptr}+#{pos}))"
  when /UInt32/
    "#{x} = m_from_uint32(*(#{dtype}*)(#{ptr}+#{pos}))"
  when /Int64/
    "#{x} = m_from_int64(*(#{dtype}*)(#{ptr}+#{pos}))"
  when /Int32/
    "#{x} = m_from_int32(*(#{dtype}*)(#{ptr}+#{pos}))"
  when /Int/
    "#{x} = m_from_sint(*(#{dtype}*)(#{ptr}+#{pos}))"
  else
    raise "unknown type: #{type_name}"
  end
end

#subclass_condition(klass) ⇒ Object

A subclass of a dtype is that dtype, so a branch has to take it. It is asked only after every exact class has been tried, which leaves the common path the pointer comparisons it always had.



275
276
277
# File 'ext/cumo/narray/gen/narray_def.rb', line 275

def subclass_condition(klass)
  "RTEST(rb_class_inherited_p(#{klass},#{type_var}))"
end