Class: AutoC::Vector

Inherits:
Association show all
Includes:
STD, Sequential
Defined in:
lib/autoc/vector.rb

Constant Summary collapse

Range =

Range

ContiguousRange

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

Constants inherited from Composite

Composite::DEFINITIONS, Composite::PRIVATE

Constants included from Entity

Entity::ReferenceSet

Instance Attribute Summary

Attributes inherited from Association

#index

Attributes inherited from Collection

#element

Attributes inherited from Composite

#_master, #visibility

Attributes inherited from Type

#signature

Instance Method Summary collapse

Methods inherited from Association

#comparable?, #copyable?, #destructible?, #hashable?, #orderable?

Methods inherited from Collection

#comparable?, #copyable?, #destructible?, #hashable?, new, #orderable?

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, #to_value

Methods included from Entity

#<=>, #complexity, #dependencies, #forward_declarations, #implementation, #interface, #position, #references, #total_dependencies, #total_references

Methods inherited from Type

abstract, #comparable?, #constructible?, #copy, #copyable?, #custom_constructible?, #custom_create, #default_constructible?, #default_create, #destroy, #destructible?, #hashable?, #inspect, #orderable?, #to_s, #to_type

Constructor Details

#initialize(type, element, parallel: nil, **kws) ⇒ Vector

Returns a new instance of Vector.



26
27
28
29
30
# File 'lib/autoc/vector.rb', line 26

def initialize(type, element, parallel: nil, **kws)
  super(type, element, :size_t, **kws)
  dependencies << STRING_H
  @parallel = parallel
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class AutoC::Composite

Instance Method Details

#_range_classObject



22
# File 'lib/autoc/vector.rb', line 22

def _range_class = Range

#rangeObject



24
# File 'lib/autoc/vector.rb', line 24

def range = @range ||= _range_class.new(self, visibility: visibility, parallel: @parallel)

#render_implementation(stream) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/autoc/vector.rb', line 72

def render_implementation(stream)
  if element.orderable?
    stream << %{
      static int
      #ifdef __POCC__
        __cdecl
      #endif
      #{ascend}(const void* left, const void* right) {
        return #{element.compare.("(*(#{element.lvalue})left)", "(*(#{element.lvalue})right)")};
      }
      static int
      #ifdef __POCC__
        __cdecl
      #endif
      #{descend}(const void* left, const void* right) {
        return -#{ascend}(left, right);
      }
      #{sort.prototype} {
        qsort(#{storage(:target)}, #{size.('*target')}, sizeof(#{element}), direction > 0 ? #{ascend} : #{descend});
      }
    }
  end
  super
end

#render_interface(stream) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/autoc/vector.rb', line 32

def render_interface(stream)
  if public?
    stream << %{
      /**
        #{defgroup}

        @brief Resizable vector of elements of type #{element}

        #{type} is a container that encapsulates dynamic size array of values of type #{element}.

        It is a contiguous direct access collection where elements can be directly referenced by an integer index belonging to the [0, @ref #{size}) range.

        For iteration over the vector elements refer to @ref #{range}.

        @see C++ [std::vector<T>](https://en.cppreference.com/w/cpp/container/vector)

        @since 2.0
      */
    }
    stream << %{
      /**
        #{ingroup}

        @brief Opaque structure holding state of the vector

        @since 2.0
      */
    }
  else
    stream << PRIVATE
  end
  stream << %{
    typedef struct {
      #{element.lvalue} elements; /**< @private */
      size_t size; /**< @private */
    } #{signature};
  }

end

#storage(target) ⇒ Object

Return C pointer to contiguous storage



97
# File 'lib/autoc/vector.rb', line 97

def storage(target) = "#{target}->elements" # Return C pointer to contiguous storage

#type_tagObject



99
# File 'lib/autoc/vector.rb', line 99

def type_tag = "#{signature}<#{element}>"