OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
KvStore.hpp
Go to the documentation of this file.
1 
2 #ifndef FOCS_KVSTORE
3 #define FOCS_KVSTORE
4 
6 
7 #include <functional>
8 #include <iterator>
9 #include <string>
10 #include <unordered_map>
11 #include <vector>
12 
13 namespace focs {
35  class KvStore {
36  using read_callback = std::function<bool(const std::pair<std::string, std::string>&)>;
37  using group_filtered_iterator = focs::FilterIterator<std::unordered_map<std::string, std::string>::const_iterator, std::function<bool(const std::pair<std::string, std::string>&)>>;
38  using group_iterator = std::vector<std::string>::const_iterator;
39  using iterator = std::unordered_map<std::string, std::string>::iterator;
40  using const_iterator = std::unordered_map<std::string, std::string>::const_iterator;
41 
42  public:
44  KvStore() = default;
51  explicit KvStore(const std::string& file);
52 
60  KvStore(const std::string& file, read_callback callback);
61 
70  bool load(const std::string& file);
71 
80  bool load(std::istream& in);
81 
90  bool load_line(const std::string& line);
91 
96  group_iterator group_begin() const;
101  group_iterator group_end() const;
102 
107  iterator begin();
112  iterator end();
113 
118  const_iterator cbegin() const;
123  const_iterator cend() const;
124 
135 
136 
154 
156  std::string& at(const std::string& k);
159 
172  KvStore::iterator find(const std::string& k);
174  KvStore::iterator find(std::string&& k);
176  KvStore::const_iterator find(std::string& k) const;
178  KvStore::const_iterator find(std::string&& k) const;
179 
190  size_t count(const std::string& k) const;
192  size_t count(std::string&& k) const;
193 
194 
203  friend std::ostream& operator<<(std::ostream& os, const KvStore& kv);
204 
238 
244  void group_separator(const std::string& s){group_separator_ = s;}
250  const std::string& group_separator(){return group_separator_;}
251 
257  void callback(read_callback callback){callback_ = callback;}
263  read_callback callback(){return callback_;}
264 
271  void switch_group(const std::string& group);
272 
273  private:
274  std::vector<std::string> groups_{};
275  std::unordered_map<std::string, std::string> kv_{};
276  std::string group_separator_{"."};
277  std::string current_group_{""};
278  std::string current_file_{""};
279  std::string read_group_{""};
280 
281  read_callback callback_{};
282 
287  void add_group(const std::string& group);
288 
289  };
290 } // namespace focs
291 
292 #endif // FOCS_KVSTORE
293 
iterator end()
std::unordered_map end iterator to recurse key-values
group_iterator group_begin() const
std::vector iterator to recurse group names
group_iterator group_end() const
std::vector end iterator to recurse group names
std::string & at(const std::string &k)
Returns a reference to the mapped value of the element identified with key k.
KvStore()=default
Default constructor, use load(std::string file) to read files.
friend std::ostream & operator<<(std::ostream &os, const KvStore &kv)
Output KvStore to stream operator.
read_callback callback()
Get the key-value callback.
Definition: KvStore.hpp:263
void callback(read_callback callback)
Set a function to be called for each key-value read.
Definition: KvStore.hpp:257
iterator begin()
std::unordered_map iterator to recurse key-values
const_iterator cbegin() const
std::unordered_map iterator to recurse key-values
Key-value file reader (commonly called par files)
Definition: KvStore.hpp:35
@ string
bool load(const std::string &file)
Read key-value file, appending values to current map.
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude resolving resolving GSFcd00179 Corrected handling of fill values for[Sensor|Solar][Zenith|Azimuth] resolving MODxl01751 Changed to validate LUT version against a value retrieved from the resolving MODxl02056 Changed to calculate Solar Diffuser angles without adjustment for estimated post launch changes in the MODIS orientation relative to incidentally resolving defects MODxl01766 Also resolves MODxl01947 Changed to ignore fill values in SCI_ABNORM and SCI_STATE rather than treating them as resolving MODxl01780 Changed to use spacecraft ancillary data to recognise when the mirror encoder data is being set by side A or side B and to change calculations accordingly This removes the need for seperate LUTs for Side A and Side B data it makes the new LUTs incompatible with older versions of the and vice versa Also resolves MODxl01685 A more robust GRing algorithm is being which will create a non default GRing anytime there s even a single geolocated pixel in a granule Removed obsolete messages from seed file
Definition: HISTORY.txt:413
bool load_line(const std::string &line)
Process key-value line, appending value to current map.
bool command(std::string &&cmd, std::string &&args)
Process a key-value store command by name.
Iterator for filtering the results of other iterators.
subroutine os(tamoy, trmoy, pizmoy, tamoyp, trmoyp, palt, phirad, nt, mu, np, rm, gb, rp, xl)
Definition: 6sm1.f:5484
const_iterator cend() const
std::unordered_map end iterator to recurse key-values
bool command_group(std::string &&group)
Change the current key group.
const std::string & group_separator()
Get the current group separator.
Definition: KvStore.hpp:250
void switch_group(const std::string &group)
Switch default group for retrieving values.
void group_separator(const std::string &s)
Set the character(s) to use between group and key when inserting into map.
Definition: KvStore.hpp:244
KvStore::iterator find(const std::string &k)
Get iterator to element.
data_t s[NROOTS]
Definition: decode_rs.h:75
bool command_include(std::string &&file)
Include another key-value store, relative to current file, into the global group.
#define bool
Definition: usrmac.h:88
size_t count(const std::string &k) const
Count elements with a specific key.
bool command_include_local(std::string &&file)
Include another key-value store, relative to current file, into the current group.
int k
Definition: decode_rs.h:73
std::string & operator[](const std::string &k)
If k matches the key of an element in the KvStore, the function returns a reference to its mapped val...