FileStore.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 
40 
41 #ifndef GNSSTK_FILE_STORE_INCLUDE
42 #define GNSSTK_FILE_STORE_INCLUDE
43 
44 #include <vector>
45 #include <map>
46 #include <iostream>
47 #include <iomanip>
48 #include "Exception.hpp"
49 
50 namespace gnsstk
51 {
53 
54 
62  template <class HeaderType> class FileStore
63  {
64  private:
65 
67  std::map<std::string, HeaderType> headerMap;
68 
69  public:
70 
72  FileStore() noexcept {};
73 
75  ~FileStore() {};
76 
78  std::vector<std::string> getFileNames() const
79  {
80  std::vector<std::string> names;
81  typename std::map<std::string, HeaderType>::const_iterator fit;
82  for(fit=headerMap.begin(); fit != headerMap.end(); fit++)
83  names.push_back(fit->first);
84  return names;
85  }
86 
89  void addFile(const std::string& fn, HeaderType& header)
90  {
91  if(headerMap.find(fn) != headerMap.end()) {
92  dump(std::cout, 1);
93  InvalidRequest e("Duplicate file name");
94  GNSSTK_THROW(e);
95  }
96  headerMap.insert(make_pair(fn,header));
97  }
98 
101  const HeaderType& getHeader(const std::string& fn) const
102  {
103  typename std::map<std::string, HeaderType>::const_iterator iter_fn = headerMap.find(fn);
104  if( iter_fn == headerMap.end())
105  {
106  InvalidRequest e("File name not found");
107  GNSSTK_THROW(e);
108  }
109  return iter_fn->second;
110  // changed from headerMap[fn] since that is a non-const
111  // member of std::map and therefore could modify
112  // headerMap, making this function not be side-effect free
113  }
114 
116  void dump(std::ostream& os = std::cout, short detail = 0)
117  const noexcept
118  {
119  int n(0);
120  os << "Dump of FileStore\n";
121  typename std::map<std::string, HeaderType>::const_iterator fit;
122  for(fit=headerMap.begin(); fit != headerMap.end(); fit++) {
123  os << " File " << std::setw(2) << ++n << ": " << fit->first;
124  if(detail >= 1) {
125  os << " (header for this file follows)\n";
126  (fit->second).dump(os);
127  }
128  else os << std::endl;
129  }
130  os << "End dump of FileStore\n";
131  }
132 
134  void clear()
135  noexcept
136  {
137  headerMap.clear();
138  }
139 
140 
142  unsigned size() const noexcept { return headerMap.size(); }
143 
144  unsigned nfiles() const noexcept { return size(); }
145 
146  }; // end class FileStore
147 
149 
150 } // namespace
151 
152 #endif // GNSSTK_FILE_STORE_INCLUDE
gnsstk::FileStore::dump
void dump(std::ostream &os=std::cout, short detail=0) const noexcept
dump a list of file names
Definition: FileStore.hpp:116
gnsstk::FileStore::addFile
void addFile(const std::string &fn, HeaderType &header)
Definition: FileStore.hpp:89
example3.header
header
Definition: example3.py:22
const
#define const
Definition: getopt.c:43
gnsstk::FileStore::headerMap
std::map< std::string, HeaderType > headerMap
A store of all headers loaded, indexed by file name.
Definition: FileStore.hpp:67
gnsstk::FileStore::~FileStore
~FileStore()
destructor
Definition: FileStore.hpp:75
gnsstk::FileStore::getFileNames
std::vector< std::string > getFileNames() const
Get a list of all the file names in the store, as a vector<string>
Definition: FileStore.hpp:78
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::FileStore::clear
void clear() noexcept
Clear the contents of the (filename, header) map.
Definition: FileStore.hpp:134
gnsstk::FileStore::FileStore
FileStore() noexcept
Constructor.
Definition: FileStore.hpp:72
gnsstk::FileStore::nfiles
unsigned nfiles() const noexcept
Definition: FileStore.hpp:144
Exception.hpp
gnsstk::FileStore::getHeader
const HeaderType & getHeader(const std::string &fn) const
Definition: FileStore.hpp:101
gnsstk::FileStore::size
unsigned size() const noexcept
Return the size of the (filename,header) map.
Definition: FileStore.hpp:142
GNSSTK_THROW
#define GNSSTK_THROW(exc)
Definition: Exception.hpp:366
example5.fn
string fn
Definition: example5.py:10
gnsstk::FileStore
Definition: FileStore.hpp:62


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