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

Attributes inherited from ErbPP

#children, #parent

Instance Method Summary collapse

Methods inherited from ErbPP

#add_child, #attr_method, #attrs, #check_params, define_attrs, #description, #find, #find_tmpl, #get, #has_attr?, #init_def, #load_erb, #method_missing, #method_missing_alias, #parents, #result, #run, #search_method_in_parents, #set, #write

Constructor Details

#initialize(erb_path, type_file) ⇒ DataType

Returns a new instance of DataType.



164
165
166
167
168
169
170
171
172
# File 'lib/erbpp/narray_def.rb', line 164

def initialize(erb_path, type_file)
  super(nil, erb_path)
  @class_alias = []
  @upcast = []
  @mod_var = "cT"
  load_type(type_file) if type_file
  dirs = template_dir || ["tmpl"]
  @tmpl_dirs = dirs.map{|d| File.join(File.dirname(erb_path),d)}
end

Dynamic Method Handling

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

Instance Attribute Details

#tmpl_dirsObject (readonly)

Returns the value of attribute tmpl_dirs.



174
175
176
# File 'lib/erbpp/narray_def.rb', line 174

def tmpl_dirs
  @tmpl_dirs
end

Instance Method Details

#class_alias(*args) ⇒ Object



240
241
242
# File 'lib/erbpp/narray_def.rb', line 240

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

#load_type(file) ⇒ Object



176
177
178
# File 'lib/erbpp/narray_def.rb', line 176

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

#math_varObject



212
213
214
# File 'lib/erbpp/narray_def.rb', line 212

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

#real_class_name(arg = nil) ⇒ Object



216
217
218
219
220
221
222
# File 'lib/erbpp/narray_def.rb', line 216

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



224
225
226
227
228
229
230
# File 'lib/erbpp/narray_def.rb', line 224

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

#real_type_nameObject



236
237
238
# File 'lib/erbpp/narray_def.rb', line 236

def real_type_name
  @real_type_name ||= real_class_name.downcase
end

#real_type_varObject



232
233
234
# File 'lib/erbpp/narray_def.rb', line 232

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

#type_nameObject Also known as: tp



203
204
205
# File 'lib/erbpp/narray_def.rb', line 203

def type_name
  @type_name ||= class_name.downcase
end

#type_varObject



208
209
210
# File 'lib/erbpp/narray_def.rb', line 208

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

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



244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/erbpp/narray_def.rb', line 244

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



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/erbpp/narray_def.rb', line 257

def upcast_rb(c,t=nil)
  if t
    t = "numo_c#{t}"
  else
    t = "cT"
  end
  if c=="Integer"
    @upcast << "#ifdef RUBY_INTEGER_UNIFICATION"
    @upcast << "rb_hash_aset(hCast, rb_cInteger, #{t});"
    @upcast << "#else"
    @upcast << "rb_hash_aset(hCast, rb_cFixnum, #{t});"
    @upcast << "rb_hash_aset(hCast, rb_cBignum, #{t});"
    @upcast << "#endif"
  else
    @upcast << "rb_hash_aset(hCast, rb_c#{c}, #{t});"
  end
end