General Purpose Geodetic Library
SgIoExternalFilter.h
Go to the documentation of this file.
1 /*
2  *
3  * This file is a part of Space Geodetic Library. The library is used by
4  * nuSolve, a part of CALC/SOLVE system, and designed to make analysis of
5  * geodetic VLBI observations.
6  * Copyright (C) 2010-2020 Sergei Bolotin.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef SG_IO_EXTERNAL_FILTER
24 #define SG_IO_EXTERNAL_FILTER
25 
26 
27 #ifdef HAVE_CONFIG_H
28 # include <config.h>
29 #endif
30 
31 
32 
33 #include <QtCore/QFile>
34 #include <QtCore/QList>
35 #include <QtCore/QString>
36 #include <QtCore/QTextStream>
37 
38 
39 #include <SgConstants.h>
40 #include <SgLogger.h>
41 #include <SgMJD.h>
42 
43 
44 
45 
46 /*=====================================================================================================*/
47 
48 
49 
50 
51 /*=====================================================================================================*/
52 
54 {
55  FLTD_Udefined = 0, //
56  FLTD_Input = 1, //
57  FLTD_Output = 2, //
58 };
59 
60 
61 
62 
63 /***===================================================================================================*/
69 //
71 {
72 public:
73  //
74  // Constructors/destructors:
75  //
79  inline SgIoExternalFilter() : name_("none"), defaultExtension_(""),
81  {isOk_ = true;};
82 
83  inline SgIoExternalFilter(const QString& name, const QString& defaultExtension,
84  const QString& command2read, const QString& command2write) :
85  name_(name), defaultExtension_(defaultExtension),
86  command2read_(command2read), command2write_(command2write)
87  {isOk_ = selfCheck();};
88 
92  {isOk_ = ef.isOk_;};
93 
97  inline ~SgIoExternalFilter() {};
98 
99 
100  //
101  // Interfaces:
102  //
103  // gets:
106  inline const QString& getName() const {return name_;};
107  inline const QString& getDefaultExtension() const {return defaultExtension_;};
108  inline const QString& getCommand2read() const {return command2read_;};
109  inline const QString& getCommand2write() const {return command2write_;};
110  inline bool isOk() const {return isOk_;};
111 
112  // sets:
113  inline void setName(const QString& name) {name_ = name;};
114  inline void setDefaultExtension(const QString& defaultExtension) {defaultExtension_ = defaultExtension;};
115  inline void setCommand2read(const QString& command2read) {command2read_ = command2read;};
116  inline void setCommand2write(const QString& command2write) {command2write_ = command2write;};
117 
118 
119  //
120  // Functions:
121  //
124  static const QString className();
125 
126  bool selfCheck();
127  FILE* openFlt(const QString& fileName, QFile& file, QTextStream& ts, FilterDirection) const;
128  static void closeFlt(FILE*& p, QFile& file, QTextStream& ts);
129 
130  //
131  // Friends:
132  //
133 
134 protected:
135  QString name_;
137  QString command2read_;
138  QString command2write_;
139  bool isOk_;
140 };
141 /*=====================================================================================================*/
142 
143 
144 
145 
146 
147 
148 /***===================================================================================================*/
155 {
156 public:
157  //
158  // Constructors/destructors:
159  //
164 
165 
167  {};
168 
173 
174 
175 
177  {filterByExt_ = handler.filterByExt_; return *this;};
178 
179 
180  //
181  // Interfaces:
182  //
183  // gets:
186  inline const QMap<QString, const SgIoExternalFilter*>& getFilterByExt() const {return filterByExt_;};
187 
188  // sets:
189  inline void setFilterByExt(const QMap<QString, const SgIoExternalFilter*>& filterByExt)
190  {filterByExt_ = filterByExt;};
191 
192  //
193  // Functions:
194  //
197  static const QString className();
198 
199  bool addFilter(const SgIoExternalFilter* filter);
200 
201  inline bool addFilter(const QString& name, const QString& defaultExtension,
202  const QString& command2read, const QString& command2write)
203  {return addFilter(new SgIoExternalFilter(name, defaultExtension, command2read, command2write));};
204 
205  bool removeFilter(const SgIoExternalFilter* filter);
206 
207  bool removeFilter(const QString& extension);
208 
209  const SgIoExternalFilter* lookupFilterByFileName(const QString& fileName);
210 
211  FILE* openFlt(const QString& fileName, QFile& file, QTextStream& ts, FilterDirection);
212 
213  inline static void closeFlt(FILE*& p, QFile& file, QTextStream& ts)
214  {SgIoExternalFilter::closeFlt(p, file, ts);};
215 
216  //
217  // Friends:
218  //
219 
220 protected:
221  QMap<QString, const SgIoExternalFilter*>
223 // SgIoExternalFilter *defaultFilter_;
224 };
225 
226 
227 
228 
229 
230 
231 
232 
233 
234 
235 
236 
237 
238 /*=====================================================================================================*/
239 
240 
241 
242 
243 
244 
245 
246 
247 /*=====================================================================================================*/
248 //
249 // constants:
250 //
251 
253 
254 /*=====================================================================================================*/
255 
256 
257 /*=====================================================================================================*/
258 #endif //SG_IO_EXTERNAL_FILTER
259 
FilterDirection
@ FLTD_Output
@ FLTD_Input
@ FLTD_Udefined
SgIoExtFilterHandler compressors
SgIoExtFilterHandler(const SgIoExtFilterHandler &handler)
bool addFilter(const SgIoExternalFilter *filter)
const QMap< QString, const SgIoExternalFilter * > & getFilterByExt() const
static const QString className()
SgIoExtFilterHandler & operator=(const SgIoExtFilterHandler &handler)
const SgIoExternalFilter * lookupFilterByFileName(const QString &fileName)
bool removeFilter(const SgIoExternalFilter *filter)
QMap< QString, const SgIoExternalFilter * > filterByExt_
void setFilterByExt(const QMap< QString, const SgIoExternalFilter * > &filterByExt)
bool addFilter(const QString &name, const QString &defaultExtension, const QString &command2read, const QString &command2write)
static void closeFlt(FILE *&p, QFile &file, QTextStream &ts)
FILE * openFlt(const QString &fileName, QFile &file, QTextStream &ts, FilterDirection)
void setDefaultExtension(const QString &defaultExtension)
const QString & getCommand2write() const
const QString & getDefaultExtension() const
SgIoExternalFilter(const QString &name, const QString &defaultExtension, const QString &command2read, const QString &command2write)
static void closeFlt(FILE *&p, QFile &file, QTextStream &ts)
void setCommand2write(const QString &command2write)
const QString & getName() const
SgIoExternalFilter(const SgIoExternalFilter &ef)
void setName(const QString &name)
FILE * openFlt(const QString &fileName, QFile &file, QTextStream &ts, FilterDirection) const
static const QString className()
const QString & getCommand2read() const
void setCommand2read(const QString &command2read)