Support CpeId in Repository and Product attributes (Fate#316160)
[platform/upstream/libzypp.git] / zypp / CpeId.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/CpeId.cc
10  */
11 #include <iostream>
12 //#include "zypp/base/LogTools.h"
13 #include "zypp/base/NonCopyable.h"
14
15 #include "zypp/CpeId.h"
16
17 using std::endl;
18
19 ///////////////////////////////////////////////////////////////////
20 namespace zypp
21 {
22   ///////////////////////////////////////////////////////////////////
23   /// \class CpeId::Impl
24   /// \brief CpeId implementation.
25   ///////////////////////////////////////////////////////////////////
26   class CpeId::Impl : private base::NonCopyable
27   {
28     friend std::ostream & operator<<( std::ostream & str, const Impl & obj );
29   public:
30     Impl() {}
31
32     Impl( const std::string & cpe_r )
33       : _cpe( cpe_r )
34     {}
35
36     Impl( const std::string & cpe_r, NoThrowType )
37       : _cpe( cpe_r )
38     {}
39
40   public:
41     const std::string & asString() const
42     { return _cpe; }
43
44     Match match( const Impl & rhs ) const
45     {
46       return _cpe == rhs._cpe ? Match::equal : Match::undefined;
47     }
48
49   private:
50     std::string _cpe;
51   };
52
53   ///////////////////////////////////////////////////////////////////
54   //
55   //    CLASS NAME : CpeId
56   //
57   ///////////////////////////////////////////////////////////////////
58
59   CpeId::CpeId()
60     : _pimpl( new Impl )
61   {}
62
63   CpeId::CpeId( const std::string & cpe_r )
64     : _pimpl( new Impl( cpe_r ) )
65   {}
66
67   CpeId::CpeId( const std::string & cpe_r, NoThrowType )
68     : _pimpl( new Impl( cpe_r, noThrow ) )
69   {}
70
71   CpeId::~CpeId()
72   {}
73
74   CpeId::operator bool() const
75   { return !_pimpl->asString().empty(); }
76
77   std::string CpeId::asString() const
78   { return _pimpl->asString(); }
79
80   CpeId::Match CpeId::match( const CpeId & rhs ) const
81   { return _pimpl->match( *rhs._pimpl ); }
82
83 } // namespace zypp
84 ///////////////////////////////////////////////////////////////////