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/repo/RepoInfoBaseImpl.h"
21 #include "zypp/ServiceInfo.h"
24 using zypp::xml::escape;
26 ///////////////////////////////////////////////////////////////////////////////
28 {//////////////////////////////////////////////////////////////////////////////
30 ///////////////////////////////////////////////////////////////////
32 // CLASS NAME : ServiceInfo::Impl
34 struct ServiceInfo::Impl : public repo::RepoInfoBase::Impl
36 typedef ServiceInfo::ReposToEnable ReposToEnable;
37 typedef ServiceInfo::ReposToDisable ReposToDisable;
41 repo::ServiceType type;
42 ReposToEnable reposToEnable;
43 ReposToDisable reposToDisable;
47 : repo::RepoInfoBase::Impl()
48 , type(repo::ServiceType::NONE_e)
51 Impl(const Url & url_)
52 : repo::RepoInfoBase::Impl()
54 , type(repo::ServiceType::NONE_e)
60 void setProbedType( const repo::ServiceType & t ) const
62 if ( type == repo::ServiceType::NONE
63 && t != repo::ServiceType::NONE )
66 const_cast<Impl*>(this)->type = t;
71 friend Impl * rwcowClone<Impl>( const Impl * rhs );
73 /** clone for RWCOW_pointer */
75 { return new Impl( *this ); }
77 ///////////////////////////////////////////////////////////////////
80 ///////////////////////////////////////////////////////////////////
82 // CLASS NAME : ServiceInfo::Impl
84 ///////////////////////////////////////////////////////////////////
86 const ServiceInfo ServiceInfo::noService;
88 ServiceInfo::ServiceInfo() : _pimpl( new Impl() ) {}
90 ServiceInfo::ServiceInfo(const string & alias)
91 : repo::RepoInfoBase(alias), _pimpl( new Impl() )
94 ServiceInfo::ServiceInfo(const string & alias, const Url & url)
95 : repo::RepoInfoBase(alias), _pimpl( new Impl(url) )
98 ServiceInfo::~ServiceInfo()
101 Url ServiceInfo::url() const { return _pimpl->url; }
102 void ServiceInfo::setUrl( const Url& url ) { _pimpl->url = url; }
104 repo::ServiceType ServiceInfo::type() const
105 { return _pimpl->type; }
106 void ServiceInfo::setType( const repo::ServiceType & type )
107 { _pimpl->type = type; }
109 void ServiceInfo::setProbedType( const repo::ServiceType &t ) const
110 { _pimpl->setProbedType( t ); }
112 bool ServiceInfo::reposToEnableEmpty() const
113 { return _pimpl->reposToEnable.empty(); }
115 ServiceInfo::ReposToEnable::size_type ServiceInfo::reposToEnableSize() const
116 { return _pimpl->reposToEnable.size(); }
118 ServiceInfo::ReposToEnable::const_iterator ServiceInfo::reposToEnableBegin() const
119 { return _pimpl->reposToEnable.begin(); }
121 ServiceInfo::ReposToEnable::const_iterator ServiceInfo::reposToEnableEnd() const
122 { return _pimpl->reposToEnable.end(); }
124 bool ServiceInfo::repoToEnableFind( const std::string & alias_r ) const
125 { return( _pimpl->reposToEnable.find( alias_r ) != _pimpl->reposToEnable.end() ); }
127 void ServiceInfo::addRepoToEnable( const std::string & alias_r )
129 _pimpl->reposToEnable.insert( alias_r );
130 _pimpl->reposToDisable.erase( alias_r );
133 void ServiceInfo::delRepoToEnable( const std::string & alias_r )
134 { _pimpl->reposToEnable.erase( alias_r ); }
136 void ServiceInfo::clearReposToEnable()
137 { _pimpl->reposToEnable.clear(); }
140 bool ServiceInfo::reposToDisableEmpty() const
141 { return _pimpl->reposToDisable.empty(); }
143 ServiceInfo::ReposToDisable::size_type ServiceInfo::reposToDisableSize() const
144 { return _pimpl->reposToDisable.size(); }
146 ServiceInfo::ReposToDisable::const_iterator ServiceInfo::reposToDisableBegin() const
147 { return _pimpl->reposToDisable.begin(); }
149 ServiceInfo::ReposToDisable::const_iterator ServiceInfo::reposToDisableEnd() const
150 { return _pimpl->reposToDisable.end(); }
152 bool ServiceInfo::repoToDisableFind( const std::string & alias_r ) const
153 { return( _pimpl->reposToDisable.find( alias_r ) != _pimpl->reposToDisable.end() ); }
155 void ServiceInfo::addRepoToDisable( const std::string & alias_r )
157 _pimpl->reposToDisable.insert( alias_r );
158 _pimpl->reposToEnable.erase( alias_r );
161 void ServiceInfo::delRepoToDisable( const std::string & alias_r )
162 { _pimpl->reposToDisable.erase( alias_r ); }
164 void ServiceInfo::clearReposToDisable()
165 { _pimpl->reposToDisable.clear(); }
168 std::ostream & ServiceInfo::dumpAsIniOn( std::ostream & str ) const
170 RepoInfoBase::dumpAsIniOn(str)
171 << "url = " << url() << endl
172 << "type = " << type() << endl;
174 if ( ! reposToEnableEmpty() )
175 str << "repostoenable = " << str::joinEscaped( reposToEnableBegin(), reposToEnableEnd() ) << endl;
176 if ( ! reposToDisableEmpty() )
177 str << "repostodisable = " << str::joinEscaped( reposToDisableBegin(), reposToDisableEnd() ) << endl;
181 std::ostream & ServiceInfo::dumpAsXMLOn(std::ostream & str) const
182 { return dumpAsXMLOn(str, ""); }
184 ostream & ServiceInfo::dumpAsXMLOn( ostream & str, const string & content) const
188 << " alias=\"" << escape(alias()) << "\""
189 << " name=\"" << escape(name()) << "\""
190 << " enabled=\"" << enabled() << "\""
191 << " autorefresh=\"" << autorefresh() << "\""
192 << " url=\"" << escape(url().asString()) << "\""
193 << " type=\"" << type().asString() << "\"";
198 str << ">" << endl << content << "</service>" << endl;
204 std::ostream & operator<<( std::ostream& str, const ServiceInfo &obj )
206 return obj.dumpAsIniOn(str);
210 ///////////////////////////////////////////////////////////////////////////////
212 ///////////////////////////////////////////////////////////////////////////////