Class: AutoC::UserDefinedType
Overview
UserDefinedType represents a user-defined custom type.
Instance Attribute Summary
Attributes inherited from Type
#type, #type_ref
Instance Method Summary
collapse
Methods inherited from Type
#==, #abort, #assert, #calloc, coerce, #extern, #free, #hash, #inline, #malloc, #method_missing, #private?, #public?, #static, #static?, #write_decls, #write_defs, #write_intf
Methods inherited from Code
#attach, #priority, #source_size, #write_decls, #write_defs, #write_intf
Constructor Details
Returns a new instance of UserDefinedType.
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
# File 'lib/autoc/type.rb', line 318
def initialize(opt)
opt = {:type => opt} if opt.is_a?(::Symbol) || opt.is_a?(::String)
if opt.is_a?(Hash)
t = opt[:type].nil? ? raise("type is not specified") : opt[:type].to_s
else
raise "argument must be a Symbol, String or Hash"
end
super(t)
@prefix = AutoC.c_id(opt[:prefix]) unless opt[:prefix].nil?
@deps = []; @deps << PublicDeclaration.new(opt[:forward]) unless opt[:forward].nil?
define_callable(:ctor, opt) {def call(obj) "((#{obj}) = 0)" end}
define_callable(:dtor, opt) {def call(obj) end}
define_callable(:copy, opt) {def call(dst, src) "((#{dst}) = (#{src}))" end}
define_callable(:equal, opt) {def call(lt, rt) "((#{lt}) == (#{rt}))" end}
define_callable(:less, opt) {def call(lt, rt) "((#{lt}) < (#{rt}))" end}
define_callable(:identify, opt) {def call(obj) "((size_t)(#{obj}))" end}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class AutoC::Type
Instance Method Details
#comparable? ⇒ Boolean
344
|
# File 'lib/autoc/type.rb', line 344
def comparable?; !@equal.nil? end
|
#constructible? ⇒ Boolean
336
|
# File 'lib/autoc/type.rb', line 336
def constructible?; !@ctor.nil? && @ctor.parameters.size == 1 end
|
#copyable? ⇒ Boolean
342
|
# File 'lib/autoc/type.rb', line 342
def copyable?; !@copy.nil? end
|
#destructible? ⇒ Boolean
340
|
# File 'lib/autoc/type.rb', line 340
def destructible?; !@dtor.nil? end
|
#entities ⇒ Object
314
|
# File 'lib/autoc/type.rb', line 314
def entities; super.concat(@deps) end
|
#hashable? ⇒ Boolean
348
|
# File 'lib/autoc/type.rb', line 348
def hashable?; !@identify.nil? end
|
#initializable? ⇒ Boolean
338
|
# File 'lib/autoc/type.rb', line 338
def initializable?; !@ctor.nil? end
|
#orderable? ⇒ Boolean
346
|
# File 'lib/autoc/type.rb', line 346
def orderable?; !@less.nil? end
|
#prefix ⇒ Object
316
|
# File 'lib/autoc/type.rb', line 316
def prefix; @prefix.nil? ? super : @prefix end
|
#write_impls(stream, define) ⇒ Object
356
|
# File 'lib/autoc/type.rb', line 356
def write_impls(stream, define) end
|
#write_intf_decls(stream, declare, define) ⇒ Object
354
|
# File 'lib/autoc/type.rb', line 354
def write_intf_decls(stream, declare, define) end
|
#write_intf_types(stream) ⇒ Object
The methods below are left empty as the user-defined types have no implementation on their own
352
|
# File 'lib/autoc/type.rb', line 352
def write_intf_types(stream) end
|