libzypp  11.13.5
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 
26  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  {
92  }
93 
94  void RepoInfoBase::setAutorefresh( bool autorefresh )
95  {
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  {
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