class AutoC::Range::ForwardRange::DirectAccessRange
@abstract
Private Instance Methods
configure()
click to toggle source
Calls superclass method
AutoC::Range::ForwardRange::BidirectionalRange#configure
# File lib/autoc/ranges.rb, line 302 def configure super method(:size_t, :size, { range: const_rvalue }).configure do header %{ @brief Get a number of elements in the range @param[in] range range to query @return a number of elements This function returns a number of elements between the range's front and back positions inclusively. As a consequence, the result changes with every invocation of position change functions (@ref #{type.pop_front}, @ref #{type.pop_back}), so be careful not to cache this value. For empty range this function returns 0. @since 2.0 } end method(:int, :check, { range: const_rvalue, index: :size_t.const_rvalue } ).configure do dependencies << size inline_code %{ assert(range); return index < #{size.(range)}; } header %{ @brief Validate specified range's index @param[in] range range to query @param[in] index index to verify @return non-zero value if speicfied index is valid and zero value otherwise This function performs the range's index validity check. In any case, this function should be used for the index validation prior getting direct access to range's elements with @ref #{type.get}, @ref #{type.view} etc. as these functions do not normally do it themselves for performance reasons. @since 2.0 } end method(iterable.element.const_lvalue, :view, { range: const_rvalue, index: :size_t.const_rvalue }).configure do header %{ @brief Get view of the specific element @param[in] range range to view element from @param[in] index position to access element at @return a view of element at `index` This function is used to get a constant reference (in form of the C pointer) to the value contained in the range at the specific position. Refer to @ref #{type.get} to get a copy of the element. @note The specified `index` is required to be within the [0, @ref #{type.size}) range. @since 2.0 } end method(iterable.element, :get, { range: const_rvalue, index: :size_t.const_rvalue }, constraint:-> { iterable.element.copyable? }).configure do dependencies << check << view inline_code %{ #{iterable.element} r; #{iterable.element.const_lvalue} e; assert(#{check.(range, index)}); e = #{view.(range, index)}; #{iterable.element.copy.(:r, '*e')}; return r; } header %{ @brief Get a copy of the specific element @param[in] range range to retrieve element from @param[in] index position to view element at @return a *copy* of element at `index` This function is used to get a *copy* of the value contained in the range at the specific position. Refer to @ref #{type.view} to get a view of the element without making an independent copy. This function requires the element type to be *copyable* (i.e. to have a well-defined copy operation). @note The specified `position` is required to be within the [0, @ref #{type.size}) range. @since 2.0 } end end