signal-array.h
Go to the documentation of this file.
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
10 #include <stdio.h>
11 
12 #include <vector>
13 
14 namespace dynamicgraph {
15 
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  SignalArray_const<Time>(const unsigned int &sizeARG = DEFAULT_SIZE)
30  : const_array(sizeARG), size(sizeARG), rank(0) {}
31 
33  : const_array(DEFAULT_SIZE), size(DEFAULT_SIZE), rank(0) {
34  addElmt(&sig);
35  }
36 
38  : const_array(siga.getSize()),
39  size(siga.getSize()),
40  rank(siga.getSize()) {
41  for (unsigned int i = 0; i < rank; ++i) const_array[i] = &siga[i];
42  }
43 
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 
52 
53  protected:
54  void addElmt(const SignalBase<Time> *el) {
55  if (rank >= size) {
56  size += DEFAULT_SIZE;
57  const_array.resize(size);
58  }
59  const_array[rank++] = el;
60  }
61 
62  public:
63  virtual SignalArray_const<Time> &operator<<(const SignalBase<Time> &sig) {
64  addElmt(&sig);
65  return *this;
66  }
67 
68  public:
69  virtual const SignalBase<Time> &operator[](const unsigned int &idx) const {
70  return *const_array[idx];
71  }
72  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 
86 template <class Time>
87 class SignalArray : public SignalArray_const<Time> {
88  public:
92 
93  protected:
94  mutable std::vector<SignalBase<Time> *> array;
95 
96  public:
97  SignalArray<Time>(const unsigned int &sizeARG = DEFAULT_SIZE)
98  : SignalArray_const<Time>(0), array(sizeARG) {
99  size = sizeARG;
100  }
101 
103  : SignalArray_const<Time>(0), array(DEFAULT_SIZE) {
104  size = DEFAULT_SIZE;
105  addElmt(&sig);
106  }
107 
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  virtual ~SignalArray<Time>() {}
115 
116  protected:
118  if (rank >= size) {
119  size += DEFAULT_SIZE;
120  array.resize(size);
121  }
122  array[rank++] = el;
123  }
124 
125  public:
126  virtual SignalArray<Time> &operator<<(SignalBase<Time> &sig) {
127  addElmt(&sig);
128  return *this;
129  }
130 
132  const SignalBase<Time> &sig) const {
133  SignalArray_const<Time> res(*this);
134  res << sig;
135  return res;
136  }
137 
138  virtual SignalBase<Time> &operator[](const unsigned int &idx) const {
139  return *array[idx];
140  }
141 };
142 
143 template <class Time>
144 SignalArray<Time> operator<<(SignalBase<Time> &sig1, SignalBase<Time> &sig2) {
145  SignalArray<Time> res(sig1);
146  res << sig2;
147  return res;
148 }
149 
150 DYNAMIC_GRAPH_DLLAPI extern SignalArray<int> sotNOSIGNAL;
151 
152 } // end of namespace dynamicgraph.
153 
154 #endif
virtual SignalBase< Time > & operator[](const unsigned int &idx) const
Definition: signal-array.h:138
dynamicgraph::SignalArray_const< double > sig
Definition: signal-all.cpp:25
void addElmt(const SignalBase< Time > *el)
Definition: signal-array.h:54
std::vector< const SignalBase< Time > * > const_array
Definition: signal-array.h:25
The base class for signals: not to be used as such.
Definition: fwd.hh:51
virtual unsigned int getSize() const
Definition: signal-array.h:72
virtual SignalArray_const< Time > & operator<<(const SignalBase< Time > &sig)
Definition: signal-array.h:63
void addElmt(SignalBase< Time > *el)
Definition: signal-array.h:117
virtual const SignalBase< Time > & operator[](const unsigned int &idx) const
Definition: signal-array.h:69
std::vector< SignalBase< Time > * > array
Definition: signal-array.h:94
DYNAMIC_GRAPH_DLLAPI SignalArray< int > sotNOSIGNAL


dynamic-graph
Author(s): Nicolas Mansard, Olivier Stasse
autogenerated on Sun Jun 25 2023 02:06:03