11 #ifndef ZYPP_USERDATA_H
12 #define ZYPP_USERDATA_H
17 #include <boost/any.hpp>
44 typedef std::map<std::string,AnyType>
DataType;
59 :
_type( std::move(type_r) )
66 UserData( std::string type_r, std::string subtype_r )
77 {
_type = std::move(type_r); }
81 explicit operator bool()
const
97 bool haskey(
const std::string & key_r )
const
107 if ( it !=
_dataP->end() && ! it->second.empty() )
119 {
dataRef()[key_r] = std::move(val_r);
return true; }
127 val = std::move(val_r);
134 bool reset(
const std::string & key_r )
137 bool reset(
const std::string & key_r )
const
141 void erase(
const std::string & key_r )
150 if ( it !=
_dataP->end() )
175 const Tp &
get(
const std::string & key_r )
const
176 {
return boost::any_cast<
const Tp &>(
getvalue( key_r ) ); }
186 Tp
get(
const std::string & key_r,
const Tp & default_r )
const
187 { Tp ret( default_r );
get( key_r, ret );
return ret; }
200 bool get(
const std::string & key_r, Tp & ret_r )
const
206 if ( it !=
_dataP->end() )
208 auto ptr = boost::any_cast<
const Tp>(&it->second);
230 {
return str <<
"UserData(" << obj.
type() <<
":" << obj.
size() <<
")";}
236 #endif // ZYPP_USERDATA_H
bool set(const std::string &key_r, AnyType val_r) const
bool empty() const
Whether data is empty.
zypp::ContentType ContentType
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
std::map< std::string, AnyType > DataType
void erase(const std::string &key_r)
Remove key from data.
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).
bool set(const std::string &key_r, AnyType val_r)
Set the value for key (nonconst version always returns true).
UserData(std::string type_r)
Ctor taking ContentType.
shared_ptr< DataType > _dataP
const AnyType & getvalue(const std::string &key_r) const
get helper returning the keys AnyType value or an empty value if key does not exist.
DataType::value_type value_type
UserData(ContentType type_r)
Ctor taking ContentType.
boost::bad_any_cast bad_AnyType_cast
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.