Class: AutoC::Collection
- Includes:
- Redirecting
- Defined in:
- lib/autoc/collection.rb
Overview
Implemented types
-
UserDefinedType user-defined custom type
-
Reference counted reference type
-
String string builder type with value semantics
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?, #sortable?, #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.
93 94 95 96 97 98 99 |
# File 'lib/autoc/collection.rb', line 93 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.
83 84 85 |
# File 'lib/autoc/collection.rb', line 83 def element @element end |
#it_ref ⇒ Object (readonly)
Returns the value of attribute it_ref.
83 84 85 |
# File 'lib/autoc/collection.rb', line 83 def it_ref @it_ref end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
87 |
# File 'lib/autoc/collection.rb', line 87 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
120 |
# File 'lib/autoc/collection.rb', line 120 def comparable?; true && element.comparable? end |
#constructible? ⇒ Boolean
Collection always has default constructor
105 |
# File 'lib/autoc/collection.rb', line 105 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
116 |
# File 'lib/autoc/collection.rb', line 116 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
112 |
# File 'lib/autoc/collection.rb', line 112 def destructible?; true && element.destructible? end |
#entities ⇒ Object
91 |
# File 'lib/autoc/collection.rb', line 91 def entities; super << element end |
#hash ⇒ Object
85 |
# File 'lib/autoc/collection.rb', line 85 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
126 127 128 129 |
# File 'lib/autoc/collection.rb', line 126 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
108 |
# File 'lib/autoc/collection.rb', line 108 def initializable?; true end |
#write_intf_decls(stream, declare, define) ⇒ Object
131 132 133 |
# File 'lib/autoc/collection.rb', line 131 def write_intf_decls(stream, declare, define) write_redirectors(stream, declare, define) end |