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::CAMEL_CASE_DECORATOR, Composite::DEFINITIONS, Composite::PRIVATE, Composite::SNAKE_CASE_DECORATOR

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, #lvalue, #memory, new, #prefix, #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.



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

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



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

def _range_class = Range

#rangeObject



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

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

#render_implementation(stream) ⇒ Object



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

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



31
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
# File 'lib/autoc/vector.rb', line 31

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



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

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

#type_tagObject



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

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