libzypp 17.37.17
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 OriginEndpoint &authority() const;
231
235 const std::vector<OriginEndpoint> &mirrors() const;
236
240 bool isValid() const;
241
242 bool addMirror( OriginEndpoint newMirror );
243 void setMirrors( std::vector<OriginEndpoint> mirrors );
244 void clearMirrors();
245
249 std::string scheme() const;
250
254 bool schemeIsDownloading() const;
255
260 return endpoint_iterator( this, 0 );
261 }
262
267 return endpoint_iterator( this, endpointCount() );
268 }
269
271 return endpoint_const_iterator( this, 0 );
272 }
273
275 return endpoint_const_iterator( this, endpointCount() );
276 }
277
281 uint endpointCount() const;
282
287 const OriginEndpoint &operator[]( uint index ) const { return at(index); }
288 OriginEndpoint &operator[]( uint index ) { return at(index); }
289
293 const OriginEndpoint &at( uint index ) const;
294 OriginEndpoint &at( uint index );
295
296 private:
297 struct Private;
299 };
300
301 ZYPP_API std::ostream & operator<<( std::ostream & str, const MirroredOrigin & origin );
302
303
326
327 public:
328 using iterator = std::vector<MirroredOrigin>::iterator;
329 using const_iterator = std::vector<MirroredOrigin>::const_iterator;
330 using size_type = size_t;
332
334
340 MirroredOriginSet( std::vector<OriginEndpoint> eps);
341
342 MirroredOriginSet( std::vector<zypp::Url> urls );
343
344 MirroredOriginSet( std::list<zypp::Url> urls );
345
352 const MirroredOrigin &at( size_type idx ) const;
353
361
369 const_iterator findByUrl( const zypp::Url &url ) const;
370
379
386 template<typename InputIterator>
387 void addEndpoints( InputIterator first, InputIterator last ) {
388 std::for_each(first,last,[this]( OriginEndpoint ep ) { addEndpoint(std::move(ep));} );
389 }
390
398 void addEndpoint( OriginEndpoint endpoint );
399
404 void addEndpoints(std::vector<OriginEndpoint> endpoints );
405
407 iterator begin();
408
410 iterator end();
411
413 const_iterator begin() const;
414
416 const_iterator end() const;
417
422 size_type size() const;
423
424 bool empty() const;
425
426 void clear();
427
432 bool hasFallbackUrls() const;
433
434 private:
435 struct Private;
437 };
438
439 ZYPP_API std::ostream & operator<<( std::ostream & str, const MirroredOriginSet & origin );
440
441}
442#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 StrMatcher &lhs, const StrMatcher &rhs)
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247
bool operator!=(const SetRelation::Enum &lhs, const SetCompare &rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
RW_pointer supporting 'copy on write' functionality.
Definition PtrTypes.h:469