Class: AutoC::UserDefinedType

Inherits:
Type
  • Object
show all
Defined in:
lib/autoc/type.rb

Overview

UserDefinedType represents a user-defined custom type.

Constant Summary

Instance Attribute Summary

Attributes inherited from Type

#type, #type_ref

Instance Method Summary (collapse)

Methods inherited from Type

#==, #abort, #assert, #calloc, coerce, #comparable?, #constructible?, #copyable?, #destructible?, #extern, #free, #hash, #hashable?, #inline, #malloc, #method_missing, #orderable?, #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

- (UserDefinedType) initialize(opt)

Returns a new instance of UserDefinedType



301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# File 'lib/autoc/type.rb', line 301

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?
  opt.default = :unset # This allows to use nil as a value to indicate that the specific method is not avaliable
  opt[:ctor].nil? ? @capability.subtract([:constructible]) : define_callable(:ctor, opt) {def call(obj) "((#{obj}) = 0)" end}
  opt[:dtor].nil? ? @capability.subtract([:destructible]) : define_callable(:dtor, opt) {def call(obj) end}
  opt[:copy].nil? ? @capability.subtract([:copyable]) : define_callable(:copy, opt) {def call(dst, src) "((#{dst}) = (#{src}))" end}
  opt[:equal].nil? ? @capability.subtract([:comparable]) : define_callable(:equal, opt) {def call(lt, rt) "((#{lt}) == (#{rt}))" end}
  opt[:less].nil? ? @capability.subtract([:orderable]) : define_callable(:less, opt) {def call(lt, rt) "((#{lt}) < (#{rt}))" end}
  opt[:identify].nil? ? @capability.subtract([:hashable]) : define_callable(:identify, opt) {def call(obj) "((size_t)(#{obj}))" end}
  # Handle specific requirements
  @capability.subtract([:constructible]) if @ctor.parameters.size > 1 # Constructible type must not have extra parameters besides self
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class AutoC::Type

Instance Method Details

- (Object) entities

PublicDeclaration



297
# File 'lib/autoc/type.rb', line 297

def entities; super.concat(@deps) end

- (Object) prefix



299
# File 'lib/autoc/type.rb', line 299

def prefix; @prefix.nil? ? super : @prefix end