libzypp 17.38.15

MirroredOrigin.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_REPO_ORIGIN_INCLUDED_H
13#define ZYPP_REPO_ORIGIN_INCLUDED_H
14
15#include <zypp-core/Url.h>
16#include <zypp-core/base/PtrTypes.h>
17
18#include <boost/iterator/iterator_facade.hpp>
19
20#include <any>
21#include <string>
22#include <vector>
23
24 namespace zypp {
25
41 class ZYPP_API OriginEndpoint {
42 public:
43
44// The header is exposed and in old SPs yast builds with c++11.
45#ifdef __cpp_lib_any
46 using SettingsMap = std::unordered_map<std::string, std::any>;
47 OriginEndpoint(zypp::Url url, SettingsMap settings );
48#endif
49
50 OriginEndpoint();
51 OriginEndpoint( zypp::Url url ); // combine with other constructor once we remove the C++11 constraint
52
53 ~OriginEndpoint() = default;
54 OriginEndpoint(const OriginEndpoint &) = default;
55 OriginEndpoint(OriginEndpoint &&) = default;
56 OriginEndpoint &operator=(const OriginEndpoint &) = default;
57 OriginEndpoint &operator=(OriginEndpoint &&) = default;
58
59 const zypp::Url &url() const;
60 zypp::Url &url();
61 void setUrl(const zypp::Url &newUrl);
62
63 bool hasConfig( const std::string &key ) const;
64
65// The header is exposed and in old SPs yast builds with c++11.
66#ifdef __cpp_lib_any
67 void setConfig( const std::string &key, std::any value );
68 const std::any &getConfig( const std::string &key ) const;
69 std::any &getConfig( const std::string &key );
70 void eraseConfigValue( const std::string &key );
71
72 const SettingsMap &config() const;
73 SettingsMap &config();
74
75 template <typename T>
76 std::enable_if_t<!std::is_same_v<T, std::any>> setConfig ( const std::string &key, T &&value ) {
77 setConfig( key, std::make_any<T>( std::forward<T>(value) ) );
78 }
79
80 template <typename T>
81 std::enable_if_t<!std::is_same_v<T, std::any>, const T&> getConfig( const std::string &key ) const {
82 const std::any &c = getConfig(key);
83 // use the pointer overloads to get to a const reference of the containing type
84 // we need to throw std::bad_any_cast manually here
85 const T* ref = std::any_cast<const T>(&c);
86 if ( !ref )
87 throw std::bad_any_cast();
88
89 return *ref;
90 }
91
92 template <typename T>
93 std::enable_if_t<!std::is_same_v<T, std::any>, T&> getConfig( const std::string &key ) {
94 std::any &c = getConfig(key);
95 // use the pointer overloads to get to a const reference of the containing type
96 // we need to throw std::bad_any_cast manually here
97 T* ref = std::any_cast<T>(&c);
98 if ( !ref )
99 throw std::bad_any_cast();
100
101 return *ref;
102 }
103#endif
104
108 std::string scheme() const;
109
113 bool schemeIsDownloading() const;
114
115 bool isValid() const;
116
117 private:
118 struct Private;
119 RWCOW_pointer<Private> _pimpl;
120 };
121
122
123 ZYPP_API std::ostream & operator<<( std::ostream & str, const OriginEndpoint & url );
124
128 ZYPP_API bool operator<( const OriginEndpoint &lhs, const OriginEndpoint &rhs );
129
133 ZYPP_API bool operator==( const OriginEndpoint &lhs, const OriginEndpoint &rhs );
134
138 ZYPP_API bool operator!=( const OriginEndpoint &lhs, const OriginEndpoint &rhs );
139
170 class ZYPP_API MirroredOrigin {
171
172 public:
173 template <class Parent, class Value>
174 class iter : public boost::iterator_facade<
175 iter<Parent, Value>
176 , Value
177 , boost::forward_traversal_tag
178 >
179 {
180 public:
181 iter(){}
182
183 explicit iter( Parent *list, uint idx )
184 : _list(list)
185 , _idx(idx)
186 {}
187
188 private:
189 friend class boost::iterator_core_access;
190
191 bool equal(iter<Parent, Value> const& other) const
192 {
193 return ((this->_list == other._list) && (this->_idx == other._idx));
194 }
195
196 void increment()
197 {
198 if ( !_list )
199 return;
200 // allow _idx max to be endpointCount for end() iterator
201 if ( (_idx+1) > _list->endpointCount() )
202 return;
203 _idx++;
204 }
205
206 Value& dereference() const
207 {
208 if ( !_list || _idx >= _list->endpointCount() )
209 throw std::out_of_range( "OriginEndpoint index out of range." );
210 return _list->operator [](_idx);
211 }
212
213 Parent *_list = nullptr;
214 uint _idx = 0;
215 };
216 using endpoint_iterator = iter<MirroredOrigin, OriginEndpoint> ;
217 using endpoint_const_iterator = iter<MirroredOrigin const, OriginEndpoint const>;
218
219 MirroredOrigin( );
220 MirroredOrigin( OriginEndpoint authority, std::vector<OriginEndpoint> mirrors = {} );
221
225 void setAuthority ( OriginEndpoint newAuthority );
226
230 const std::vector<OriginEndpoint> &authorities() const;
231
235 const OriginEndpoint &authority() const;
236
240 const std::vector<OriginEndpoint> &mirrors() const;
241
245 bool isValid() const;
246
247 bool addAuthority( OriginEndpoint newAuthority );
248 bool addMirror( OriginEndpoint newMirror );
249 void setMirrors( std::vector<OriginEndpoint> mirrors );
250 void clearMirrors();
251
255 std::string scheme() const;
256
260 bool schemeIsDownloading() const;
261
265 endpoint_iterator begin() {
266 return endpoint_iterator( this, 0 );
267 }
268
272 endpoint_iterator end() {
273 return endpoint_iterator( this, endpointCount() );
274 }
275
276 endpoint_const_iterator begin() const {
277 return endpoint_const_iterator( this, 0 );
278 }
279
280 endpoint_const_iterator end() const {
281 return endpoint_const_iterator( this, endpointCount() );
282 }
283
287 uint endpointCount() const;
288
292 uint authorityCount() const;
293
298 const OriginEndpoint &operator[]( uint index ) const { return at(index); }
299 OriginEndpoint &operator[]( uint index ) { return at(index); }
300
304 const OriginEndpoint &at( uint index ) const;
305 OriginEndpoint &at( uint index );
306
307 private:
308 struct Private;
309 RWCOW_pointer<Private> _pimpl;
310 };
311
312 ZYPP_API std::ostream & operator<<( std::ostream & str, const MirroredOrigin & origin );
313
314
336 class ZYPP_API MirroredOriginSet {
337
338 public:
339 using iterator = std::vector<MirroredOrigin>::iterator;
340 using const_iterator = std::vector<MirroredOrigin>::const_iterator;
341 using size_type = size_t;
342 using value_type = MirroredOrigin;
343
344 MirroredOriginSet( );
345
351 MirroredOriginSet( std::vector<OriginEndpoint> eps);
352
353 MirroredOriginSet( std::vector<zypp::Url> urls );
354
355 MirroredOriginSet( std::list<zypp::Url> urls );
356
363 const MirroredOrigin &at( size_type idx ) const;
364
371 MirroredOrigin &at( size_type idx );
372
380 const_iterator findByUrl( const zypp::Url &url ) const;
381
389 iterator findByUrl( const zypp::Url &url );
390
397 template<typename InputIterator>
398 void addEndpoints( InputIterator first, InputIterator last ) {
399 std::for_each(first,last,[this]( OriginEndpoint ep ) { addEndpoint(std::move(ep));} );
400 }
401
409 void addAuthorityEndpoint( OriginEndpoint endpoint );
410
418 void addEndpoint( OriginEndpoint endpoint );
419
424 void addEndpoints(std::vector<OriginEndpoint> endpoints );
425
427 iterator begin();
428
430 iterator end();
431
433 const_iterator begin() const;
434
436 const_iterator end() const;
437
442 size_type size() const;
443
444 bool empty() const;
445
446 void clear();
447
452 bool hasFallbackUrls() const;
453
454 private:
455 struct Private;
456 RWCOW_pointer<Private> _pimpl;
457 };
458
459 ZYPP_API std::ostream & operator<<( std::ostream & str, const MirroredOriginSet & origin );
460
461}
462#endif
PtrTypes.h
Url.h
zypp::MirroredOriginSet
A smart container that manages a collection of MirroredOrigin objects, automatically grouping endpoin...
Definition MirroredOrigin.h:336
zypp::MirroredOriginSet::MirroredOriginSet
MirroredOriginSet(std::list< zypp::Url > urls)
zypp::MirroredOriginSet::findByUrl
const_iterator findByUrl(const zypp::Url &url) const
Finds the MirroredOrigin that contains a specific URL.
Definition MirroredOrigin.cc:413
zypp::MirroredOriginSet::at
const MirroredOrigin & at(size_type idx) const
Accesses the MirroredOrigin at a specific index.
Definition MirroredOrigin.cc:384
zypp::MirroredOriginSet::value_type
MirroredOrigin value_type
Definition MirroredOrigin.h:342
zypp::MirroredOriginSet::MirroredOriginSet
MirroredOriginSet()
Definition MirroredOrigin.cc:359
zypp::MirroredOriginSet::const_iterator
std::vector< MirroredOrigin >::const_iterator const_iterator
Definition MirroredOrigin.h:340
zypp::MirroredOriginSet::_pimpl
RWCOW_pointer< Private > _pimpl
Definition MirroredOrigin.h:456
zypp::MirroredOriginSet::iterator
std::vector< MirroredOrigin >::iterator iterator
Definition MirroredOrigin.h:339
zypp::MirroredOriginSet::size_type
size_t size_type
Definition MirroredOrigin.h:341
zypp::MirroredOriginSet::addEndpoints
void addEndpoints(InputIterator first, InputIterator last)
A convenience method to add multiple endpoints from a range.
Definition MirroredOrigin.h:398
zypp::MirroredOriginSet::addEndpoint
void addEndpoint(OriginEndpoint endpoint)
Adds a single endpoint, routing it to the correct MirroredOrigin.
Definition MirroredOrigin.cc:440
zypp::MirroredOrigin::iter
Definition MirroredOrigin.h:179
zypp::MirroredOrigin::iter::equal
bool equal(iter< Parent, Value > const &other) const
Definition MirroredOrigin.h:191
zypp::MirroredOrigin::iter::iter
iter(Parent *list, uint idx)
Definition MirroredOrigin.h:183
zypp::MirroredOrigin::iter< MirroredOrigin, OriginEndpoint >::_idx
uint _idx
Definition MirroredOrigin.h:214
zypp::MirroredOrigin::iter::iter
iter()
Definition MirroredOrigin.h:181
zypp::MirroredOrigin::iter::dereference
Value & dereference() const
Definition MirroredOrigin.h:206
zypp::MirroredOrigin::iter< MirroredOrigin, OriginEndpoint >::_list
MirroredOrigin * _list
Definition MirroredOrigin.h:213
zypp::MirroredOrigin::iter::increment
void increment()
Definition MirroredOrigin.h:196
zypp::MirroredOrigin
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
Definition MirroredOrigin.h:170
zypp::MirroredOrigin::operator[]
OriginEndpoint & operator[](uint index)
Definition MirroredOrigin.h:299
zypp::MirroredOrigin::mirrors
const std::vector< OriginEndpoint > & mirrors() const
Definition MirroredOrigin.cc:214
zypp::MirroredOrigin::end
endpoint_const_iterator end() const
Definition MirroredOrigin.h:280
zypp::MirroredOrigin::at
const OriginEndpoint & at(uint index) const
Definition MirroredOrigin.cc:321
zypp::MirroredOrigin::end
endpoint_iterator end()
Definition MirroredOrigin.h:272
zypp::MirroredOrigin::_pimpl
RWCOW_pointer< Private > _pimpl
Definition MirroredOrigin.h:309
zypp::MirroredOrigin::endpoint_const_iterator
iter< MirroredOrigin const, OriginEndpoint const > endpoint_const_iterator
Definition MirroredOrigin.h:217
zypp::MirroredOrigin::MirroredOrigin
MirroredOrigin()
Definition MirroredOrigin.cc:155
zypp::MirroredOrigin::begin
endpoint_iterator begin()
Definition MirroredOrigin.h:265
zypp::MirroredOrigin::endpoint_iterator
iter< MirroredOrigin, OriginEndpoint > endpoint_iterator
Definition MirroredOrigin.h:216
zypp::MirroredOrigin::begin
endpoint_const_iterator begin() const
Definition MirroredOrigin.h:276
zypp::MirroredOrigin::authority
const OriginEndpoint & authority() const
Definition MirroredOrigin.cc:205
zypp::MirroredOrigin::operator[]
const OriginEndpoint & operator[](uint index) const
Definition MirroredOrigin.h:298
zypp::MirroredOrigin::endpointCount
uint endpointCount() const
Definition MirroredOrigin.cc:311
zypp::OriginEndpoint
Represents a single, configurable network endpoint, combining a URL with specific access settings.
Definition MirroredOrigin.h:41
zypp::OriginEndpoint::OriginEndpoint
OriginEndpoint(OriginEndpoint &&)=default
zypp::OriginEndpoint::OriginEndpoint
OriginEndpoint(const OriginEndpoint &)=default
zypp::OriginEndpoint::operator=
OriginEndpoint & operator=(OriginEndpoint &&)=default
zypp::OriginEndpoint::OriginEndpoint
OriginEndpoint()
Definition MirroredOrigin.cc:36
zypp::OriginEndpoint::_pimpl
RWCOW_pointer< Private > _pimpl
Definition MirroredOrigin.h:119
zypp::OriginEndpoint::url
const zypp::Url & url() const
Definition MirroredOrigin.cc:53
zypp::OriginEndpoint::~OriginEndpoint
~OriginEndpoint()=default
zypp::OriginEndpoint::setUrl
void setUrl(const zypp::Url &newUrl)
Definition MirroredOrigin.cc:58
zypp::OriginEndpoint::hasConfig
bool hasConfig(const std::string &key) const
Definition MirroredOrigin.cc:63
zypp::OriginEndpoint::operator=
OriginEndpoint & operator=(const OriginEndpoint &)=default
zypp::Url
Url manipulation class.
Definition Url.h:93
std::enable_if_t
typename enable_if< B, T >::type enable_if_t
Definition TypeTraits.h:45
str
String related utilities and Regular expression matching.
zypp::url
Url details namespace.
Definition UrlBase.cc:58
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::operator<
bool operator<(const Capability &lhs, const Capability &rhs)
relates: Capability Arbitrary order.
Definition Capability.h:317
zypp::operator!=
bool operator!=(const Capability &lhs, const Capability &rhs)
relates: Capability
Definition Capability.h:313
zypp::operator==
bool operator==(const Capability &lhs, const Capability &rhs)
relates: Capability
Definition Capability.h:309
zypp::ZYPP_API
const Arch Arch_empty ZYPP_API
relates: Arch This is an empty Arch represented by an empty string.
Definition Arch.h:173
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const Capabilities &obj)
relates: Capabilities Stream output
Definition Capabilities.cc:65
zypp::RWCOW_pointer
RW_pointer supporting 'copy on write' functionality.
Definition PtrTypes.h:469