DLS  1.6
Data.h
1 /******************************************************************************
2  *
3  * This file is part of the Data Logging Service (DLS).
4  *
5  * DLS is free software: you can redistribute it and/or modify it under the
6  * terms of the GNU General Public License as published by the Free Software
7  * Foundation, either version 3 of the License, or (at your option) any later
8  * version.
9  *
10  * DLS is distributed in the hope that it will be useful, but WITHOUT ANY
11  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with DLS. If not, see <http://www.gnu.org/licenses/>.
17  *
18  *****************************************************************************/
19 
20 #ifndef LibDLSDataH
21 #define LibDLSDataH
22 
23 /*****************************************************************************/
24 
25 #include <vector>
26 
27 #include "globals.h"
28 #include "Time.h"
29 
30 namespace DlsProto {
31  class Data;
32 }
33 
34 namespace LibDLS {
35 
36 /*************************************************************************/
37 
41 {
42  public:
43  Data();
44  Data(const Data &);
45  Data(const DlsProto::Data &);
46  ~Data();
47 
48  template <class T>
49  void import(Time, Time, MetaType, unsigned int,
50  unsigned int, unsigned int &, T*, unsigned int);
51 
52  void push_back(const Data &);
53 
54  Time start_time() const { return _start_time; }
55  Time end_time() const {
56  return _start_time + _time_per_value * _data.size();
57  }
58  Time time_per_value() const { return _time_per_value; }
59  MetaType meta_type() const { return _meta_type; }
60  unsigned int meta_level() const { return _meta_level; }
61 
62  size_t size() const { return _data.size(); }
63  double value(unsigned int index) const { return _data[index]; }
64  Time time(unsigned int index) const {
65  return _start_time + _time_per_value * index;
66  }
67 
68  int calc_min_max(double *, double *) const;
69 
70  protected:
71  Time _start_time;
72  Time _time_per_value;
73  MetaType _meta_type;
74  unsigned int _meta_level;
75  std::vector<double> _data;
76 };
77 
78 /*****************************************************************************/
79 
82 template <class T>
84  Time time,
85  Time tpv,
86  MetaType meta_type,
87  unsigned int meta_level,
88  unsigned int decimation,
89  unsigned int &decimationCounter,
90  T *data,
91  unsigned int size
92  )
93 {
94  unsigned int i;
95 
96  _start_time = time + tpv * decimationCounter;
97  _time_per_value = tpv * decimation;
98  _meta_type = meta_type;
99  _meta_level = meta_level;
100  _data.clear();
101 
102  for (i = 0; i < size; i++) {
103  if (!decimationCounter) {
104  _data.push_back((double) data[i]);
105  decimationCounter = decimation - 1;
106  } else {
107  decimationCounter--;
108  }
109  }
110 }
111 
112 /*****************************************************************************/
113 
114 } // namespace
115 
116 /*****************************************************************************/
117 
118 #endif
Global data structures and functions.
MetaType
Meta type for recorded data.
Definition: globals.h:103
Block of data values.
Definition: Data.h:40
Definition: Channel.h:44
Datentyp zur Speicherung der Zeit in Mikrosekunden.
Definition: Time.h:46
#define DLS_PUBLIC
Macro for public method definitions (empty on non-win32).
Definition: globals.h:57
void import(Time, Time, MetaType, unsigned int, unsigned int, unsigned int &, T *, unsigned int)
Imports data block properties.
Definition: Data.h:83