UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
trace.hpp
1 /* trace.hpp */
2 /* $Id: trace.hpp 22204 2013-07-11 13:40:55Z urij $ */
3 #ifndef __trace_hpp
4 #define __trace_hpp
5 
6 #include <cstddef>
7 #include <string>
8 #include <vector>
9 #include <map>
10 
11 union TrHdrAttrVal;
12 
14 class Trace
15 {
16 public:
17 
18  /*
19  * Basic types.
20  */
21  typedef float AmplT;
22  typedef float TimeT;
23  typedef float OffsetT;
24  typedef std::vector<AmplT> AmplsStorageT;
25  typedef AmplsStorageT::iterator iterator;
26  typedef AmplsStorageT::const_iterator const_iterator;
29  class Header
30  {
31  public:
32 
34  enum AttrId
35  {
36  TA_NTR = 0,
56  TA_L,
72  };
73 
75  static std::string toString(const AttrId &attr);
76 
78  Header();
79 
81  Header(TimeT i_t0, TimeT i_timestep, OffsetT i_offset);
82 
85  bool compatiable(const Header &hdr) const;
86 
88  bool operator==(const Header &hdr) const;
89 
90 
93  template <typename T>
94  void setAttr(AttrId id, const T& value);
95 
98  template <typename T>
99  const T& getAttrValue(AttrId id, bool *result = 0x0) const;
100 
102  bool hasAttr(AttrId id) const;
103 
105  void clearAttrs();
106 
107 
109  bool hasNAN();
110 
112  bool hasInf();
113 
115  bool hasNANInf();
116 
117 
120 
123 
126 
128  std::map<AttrId, TrHdrAttrVal> m_attrs;
129 
130  private:
131 
132  static TrHdrAttrVal m_tmp_attribute;
133  };
134 
135  /*
136  * Operators.
137  */
138 
140  const AmplT& operator[](size_t n) const {return at(n);}
141 
143  AmplT& operator[](size_t n) {return at(n);}
144 
146  Trace& operator=(const Trace &tr);
147 
149  bool operator==(const Trace &tr) const;
150 
152  Trace operator+(const Trace &tr) const;
153 
155  Trace operator-(const Trace &tr) const;
156 
158  Trace& operator+=(const Trace& that);
159  Trace& operator-=(const Trace& that);
160  Trace& operator*=(AmplT value);
161  Trace& operator/=(AmplT value);
162 
163  /*
164  * Constructors.
165  */
166 
168  Trace();
169 
171  explicit Trace(const Header &hdr);
172 
175  Trace(const Header &hdr, size_t size, AmplT ampl);
176 
178  template <typename Iterator>
179  Trace(const Header &hdr, Iterator first, Iterator last)
180  {m_hdr = hdr; m_ampls = AmplsStorageT(first, last);}
181 
183  Trace(const Trace &tr);
184 
186  Trace* clone() const;
187 
189  virtual ~Trace();
190 
191  /*
192  * Accesors.
193  */
194 
196  const Header& header() const {return m_hdr;}
197 
199  const_iterator begin() const;
200  const_iterator end() const;
201 
203  const AmplT& at(size_t n) const;
204 
206  size_t size() const;
207 
209  TimeT duration() const;
210 
211  /*
212  * Modificators.
213  */
214 
216  Header& header() {return m_hdr;}
217 
219  iterator begin();
220  iterator end();
221 
223  AmplT& at(size_t n);
224 
226  void clear();
227 
229  void resize(size_t n, AmplT ampl = 0.);
230 
232  void erase(iterator first, iterator last);
233 
236  void shift(TimeT s);
237 
239  void shift_old(TimeT s);
240 
243  static void applyKin(Trace &trace,
244  const std::vector<AmplT> &tsrc,
245  const std::vector<AmplT> &tres,
246  const double &max_shift_ratio = 10e+6 );
247 
249  static void expand(Trace &trace, size_t n1, size_t n2, Trace::AmplT ampl = 0.);
250 
252  static void reduce(Trace &trace, size_t n1, size_t n2);
253 
255  void fill(const AmplT &ampl);
256 
257  /*
258  * Working with windows.
259  */
260 
262  const Trace& set_window(TimeT start, TimeT duration) const;
263 
265  TimeT get_window_start() const;
266 
268  TimeT get_window_duration() const;
269 
271  void remove_window() const;
272 
274  bool is_windowed() const;
275 
276 
277  /*
278  * Check data correctness.
279  */
280 
282  bool hasNAN();
283 
285  bool hasInf();
286 
288  bool hasNANInf();
289 
290 protected:
291 
294 
296  AmplsStorageT m_ampls;
297 
299  struct Window
300  {
301  size_t left;
302  size_t right;
303  };
304 
306  mutable std::vector<Window> m_win_stack;
307 };
308 
309 #ifdef GE_BUILD
310 #include <trace_inline.hpp>
311 #else
312 #include <s2proc/trace_inline.hpp>
313 #endif
314 
315 #endif /* trace.hpp */
float AmplT
Definition: trace.hpp:21
std::vector< Window > m_win_stack
Definition: trace.hpp:306
Definition: trace_inline.hpp:9
Trace operator+(const Trace &tr) const
static void expand(Trace &trace, size_t n1, size_t n2, Trace::AmplT ampl=0.)
Header & header()
Definition: trace.hpp:216
Definition: trace.hpp:44
Definition: trace.hpp:54
Definition: trace.hpp:62
Definition: trace.hpp:67
TimeT get_window_duration() const
float OffsetT
Definition: trace.hpp:23
bool hasNANInf()
Definition: trace.hpp:40
Definition: trace.hpp:45
float TimeT
Definition: trace.hpp:22
Definition: trace.hpp:41
Definition: trace.hpp:65
void erase(iterator first, iterator last)
void clear()
size_t size() const
const Trace & set_window(TimeT start, TimeT duration) const
bool hasInf()
const Header & header() const
Definition: trace.hpp:196
void shift_old(TimeT s)
Header m_hdr
Definition: trace.hpp:293
bool operator==(const Header &hdr) const
Definition: trace.hpp:70
Trace & operator+=(const Trace &that)
bool compatiable(const Header &hdr) const
static void reduce(Trace &trace, size_t n1, size_t n2)
Trace * clone() const
TimeT duration() const
Definition: trace.hpp:299
const AmplT & at(size_t n) const
Definition: trace.hpp:36
void resize(size_t n, AmplT ampl=0.)
bool is_windowed() const
Definition: trace.hpp:58
void clearAttrs()
bool operator==(const Trace &tr) const
Definition: trace.hpp:37
TimeT timestep
Definition: trace.hpp:122
Definition: trace.hpp:51
void shift(TimeT s)
TimeT t0
Definition: trace.hpp:119
Trace operator-(const Trace &tr) const
Definition: trace.hpp:39
Definition: trace.hpp:14
Definition: trace.hpp:60
Definition: trace.hpp:69
AmplT & operator[](size_t n)
Definition: trace.hpp:143
const T & getAttrValue(AttrId id, bool *result=0x0) const
Definition: trace_inline.hpp:48
bool hasNANInf()
Definition: trace.hpp:43
bool hasAttr(AttrId id) const
void remove_window() const
Definition: trace.hpp:29
Definition: trace.hpp:50
void fill(const AmplT &ampl)
Definition: trace.hpp:56
OffsetT offset
Definition: trace.hpp:125
Definition: trace.hpp:63
Definition: trace.hpp:57
virtual ~Trace()
static void applyKin(Trace &trace, const std::vector< AmplT > &tsrc, const std::vector< AmplT > &tres, const double &max_shift_ratio=10e+6)
Definition: trace.hpp:49
Trace(const Header &hdr, Iterator first, Iterator last)
Definition: trace.hpp:179
const_iterator begin() const
std::vector< AmplT > AmplsStorageT
Definition: trace.hpp:24
Definition: trace.hpp:71
Definition: trace.hpp:52
TimeT get_window_start() const
Definition: trace.hpp:68
Definition: trace.hpp:47
const AmplT & operator[](size_t n) const
Definition: trace.hpp:140
Definition: trace.hpp:53
AmplsStorageT::iterator iterator
Definition: trace.hpp:25
void setAttr(AttrId id, const T &value)
Definition: trace_inline.hpp:33
size_t right
Definition: trace.hpp:302
Definition: trace.hpp:64
AmplsStorageT::const_iterator const_iterator
Definition: trace.hpp:26
static std::string toString(const AttrId &attr)
AttrId
Definition: trace.hpp:34
bool hasNAN()
Trace & operator=(const Trace &tr)