Class: AutoC::Collection
- Includes:
- Redirecting
- Defined in:
- lib/autoc/collection.rb
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
Collection always has equality tester but the element is required to be comparable on its own because collection comparison incurs comparison of all contained elements.
-
#constructible? ⇒ Boolean
Collection always has default constructor.
-
#copyable? ⇒ Boolean
Collection always has copy constructor but the element is required to be copyable on its own because collection copying incurs copying of all contained elements.
-
#destructible? ⇒ Boolean
Collection always has destructor but the element is required to be destructible on its own because collection destruction incurs destruction of all contained elements.
- #entities ⇒ Object
- #hash ⇒ Object
-
#hashable? ⇒ Boolean
Collection always has hash calculation function but the element is required to be hashable on its own because collection comparison incurs hash calculation for all contained elements.
-
#initializable? ⇒ Boolean
Collection always has constructor.
-
#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, #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.
87 88 89 90 91 92 93 |
# File 'lib/autoc/collection.rb', line 87 def initialize(type_name, element_type, visibility = :public) super(type_name, visibility) @it_ref = "#{it}*" @element = Type.coerce(element_type) initialize_redirectors element_requirement(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.
77 78 79 |
# File 'lib/autoc/collection.rb', line 77 def element @element end |
#it_ref ⇒ Object (readonly)
Returns the value of attribute it_ref.
77 78 79 |
# File 'lib/autoc/collection.rb', line 77 def it_ref @it_ref end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
81 |
# File 'lib/autoc/collection.rb', line 81 def ==(other) super && element == other.element end |
#comparable? ⇒ Boolean
Collection always has equality tester but the element is required to be comparable on its own because collection comparison incurs comparison of all contained elements
114 |
# File 'lib/autoc/collection.rb', line 114 def comparable?; true && element.comparable? end |
#constructible? ⇒ Boolean
Collection always has default constructor
99 |
# File 'lib/autoc/collection.rb', line 99 def constructible?; true end |
#copyable? ⇒ Boolean
Collection always has copy constructor but the element is required to be copyable on its own because collection copying incurs copying of all contained elements
110 |
# File 'lib/autoc/collection.rb', line 110 def copyable?; true && element.copyable? end |
#destructible? ⇒ Boolean
Collection always has destructor but the element is required to be destructible on its own because collection destruction incurs destruction of all contained elements
106 |
# File 'lib/autoc/collection.rb', line 106 def destructible?; true && element.destructible? end |
#entities ⇒ Object
85 |
# File 'lib/autoc/collection.rb', line 85 def entities; super << element end |
#hash ⇒ Object
79 |
# File 'lib/autoc/collection.rb', line 79 def hash; super ^ element.hash end |
#hashable? ⇒ Boolean
Collection always has hash calculation function but the element is required to be hashable on its own because collection comparison incurs hash calculation for all contained elements
120 121 122 123 |
# File 'lib/autoc/collection.rb', line 120 def hashable? # Since using collection as an element of a hash-based container also requires it to be comparable as well comparable? && element.hashable? end |
#initializable? ⇒ Boolean
Collection always has constructor
102 |
# File 'lib/autoc/collection.rb', line 102 def initializable?; true end |
#write_intf_decls(stream, declare, define) ⇒ Object
125 126 127 |
# File 'lib/autoc/collection.rb', line 125 def write_intf_decls(stream, declare, define) write_redirectors(stream, declare, define) end |