version  0.0.1
Defines the C++ API for MsPASS
MetadataDefinitions.h
1 #ifndef _METADATADEFINITIONS_H_
2 #define _METADATADEFINITIONS_H_
3 #include <map>
4 #include <tuple>
5 namespace mspass{
6 namespace utility{
7 enum class MDDefFormat
8 {
9  PF,
10  YAML
11 };
12 
31 {
32 public:
42  MetadataDefinitions(const std::string mdname);
51  MetadataDefinitions(const std::string mdname,const mspass::utility::MDDefFormat form);
55  bool is_defined(const std::string key) const noexcept;
62  std::string concept(const std::string key) const;
69  mspass::utility::MDtype type(const std::string key) const;
70  std::list<std::string> keys() const;
81  void add(const std::string key, const std::string concept_, const MDtype mdt);
90  bool has_alias(const std::string key) const;
98  bool is_alias(const std::string key) const;
99  std::list<std::string> aliases(const std::string key) const;
112  std::pair<std::string,mspass::utility::MDtype> unique_name(const std::string aliasname) const;
118  void add_alias(const std::string key, const std::string aliasname);
126  bool writeable(const std::string key) const;
134  bool readonly(const std::string key) const;
146  void set_readonly(const std::string key);
158  void set_writeable(const std::string key);
166  bool is_normalized(const std::string key) const;
195  std::string unique_id_key(const std::string key) const;
211  std::string collection(const std::string key) const;
224  std::pair<std::string,std::string> normalize_data(const std::string key) const;
240 std::list<std::string> apply_aliases(mspass::utility::Metadata& d,
241  const std::list<std::string> aliaslist);
278 private:
279  std::map<std::string,MDtype> tmap;
280  std::map<std::string,std::string> cmap;
281  std::multimap<std::string,std::string> aliasmap;
282  std::map<std::string,std::string> alias_xref;
283  std::set<std::string> roset;
284  /* This map is used to handle normalized data in any database. For the
285  initial design the data could be a pair, but I make it a tuple because I
286  can conveive extensions that would require additional information to provides
287  a unique index definition. e.g. the antelope indexing of sta,chan,time:endtime.
288  */
289  std::map<std::string,std::tuple<std::string,std::string>> unique_id_data;
290  void pfreader(const std::string pfname);
291  void yaml_reader(const std::string fname);
292 
293 };
294 } // end utility namespace
295 } // end mspass namespace
296 #endif
Define properties of Metadata known to mspass.
Definition: MetadataDefinitions.h:31
MetadataDefinitions(const std::string mdname, const mspass::utility::MDDefFormat form)
Construct from a file with variable formats.
void add_alias(const std::string key, const std::string aliasname)
Definition: MetadataDefinitions.cc:162
bool has_alias(const std::string key) const
Methods to handle aliases.
Definition: MetadataDefinitions.cc:137
std::list< std::string > apply_aliases(mspass::utility::Metadata &d, const std::list< std::string > aliaslist)
Apply a set of aliases to data.
Definition: MetadataDefinitions.cc:520
MetadataDefinitions & operator=(const MetadataDefinitions &other)
Definition: MetadataDefinitions.cc:214
bool writeable(const std::string key) const
Definition: MetadataDefinitions.cc:271
void set_readonly(const std::string key)
Lock a parameter to assure it will not be saved.
Definition: MetadataDefinitions.cc:312
void clear_aliases(mspass::utility::Metadata &d)
Restore any aliases to unique names.
Definition: MetadataDefinitions.cc:545
void add(const std::string key, const std::string concept_, const MDtype mdt)
Definition: MetadataDefinitions.cc:132
MetadataDefinitions()
Definition: MetadataDefinitions.cc:46
std::string concept(const std::string key) const
Definition: MetadataDefinitions.cc:102
bool is_alias(const std::string key) const
Ask if a key is a registered alias.
Definition: MetadataDefinitions.cc:168
MetadataDefinitions & operator+=(const MetadataDefinitions &other)
Accumulate additional definitions.
Definition: MetadataDefinitions.cc:227
std::pair< std::string, mspass::utility::MDtype > unique_name(const std::string aliasname) const
Definition: MetadataDefinitions.cc:179
std::string unique_id_key(const std::string key) const
Returns a unique identifier for a normalized attribute.
Definition: MetadataDefinitions.cc:339
mspass::utility::MDtype type(const std::string key) const
Definition: MetadataDefinitions.cc:116
void set_writeable(const std::string key)
Force a key:value pair to be writeable.
Definition: MetadataDefinitions.cc:320
bool readonly(const std::string key) const
Definition: MetadataDefinitions.cc:308
std::pair< std::string, std::string > normalize_data(const std::string key) const
Special method for efficiency.
Definition: MetadataDefinitions.cc:366
std::string collection(const std::string key) const
Definition: MetadataDefinitions.cc:353
bool is_defined(const std::string key) const noexcept
Definition: MetadataDefinitions.cc:79
bool is_normalized(const std::string key) const
Test if a key:value pair is set as normalized.
Definition: MetadataDefinitions.cc:330
Definition: Metadata.h:76