Class: AutoC::Collection
Overview
Implemented collections
-
Vector a fixed-sized array
-
List a single linked list
-
Queue a double linked list
-
HashSet a hash-based set
-
HashMap a hash-based map
Ruby side operation
.Complete example for generation of a list of integers collection:
- source,ruby
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.hand the C sourcetest_auto.care 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:
- source,c
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.
Constant Summary
Constants inherited from Type
Instance Attribute Summary collapse
-
#element ⇒ Object
readonly
Returns the value of attribute element.
Attributes inherited from Type
Class Method Summary collapse
Instance Method Summary collapse
- #copy(*args) ⇒ Object
- #ctor(*args) ⇒ Object
- #dtor(*args) ⇒ Object
- #entities ⇒ Object
- #equal(*args) ⇒ Object
- #identify(*args) ⇒ Object
-
#initialize(type_name, element_type, visibility = :public) ⇒ Collection
constructor
A new instance of Collection.
- #less(*args) ⇒ Object
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 (readonly)
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 |