Class: AutoC::Collection
Overview
Implemented types
-
UserDefinedType user-defined custom type
-
Reference counted reference type
Implemented collections
Ruby side operation
In the above example a C module Test represented by the C header test_auto.h and the C source test_auto.c is generated. The C++ counterpart of the generated collection is std::forward_list<int>.
C interface
Element types: values, references
Collections may contain both value and reference types, including other collections.
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.
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
-
#element ⇒ Object
readonly
Returns the value of attribute element.
-
#it_ref ⇒ Object
readonly
Returns the value of attribute it_ref.
Attributes inherited from Type
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #comparable? ⇒ Boolean
- #copyable? ⇒ Boolean
- #entities ⇒ Object
- #hash ⇒ Object
- #hashable? ⇒ Boolean
-
#initialize(type_name, element_type, visibility = :public) ⇒ Collection
constructor
A new instance of Collection.
- #write_intf_decls(stream, declare, define) ⇒ Object
Methods inherited from Type
#abort, #assert, #calloc, coerce, #constructible?, #destructible?, #extern, #free, #inline, #malloc, #method_missing, #orderable?, #prefix, #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
#initialize(type_name, element_type, visibility = :public) ⇒ Collection
Returns a new instance of Collection.
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/autoc/collection.rb', line 85 def initialize(type_name, element_type, visibility = :public) super(type_name, visibility) @it_ref = "#{it}*" @element = Type.coerce(element_type) @ctor = define_function(:ctor, Function::Signature.new([type_ref^:self])) @dtor = define_function(:dtor, Function::Signature.new([type_ref^:self])) @copy = define_function(:copy, Function::Signature.new([type_ref^:dst, type_ref^:src])) @equal = define_function(:equal, Function::Signature.new([type_ref^:lt, type_ref^:rt], :int)) @identify = define_function(:identify, Function::Signature.new([type_ref^:self], :size_t)) @less = define_function(:less, Function::Signature.new([type_ref^:lt, type_ref^:rt], :int)) element_type_check(element) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class AutoC::Type
Instance Attribute Details
#element ⇒ Object (readonly)
Returns the value of attribute element.
75 76 77 |
# File 'lib/autoc/collection.rb', line 75 def element @element end |
#it_ref ⇒ Object (readonly)
Returns the value of attribute it_ref.
75 76 77 |
# File 'lib/autoc/collection.rb', line 75 def it_ref @it_ref end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
79 |
# File 'lib/autoc/collection.rb', line 79 def ==(other) super && element == other.element end |
#comparable? ⇒ Boolean
117 |
# File 'lib/autoc/collection.rb', line 117 def comparable?; super && element.comparable? end |
#copyable? ⇒ Boolean
115 |
# File 'lib/autoc/collection.rb', line 115 def copyable?; super && element.copyable? end |
#entities ⇒ Object
83 |
# File 'lib/autoc/collection.rb', line 83 def entities; super << element end |
#hash ⇒ Object
77 |
# File 'lib/autoc/collection.rb', line 77 def hash; super ^ element.hash end |
#hashable? ⇒ Boolean
119 |
# File 'lib/autoc/collection.rb', line 119 def hashable?; super && element.hashable? end |
#write_intf_decls(stream, declare, define) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/autoc/collection.rb', line 98 def write_intf_decls(stream, declare, define) # Emit default redirection macros # Unlike other special methods the constructors may have extra arguments # Assume the constructor's first parameter is always a target ctor_ex = ctor.parameters.names[1..-1] ctor_lt = ["self"].concat(ctor_ex).join(',') ctor_rt = ["&self"].concat(ctor_ex).join(',') stream << %$ #define _#{ctor}(#{ctor_lt}) #{ctor}(#{ctor_rt}) #define _#{dtor}(self) #{dtor}(&self) #define _#{identify}(self) #{identify}(&self) #define _#{copy}(dst,src) #{copy}(&dst,&src) #define _#{equal}(lt,rt) #{equal}(<,&rt) #define _#{less}(lt,rt) #{less}(<,&rt) $ end |