11 #ifndef ZYPP_USERDATA_H 12 #define ZYPP_USERDATA_H 17 #include <boost/any.hpp> 44 typedef std::map<std::string,AnyType>
DataType;
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() )
118 bool set(
const std::string & key_r,
AnyType val_r )
119 {
dataRef()[key_r] = std::move(val_r);
return true; }
121 bool set(
const std::string & key_r,
AnyType val_r )
const 127 val = std::move(val_r);
134 bool reset(
const std::string & key_r )
135 {
return set( key_r,
AnyType() ); }
137 bool reset(
const std::string & key_r )
const 138 {
return set( key_r,
AnyType() ); }
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 zypp::ContentType ContentType
std::ostream & operator<<(std::ostream &str, const UserData &obj)
size_type size() const
Size of data.
DataType & dataRef() const
String related utilities and Regular expression matching.
DataType::size_type size_type
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.
std::map< std::string, AnyType > DataType
void erase(const std::string &key_r)
Remove key from data.
DataType::const_iterator const_iterator
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).
const DataType & data() const
The data.
UserData(std::string type_r)
Ctor taking ContentType.
shared_ptr< DataType > _dataP
const ContentType & type() const
Get type.
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.
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
Easy-to use interface to the ZYPP dependency resolver.
bool empty() const
Whether data is empty.
Mime type like 'type/subtype' classification of content.