libzypp  14.48.5
zypp::callback::UserData Class Reference

Typesafe passing of user data via callbacks. More...

#include <UserData.h>

Public Member Functions

 UserData ()
 Default ctor. More...
 
 UserData (ContentType type_r)
 Ctor taking ContentType. More...
 
 UserData (std::string type_r)
 Ctor taking ContentType. More...
 
 UserData (std::string type_r, std::string subtype_r)
 Ctor taking ContentType. More...
 
const ContentTypetype () const
 Get type. More...
 
void type (ContentType type_r)
 Set type. More...
 
 operator bool () const
 Validate object in a boolean context: has data. More...
 
bool empty () const
 Whether data is empty. More...
 
size_type size () const
 Size of data. More...
 
const DataTypedata () const
 The data. More...
 
bool haskey (const std::string &key_r) const
 Whether key_r is in data. More...
 
bool hasvalue (const std::string &key_r) const
 Whether key_r is in data and value is not empty. More...
 
bool set (const std::string &key_r, boost::any val_r)
 Set the value for key (nonconst version always returns true). More...
 
bool set (const std::string &key_r, boost::any val_r) const
 
bool reset (const std::string &key_r)
 Set an empty value for key_r (if possible). More...
 
bool reset (const std::string &key_r) const
 
void erase (const std::string &key_r)
 Remove key from data. More...
 
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. More...
 
template<class Tp >
const Tp & get (const std::string &key_r) const
 Pass back a const Tp & reference to key_r value. More...
 
template<class Tp >
Tp get (const std::string &key_r, const Tp &default_r) const
 Pass back a Tp copy of key_r value. More...
 
template<class Tp >
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;. More...
 

Private Types

typedef std::map< std::string,
boost::any > 
DataType
 
typedef DataType::size_type size_type
 
typedef DataType::key_type key_type
 
typedef DataType::value_type value_type
 
typedef DataType::const_iterator const_iterator
 

Private Member Functions

DataTypedataRef () const
 

Private Attributes

ContentType _type
 
shared_ptr< DataType_dataP
 

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &str, const UserData &obj)
 

Detailed Description

Typesafe passing of user data via callbacks.

Basically a std::map<std::string,boost::any> plus associated ContentType.

Constness protects non-empty values from being modified. It is possible to overwrite empty values or to add new ones.

Definition at line 38 of file UserData.h.

Member Typedef Documentation

typedef std::map<std::string,boost::any> zypp::callback::UserData::DataType
private

Definition at line 40 of file UserData.h.

typedef DataType::size_type zypp::callback::UserData::size_type
private

Definition at line 41 of file UserData.h.

typedef DataType::key_type zypp::callback::UserData::key_type
private

Definition at line 42 of file UserData.h.

typedef DataType::value_type zypp::callback::UserData::value_type
private

Definition at line 43 of file UserData.h.

typedef DataType::const_iterator zypp::callback::UserData::const_iterator
private

Definition at line 44 of file UserData.h.

Constructor & Destructor Documentation

zypp::callback::UserData::UserData ( )
inline

Default ctor.

Definition at line 47 of file UserData.h.

zypp::callback::UserData::UserData ( ContentType  type_r)
inlineexplicit

Ctor taking ContentType.

Definition at line 51 of file UserData.h.

zypp::callback::UserData::UserData ( std::string  type_r)
inlineexplicit

Ctor taking ContentType.

Definition at line 55 of file UserData.h.

zypp::callback::UserData::UserData ( std::string  type_r,
std::string  subtype_r 
)
inline

Ctor taking ContentType.

Definition at line 59 of file UserData.h.

Member Function Documentation

const ContentType& zypp::callback::UserData::type ( ) const
inline

Get type.

Definition at line 65 of file UserData.h.

void zypp::callback::UserData::type ( ContentType  type_r)
inline

Set type.

Definition at line 69 of file UserData.h.

zypp::callback::UserData::operator bool ( ) const
inlineexplicit

Validate object in a boolean context: has data.

Definition at line 74 of file UserData.h.

bool zypp::callback::UserData::empty ( ) const
inline

Whether data is empty.

Definition at line 78 of file UserData.h.

size_type zypp::callback::UserData::size ( ) const
inline

Size of data.

Definition at line 82 of file UserData.h.

const DataType& zypp::callback::UserData::data ( ) const
inline

The data.

Definition at line 86 of file UserData.h.

bool zypp::callback::UserData::haskey ( const std::string &  key_r) const
inline

Whether key_r is in data.

Definition at line 90 of file UserData.h.

bool zypp::callback::UserData::hasvalue ( const std::string &  key_r) const
inline

Whether key_r is in data and value is not empty.

Definition at line 94 of file UserData.h.

bool zypp::callback::UserData::set ( const std::string &  key_r,
boost::any  val_r 
)
inline

Set the value for key (nonconst version always returns true).

Const version is allowed to set empty values or to add new ones only.

Definition at line 111 of file UserData.h.

bool zypp::callback::UserData::set ( const std::string &  key_r,
boost::any  val_r 
) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 114 of file UserData.h.

bool zypp::callback::UserData::reset ( const std::string &  key_r)
inline

Set an empty value for key_r (if possible).

Definition at line 127 of file UserData.h.

bool zypp::callback::UserData::reset ( const std::string &  key_r) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 130 of file UserData.h.

void zypp::callback::UserData::erase ( const std::string &  key_r)
inline

Remove key from data.

Definition at line 134 of file UserData.h.

const boost::any& zypp::callback::UserData::getvalue ( const std::string &  key_r) const
inline

Return the keys boost::any value or an empty value if key does not exist.

Definition at line 138 of file UserData.h.

template<class Tp >
const Tp& zypp::callback::UserData::get ( const std::string &  key_r) const
inline

Pass back a const Tp & reference to key_r value.

Exceptions
boost::bad_any_castif key is not set or value is not of appropriate type
std::string value( "defaultvalue" );
try
{
value = data.get<std::string>( "mykey" );
}
catch ( const boost::bad_any_cast & )
{
// no "mykey" or not a std::sting
}

Definition at line 168 of file UserData.h.

template<class Tp >
Tp zypp::callback::UserData::get ( const std::string &  key_r,
const Tp &  default_r 
) const
inline

Pass back a Tp copy of key_r value.

Exceptions
boost::bad_any_castif key is not set or value is not of appropriate type
std::string value = data.get<std::string>( "mykey", "defaultvalue" );

Definition at line 179 of file UserData.h.

template<class Tp >
bool zypp::callback::UserData::get ( const std::string &  key_r,
Tp &  ret_r 
) const
inline

If the value for key_r is of the same type as ret_r, pass it back in ret_r and return true;.

std::string value( "defaultvalue" );
if ( ! data.get<std::string>( "mykey", value )
{
// no "mykey" or not a std::sting
}

Definition at line 193 of file UserData.h.

DataType& zypp::callback::UserData::dataRef ( ) const
inlineprivate

Definition at line 213 of file UserData.h.

Friends And Related Function Documentation

std::ostream & operator<< ( std::ostream &  str,
const UserData obj 
)
related

Stream output

Definition at line 222 of file UserData.h.

Member Data Documentation

ContentType zypp::callback::UserData::_type
private

Definition at line 217 of file UserData.h.

shared_ptr<DataType> zypp::callback::UserData::_dataP
mutableprivate

Definition at line 218 of file UserData.h.


The documentation for this class was generated from the following file: