11#ifndef ZYPP_USERDATA_H
12#define ZYPP_USERDATA_H
17#include <boost/any.hpp>
19#include <zypp/base/PtrTypes.h>
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() )
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() <<
")";}
Mime type like 'type/subtype' classification of content.
Typesafe passing of user data via callbacks.
DataType::const_iterator const_iterator
bool reset(const std::string &key_r)
Set an empty value for key_r (if possible).
void type(ContentType type_r)
Set type.
const Tp & get(const std::string &key_r) const
Pass back a const Tp & reference to key_r value.
const DataType & data() const
The data.
shared_ptr< DataType > _dataP
const ContentType & type() const
Get type.
UserData(ContentType type_r)
Ctor taking ContentType.
DataType & dataRef() const
DataType::size_type size_type
bool hasvalue(const std::string &key_r) const
Whether key_r is in data and value is not empty.
bool get(const std::string &key_r, Tp &ret_r) const
If the value for key_r is of the same type as ret_r, pass it back in ret_r and return true;.
void erase(const std::string &key_r)
Remove key from data.
boost::bad_any_cast bad_AnyType_cast
size_type size() const
Size of data.
DataType::key_type key_type
std::ostream & operator<<(std::ostream &str, const UserData &obj)
Stream output.
bool set(const std::string &key_r, AnyType val_r)
Set the value for key (nonconst version always returns true).
bool set(const std::string &key_r, AnyType val_r) const
DataType::value_type value_type
bool haskey(const std::string &key_r) const
Whether key_r is in data.
UserData(std::string type_r, std::string subtype_r)
Ctor taking ContentType.
zypp::ContentType ContentType
std::map< std::string, AnyType > DataType
UserData(std::string type_r)
Ctor taking ContentType.
bool empty() const
Whether data is empty.
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.
Tp get(const std::string &key_r, const Tp &default_r) const
Pass back a Tp copy of key_r value.
bool reset(const std::string &key_r) const
String related utilities and Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.