- use shared_ptr instead of the intrusive one
[platform/upstream/libzypp.git] / zypp / ServiceInfo.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/ServiceInfo.cc
10  *
11  */
12 #include <ostream>
13 #include <iostream>
14
15 #include "zypp/parser/xml/XmlEscape.h"
16
17 #include "zypp/RepoInfo.h"
18 #include "zypp/parser/RepoindexFileReader.h"
19 #include "zypp/repo/RepoInfoBaseImpl.h"
20
21 #include "zypp/ServiceInfo.h"
22
23 using namespace std;
24 using zypp::xml::escape;
25
26 ///////////////////////////////////////////////////////////////////////////////
27 namespace zypp 
28 {//////////////////////////////////////////////////////////////////////////////
29
30
31   struct RepoInfoCollector
32   {
33     vector<RepoInfo> repos;
34     bool collect(const RepoInfo & info)
35     {
36       repos.push_back(info);
37       return true;
38     }
39   };
40
41   ///////////////////////////////////////////////////////////////////
42   //
43   //  CLASS NAME : ServiceInfo::Impl
44   //
45   struct ServiceInfo::Impl : public repo::RepoInfoBase::Impl
46   {
47   public:
48     Url url;
49
50   public:
51     Impl() : repo::RepoInfoBase::Impl() {}
52
53     Impl(const Url & url_) : url(url_) {}
54
55   private:
56     friend Impl * rwcowClone<Impl>( const Impl * rhs );
57
58     /** clone for RWCOW_pointer */
59     Impl * clone() const
60     { return new Impl( *this ); }
61   };
62   ///////////////////////////////////////////////////////////////////
63
64
65   ///////////////////////////////////////////////////////////////////
66   //
67   //  CLASS NAME : ServiceInfo::Impl
68   //
69   ///////////////////////////////////////////////////////////////////
70
71   const ServiceInfo ServiceInfo::noService;
72   
73   ServiceInfo::ServiceInfo() : _pimpl( new Impl() ) {}
74
75   ServiceInfo::ServiceInfo(const string & alias)
76     : repo::RepoInfoBase(alias), _pimpl( new Impl() )
77   {}
78
79   ServiceInfo::ServiceInfo(const string & alias, const Url & url)
80     : repo::RepoInfoBase(alias), _pimpl( new Impl(url) )
81   {}
82
83   Url ServiceInfo::url() const { return _pimpl->url; }
84   void ServiceInfo::setUrl( const Url& url ) { _pimpl->url = url; }
85
86
87   std::ostream & ServiceInfo::dumpAsIniOn( std::ostream & str ) const
88   {
89     return RepoInfoBase::dumpAsIniOn(str) << "url = " << url() << endl;
90   }
91
92   std::ostream & ServiceInfo::dumpAsXMLOn( std::ostream & str) const
93   {
94     return str
95       << "<service"
96       << " alias=\"" << escape(alias()) << "\""
97       << " name=\"" << escape(name()) << "\""
98       << " enabled=\"" << enabled() << "\""
99       << " autorefresh=\"" << autorefresh() << "\""
100       << " url=\"" << escape(url().asString()) << "\""
101       << "/>" << endl;
102   }
103   
104   std::ostream & operator<<( std::ostream& str, const ServiceInfo &obj )
105   {
106     return obj.dumpAsIniOn(str);
107   }
108
109
110 ///////////////////////////////////////////////////////////////////////////////
111 } //namespace zypp
112 ///////////////////////////////////////////////////////////////////////////////