Imported Upstream version 15.0.0
[platform/upstream/libzypp.git] / zypp / UserData.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/UserData.h
10  */
11 #ifndef ZYPP_USERDATA_H
12 #define ZYPP_USERDATA_H
13
14 #include <iosfwd>
15 #include <string>
16 #include <map>
17 #include <boost/any.hpp>
18
19 #include "zypp/base/PtrTypes.h"
20 #include "zypp/ContentType.h"
21
22 ///////////////////////////////////////////////////////////////////
23 namespace zypp
24 {
25   ///////////////////////////////////////////////////////////////////
26   namespace callback
27   {
28     ///////////////////////////////////////////////////////////////////
29     /// \class UserData
30     /// \brief Typesafe passing of user data via callbacks
31     ///
32     /// Basically a <tt>std::map<std::string,boost::any></tt> plus
33     /// associated \ref ContentType.
34     ///////////////////////////////////////////////////////////////////
35     class UserData
36     {
37       typedef std::map<std::string,boost::any> DataType;
38     public:
39       /** Default ctor */
40       UserData()
41       {}
42
43     public:
44       /** Get type */
45       const ContentType & type() const
46       { return _type; }
47
48       /** Set type */
49       void type( const ContentType & type_r )
50       { _type = type_r; }
51
52     public:
53       /**  Validate object in a boolean context: has data */
54       explicit operator bool() const
55       { return ! ( _dataP == nullptr || _dataP->empty() ); }
56
57     private:
58       ContentType               _type;
59       shared_ptr<DataType>      _dataP;
60     };
61
62     /** \relates UserData Stream output */
63     inline std::ostream & operator<<( std::ostream & str, const UserData & obj )
64     { return str << "UserData(" << obj.type() << ")";}
65
66   } // namespace callback
67   ///////////////////////////////////////////////////////////////////
68 } // namespace zypp
69 ///////////////////////////////////////////////////////////////////
70 #endif // ZYPP_USERDATA_H