ServiceInfo.cc

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #include <ostream>
00013 #include <iostream>
00014 
00015 #include "zypp/base/String.h"
00016 #include "zypp/parser/xml/XmlEscape.h"
00017 
00018 #include "zypp/RepoInfo.h"
00019 #include "zypp/repo/RepoInfoBaseImpl.h"
00020 
00021 #include "zypp/ServiceInfo.h"
00022 
00023 using namespace std;
00024 using zypp::xml::escape;
00025 
00027 namespace zypp
00028 {
00029 
00031   //
00032   //  CLASS NAME : ServiceInfo::Impl
00033   //
00034   struct ServiceInfo::Impl : public repo::RepoInfoBase::Impl
00035   {
00036     typedef ServiceInfo::ReposToEnable  ReposToEnable;
00037     typedef ServiceInfo::ReposToDisable ReposToDisable;
00038 
00039   public:
00040     Url url;
00041     repo::ServiceType type;
00042     ReposToEnable  reposToEnable;
00043     ReposToDisable reposToDisable;
00044 
00045   public:
00046     Impl()
00047       : repo::RepoInfoBase::Impl()
00048       , type(repo::ServiceType::NONE_e)
00049     {}
00050 
00051     Impl(const Url & url_)
00052       : repo::RepoInfoBase::Impl()
00053       , url(url_)
00054       , type(repo::ServiceType::NONE_e)
00055     {}
00056 
00057     ~Impl()
00058     {}
00059 
00060     void setProbedType( const repo::ServiceType & t ) const
00061     {
00062       if ( type == repo::ServiceType::NONE
00063            && t != repo::ServiceType::NONE )
00064       {
00065         // lazy init!
00066         const_cast<Impl*>(this)->type = t;
00067       }
00068     }
00069 
00070   private:
00071     friend Impl * rwcowClone<Impl>( const Impl * rhs );
00072 
00074     Impl * clone() const
00075     { return new Impl( *this ); }
00076   };
00078 
00079 
00081   //
00082   //  CLASS NAME : ServiceInfo::Impl
00083   //
00085 
00086   const ServiceInfo ServiceInfo::noService;
00087 
00088   ServiceInfo::ServiceInfo() : _pimpl( new Impl() ) {}
00089 
00090   ServiceInfo::ServiceInfo(const string & alias)
00091     : repo::RepoInfoBase(alias), _pimpl( new Impl() )
00092   {}
00093 
00094   ServiceInfo::ServiceInfo(const string & alias, const Url & url)
00095     : repo::RepoInfoBase(alias), _pimpl( new Impl(url) )
00096   {}
00097 
00098   ServiceInfo::~ServiceInfo()
00099   {}
00100 
00101   Url ServiceInfo::url() const { return _pimpl->url; }
00102   void ServiceInfo::setUrl( const Url& url ) { _pimpl->url = url; }
00103 
00104   repo::ServiceType ServiceInfo::type() const
00105   { return _pimpl->type; }
00106   void ServiceInfo::setType( const repo::ServiceType & type )
00107   { _pimpl->type = type; }
00108 
00109   void ServiceInfo::setProbedType( const repo::ServiceType &t ) const
00110   { _pimpl->setProbedType( t ); }
00111 
00112   bool ServiceInfo::reposToEnableEmpty() const
00113   { return _pimpl->reposToEnable.empty(); }
00114 
00115   ServiceInfo::ReposToEnable::size_type ServiceInfo::reposToEnableSize() const
00116   { return _pimpl->reposToEnable.size(); }
00117 
00118   ServiceInfo::ReposToEnable::const_iterator ServiceInfo::reposToEnableBegin() const
00119   { return _pimpl->reposToEnable.begin(); }
00120 
00121   ServiceInfo::ReposToEnable::const_iterator ServiceInfo::reposToEnableEnd() const
00122   { return _pimpl->reposToEnable.end(); }
00123 
00124   bool ServiceInfo::repoToEnableFind( const std::string & alias_r ) const
00125   { return( _pimpl->reposToEnable.find( alias_r ) != _pimpl->reposToEnable.end() ); }
00126 
00127   void ServiceInfo::addRepoToEnable( const std::string & alias_r )
00128   {
00129     _pimpl->reposToEnable.insert( alias_r );
00130     _pimpl->reposToDisable.erase( alias_r );
00131   }
00132 
00133   void ServiceInfo::delRepoToEnable( const std::string & alias_r )
00134   { _pimpl->reposToEnable.erase( alias_r ); }
00135 
00136   void ServiceInfo::clearReposToEnable()
00137   { _pimpl->reposToEnable.clear(); }
00138 
00139 
00140   bool ServiceInfo::reposToDisableEmpty() const
00141   { return _pimpl->reposToDisable.empty(); }
00142 
00143   ServiceInfo::ReposToDisable::size_type ServiceInfo::reposToDisableSize() const
00144   { return _pimpl->reposToDisable.size(); }
00145 
00146   ServiceInfo::ReposToDisable::const_iterator ServiceInfo::reposToDisableBegin() const
00147   { return _pimpl->reposToDisable.begin(); }
00148 
00149   ServiceInfo::ReposToDisable::const_iterator ServiceInfo::reposToDisableEnd() const
00150   { return _pimpl->reposToDisable.end(); }
00151 
00152   bool ServiceInfo::repoToDisableFind( const std::string & alias_r ) const
00153   { return( _pimpl->reposToDisable.find( alias_r ) != _pimpl->reposToDisable.end() ); }
00154 
00155   void ServiceInfo::addRepoToDisable( const std::string & alias_r )
00156   {
00157     _pimpl->reposToDisable.insert( alias_r );
00158     _pimpl->reposToEnable.erase( alias_r );
00159   }
00160 
00161   void ServiceInfo::delRepoToDisable( const std::string & alias_r )
00162   { _pimpl->reposToDisable.erase( alias_r ); }
00163 
00164   void ServiceInfo::clearReposToDisable()
00165   { _pimpl->reposToDisable.clear(); }
00166 
00167 
00168   std::ostream & ServiceInfo::dumpAsIniOn( std::ostream & str ) const
00169   {
00170     RepoInfoBase::dumpAsIniOn(str)
00171       << "url = " << url() << endl
00172       << "type = " << type() << endl;
00173 
00174     if ( ! reposToEnableEmpty() )
00175       str << "repostoenable = " << str::joinEscaped( reposToEnableBegin(), reposToEnableEnd() ) << endl;
00176     if ( ! reposToDisableEmpty() )
00177       str << "repostodisable = " << str::joinEscaped( reposToDisableBegin(), reposToDisableEnd() ) << endl;
00178     return str;
00179   }
00180 
00181   std::ostream & ServiceInfo::dumpAsXMLOn(std::ostream & str) const
00182   { return dumpAsXMLOn(str, ""); }
00183 
00184   ostream & ServiceInfo::dumpAsXMLOn( ostream & str, const string & content) const
00185   {
00186     str
00187       << "<service"
00188       << " alias=\"" << escape(alias()) << "\""
00189       << " name=\"" << escape(name()) << "\""
00190       << " enabled=\"" << enabled() << "\""
00191       << " autorefresh=\"" << autorefresh() << "\""
00192       << " url=\"" << escape(url().asString()) << "\""
00193       << " type=\"" << type().asString() << "\"";
00194 
00195     if (content.empty())
00196       str << "/>" << endl;
00197     else
00198       str << ">" << endl << content << "</service>" << endl;
00199 
00200     return str;
00201   }
00202 
00203 
00204   std::ostream & operator<<( std::ostream& str, const ServiceInfo &obj )
00205   {
00206     return obj.dumpAsIniOn(str);
00207   }
00208 
00209 
00211 } //namespace zypp

doxygen