Class: AutoC::Range
Abstract
Overview
Constant Summary
collapse
- INFO =
Code.new interface: %{
/**
@page Range
@brief Generalization of the iterator
A range is a means of traversing through the container's contents in which it is similar to the iterator.
Current implementation is loosely modeled after the [D language ranges](https://dlang.org/phobos/std_range.html).
Note that current ranges' implementation is fairly basic lacking iterable alteration, thread safety etc.
On the other hand, all currently implemented ranges are the simple value types which do not require explicit
copying/destruction thus making life slightly easier.
Therefore they can be passed out in/out the functions as is - just watch out the dangers of passing the
iterable values they are bound to.
A sample code involving iteration over the contents of a hypothetical `List` iterable value is shown below.
@code{.c}
List list;
...
for(ListRange r = ListRangeNew(&list); !ListRangeEmpty(&r); ListRangePopFront(&r)) {
... = ListRangeTakeFront(&r);
}
@endcode
Currently implemented range archetypes:
@subpage InputRange
@subpage ForwardRange
@subpage BidirectionalRange
@subpage DirectAccessRange
@since 2.0
@page InputRange
@brief Basic unidirectional range
An input range is a @ref Range which sports a single direction of traversing the elements.
@since 2.0
@page ForwardRange
@brief Unidirectional range with checkpoint
A forward range is an @ref InputRange which also allows to make a snapshot of the current range's state for possible fallback.
@since 2.0
@page BidirectionalRange
@brief Basic bidirectional range
A bidirectional range is a @ref ForwardRange which can also be traversed backwards.
@since 2.0
@page DirectAccessRange
@brief Bidirectional range with indexed access to specific elements
A random access range is a @ref BidirectionalRange which is also capable of accessing the elements directly using index.
@since 2.0
*/
}
Constants inherited
from Composite
Composite::DEFINITIONS, Composite::PRIVATE
Constants included
from Entity
Entity::ReferenceSet
Constants included
from STD
STD::ASSERT_H, STD::BOOL, STD::CHAR, STD::COMPLEX, STD::COMPLEX_H, STD::DOUBLE, STD::DOUBLE_COMPLEX, STD::DOUBLE_T, STD::FLOAT, STD::FLOAT_COMPLEX, STD::FLOAT_T, STD::INT, STD::INTMAX_T, STD::INTPTR_T, STD::INTTYPES_H, STD::LONG, STD::LONG_DOUBLE, STD::LONG_DOUBLE_COMPLEX, STD::LONG_LONG, STD::MALLOC_H, STD::MATH_H, STD::PTRDIFF_T, STD::SHORT, STD::SIGNED_CHAR, STD::SIZE_T, STD::STDBOOL_H, STD::STDDEF_H, STD::STDLIB_H, STD::STRING_H, STD::UINTMAX_T, STD::UINTPTR_T, STD::UNSIGNED, STD::UNSIGNED_CHAR, STD::UNSIGNED_LONG, STD::UNSIGNED_LONG_LONG, STD::UNSIGNED_SHORT, STD::WCHAR_T
Instance Attribute Summary collapse
Attributes inherited from Composite
#_master, #visibility
Attributes inherited from Type
#signature
Instance Method Summary
collapse
Methods inherited from Composite
allocator, allocator=, #const_lvalue, #const_rvalue, decorator, decorator=, #defgroup, hasher, #hasher, hasher=, #identifier, #ingroup, #inspect, #internal?, #lvalue, #memory, new, #prefix, #private?, #public?, #respond_to_missing?, #rvalue
Methods included from Entity
#<=>, #complexity, #dependencies, #forward_declarations, #implementation, #interface, #position, #references, #total_dependencies, #total_references
Methods inherited from Type
abstract, #constructible?, #copy, #custom_constructible?, #custom_create, #default_create, #destroy, #hashable?, #inspect, #to_s, #to_type
Constructor Details
#initialize(iterable, visibility:) ⇒ Range
Returns a new instance of Range.
27
28
29
30
|
# File 'lib/autoc/ranges.rb', line 27
def initialize(iterable, visibility:)
super(iterable.identifier(:range, abbreviate: internal?), visibility:)
dependencies << (@iterable = iterable) << INFO
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class AutoC::Composite
Instance Attribute Details
#iterable ⇒ Object
Also known as:
_iterable
Returns the value of attribute iterable.
17
18
19
|
# File 'lib/autoc/ranges.rb', line 17
def iterable
@iterable
end
|
Instance Method Details
#brief ⇒ Object
34
|
# File 'lib/autoc/ranges.rb', line 34
def brief = "@brief Range (iterator) for type #{iterable.type_tag}"
|
#comparable? ⇒ Boolean
21
|
# File 'lib/autoc/ranges.rb', line 21
def comparable? = false
|
#copyable? ⇒ Boolean
23
|
# File 'lib/autoc/ranges.rb', line 23
def copyable? = false
|
#default_constructible? ⇒ Boolean
19
|
# File 'lib/autoc/ranges.rb', line 19
def default_constructible? = false
|
#destructible? ⇒ Boolean
20
|
# File 'lib/autoc/ranges.rb', line 20
def destructible? = false
|
#orderable? ⇒ Boolean
22
|
# File 'lib/autoc/ranges.rb', line 22
def orderable? = false
|
#render_type_description(stream) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/autoc/ranges.rb', line 36
def render_type_description(stream)
stream << %{
/**
#{defgroup}
#{brief}
Range is means of traversing though the container contents in a sequential manner.
It is basically an extension of iterator.
It can be used the following way:
@code{.c}
for(#{signature} r = #{new}(&it); !#{empty}(&r); #{pop_front}(&r)) { ... }
@endcode
@see @ref Range
@since 2.0
*/
}
end
|
#to_value ⇒ Object
25
|
# File 'lib/autoc/ranges.rb', line 25
def to_value = @v ||= Value.new(self)
|
#type_tag ⇒ Object
32
|
# File 'lib/autoc/ranges.rb', line 32
def type_tag = "#{iterable.type_tag}::Range"
|