10 #include <boost/any.hpp>
11 #include <pybind11/pybind11.h>
12 #include "mspass/utility/MsPASSError.h"
13 #include "mspass/utility/BasicMetadata.h"
32 std::string pretty_name(boost::core::demangle(Texpected));
33 ss<<
"Error trying to extract Metadata with key="<<key<<std::endl
34 <<
"No value associated with this key is set in Metadata object"<<std::endl
35 <<
"Expected an entry of type="<<pretty_name<<std::endl;
46 const char *Texpected,
const char *Tactual)
48 ss <<
"Error in Metadata get method. Type mismatch in attem to get "
49 <<
"data with key="<<key<<std::endl
50 <<
"boost::any bad_any_cast wrote this message: "<<std::endl
51 << boostmessage<<std::endl;
52 std::string name_e(boost::core::demangle(Texpected));
53 ss <<
"Trying to convert to data of type="<<name_e<<std::endl;
54 std::string name_a(boost::core::demangle(Tactual));
55 ss <<
"Actual entry has type="<<name_a<<std::endl;
64 MetadataGetError operator=(
const MetadataGetError& parent)
94 Metadata(std::ifstream& ifs,
const std::string form=std::string(
"pf"));
138 val=get<double>(key);
145 fval=get<float>(key);
159 int get_int(
const std::string key)
const override
171 return static_cast<int>(lval);
196 return static_cast<long>(ival);
213 std::string
get_string(
const std::string key)
const override{
216 val=get<std::string>(key);
228 bool get_bool(
const std::string key)
const override{
250 template <
typename T> T
get(
const std::string key)
const;
265 template <
typename T> T
get(
const char *key)
const
269 val=get<T>(std::string(key));
283 boost::any
get_any(
const std::string key)
const {
284 std::map<std::string,boost::any>::const_iterator iptr;
292 std::string type(
const std::string key)
const;
293 template <
typename T>
void put(
const std::string key, T val) noexcept
297 changed_or_set.insert(key);
299 template <
typename T>
void put (
const char *key, T val) noexcept
304 md[std::string(key)]=aval;
305 changed_or_set.insert(std::string(key));
307 void put(
const std::string key,
const double val)
override
309 this->put<double>(key,val);
311 void put(
const std::string key,
const int val)
override
313 this->put<int>(key,val);
315 void put(
const std::string key,
const bool val)
override
317 this->put<bool>(key,val);
319 void put(
const std::string key,
const std::string val)
override
321 this->put<std::string>(key,val);
327 void put(
const char *key,
const char *val)
329 std::string sval(val);
330 this->put<std::string>(key,val);
332 void put(std::string key,
const char *val)
334 this->put(key.c_str(),val);
336 void put_object(
const std::string key,
const pybind11::object val)
338 this->put<pybind11::object>(key,val);
340 void put_int(
const std::string key,
const int val)
342 this->put<int>(key,val);
344 void put_string(
const std::string key,
const std::string val)
346 this->put<std::string>(key,val);
348 void put_bool(
const std::string key,
const bool val)
350 this->put<bool>(key,val);
352 void put_double(
const std::string key,
const double val)
354 this->put<double>(key,val);
356 void put_long(
const std::string key,
const long val)
358 this->put<long>(key,val);
383 void append_chain(
const std::string key,
const std::string val,
384 const std::string separator=std::string(
":"));
389 return changed_or_set;
403 changed_or_set.clear();
406 std::set<std::string>
keys() const noexcept;
409 bool is_defined(const std::
string key) const noexcept;
418 void erase(const std::
string key);
427 std::
size_t size() const noexcept;
429 std::map<std::
string,boost::any>::const_iterator
begin() const noexcept;
431 std::map<std::
string,boost::any>::const_iterator
end() const noexcept;
446 void change_key(const std::
string oldkey, const std::
string newkey);
465 friend std::ostringstream& operator<<(std::ostringstream&,
468 std::map<std::
string,boost::any> md;
470 std::set<std::
string> changed_or_set;
472 template <typename T> T
Metadata::
get(const std::
string key)
const
475 std::map<std::string,boost::any>::const_iterator iptr;
481 boost::any aval=iptr->second;
483 result=boost::any_cast<T>(aval);
484 }
catch(boost::bad_any_cast& err)
486 const std::type_info &ti = aval.type();
500 std::string demangled_name(
const boost::any val);
536 typedef std::list<Metadata_typedef> MetadataList;
562 const MetadataList& mdlist);
584 std::string serialize_metadata(
const Metadata &md);
596 Metadata restore_serialized_metadata(
const std::string);
Base class for error object thrown by MsPASS library routines.
Definition: MsPASSError.h:40
MsPASSError()
Definition: MsPASSError.h:46
std::string message
Definition: MsPASSError.h:109
ErrorSeverity badness
Definition: MsPASSError.h:116