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  namespace maquina
18  {
20 
28  template<typename TIndex, typename TValue>
29  class SpanSpan
30  {
31  public:
32  SpanSpan() {}
33  SpanSpan(const gsl::span<TIndex>& offsets, const gsl::span<TValue>& values) :
34  _offsets(offsets),
35  _values(values) {}
36 
38  size_t size() const
39  {
40  return _offsets.size()-1;
41  }
42 
44  size_t length() const
45  {
46  return *_offsets.rbegin();
47  }
48 
50  const gsl::span<TValue> operator[](size_t index) const
51  {
52  const auto begin = _offsets[index];
53  return {&_values[begin], _offsets[index+1]-begin};
54  }
55 
57 
59  const gsl::span<TIndex>& offsets() const
60  {
61  return _offsets;
62  }
63 
65  const gsl::span<TValue>& values() const
66  {
67  return _values;
68  }
69 
70  private:
71  gsl::span<TIndex> _offsets;
72  gsl::span<TValue> _values;
73  };
74  }
SpanSpan(const gsl::span< TIndex > &offsets, const gsl::span< TValue > &values)
Definition: SpanSpan.h:33
SpanSpan()
Definition: SpanSpan.h:32
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:44
const gsl::span< TValue > operator[](size_t index) const
Returns the i-th sub-vector.
Definition: SpanSpan.h:50
size_t size() const
Return the number of sub-vectors.
Definition: SpanSpan.h:38
const gsl::span< TIndex > & offsets() const
Returns the offsets of each sub-vectors.
Definition: SpanSpan.h:59
A view on a "vector of sub-vectors of values" container.
Definition: SpanSpan.h:29
const gsl::span< TValue > & values() const
Returns the concatenated values of all the sub-vectors.
Definition: SpanSpan.h:65