Rumba C++ SDK
SpanSpan.h
Go to the documentation of this file.
1 /*
2 
3  *
4  ***
5  *****
6  ********************* Mercenaries Engineering SARL
7  ***************** Copyright (C) 2018
8  *************
9  ********* http://www.mercenaries-engineering.com
10  ***********
11  **** ****
12  ** **
13 
14 */
15 #pragma once
16 
17 #include <gsl/span>
18 
19  namespace maquina
20  {
22 
30  template<typename TIndex, typename TValue>
31  class SpanSpan
32  {
33  public:
34  SpanSpan() {}
35  SpanSpan(const gsl::span<TIndex>& offsets, const gsl::span<TValue>& values) :
36  _offsets(offsets),
37  _values(values) {}
38 
40  size_t size() const
41  {
42  return _offsets.size()-1;
43  }
44 
46  size_t length() const
47  {
48  return *_offsets.rbegin();
49  }
50 
52  const gsl::span<TValue> operator[](size_t index) const
53  {
54  const auto begin = _offsets[index];
55  return {_values.data()+begin, _offsets[index+1]-begin};
56  }
57 
59 
61  const gsl::span<TIndex>& offsets() const
62  {
63  return _offsets;
64  }
65 
67  const gsl::span<TValue>& values() const
68  {
69  return _values;
70  }
71 
72  private:
73  gsl::span<TIndex> _offsets;
74  gsl::span<TValue> _values;
75  };
76  }
SpanSpan(const gsl::span< TIndex > &offsets, const gsl::span< TValue > &values)
Definition: SpanSpan.h:35
SpanSpan()
Definition: SpanSpan.h:34
This version of the SDK is unstable, i-e, it may change with no warning.
Definition: AddCurveAction.h:20
size_t length() const
Return the total number of values.
Definition: SpanSpan.h:46
const gsl::span< TValue > operator[](size_t index) const
Returns the i-th sub-vector.
Definition: SpanSpan.h:52
size_t size() const
Return the number of sub-vectors.
Definition: SpanSpan.h:40
const gsl::span< TIndex > & offsets() const
Returns the offsets of each sub-vectors.
Definition: SpanSpan.h:61
A view on a "vector of sub-vectors of values" container.
Definition: SpanSpan.h:31
const gsl::span< TValue > & values() const
Returns the concatenated values of all the sub-vectors.
Definition: SpanSpan.h:67