libzypp 17.38.6
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>
17
18#include <boost/iterator/iterator_facade.hpp>
19
20#include <any>
21#include <string>
22#include <vector>
23
24namespace zypp {
25
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
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;
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;
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
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:
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
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 };
218
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
266 return endpoint_iterator( this, 0 );
267 }
268
273 return endpoint_iterator( this, endpointCount() );
274 }
275
277 return endpoint_const_iterator( this, 0 );
278 }
279
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;
310 };
311
312 ZYPP_API std::ostream & operator<<( std::ostream & str, const MirroredOrigin & origin );
313
314
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;
343
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
372
380 const_iterator findByUrl( const zypp::Url &url ) const;
381
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;
457 };
458
459 ZYPP_API std::ostream & operator<<( std::ostream & str, const MirroredOriginSet & origin );
460
461}
462#endif
A smart container that manages a collection of MirroredOrigin objects, automatically grouping endpoin...
MirroredOriginSet(std::list< zypp::Url > urls)
const_iterator findByUrl(const zypp::Url &url) const
Finds the MirroredOrigin that contains a specific URL.
const MirroredOrigin & at(size_type idx) const
Accesses the MirroredOrigin at a specific index.
std::vector< MirroredOrigin >::const_iterator const_iterator
RWCOW_pointer< Private > _pimpl
std::vector< MirroredOrigin >::iterator iterator
void addEndpoints(InputIterator first, InputIterator last)
A convenience method to add multiple endpoints from a range.
void addEndpoint(OriginEndpoint endpoint)
Adds a single endpoint, routing it to the correct MirroredOrigin.
bool equal(iter< Parent, Value > const &other) const
iter(Parent *list, uint idx)
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
OriginEndpoint & operator[](uint index)
const std::vector< OriginEndpoint > & mirrors() const
endpoint_const_iterator end() const
const OriginEndpoint & at(uint index) const
endpoint_iterator end()
RWCOW_pointer< Private > _pimpl
iter< MirroredOrigin const, OriginEndpoint const > endpoint_const_iterator
endpoint_iterator begin()
iter< MirroredOrigin, OriginEndpoint > endpoint_iterator
endpoint_const_iterator begin() const
const OriginEndpoint & authority() const
const OriginEndpoint & operator[](uint index) const
Represents a single, configurable network endpoint, combining a URL with specific access settings.
OriginEndpoint(OriginEndpoint &&)=default
OriginEndpoint(const OriginEndpoint &)=default
OriginEndpoint & operator=(OriginEndpoint &&)=default
RWCOW_pointer< Private > _pimpl
const zypp::Url & url() const
~OriginEndpoint()=default
void setUrl(const zypp::Url &newUrl)
bool hasConfig(const std::string &key) const
OriginEndpoint & operator=(const OriginEndpoint &)=default
Url manipulation class.
Definition Url.h:93
typename enable_if< B, T >::type enable_if_t
Definition TypeTraits.h:45
String related utilities and Regular expression matching.
Url details namespace.
Definition UrlBase.cc:58
Easy-to use interface to the ZYPP dependency resolver.
bool operator<(const Capability &lhs, const Capability &rhs)
relates: Capability Arbitrary order.
Definition Capability.h:317
bool operator!=(const Capability &lhs, const Capability &rhs)
relates: Capability
Definition Capability.h:313
bool operator==(const Capability &lhs, const Capability &rhs)
relates: Capability
Definition Capability.h:309
const Arch Arch_empty ZYPP_API
relates: Arch This is an empty Arch represented by an empty string.
Definition Arch.h:173
std::ostream & operator<<(std::ostream &str, const Capabilities &obj)
relates: Capabilities Stream output
RW_pointer supporting 'copy on write' functionality.
Definition PtrTypes.h:469