11#ifndef ZYPP_CORE_USERDATA_H
12#define ZYPP_CORE_USERDATA_H
17#include <boost/any.hpp>
19#include <zypp/base/PtrTypes.h>
44 typedef std::map<std::string,AnyType>
DataType;
58 explicit UserData( ContentType type_r )
62 explicit UserData( std::string type_r )
66 UserData( std::string type_r, std::string subtype_r )
67 :
UserData( ContentType(
std::move(type_r),
std::move(subtype_r) ) )
72 const ContentType &
type()
const
76 void type( ContentType type_r )
77 {
_type = std::move(type_r); }
81 explicit operator bool()
const
89 size_type
size()
const
97 bool haskey(
const std::string & key_r )
const
101 bool hasvalue(
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 )
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);
229 inline std::ostream &
operator<<( std::ostream &
str,
const UserData & obj )
230 {
return str <<
"UserData(" << obj.type() <<
":" << obj.size() <<
")";}
Mime type like 'type/subtype' classification of content.
DataType::const_iterator const_iterator
bool reset(const std::string &key_r)
Set an empty value for key_r (if possible).
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.
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.
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
bool set(const std::string &key_r, AnyType val_r)
Set the value for key (nonconst version always returns true).
DataType::value_type value_type
bool haskey(const std::string &key_r) const
Whether key_r is in data.
zypp::ContentType ContentType
std::map< std::string, AnyType > DataType
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.
String related utilities and Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)