GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/dynamic-graph/signal-array.h Lines: 48 52 92.3 %
Date: 2023-03-15 12:04:10 Branches: 20 36 55.6 %

Line Branch Exec Source
1
// -*- mode: c++ -*-
2
// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse,
3
// JRL, CNRS/AIST.
4
//
5
6
#ifndef DYNAMIC_GRAPH_SIGNAL_ARRAY_H
7
#define DYNAMIC_GRAPH_SIGNAL_ARRAY_H
8
#include <dynamic-graph/dynamic-graph-api.h>
9
#include <dynamic-graph/signal-base.h>
10
#include <stdio.h>
11
12
#include <vector>
13
14
namespace dynamicgraph {
15
16
/// \ingroup dgraph
17
///
18
/// \brief TODO
19
template <class Time>
20
class SignalArray_const {
21
 public:
22
  static const int DEFAULT_SIZE = 20;
23
24
 protected:
25
  std::vector<const SignalBase<Time> *> const_array;
26
  unsigned int size, rank;
27
28
 public:
29
37
  SignalArray_const<Time>(const unsigned int &sizeARG = DEFAULT_SIZE)
30
37
      : const_array(sizeARG), size(sizeARG), rank(0) {}
31
32
9
  SignalArray_const<Time>(const SignalBase<Time> &sig)
33
9
      : const_array(DEFAULT_SIZE), size(DEFAULT_SIZE), rank(0) {
34
9
    addElmt(&sig);
35
9
  }
36
37
1
  SignalArray_const<Time>(const SignalArray<Time> &siga)
38
      : const_array(siga.getSize()),
39
        size(siga.getSize()),
40


1
        rank(siga.getSize()) {
41

3
    for (unsigned int i = 0; i < rank; ++i) const_array[i] = &siga[i];
42
1
  }
43
44
  SignalArray_const<Time>(const SignalArray_const<Time> &siga)
45
      : const_array(siga.getSize()),
46
        size(siga.getSize()),
47
        rank(siga.getSize()) {
48
    for (unsigned int i = 0; i < rank; ++i) const_array[i] = &siga[i];
49
  }
50
51
72
  virtual ~SignalArray_const<Time>() {}
52
53
 protected:
54
13
  void addElmt(const SignalBase<Time> *el) {
55
13
    if (rank >= size) {
56
2
      size += DEFAULT_SIZE;
57
2
      const_array.resize(size);
58
    }
59
13
    const_array[rank++] = el;
60
13
  }
61
62
 public:
63
4
  virtual SignalArray_const<Time> &operator<<(const SignalBase<Time> &sig) {
64
4
    addElmt(&sig);
65
4
    return *this;
66
  }
67
68
 public:
69
9
  virtual const SignalBase<Time> &operator[](const unsigned int &idx) const {
70
9
    return *const_array[idx];
71
  }
72
59
  virtual unsigned int getSize() const { return rank; }
73
};
74
75
template <class Time>
76
SignalArray_const<Time> operator<<(const SignalBase<Time> &sig1,
77
                                   const SignalBase<Time> &sig2) {
78
  SignalArray_const<Time> res(sig1);
79
  res << sig2;
80
  return res;
81
}
82
83
/// \ingroup dgraph
84
///
85
/// \brief TODO
86
template <class Time>
87
class SignalArray : public SignalArray_const<Time> {
88
 public:
89
  using SignalArray_const<Time>::DEFAULT_SIZE;
90
  using SignalArray_const<Time>::size;
91
  using SignalArray_const<Time>::rank;
92
93
 protected:
94
  mutable std::vector<SignalBase<Time> *> array;
95
96
 public:
97
20
  SignalArray<Time>(const unsigned int &sizeARG = DEFAULT_SIZE)
98

20
      : SignalArray_const<Time>(0), array(sizeARG) {
99
20
    size = sizeARG;
100
20
  }
101
102
10
  SignalArray<Time>(SignalBase<Time> &sig)
103

10
      : SignalArray_const<Time>(0), array(DEFAULT_SIZE) {
104
10
    size = DEFAULT_SIZE;
105
10
    addElmt(&sig);
106
10
  }
107
108
  SignalArray<Time>(const SignalArray<Time> &siga)
109
      : SignalArray_const<Time>(siga.getSize()), array(siga.getSize()) {
110
    rank = siga.getSize();
111
    for (unsigned int i = 0; i < rank; ++i) array[i] = &siga[i];
112
  }
113
114
48
  virtual ~SignalArray<Time>() {}
115
116
 protected:
117
28
  void addElmt(SignalBase<Time> *el) {
118
28
    if (rank >= size) {
119
1
      size += DEFAULT_SIZE;
120
1
      array.resize(size);
121
    }
122
28
    array[rank++] = el;
123
28
  }
124
125
 public:
126
18
  virtual SignalArray<Time> &operator<<(SignalBase<Time> &sig) {
127
18
    addElmt(&sig);
128
18
    return *this;
129
  }
130
131
  virtual SignalArray_const<Time> operator<<(
132
      const SignalBase<Time> &sig) const {
133
    SignalArray_const<Time> res(*this);
134
    res << sig;
135
    return res;
136
  }
137
138
25
  virtual SignalBase<Time> &operator[](const unsigned int &idx) const {
139
25
    return *array[idx];
140
  }
141
};
142
143
template <class Time>
144
8
SignalArray<Time> operator<<(SignalBase<Time> &sig1, SignalBase<Time> &sig2) {
145
8
  SignalArray<Time> res(sig1);
146
8
  res << sig2;
147
8
  return res;
148
}
149
150
DYNAMIC_GRAPH_DLLAPI extern SignalArray<int> sotNOSIGNAL;
151
152
}  // end of namespace dynamicgraph.
153
154
#endif  //! DYNAMIC_GRAPH_SIGNAL_ARRAY_H