libzypp  17.25.1
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 std::endl;
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;
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 
78  : _pimpl( new Impl() )
79  {}
80 
81  RepoInfoBase::RepoInfoBase(const std::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 
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
zypp::repo::RepoInfoBase::dumpAsIniOn
virtual std::ostream & dumpAsIniOn(std::ostream &str) const
Write this RepoInfoBase object into str in a .repo (ini) file format.
Definition: RepoInfoBase.cc:150
zypp::repo::RepoInfoBase::Impl::clone
Impl * clone() const
clone for RWCOW_pointer
Definition: RepoInfoBase.cc:66
zypp::repo::RepoInfoBase::rawName
std::string rawName() const
The raw metadata name (no default, no variables replaced).
Definition: RepoInfoBase.cc:124
RepoVariables.h
zypp::repo::RepoInfoBase::Impl::_autorefresh
TriBool _autorefresh
Definition: RepoInfoBase.cc:48
zypp::repo::RepoInfoBase::setAutorefresh
void setAutorefresh(bool autorefresh)
enable or disable autorefresh
Definition: RepoInfoBase.cc:91
ZConfig.h
zypp::repo::RepoInfoBase::setName
void setName(const std::string &name)
set the repository name
Definition: RepoInfoBase.cc:97
zypp::repo::RepoInfoBase::enabled
bool enabled() const
If enabled is false, then this repository must be ignored as if does not exists, except when checking...
Definition: RepoInfoBase.cc:104
zypp::repo::RepoInfoBase::Impl::_name
RepoVariablesReplacedString _name
Definition: RepoInfoBase.cc:51
zypp::repo::RepoInfoBase::Impl
RepoInfoBase data.
Definition: RepoInfoBase.cc:34
zypp::repo::RepoInfoBase::setFilepath
void setFilepath(const Pathname &filename)
set the path to the .repo file
Definition: RepoInfoBase.cc:100
Pathname.h
zypp::repo::RepoInfoBase::dumpAsXmlOn
virtual std::ostream & dumpAsXmlOn(std::ostream &str, const std::string &content="") const
Write an XML representation of this object with content (if available).
Definition: RepoInfoBase.cc:162
zypp::repo::RepoVariablesStringReplacer
Functor replacing repository variables.
Definition: RepoVariables.h:105
zypp::repo::RepoInfoBase::Impl::_escaped_alias
std::string _escaped_alias
Definition: RepoInfoBase.cc:50
bool
zypp::repo::RepoInfoBase::Impl::Impl
Impl()
Definition: RepoInfoBase.cc:36
zypp::repo::RepoInfoBase::Impl::_filepath
Pathname _filepath
Definition: RepoInfoBase.cc:52
zypp::repo::RepoInfoBase::escaped_alias
std::string escaped_alias() const
Same as alias(), just escaped in a way to be a valid file name.
Definition: RepoInfoBase.cc:114
zypp::repo::operator<<
std::ostream & operator<<(std::ostream &str, const DeltaCandidates &obj)
Definition: DeltaCandidates.cc:107
zypp::repo::RepoInfoBase::_pimpl
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: RepoInfoBase.h:160
zypp::repo::RepoInfoBase::alias
std::string alias() const
unique identifier for this source.
Definition: RepoInfoBase.cc:111
zypp::str::replaceAll
std::string & replaceAll(std::string &str_r, const std::string &from_r, const std::string &to_r)
Replace all occurrences of from_r with to_r in str_r (inplace).
Definition: String.cc:321
zypp::repo::RepoInfoBase::Impl::_alias
std::string _alias
Definition: RepoInfoBase.cc:49
zypp::repo::RepoInfoBase::name
std::string name() const
Repository name.
Definition: RepoInfoBase.cc:117
zypp::ZConfig::instance
static ZConfig & instance()
Singleton ctor.
Definition: Resolver.cc:126
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
zypp::repo::RepoInfoBase::label
std::string label() const
Label for use in messages for the user interface.
Definition: RepoInfoBase.cc:127
RepoInfoBase.h
zypp::repo::RepoInfoBase::setEnabled
void setEnabled(bool enabled)
enable or disable the repository
Definition: RepoInfoBase.cc:88
zypp::repo::RepoInfoBase::filepath
Pathname filepath() const
File where this repo was read from.
Definition: RepoInfoBase.cc:134
zypp::repo::RepoInfoBase
Base class implementing common features of RepoInfo and ServiceInfo.
Definition: RepoInfoBase.h:39
TriBool.h
zypp::repo::RepoInfoBase::RepoInfoBase
RepoInfoBase()
Definition: RepoInfoBase.cc:77
zypp::repo::RepoInfoBase::autorefresh
bool autorefresh() const
If true, the repostory must be refreshed before creating resolvables from it.
Definition: RepoInfoBase.cc:108
zypp::repo::RepoInfoBase::Impl::_enabled
TriBool _enabled
Definition: RepoInfoBase.cc:47
zypp::repo::RepoInfoBase::Impl::Impl
Impl(const std::string &alias_r)
Definition: RepoInfoBase.cc:41
zypp::filesystem::Pathname
Pathname.
Definition: Pathname.h:44
RepoVariablesReplacedString
base::ValueTransform< std::string, repo::RepoVariablesStringReplacer > RepoVariablesReplacedString
Definition: RepoVariables.h:127
zypp::repo::RepoInfoBase::Impl::setAlias
void setAlias(const std::string &alias_r)
Definition: RepoInfoBase.cc:56
str
String related utilities and Regular expression matching.
zypp::repo::RepoInfoBase::setAlias
void setAlias(const std::string &alias)
set the repository alias
Definition: RepoInfoBase.cc:94
zypp::TriBool
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
Definition: String.h:30
zypp::repo::RepoInfoBase::~RepoInfoBase
virtual ~RepoInfoBase()
Definition: RepoInfoBase.cc:85
zypp::repo::RepoInfoBase::dumpOn
virtual std::ostream & dumpOn(std::ostream &str) const
Write a human-readable representation of this RepoInfoBase object into the str stream.
Definition: RepoInfoBase.cc:138