DLS  1.6
Export.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 LibDLSExportH
21 #define LibDLSExportH
22 
23 /*****************************************************************************/
24 
25 #include <fstream>
26 #include <memory>
27 
28 #include "Exception.h"
29 #include "Channel.h"
30 #include "Job.h"
31 #include "Dir.h"
32 #include "globals.h"
33 
34 /*****************************************************************************/
35 
36 namespace LibDLS
37 {
38  class File;
39 
40  /*************************************************************************/
41 
42  class DLS_PUBLIC ExportException:
43  public Exception
44  {
45  public:
46  ExportException(const std::string &pmsg): Exception(pmsg) {};
47  };
48 
49  /*************************************************************************/
50 
51  typedef struct
52  {
53  long type;
54  long mrows;
55  long ncols;
56  long imagf;
57  long namelen;
58  }
59  Mat4Header;
60 
61  /*************************************************************************/
62 
63  class DLS_PUBLIC Export
64  {
65  public:
66  Export();
67  virtual ~Export();
68 
69  void setReferenceTime(const Time &);
70  void setTrim(const Time &, const Time &);
71 
72  virtual void open(const std::string &,
73  const std::string &,
74  const Time &start, const Time &end);
75  virtual void close();
76  virtual void begin(
77  const Directory &,
78  const Channel &,
79  const std::string &,
80  const std::string & = std::string()
81  ) = 0;
82  virtual void data(const Data *) = 0;
83  virtual void end() = 0;
84  virtual void addMessage(const Job::Message &);
85 
86  protected:
87  class Impl;
88  std::unique_ptr<Impl> const _impl;
89 
90  explicit Export(Impl * impl);
91  };
92 
93  /*************************************************************************/
94 
95  class DLS_PUBLIC ExportAscii:
96  public Export
97  {
98  public:
99  ExportAscii();
100  ~ExportAscii();
101 
102  void begin(
103  const Directory &,
104  const Channel &,
105  const std::string &,
106  const std::string & = std::string()
107  );
108  void data(const Data *);
109  void end();
110 
111  private:
112  std::ofstream _file;
113  };
114 
115  /*************************************************************************/
116 
117  class DLS_PUBLIC ExportMat4:
118  public Export
119  {
120  public:
121  ExportMat4();
122  ~ExportMat4();
123 
124  void begin(
125  const Directory &,
126  const Channel &,
127  const std::string &,
128  const std::string & = std::string()
129  );
130  void data(const Data *);
131  void end();
132 
133  private:
134  Mat4Header _header;
135  File *_file;
136  };
137 
138  /*************************************************************************/
139 
140  /* HDF-5 support may be disabled in the library. In this case you will get
141  * a linker error complaining about an undefined reference.
142  */
143  class ExportHDF5:
144  public Export
145  {
146  public:
147  ExportHDF5();
148  ~ExportHDF5();
149 
150  void open(const std::string &,
151  const std::string &,
152  const Time &start, const Time &end);
153  void close();
154  void begin(
155  const Directory &,
156  const Channel &,
157  const std::string &,
158  const std::string & = std::string()
159  );
160  void data(const Data *);
161  void end();
162  void addMessage(const Job::Message &);
163 
164  private:
165  class ImplHDF5;
166  };
167 }
168 
169 /*****************************************************************************/
170 
171 #endif
Global data structures and functions.
Definition: Channel.h:44
#define DLS_PUBLIC
Macro for public method definitions (empty on non-win32).
Definition: globals.h:57