Class: AutoC::Collection
Overview
Ruby side operation
Complete example for generation of a list of integers collection:
require "autoc"
AutoC::Module.generate!(:Test) do |c|
c << AutoC::List.new(:IntList, :int)
end
In the above example a C module Test represented by the C header test_auto.h and the C source test_auto.c are generated.
The C++ counterpart of the generated collection is std::forward_list<int>.
C interface
Element types: values, references
Thread safety
|
Warning
|
In its current state the implemented collections are not thread-safe.
|
Iteration
At the moment a fairly simple iteration functionality is implemented.
The iterators are modeled after the C# language.
All implemented iterators do not require destruction after use.
Basic iterator usage example:
MyVector c;
MyVectorIt it;
...
MyVectorItCtor(&it, &c);
while(MyVectorItMove(&it)) {
Element e = MyVectorItGet(&it);
...
ElementDtor(e);
}
|
Warning
|
the collection being iterated must not be modified in any way otherwise the iterator behavior is undefined.
|
Instance Attribute Summary collapse
Attributes inherited from Type
#type
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Type
#abort, #assert, #calloc, #extern, #free, #inline, #malloc, #method_missing, #static, #write_decls, #write_defs, #write_exported_declarations, #write_exported_types, #write_implementations, #write_intf
Methods inherited from Code
#attach, #priority, #source_size, #write_decls, #write_defs, #write_intf
Constructor Details
#initialize(type_name, element_type, visibility = :public) ⇒ Collection
Returns a new instance of Collection.
75
76
77
78
|
# File 'lib/autoc/collection.rb', line 75
def initialize(type_name, element_type, visibility = :public)
super(type_name, visibility)
@element = Collection.coerce(element_type)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class AutoC::Type
Instance Attribute Details
#element ⇒ Object
Returns the value of attribute element.
71
72
73
|
# File 'lib/autoc/collection.rb', line 71
def element
@element
end
|
Class Method Details
.coerce(type) ⇒ Object
67
68
69
|
# File 'lib/autoc/collection.rb', line 67
def self.coerce(type)
type.is_a?(Type) ? type : UserDefinedType.new(type)
end
|
Instance Method Details
#copy(*args) ⇒ Object
100
101
102
103
104
105
106
107
108
|
# File 'lib/autoc/collection.rb', line 100
def copy(*args)
if args.empty?
super()
else
check_args(args, 2)
dst, src = args
super() + "(&#{dst}, &#{src})"
end
end
|
#ctor(*args) ⇒ Object
80
81
82
83
84
85
86
87
88
|
# File 'lib/autoc/collection.rb', line 80
def ctor(*args)
if args.empty?
super()
else
check_args(args, 1)
obj = args.first
super() + "(&#{obj})"
end
end
|
#dtor(*args) ⇒ Object
90
91
92
93
94
95
96
97
98
|
# File 'lib/autoc/collection.rb', line 90
def dtor(*args)
if args.empty?
super()
else
check_args(args, 1)
obj = args.first
super() + "(&#{obj})"
end
end
|
#entities ⇒ Object
73
|
# File 'lib/autoc/collection.rb', line 73
def entities; super + [element] end
|
#equal(*args) ⇒ Object
110
111
112
113
114
115
116
117
118
|
# File 'lib/autoc/collection.rb', line 110
def equal(*args)
if args.empty?
super()
else
check_args(args, 2)
lt, rt = args
super() + "(&#{lt}, &#{rt})"
end
end
|
#identify(*args) ⇒ Object
124
125
126
|
# File 'lib/autoc/collection.rb', line 124
def identify(*args)
args.empty? ? super() : raise("#{self.class} provides no hashing functionality")
end
|
#less(*args) ⇒ Object
120
121
122
|
# File 'lib/autoc/collection.rb', line 120
def less(*args)
args.empty? ? super() : raise("#{self.class} provides no ordering functionality")
end
|