17f7df5e589e3beab21a40ec631e843ee1c025c1
[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     typedef ServiceInfo::CatalogsToEnable CatalogsToEnable;
48
49   public:
50     Url url;
51     CatalogsToEnable catalogsToEnable;
52
53   public:
54     Impl() : repo::RepoInfoBase::Impl() {}
55
56     Impl(const Url & url_) : url(url_) {}
57
58   private:
59     friend Impl * rwcowClone<Impl>( const Impl * rhs );
60
61     /** clone for RWCOW_pointer */
62     Impl * clone() const
63     { return new Impl( *this ); }
64   };
65   ///////////////////////////////////////////////////////////////////
66
67
68   ///////////////////////////////////////////////////////////////////
69   //
70   //  CLASS NAME : ServiceInfo::Impl
71   //
72   ///////////////////////////////////////////////////////////////////
73
74   const ServiceInfo ServiceInfo::noService;
75
76   ServiceInfo::ServiceInfo() : _pimpl( new Impl() ) {}
77
78   ServiceInfo::ServiceInfo(const string & alias)
79     : repo::RepoInfoBase(alias), _pimpl( new Impl() )
80   {}
81
82   ServiceInfo::ServiceInfo(const string & alias, const Url & url)
83     : repo::RepoInfoBase(alias), _pimpl( new Impl(url) )
84   {}
85
86   Url ServiceInfo::url() const { return _pimpl->url; }
87   void ServiceInfo::setUrl( const Url& url ) { _pimpl->url = url; }
88
89
90   bool catalogsToEnableEmpty() const
91   { return _pimpl->catalogsToEnable.empty(); }
92
93   CatalogsToEnable::size_type catalogsToEnableSize() const
94   { return _pimpl->catalogsToEnable.size(); }
95
96   CatalogsToEnable::const_iterator catalogsToEnableBegin() const
97   { return _pimpl->catalogsToEnable.begin(); }
98
99   CatalogsToEnable::const_iterator catalogsToEnableEnd() const
100   { return _pimpl->catalogsToEnable.end(); }
101
102   bool catalogToEnableFind( const std::string & alias_r ) const
103   { return( _pimpl->catalogsToEnable.find( alias_r ) != _pimpl->catalogsToEnable.end() ); }
104
105   void addCatalogToEnable( const std::string & alias_r )
106   { return _pimpl->catalogsToEnable.insert( alias_r ); }
107
108   void delCatalogToEnable( const std::string & alias_r )
109   { return _pimpl->catalogsToEnable.erase( alias_r ); }
110
111
112   std::ostream & ServiceInfo::dumpAsIniOn( std::ostream & str ) const
113   {
114     return RepoInfoBase::dumpAsIniOn(str)
115         << "url = " << url() << endl;
116   }
117
118   std::ostream & ServiceInfo::dumpAsXMLOn( std::ostream & str) const
119   {
120     return str
121       << "<service"
122       << " alias=\"" << escape(alias()) << "\""
123       << " name=\"" << escape(name()) << "\""
124       << " enabled=\"" << enabled() << "\""
125       << " autorefresh=\"" << autorefresh() << "\""
126       << " url=\"" << escape(url().asString()) << "\""
127       << "/>" << endl;
128   }
129
130   std::ostream & operator<<( std::ostream& str, const ServiceInfo &obj )
131   {
132     return obj.dumpAsIniOn(str);
133   }
134
135
136 ///////////////////////////////////////////////////////////////////////////////
137 } //namespace zypp
138 ///////////////////////////////////////////////////////////////////////////////