libzypp  13.10.6
RepoInfoBase.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <iostream>
13 
14 #include "zypp/ZConfig.h"
16 
17 #include "zypp/repo/RepoInfoBase.h"
19 
20 using namespace std;
21 
23 namespace zypp
24 {
25  namespace repo
27  {
28 
30  //
31  // CLASS NAME : RepoInfoBase::Impl
32  //
34 
36  inline std::ostream & operator<<( std::ostream & str, const RepoInfoBase::Impl & obj )
37  {
38  return str << "RepoInfo::Impl";
39  }
40 
41  void RepoInfoBase::Impl::setAlias(const string & alias_)
42  {
43  this->alias = alias_;
44  // replace slashes with underscores
45  std::string fnd="/";
46  std::string rep="_";
47  std::string escaped_alias = alias_;
48  size_t pos = escaped_alias.find(fnd);
49  while (pos != string::npos)
50  {
51  escaped_alias.replace(pos, fnd.length(), rep);
52  pos = escaped_alias.find(fnd, pos+rep.length());
53  }
54  this->escaped_alias = escaped_alias;
55  }
56 
58  //
59  // CLASS NAME : RepoInfoBase
60  //
62 
64  //
65  // METHOD NAME : RepoInfoBase::RepoInfoBase
66  // METHOD TYPE : Ctor
67  //
68  RepoInfoBase::RepoInfoBase()
69  : _pimpl( new Impl() )
70  {}
71 
73  //
74  // METHOD NAME : RepoInfoBase::RepoInfoBase
75  // METHOD TYPE : Ctor
76  //
77  RepoInfoBase::RepoInfoBase(const string & alias)
78  : _pimpl( new Impl(alias) )
79  {}
80 
82  //
83  // METHOD NAME : RepoInfoBase::~RepoInfoBase
84  // METHOD TYPE : Dtor
85  //
87  {}
88 
89  void RepoInfoBase::setEnabled( bool enabled )
90  {
91  _pimpl->enabled = enabled;
92  }
93 
94  void RepoInfoBase::setAutorefresh( bool autorefresh )
95  {
96  _pimpl->autorefresh = autorefresh;
97  }
98 
99  void RepoInfoBase::setAlias( const std::string &alias )
100  {
101  _pimpl->setAlias(alias);
102  }
103 
104  void RepoInfoBase::setName( const std::string &name )
105  {
106  _pimpl->name = name;
107  }
108 
109  void RepoInfoBase::setFilepath( const Pathname &filepath )
110  {
111  _pimpl->filepath = filepath;
112  }
113 
114  // true by default (if not set by setEnabled())
116  { return indeterminate(_pimpl->enabled) ? true : (bool) _pimpl->enabled; }
117 
118  // false by default (if not set by setAutorefresh())
120  { return indeterminate(_pimpl->autorefresh) ? false : (bool) _pimpl->autorefresh; }
121 
122  std::string RepoInfoBase::alias() const
123  { return _pimpl->alias; }
124 
125  std::string RepoInfoBase::escaped_alias() const
126  { return _pimpl->escaped_alias; }
127 
128  std::string RepoInfoBase::name() const
129  {
130  if ( _pimpl->name.empty() )
131  {
132  return alias();
133  }
134 
136  return replacer(_pimpl->name);
137  }
138 
139  std::string RepoInfoBase::label() const
140  {
141  if ( ZConfig::instance().repoLabelIsAlias() )
142  return alias();
143  return name();
144  }
145 
146  Pathname RepoInfoBase::filepath() const
147  { return _pimpl->filepath; }
148 
149 
150  std::ostream & RepoInfoBase::dumpOn( std::ostream & str ) const
151  {
152  str << "--------------------------------------" << std::endl;
153  str << "- alias : " << alias() << std::endl;
154  str << "- name : " << name() << std::endl;
155  str << "- enabled : " << enabled() << std::endl;
156  str << "- autorefresh : " << autorefresh() << std::endl;
157 
158  return str;
159  }
160 
161  std::ostream & RepoInfoBase::dumpAsIniOn( std::ostream & str ) const
162  {
163  // we save the original data without variable replacement
164  str << "[" << alias() << "]" << endl;
165  str << "name=" << name() << endl;
166  str << "enabled=" << (enabled() ? "1" : "0") << endl;
167  str << "autorefresh=" << (autorefresh() ? "1" : "0") << endl;
168 
169  return str;
170  }
171 
172  std::ostream & RepoInfoBase::dumpAsXMLOn(std::ostream & str) const
173  { return dumpAsXMLOn(str, ""); }
174 
175  std::ostream & RepoInfoBase::dumpAsXMLOn( std::ostream & str, const std::string & content) const
176  {
177  return str << "<!-- there's no XML representation of RepoInfoBase -->" << endl;
178  }
179 
180  std::ostream & operator<<( std::ostream & str, const RepoInfoBase & obj )
181  {
182  return obj.dumpOn(str);
183  }
185 
187  } // namespace repo
190 } // namespace zypp
std::string name() const
Repository short label.
std::string alias() const
unique identifier for this source.
std::string escaped_alias() const
Same as alias(), just escaped in a way to be a valid file name.
void setAutorefresh(bool autorefresh)
enable or disable autorefresh
Definition: RepoInfoBase.cc:94
static ZConfig & instance()
Singleton ctor.
Definition: ZConfig.cc:655
Pathname filepath() const
File where this repo was read from.
void setEnabled(bool enabled)
enable or disable the repository
Definition: RepoInfoBase.cc:89
void setAlias(const std::string &alias)
set the repository alias
Definition: RepoInfoBase.cc:99
void setFilepath(const Pathname &filename)
set the path to the .repo file
virtual std::ostream & dumpAsIniOn(std::ostream &str) const
Write this RepoInfoBase object into str in a .repo (ini) file format.
virtual std::ostream & dumpOn(std::ostream &str) const
Write a human-readable representation of this RepoInfoBase object into the str stream.
bool enabled() const
If enabled is false, then this repository must be ignored as if does not exists, except when checking...
virtual std::ostream & dumpAsXMLOn(std::ostream &str) const
Write an XML representation of this object.
std::string label() const
Label for use in messages for the user interface.
std::ostream & operator<<(std::ostream &str, const DeltaCandidates &obj)
std::ostream & operator<<(std::ostream &str, const ::_Dataiterator *obj)
Definition: LookupAttr.cc:799
bool autorefresh() const
If true, the repostory must be refreshed before creating resolvables from it.
Functor replacing repository variables.
Definition: RepoVariables.h:34
Base class implementing common features of RepoInfo and ServiceInfo.
Definition: RepoInfoBase.h:36
void setName(const std::string &name)
set the repository name
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: RepoInfoBase.h:155