libzypp  17.14.0
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"
18 #include "zypp/TriBool.h"
19 #include "zypp/Pathname.h"
20 
21 using namespace std;
22 
24 namespace zypp
25 {
27  namespace repo
28  {
29 
35  {
36  Impl()
37  : _enabled( indeterminate )
38  , _autorefresh( indeterminate )
39  {}
40 
41  Impl( const std::string & alias_r )
42  : _enabled( indeterminate )
43  , _autorefresh( indeterminate )
44  { setAlias( alias_r ); }
45 
46  public:
49  std::string _alias;
50  std::string _escaped_alias;
52  Pathname _filepath;
53 
54  public:
55 
56  void setAlias( const std::string & alias_r )
57  {
58  _alias = _escaped_alias = alias_r;
59  // replace slashes with underscores
60  str::replaceAll( _escaped_alias, "/", "_" );
61  }
62 
63  private:
64  friend Impl * rwcowClone<Impl>( const Impl * rhs );
66  Impl * clone() const
67  { return new Impl( *this ); }
68  };
70 
72  //
73  // CLASS NAME : RepoInfoBase
74  //
76 
77  RepoInfoBase::RepoInfoBase()
78  : _pimpl( new Impl() )
79  {}
80 
81  RepoInfoBase::RepoInfoBase(const string & alias)
82  : _pimpl( new Impl(alias) )
83  {}
84 
86  {}
87 
88  void RepoInfoBase::setEnabled( bool enabled )
89  { _pimpl->_enabled = enabled; }
90 
91  void RepoInfoBase::setAutorefresh( bool autorefresh )
93 
94  void RepoInfoBase::setAlias( const std::string &alias )
95  { _pimpl->setAlias(alias); }
96 
97  void RepoInfoBase::setName( const std::string &name )
98  { _pimpl->_name.raw() = name; }
99 
100  void RepoInfoBase::setFilepath( const Pathname &filepath )
101  { _pimpl->_filepath = filepath; }
102 
103  // true by default (if not set by setEnabled())
105  { return indeterminate(_pimpl->_enabled) ? true : (bool) _pimpl->_enabled; }
106 
107  // false by default (if not set by setAutorefresh())
109  { return indeterminate(_pimpl->_autorefresh) ? false : (bool) _pimpl->_autorefresh; }
110 
111  std::string RepoInfoBase::alias() const
112  { return _pimpl->_alias; }
113 
114  std::string RepoInfoBase::escaped_alias() const
115  { return _pimpl->_escaped_alias; }
116 
117  std::string RepoInfoBase::name() const
118  {
119  if ( rawName().empty() )
120  return alias();
122  }
123 
124  std::string RepoInfoBase::rawName() const
125  { return _pimpl->_name.raw(); }
126 
127  std::string RepoInfoBase::label() const
128  {
129  if ( ZConfig::instance().repoLabelIsAlias() )
130  return alias();
131  return name();
132  }
133 
134  Pathname RepoInfoBase::filepath() const
135  { return _pimpl->_filepath; }
136 
137 
138  std::ostream & RepoInfoBase::dumpOn( std::ostream & str ) const
139  {
140  str << "--------------------------------------" << std::endl;
141  str << "- alias : " << alias() << std::endl;
142  if ( ! rawName().empty() )
143  str << "- name : " << rawName() << std::endl;
144  str << "- enabled : " << enabled() << std::endl;
145  str << "- autorefresh : " << autorefresh() << std::endl;
146 
147  return str;
148  }
149 
150  std::ostream & RepoInfoBase::dumpAsIniOn( std::ostream & str ) const
151  {
152  // we save the original data without variable replacement
153  str << "[" << alias() << "]" << endl;
154  if ( ! rawName().empty() )
155  str << "name=" << rawName() << endl;
156  str << "enabled=" << (enabled() ? "1" : "0") << endl;
157  str << "autorefresh=" << (autorefresh() ? "1" : "0") << endl;
158 
159  return str;
160  }
161 
162  std::ostream & RepoInfoBase::dumpAsXmlOn( std::ostream & str, const std::string & content ) const
163  {
164  return str << "<!-- there's no XML representation of RepoInfoBase -->" << endl;
165  }
166 
167  std::ostream & operator<<( std::ostream & str, const RepoInfoBase & obj )
168  {
169  return obj.dumpOn(str);
170  }
171 
172  } // namespace repo
174 } // namespace zypp