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;
45  /***
46  * @brief
47  * @param kv_store supplied key-value
48  */
49  explicit KvStore(std::unordered_map<std::string,std::string> & kv_store);
56  explicit KvStore(const std::string& file);
57 
65  KvStore(const std::string& file, read_callback callback);
66 
75  bool load(const std::string& file);
76 
85  bool load(std::istream& in);
86 
95  bool load_line(const std::string& line);
96 
101  group_iterator group_begin() const;
106  group_iterator group_end() const;
107 
112  iterator begin();
117  iterator end();
118 
123  const_iterator cbegin() const;
128  const_iterator cend() const;
129 
140 
141 
159 
161  std::string& at(const std::string& k);
164 
177  KvStore::iterator find(const std::string& k);
179  KvStore::iterator find(std::string&& k);
181  KvStore::const_iterator find(std::string& k) const;
183  KvStore::const_iterator find(std::string&& k) const;
184 
195  size_t count(const std::string& k) const;
197  size_t count(std::string&& k) const;
198 
199 
208  friend std::ostream& operator<<(std::ostream& os, const KvStore& kv);
209 
243 
249  void group_separator(const std::string& s){group_separator_ = s;}
255  const std::string& group_separator(){return group_separator_;}
256 
262  void callback(read_callback callback){callback_ = callback;}
268  read_callback callback(){return callback_;}
269 
276  void switch_group(const std::string& group);
277 
278  private:
279  std::vector<std::string> groups_{};
280  std::unordered_map<std::string, std::string> kv_{};
281  std::string group_separator_{"."};
282  std::string current_group_{""};
283  std::string current_file_{""};
284  std::string read_group_{""};
285 
286  read_callback callback_{};
287 
292  void add_group(const std::string& group);
293 
294  };
295 } // namespace focs
296 
297 #endif // FOCS_KVSTORE
298 
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:268
void callback(read_callback callback)
Set a function to be called for each key-value read.
Definition: KvStore.hpp:262
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:255
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:249
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...