FileFilterFrame.hpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
44 #ifndef GNSSTK_FILEFILTERFRAME_HPP
45 #define GNSSTK_FILEFILTERFRAME_HPP
46 
47 #include "FileSpec.hpp"
48 #include "FileFilter.hpp"
49 #include "FileSpecFind.hpp"
50 #include "FileUtils.hpp"
51 
52 namespace gnsstk
53 {
55 
56 
72  template <class FileStream, class FileData>
73  class FileFilterFrame : public FileFilter<FileData>
74  {
75  public:
78  FileFilterFrame(const gnsstk::CommonTime& start =
80  const gnsstk::CommonTime& end =
82 
85  FileFilterFrame(const std::vector<std::string>& fileList,
86  const gnsstk::CommonTime& start =
88  const gnsstk::CommonTime& end =
90 
93  FileFilterFrame(const std::string& filename,
94  const gnsstk::CommonTime& start =
96  const gnsstk::CommonTime& end =
98 
102  FileFilterFrame(const FileSpec& spec,
103  const gnsstk::CommonTime& start =
105  const gnsstk::CommonTime& end =
109 
115  newSource(const FileSpec& filespec,
116  const gnsstk::CommonTime& start =
118  const gnsstk::CommonTime& end =
122 
126  newSource(const std::string& filename,
127  const gnsstk::CommonTime& start =
129  const gnsstk::CommonTime& end =
131 
135  newSource(const std::vector<std::string>& fileList,
136  const gnsstk::CommonTime& start =
138  const gnsstk::CommonTime& end =
140 
141  virtual ~FileFilterFrame() {}
142 
154  bool writeFile(const std::string& outputFile,
155  const bool append = false) const;
156 
167  bool writeFile(FileStream& stream) const;
168 
169  protected:
173 
174 
175  protected:
180 
181  };
182 
184 
185  template <class FileStream, class FileData>
188  const gnsstk::CommonTime& end)
189  : startTime(start), endTime(end)
190  {}
191 
192  template <class FileStream, class FileData>
194  FileFilterFrame(const std::vector<std::string>& fileList,
195  const gnsstk::CommonTime& start,
196  const gnsstk::CommonTime& end)
197  : startTime(start), endTime(end)
198  {
199  typename std::vector<std::string>::const_iterator itr;
200  for (itr = fileList.begin(); itr != fileList.end(); itr++)
201  {
202  fs.newSpec(*itr);
203  init();
204  }
205  }
206 
207  template <class FileStream, class FileData>
209  FileFilterFrame(const std::string& filename,
210  const gnsstk::CommonTime& start,
211  const gnsstk::CommonTime& end)
212  : fs(filename), startTime(start), endTime(end)
213  {
214  init();
215  }
216 
217  template <class FileStream, class FileData>
220  const gnsstk::CommonTime& start,
221  const gnsstk::CommonTime& end,
222  const FileSpecFind::Filter& filter)
223  : fs(spec), startTime(start), endTime(end)
224  {
225  init(filter);
226  }
227 
228  template <class FileStream, class FileData>
231  newSource(const FileSpec& filespec,
232  const gnsstk::CommonTime& start,
233  const gnsstk::CommonTime& end,
234  const FileSpecFind::Filter& filter)
235  {
236  startTime = start;
237  endTime = end;
238 
239  fs = filespec;
240  init(filter);
241  return *this;
242  }
243 
244  template <class FileStream, class FileData>
247  newSource(const std::string& filename,
248  const gnsstk::CommonTime& start,
249  const gnsstk::CommonTime& end)
250  {
251  startTime = start;
252  endTime = end;
253 
254  fs.newSpec(filename);
255  init();
256  return *this;
257  }
258 
259  template <class FileStream, class FileData>
262  newSource(const std::vector<std::string>& fileList,
263  const gnsstk::CommonTime& start,
264  const gnsstk::CommonTime& end)
265  {
266  startTime = start;
267  endTime = end;
268 
269  typename std::vector<std::string>::const_iterator itr;
270  for (itr = fileList.begin(); itr != fileList.end(); itr++)
271  {
272  fs.newSpec(*itr);
273  init();
274  }
275  return *this;
276  }
277 
278  template <class FileStream, class FileData>
279  void
282  {
283  // find the files
284  std::list<std::string> listOfFiles =
285  FileSpecFind::find(fs, startTime, endTime, filter);
286 
287  // for each file, read it into the filter
288  for (const auto& i : listOfFiles)
289  {
290  FileStream s(i.c_str());
291 
292  if (s.good())
293  {
294  FileData data;
295  while (s >> data)
296  this->addData(data);
297  }
298  }
299  }
300 
301  template <class FileStream, class FileData>
303  writeFile(const std::string& str,
304  const bool append) const
305  {
306  if (!this->dataVec.empty())
307  {
308  // make the directory (if needed)
309  std::string::size_type pos = str.rfind('/');
310  if (pos != std::string::npos)
311  gnsstk::FileUtils::makeDir(str.substr(0,pos).c_str(), 0755);
312 
313  std::ios::openmode mode = std::ios::out;
314  if (append)
315  mode |= (std::ios::app|std::ios::ate);
316 
317  FileStream stream(str.c_str(), mode);
318  return writeFile(stream);
319  }
320 
321  return true;
322  }
323 
324  template <class FileStream, class FileData>
326  writeFile(FileStream& stream) const
327  {
328  if (!this->dataVec.empty())
329  {
330  stream.exceptions(std::ios::failbit);
331 
332  typename std::list<FileData>::const_iterator index;
333  for(index = this->dataVec.begin(); index != this->dataVec.end(); index++)
334  (*index).putRecord(stream);
335  }
336 
337  return true;
338  }
339 
340 } // namespace gnsstk
341 
342 #endif // GNSSTK_FILEFILTERFRAME_HPP
gnsstk::FileFilterFrame::writeFile
bool writeFile(const std::string &outputFile, const bool append=false) const
Definition: FileFilterFrame.hpp:303
gnsstk::FileFilterFrame::~FileFilterFrame
virtual ~FileFilterFrame()
Definition: FileFilterFrame.hpp:141
gnsstk::FileSpecFind::Filter
std::multimap< FileSpec::FileSpecType, std::string > Filter
Data type for storing desired FileSpec values.
Definition: FileSpecFind.hpp:87
gnsstk::FileFilter
Definition: FileFilter.hpp:76
gnsstk::CommonTime::BEGINNING_OF_TIME
static const GNSSTK_EXPORT CommonTime BEGINNING_OF_TIME
earliest representable CommonTime
Definition: CommonTime.hpp:102
FileFilter.hpp
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::FileSpecFind::find
static std::list< std::string > find(const std::string &fileSpec, const CommonTime &start, const CommonTime &end, const FileSpec::FSTStringMap &fsts=FileSpec::FSTStringMap())
Definition: FileSpecFind.cpp:225
gnsstk::FileSpec
Definition: FileSpec.hpp:80
gnsstk::CommonTime::END_OF_TIME
static const GNSSTK_EXPORT CommonTime END_OF_TIME
latest representable CommonTime
Definition: CommonTime.hpp:104
FileSpec.hpp
gnsstk::FileFilterFrame::FileFilterFrame
FileFilterFrame(const gnsstk::CommonTime &start=gnsstk::CommonTime::BEGINNING_OF_TIME, const gnsstk::CommonTime &end=gnsstk::CommonTime::END_OF_TIME)
Definition: FileFilterFrame.hpp:187
gnsstk::CommonTime
Definition: CommonTime.hpp:84
FileUtils.hpp
example4.pos
pos
Definition: example4.py:125
gnsstk::FileFilterFrame::startTime
gnsstk::CommonTime startTime
the start and end dates for the filter.
Definition: FileFilterFrame.hpp:179
example3.data
data
Definition: example3.py:22
gnsstk::FileFilter::end
std::list< FileData >::const_iterator end() const
Definition: FileFilter.hpp:313
gnsstk::FileUtils::makeDir
int makeDir(const std::string &path, unsigned mode)
Definition: FileUtils.hpp:106
gnsstk::FileFilterFrame::fs
FileSpec fs
The file spec for this filter.
Definition: FileFilterFrame.hpp:177
FileSpecFind.hpp
gnsstk::FileFilterFrame::endTime
gnsstk::CommonTime endTime
Definition: FileFilterFrame.hpp:179
gnsstk::FileFilterFrame::init
void init(const FileSpecFind::Filter &filter=FileSpecFind::Filter())
Definition: FileFilterFrame.hpp:281
gnsstk::FileFilterFrame
Definition: FileFilterFrame.hpp:73
gnsstk::FileFilterFrame::newSource
FileFilterFrame & newSource(const FileSpec &filespec, const gnsstk::CommonTime &start=gnsstk::CommonTime::BEGINNING_OF_TIME, const gnsstk::CommonTime &end=gnsstk::CommonTime::END_OF_TIME, const FileSpecFind::Filter &filter=FileSpecFind::Filter())
Definition: FileFilterFrame.hpp:231
gnsstk::FileSpec::newSpec
virtual FileSpec & newSpec(const std::string &fileSpec)
Definition: FileSpec.hpp:160
gnsstk::FileFilter::filter
FileFilter & filter(Predicate up)
Definition: FileFilter.hpp:199


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:39