16 #ifndef _d2k_any_data_h 17 #define _d2k_any_data_h 19 #include <deal2lkit/config.h> 24 #include <boost/any.hpp> 75 template <
typename type>
76 void add_copy (
const type &entry,
const std::string &name);
84 template <
typename type>
85 void add_ref (
type &entry,
const std::string &name);
95 template <
typename type>
96 type &
get (
const std::string &name);
106 template <
typename type>
107 const type &
get (
const std::string &name)
const;
115 inline bool have (
const std::string &name)
const;
123 template <
class STREAM>
124 void print_info (STREAM &os);
128 <<
"No entry with the name " << arg1 <<
" exists.");
133 <<
"The requested type " << arg1
134 <<
" and the stored type " << arg2
135 <<
" must coincide");
139 std::map<std::string, boost::any> mydata;
142 template <
typename type>
143 void AnyData::add_copy (
const type &entry,
const std::string &name)
145 mydata[name] = entry;
148 template <
typename type>
149 void AnyData::add_ref (
type &entry,
const std::string &name)
155 template <
typename type>
156 type &AnyData::get(
const std::string &name)
158 Assert( mydata.find(name) != mydata.end(),
163 if (mydata[name].
type() ==
typeid(
type *) )
165 p = boost::any_cast<
type *>(mydata[name]);
167 else if (mydata[name].
type() ==
typeid(
type))
169 p = boost::any_cast<
type>(&mydata[name]);
180 template <
typename type>
181 const type &AnyData::get(
const std::string &name)
const 183 Assert( mydata.find(name) != mydata.end(),
186 typedef std::map<std::string, boost::any>::const_iterator it_type;
188 it_type it = mydata.find(name);
190 if (it->second.type() ==
typeid(
type *) )
192 const type *p = boost::any_cast<
type *>(it->second);
195 else if (it->second.type() ==
typeid(
type))
197 const type *p = boost::any_cast<
type>(&it->second);
210 bool AnyData::have(
const std::string &name)
const 212 return mydata.find(name) != mydata.end();
215 template <
class STREAM>
217 void AnyData::print_info(STREAM &os)
219 for (std::map<std::string, boost::any>::iterator it=mydata.begin(); it != mydata.end(); ++it)
223 <<
demangle(it->second.type().name())
static::ExceptionBase & ExcNameNotFound(std::string arg1)
#define DeclException2(Exception2, type1, type2, outsequence)
DeclException1(ExcCannottExecuteCommand, std::string,<< "Cannot execute command "<< arg1<< "\Please verify you have "<< "the needed permissions.")
Cannot execute std::system(command)
std::string type(const T &t)
Return a human readable name of the type passed as argument.
#define Assert(cond, exc)
static::ExceptionBase & ExcTypeMismatch(char *arg1, char *arg2)
std::string demangle(const char *name)
Demangle c++ names.
Store any amount of any type of data accessible by an identifier string.