Next: , Previous: C++ Union, Up: C++ mappings


6.2.9 Mapping for sequence types

GenoM IDL sequences mapping differ for bounded or unbouded variations of the sequence. The unbounded sequences maps onto the std::vector template class provided by the C++ standard. The bounded sequence maps onto a C++ genom::bounded_sequence template class. The definition of genom::bounded_sequence is very similar to std::array but provides a variable number of elements.

For instance, the following IDL:

      typedef sequence<long> unbounded;
      typedef sequence<long,16> bounded;

would map into

      typedef std::vector<int32_t> unbounded;
      typedef genom::bounded_sequence<int32_t, 16> bounded;

The interface of genom::bounded_sequence is the following:

  template <typename T, size_t N>
  struct bounded_sequence {
    // types:
    typedef T                                     value_type;
    typedef value_type&                           reference;
    typedef const value_type&                     const_reference;
    typedef value_type*                           iterator;
    typedef const value_type*                     const_iterator;
    typedef value_type*                           pointer;
    typedef const value_type*                     const_pointer;
    typedef size_t                                size_type;
    typedef ptrdiff_t                             difference_type;
    typedef std::reverse_iterator<iterator>       reverse_iterator;
    typedef std::reverse_iterator<const_iterator> const_reverse_iterator;

    value_type e[N];
    size_type n;

    // No explicit construct/copy/destroy for aggregate type

    void fill(const value_type &u);

    // iterators:
    iterator begin();
    iterator end();
    const_iterator begin() const;
    const_iterator end() const;

    reverse_iterator rbegin();
    reverse_iterator rend();
    const_reverse_iterator rbegin() const;
    const_reverse_iterator rend() const;

    const_iterator cbegin() const;
    const_iterator cend() const;
    const_reverse_iterator crbegin() const;
    const_reverse_iterator crend() const;

    // capacity:
    size_type size() const;
    void resize(size_type l, value_type u = value_type());
    size_type max_size() const;
    bool empty() const;

    // element access:
    reference operator[](size_type i);
    const_reference operator[](size_type i) const;
    reference at(size_type i);
    const_reference at(size_type i) const;

    reference front();
    const_reference front() const;
    reference back();
    const_reference back() const;
    value_type *data();
    const value_type *data() const;

    // modifiers
    void swap(bounded_sequence &a);
    void clear();
  };