11 #ifndef ZYPP_USERDATA_H
12 #define ZYPP_USERDATA_H
17 #include <boost/any.hpp>
40 typedef std::map<std::string,boost::any>
DataType;
52 :
_type( std::move(type_r) )
59 UserData( std::string type_r, std::string subtype_r )
70 {
_type = std::move(type_r); }
74 explicit operator bool()
const
90 bool haskey(
const std::string & key_r )
const
94 bool hasvalue(
const std::string & key_r )
const
100 if ( it !=
_dataP->end() && ! it->second.empty() )
111 bool set(
const std::string & key_r, boost::any val_r )
112 {
dataRef()[key_r] = std::move(val_r);
return true; }
114 bool set(
const std::string & key_r, boost::any val_r )
const
117 boost::any & val(
dataRef()[key_r] );
120 val = std::move(val_r);
127 bool reset(
const std::string & key_r )
128 {
return set( key_r, boost::any() ); }
130 bool reset(
const std::string & key_r )
const
131 {
return set( key_r, boost::any() ); }
134 void erase(
const std::string & key_r )
138 const boost::any &
getvalue(
const std::string & key_r )
const
143 if ( it !=
_dataP->end() )
148 static const boost::any none;
168 const Tp &
get(
const std::string & key_r )
const
169 {
return boost::any_cast<
const Tp &>(
getvalue( key_r ) ); }
179 Tp
get(
const std::string & key_r,
const Tp & default_r )
const
180 { Tp ret( default_r );
get( key_r, ret );
return ret; }
193 bool get(
const std::string & key_r, Tp & ret_r )
const
199 if ( it !=
_dataP->end() )
201 auto ptr = boost::any_cast<
const Tp>(&it->second);
223 {
return str <<
"UserData(" << obj.
type() <<
":" << obj.
size() <<
")";}
229 #endif // ZYPP_USERDATA_H
bool empty() const
Whether data is empty.
std::ostream & operator<<(std::ostream &str, const UserData &obj)
bool hasvalue(const std::string &key_r) const
Whether key_r is in data and value is not empty.
bool reset(const std::string &key_r) const
DataType::size_type size_type
void erase(const std::string &key_r)
Remove key from data.
bool set(const std::string &key_r, boost::any val_r) const
DataType::const_iterator const_iterator
size_type size() const
Size of data.
void type(ContentType type_r)
Set type.
UserData(std::string type_r, std::string subtype_r)
Ctor taking ContentType.
bool reset(const std::string &key_r)
Set an empty value for key_r (if possible).
UserData(std::string type_r)
Ctor taking ContentType.
shared_ptr< DataType > _dataP
DataType::value_type value_type
const boost::any & getvalue(const std::string &key_r) const
Return the keys boost::any value or an empty value if key does not exist.
UserData(ContentType type_r)
Ctor taking ContentType.
std::map< std::string, boost::any > DataType
DataType::key_type key_type
Typesafe passing of user data via callbacks.
bool haskey(const std::string &key_r) const
Whether key_r is in data.
DataType & dataRef() const
const ContentType & type() const
Get type.
const DataType & data() const
The data.
Mime type like 'type/subtype' classification of content.
bool set(const std::string &key_r, boost::any val_r)
Set the value for key (nonconst version always returns true).