libzypp: zypp/repo/RepoInfoBase.cc Source File

libzypp 17.36.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>
15#include <zypp/repo/RepoVariables.h>
16
17#include <zypp/repo/RepoInfoBase.h>
18#include <zypp/TriBool.h>
19#include <zypp/Pathname.h>
20
21using std::endl;
22
24namespace zypp
25{
27 namespace repo
28 {
29
34 struct RepoInfoBase::Impl
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:
47 TriBool _enabled;
48 TriBool _autorefresh;
49 std::string _alias;
50 std::string _escaped_alias;
51 RepoVariablesReplacedString _name;
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 };
69
70
72 //
73 // CLASS NAME : RepoInfoBase
74 //
76
77 RepoInfoBase::RepoInfoBase()
78 : _pimpl( new Impl() )
79 {}
80
81 RepoInfoBase::RepoInfoBase(const std::string & alias)
82 : _pimpl( new Impl(alias) )
83 {}
84
85 RepoInfoBase::~RepoInfoBase()
86 {}
87
88 void RepoInfoBase::setEnabled( bool enabled )
89 { _pimpl->_enabled = enabled; }
90
91 void RepoInfoBase::setAutorefresh( bool autorefresh )
92 { _pimpl->_autorefresh = 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())
104 bool RepoInfoBase::enabled() const
105 { return indeterminate(_pimpl->_enabled) ? true : (bool) _pimpl->_enabled; }
106
107 // false by default (if not set by setAutorefresh())
108 bool RepoInfoBase::autorefresh() const
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();
121 return repo::RepoVariablesStringReplacer()( rawName() );
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
RepoInfoBase.h
RepoVariables.h
RepoVariablesReplacedString
base::ValueTransform< std::string, repo::RepoVariablesStringReplacer > RepoVariablesReplacedString
Helper managing repo variables replaced strings.
Definition RepoVariables.h:127
ZConfig.h
bool
zypp::ZConfig::instance
static ZConfig & instance()
Singleton ctor.
Definition ZConfig.cc:940
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:47
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
zypp::repo::RepoInfoBase::label
std::string label() const
Label for use in messages for the user interface.
Definition RepoInfoBase.cc:127
zypp::repo::RepoInfoBase::setAutorefresh
void setAutorefresh(bool autorefresh)
enable or disable autorefresh
Definition RepoInfoBase.cc:91
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::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::setFilepath
void setFilepath(const Pathname &filename)
set the path to the .repo file
Definition RepoInfoBase.cc:100
zypp::repo::RepoInfoBase::setAlias
void setAlias(const std::string &alias)
set the repository alias
Definition RepoInfoBase.cc:94
zypp::repo::RepoInfoBase::RepoInfoBase
RepoInfoBase()
Definition RepoInfoBase.cc:77
zypp::repo::RepoInfoBase::filepath
Pathname filepath() const
File where this repo was read from.
Definition RepoInfoBase.cc:134
zypp::repo::RepoInfoBase::setName
void setName(const std::string &name)
set the repository name
Definition RepoInfoBase.cc:97
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::name
std::string name() const
Repository name.
Definition RepoInfoBase.cc:117
zypp::repo::RepoInfoBase::rawName
std::string rawName() const
The raw metadata name (no default, no variables replaced).
Definition RepoInfoBase.cc:124
zypp::repo::RepoInfoBase::~RepoInfoBase
virtual ~RepoInfoBase()
Definition RepoInfoBase.cc:85
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::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::setEnabled
void setEnabled(bool enabled)
enable or disable the repository
Definition RepoInfoBase.cc:88
zypp::repo::RepoInfoBase::_pimpl
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition RepoInfoBase.h:168
zypp::repo::RepoInfoBase::alias
std::string alias() const
unique identifier for this source.
Definition RepoInfoBase.cc:111
str
String related utilities and Regular expression matching.
zypp::repo
Definition DeltaCandidates.cc:30
zypp::repo::operator<<
std::ostream & operator<<(std::ostream &str, const DeltaCandidates &obj)
Definition DeltaCandidates.cc:108
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:331
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
zypp::TriBool
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
Definition String.h:30
zypp::repo::RepoInfoBase::Impl
RepoInfoBase data.
Definition RepoInfoBase.cc:35
zypp::repo::RepoInfoBase::Impl::setAlias
void setAlias(const std::string &alias_r)
Definition RepoInfoBase.cc:56
zypp::repo::RepoInfoBase::Impl::Impl
Impl()
Definition RepoInfoBase.cc:36
zypp::repo::RepoInfoBase::Impl::Impl
Impl(const std::string &alias_r)
Definition RepoInfoBase.cc:41
zypp::repo::RepoInfoBase::Impl::rwcowClone
friend Impl * rwcowClone(const Impl *rhs)
zypp::repo::RepoInfoBase::Impl::_enabled
TriBool _enabled
Definition RepoInfoBase.cc:47
zypp::repo::RepoInfoBase::Impl::_alias
std::string _alias
Definition RepoInfoBase.cc:49
zypp::repo::RepoInfoBase::Impl::_autorefresh
TriBool _autorefresh
Definition RepoInfoBase.cc:48
zypp::repo::RepoInfoBase::Impl::_name
RepoVariablesReplacedString _name
Definition RepoInfoBase.cc:51
zypp::repo::RepoInfoBase::Impl::_filepath
Pathname _filepath
Definition RepoInfoBase.cc:52
zypp::repo::RepoInfoBase::Impl::clone
Impl * clone() const
clone for RWCOW_pointer
Definition RepoInfoBase.cc:66
zypp::repo::RepoInfoBase::Impl::_escaped_alias
std::string _escaped_alias
Definition RepoInfoBase.cc:50
zypp::repo::RepoVariablesStringReplacer
Functor replacing repository variables.
Definition RepoVariables.h:106
Pathname.h
TriBool.h