Class: DataType

Inherits:
ErbPP show all
Includes:
DefMethod
Defined in:
lib/erbpp/narray_def.rb

Overview


Constant Summary

Constants inherited from ErbPP

ErbPP::ATTRS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DefMethod

#accum, #accum_binary, #accum_index, #binary, #binary2, #bit_count, #bit_reduce, #cast_array, #cast_func, #cond_binary, #cond_unary, #cum, #def_alias, #def_allocate, #def_id, #def_method, #def_singleton, #find_method, #find_tmpl, #math, #pow, #qsort, #set2, #store, #store_array, #store_bit, #store_from, #store_numeric, #unary, #unary2

Methods inherited from ErbPP

#attr_method, #attrs, #check_params, define_attrs, #has_attr?, #load_erb, #method_missing, #method_missing_alias, #parents, #result, #run, #search_method_in_parents

Constructor Details

#initialize(erb_path, type_file) ⇒ DataType

Returns a new instance of DataType.



153
154
155
156
157
158
159
160
161
# File 'lib/erbpp/narray_def.rb', line 153

def initialize(erb_path, type_file)
  super(nil, erb_path)
  @class_alias = []
  @upcast = []
  @mod_var = "cT"
  load_type(type_file) if type_file
  dir = template_dir || "tmpl"
  @tmpl_dir = File.join(File.dirname(erb_path),dir)
end

Dynamic Method Handling

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

Instance Attribute Details

#tmpl_dirObject (readonly)

Returns the value of attribute tmpl_dir.



163
164
165
# File 'lib/erbpp/narray_def.rb', line 163

def tmpl_dir
  @tmpl_dir
end

Instance Method Details

#class_alias(*args) ⇒ Object



227
228
229
# File 'lib/erbpp/narray_def.rb', line 227

def class_alias(*args)
  @class_alias.concat(args)
end

#load_type(file) ⇒ Object



165
166
167
# File 'lib/erbpp/narray_def.rb', line 165

def load_type(file)
  eval File.read(file)
end

#math_varObject



199
200
201
# File 'lib/erbpp/narray_def.rb', line 199

def math_var
  @math_var ||= "numo_m"+class_name+"Math"
end

#real_class_name(arg = nil) ⇒ Object



203
204
205
206
207
208
209
# File 'lib/erbpp/narray_def.rb', line 203

def real_class_name(arg=nil)
  if arg.nil?
    @real_class_name ||= class_name
  else
    @real_class_name = arg
  end
end

#real_ctype(arg = nil) ⇒ Object



211
212
213
214
215
216
217
# File 'lib/erbpp/narray_def.rb', line 211

def real_ctype(arg=nil)
  if arg.nil?
    @real_ctype ||= ctype
  else
    @real_ctype = arg
  end
end

#real_type_nameObject



223
224
225
# File 'lib/erbpp/narray_def.rb', line 223

def real_type_name
  @real_type_name ||= real_class_name.downcase
end

#real_type_varObject



219
220
221
# File 'lib/erbpp/narray_def.rb', line 219

def real_type_var
  @real_type_var ||= "numo_c"+real_class_name
end

#type_nameObject Also known as: tp



190
191
192
# File 'lib/erbpp/narray_def.rb', line 190

def type_name
  @type_name ||= class_name.downcase
end

#type_varObject



195
196
197
# File 'lib/erbpp/narray_def.rb', line 195

def type_var
  @type_var ||= "numo_c"+class_name
end

#upcast(c = nil, t = nil) ⇒ Object



231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/erbpp/narray_def.rb', line 231

def upcast(c=nil,t=nil)
  if c
    if t
      t = "numo_c#{t}"
    else
      t = "cT"
    end
    @upcast << "rb_hash_aset(hCast, numo_c#{c}, #{t});"
  else
    @upcast
  end
end

#upcast_rb(c, t = nil) ⇒ Object



244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/erbpp/narray_def.rb', line 244

def upcast_rb(c,t=nil)
  if t
    t = "numo_c#{t}"
  else
    t = "cT"
  end
  if c=="Integer"
    if defined?(Fixnum) && Fixnum != Integer
      @upcast << "rb_hash_aset(hCast, rb_cFixnum, #{t});"
      @upcast << "rb_hash_aset(hCast, rb_cBignum, #{t});"
    else
      # RUBY_VERSION >= "2.4.0"
      @upcast << "rb_hash_aset(hCast, rb_cInteger, #{t});"
    end
  else
    @upcast << "rb_hash_aset(hCast, rb_c#{c}, #{t});"
  end
end