RepoInfoBase.cc

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #include <iostream>
00013 
00014 #include "zypp/ZConfig.h"
00015 #include "zypp/repo/RepoVariables.h"
00016 
00017 #include "zypp/repo/RepoInfoBase.h"
00018 #include "zypp/repo/RepoInfoBaseImpl.h"
00019 
00020 using namespace std;
00021 
00023 namespace zypp
00024 { 
00025 
00026   namespace repo
00027   { 
00028 
00030   //
00031   //    CLASS NAME : RepoInfoBase::Impl
00032   //
00034 
00036   inline std::ostream & operator<<( std::ostream & str, const RepoInfoBase::Impl & obj )
00037   {
00038     return str << "RepoInfo::Impl";
00039   }
00040 
00041   void RepoInfoBase::Impl::setAlias(const string & alias_)
00042   {
00043     this->alias = alias_;
00044     // replace slashes with underscores
00045     std::string fnd="/";
00046     std::string rep="_";
00047     std::string escaped_alias = alias_;
00048     size_t pos = escaped_alias.find(fnd);
00049     while (pos != string::npos)
00050     {
00051       escaped_alias.replace(pos, fnd.length(), rep);
00052       pos = escaped_alias.find(fnd, pos+rep.length());
00053     }
00054     this->escaped_alias = escaped_alias;
00055   }
00056 
00058   //
00059   //    CLASS NAME : RepoInfoBase
00060   //
00062 
00064   //
00065   //    METHOD NAME : RepoInfoBase::RepoInfoBase
00066   //    METHOD TYPE : Ctor
00067   //
00068   RepoInfoBase::RepoInfoBase()
00069     : _pimpl( new Impl() )
00070   {}
00071 
00073   //
00074   //    METHOD NAME : RepoInfoBase::RepoInfoBase
00075   //    METHOD TYPE : Ctor
00076   //
00077   RepoInfoBase::RepoInfoBase(const string & alias)
00078     : _pimpl( new Impl(alias) )
00079   {}
00080 
00082   //
00083   //    METHOD NAME : RepoInfoBase::~RepoInfoBase
00084   //    METHOD TYPE : Dtor
00085   //
00086   RepoInfoBase::~RepoInfoBase()
00087   {}
00088 
00089   void RepoInfoBase::setEnabled( bool enabled )
00090   {
00091     _pimpl->enabled = enabled;
00092   }
00093 
00094   void RepoInfoBase::setAutorefresh( bool autorefresh )
00095   {
00096     _pimpl->autorefresh = autorefresh;
00097   }
00098 
00099   void RepoInfoBase::setAlias( const std::string &alias )
00100   {
00101     _pimpl->setAlias(alias);
00102   }
00103 
00104   void RepoInfoBase::setName( const std::string &name )
00105   {
00106     _pimpl->name = name;
00107   }
00108 
00109   void RepoInfoBase::setFilepath( const Pathname &filepath )
00110   {
00111     _pimpl->filepath = filepath;
00112   }
00113 
00114   // true by default (if not set by setEnabled())
00115   bool RepoInfoBase::enabled() const
00116   { return indeterminate(_pimpl->enabled) ? true : (bool) _pimpl->enabled; }
00117 
00118   // false by default (if not set by setAutorefresh())
00119   bool RepoInfoBase::autorefresh() const
00120   { return indeterminate(_pimpl->autorefresh) ? false : (bool) _pimpl->autorefresh; }
00121 
00122   std::string RepoInfoBase::alias() const
00123   { return _pimpl->alias; }
00124 
00125   std::string RepoInfoBase::escaped_alias() const
00126   { return _pimpl->escaped_alias; }
00127 
00128   std::string RepoInfoBase::name() const
00129   {
00130     if ( _pimpl->name.empty() )
00131     {
00132       return alias();
00133     }
00134 
00135     repo::RepoVariablesStringReplacer replacer;
00136     return replacer(_pimpl->name);
00137   }
00138 
00139   std::string RepoInfoBase::label() const
00140   {
00141     if ( ZConfig::instance().repoLabelIsAlias() )
00142       return alias();
00143     return name();
00144   }
00145 
00146   Pathname RepoInfoBase::filepath() const
00147   { return _pimpl->filepath; }
00148 
00149 
00150   std::ostream & RepoInfoBase::dumpOn( std::ostream & str ) const
00151   {
00152     str << "--------------------------------------" << std::endl;
00153     str << "- alias       : " << alias() << std::endl;
00154     str << "- name        : " << name() << std::endl;
00155     str << "- enabled     : " << enabled() << std::endl;
00156     str << "- autorefresh : " << autorefresh() << std::endl;
00157 
00158     return str;
00159   }
00160 
00161   std::ostream & RepoInfoBase::dumpAsIniOn( std::ostream & str ) const
00162   {
00163     // we save the original data without variable replacement
00164     str << "[" << alias() << "]" << endl;
00165     str << "name=" << name() << endl;
00166     str << "enabled=" << (enabled() ? "1" : "0") << endl;
00167     str << "autorefresh=" << (autorefresh() ? "1" : "0") << endl;
00168 
00169     return str;
00170   }
00171 
00172   std::ostream & RepoInfoBase::dumpAsXMLOn(std::ostream & str) const
00173   { return dumpAsXMLOn(str, ""); }
00174 
00175   std::ostream & RepoInfoBase::dumpAsXMLOn( std::ostream & str, const std::string & content) const
00176   {
00177     return str << "<!-- there's no XML representation of RepoInfoBase -->" << endl;
00178   }
00179 
00180   std::ostream & operator<<( std::ostream & str, const RepoInfoBase & obj )
00181   {
00182     return obj.dumpOn(str);
00183   }
00185 
00187   } // namespace repo
00190 } // namespace zypp

doxygen