1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/ServiceInfo.cc
15 #include "zypp/base/String.h"
16 #include "zypp/parser/xml/XmlEscape.h"
18 #include "zypp/RepoInfo.h"
19 #include "zypp/parser/RepoindexFileReader.h"
20 #include "zypp/repo/RepoInfoBaseImpl.h"
22 #include "zypp/ServiceInfo.h"
25 using zypp::xml::escape;
27 ///////////////////////////////////////////////////////////////////////////////
29 {//////////////////////////////////////////////////////////////////////////////
32 struct RepoInfoCollector
34 vector<RepoInfo> repos;
35 bool collect(const RepoInfo & info)
37 repos.push_back(info);
42 ///////////////////////////////////////////////////////////////////
44 // CLASS NAME : ServiceInfo::Impl
46 struct ServiceInfo::Impl : public repo::RepoInfoBase::Impl
48 typedef ServiceInfo::CatalogsToEnable CatalogsToEnable;
49 typedef ServiceInfo::CatalogsToDisable CatalogsToDisable;
53 CatalogsToEnable catalogsToEnable;
54 CatalogsToDisable catalogsToDisable;
57 Impl() : repo::RepoInfoBase::Impl() {}
59 Impl(const Url & url_) : url(url_) {}
62 friend Impl * rwcowClone<Impl>( const Impl * rhs );
64 /** clone for RWCOW_pointer */
66 { return new Impl( *this ); }
68 ///////////////////////////////////////////////////////////////////
71 ///////////////////////////////////////////////////////////////////
73 // CLASS NAME : ServiceInfo::Impl
75 ///////////////////////////////////////////////////////////////////
77 const ServiceInfo ServiceInfo::noService;
79 ServiceInfo::ServiceInfo() : _pimpl( new Impl() ) {}
81 ServiceInfo::ServiceInfo(const string & alias)
82 : repo::RepoInfoBase(alias), _pimpl( new Impl() )
85 ServiceInfo::ServiceInfo(const string & alias, const Url & url)
86 : repo::RepoInfoBase(alias), _pimpl( new Impl(url) )
89 Url ServiceInfo::url() const { return _pimpl->url; }
90 void ServiceInfo::setUrl( const Url& url ) { _pimpl->url = url; }
93 bool ServiceInfo::catalogsToEnableEmpty() const
94 { return _pimpl->catalogsToEnable.empty(); }
96 ServiceInfo::CatalogsToEnable::size_type ServiceInfo::catalogsToEnableSize() const
97 { return _pimpl->catalogsToEnable.size(); }
99 ServiceInfo::CatalogsToEnable::const_iterator ServiceInfo::catalogsToEnableBegin() const
100 { return _pimpl->catalogsToEnable.begin(); }
102 ServiceInfo::CatalogsToEnable::const_iterator ServiceInfo::catalogsToEnableEnd() const
103 { return _pimpl->catalogsToEnable.end(); }
105 bool ServiceInfo::catalogToEnableFind( const std::string & alias_r ) const
106 { return( _pimpl->catalogsToEnable.find( alias_r ) != _pimpl->catalogsToEnable.end() ); }
108 void ServiceInfo::addCatalogToEnable( const std::string & alias_r )
109 { _pimpl->catalogsToEnable.insert( alias_r ); }
111 void ServiceInfo::delCatalogToEnable( const std::string & alias_r )
112 { _pimpl->catalogsToEnable.erase( alias_r ); }
115 bool ServiceInfo::catalogsToDisableEmpty() const
116 { return _pimpl->catalogsToDisable.empty(); }
118 ServiceInfo::CatalogsToDisable::size_type ServiceInfo::catalogsToDisableSize() const
119 { return _pimpl->catalogsToDisable.size(); }
121 ServiceInfo::CatalogsToDisable::const_iterator ServiceInfo::catalogsToDisableBegin() const
122 { return _pimpl->catalogsToDisable.begin(); }
124 ServiceInfo::CatalogsToDisable::const_iterator ServiceInfo::catalogsToDisableEnd() const
125 { return _pimpl->catalogsToDisable.end(); }
127 bool ServiceInfo::catalogToDisableFind( const std::string & alias_r ) const
128 { return( _pimpl->catalogsToDisable.find( alias_r ) != _pimpl->catalogsToDisable.end() ); }
130 void ServiceInfo::addCatalogToDisable( const std::string & alias_r )
131 { _pimpl->catalogsToDisable.insert( alias_r ); }
133 void ServiceInfo::delCatalogToDisable( const std::string & alias_r )
134 { _pimpl->catalogsToDisable.erase( alias_r ); }
137 std::ostream & ServiceInfo::dumpAsIniOn( std::ostream & str ) const
139 RepoInfoBase::dumpAsIniOn(str) << "url = " << url() << endl;
140 if ( ! catalogsToEnableEmpty() )
141 str << "catalogstoenable = " << str::joinEscaped( catalogsToEnableBegin(), catalogsToEnableEnd() ) << endl;
142 if ( ! catalogsToDisableEmpty() )
143 str << "catalogstodisable = " << str::joinEscaped( catalogsToDisableBegin(), catalogsToDisableEnd() ) << endl;
147 std::ostream & ServiceInfo::dumpAsXMLOn(std::ostream & str) const
148 { return dumpAsXMLOn(str, ""); }
150 ostream & ServiceInfo::dumpAsXMLOn( ostream & str, const string & content) const
154 << " alias=\"" << escape(alias()) << "\""
155 << " name=\"" << escape(name()) << "\""
156 << " enabled=\"" << enabled() << "\""
157 << " autorefresh=\"" << autorefresh() << "\""
158 << " url=\"" << escape(url().asString()) << "\"";
163 str << ">" << endl << content << "</service>" << endl;
169 std::ostream & operator<<( std::ostream& str, const ServiceInfo &obj )
171 return obj.dumpAsIniOn(str);
175 ///////////////////////////////////////////////////////////////////////////////
177 ///////////////////////////////////////////////////////////////////////////////