libzypp 17.37.10

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 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
259 endpoint_iterator begin() {
260 return endpoint_iterator( this, 0 );
261 }
262
266 endpoint_iterator end() {
267 return endpoint_iterator( this, endpointCount() );
268 }
269
270 endpoint_const_iterator begin() const {
271 return endpoint_const_iterator( this, 0 );
272 }
273
274 endpoint_const_iterator end() const {
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;
298 RWCOW_pointer<Private> _pimpl;
299 };
300
301 ZYPP_API std::ostream & operator<<( std::ostream & str, const MirroredOrigin & origin );
302
303
325 class ZYPP_API MirroredOriginSet {
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;
331 using value_type = MirroredOrigin;
332
333 MirroredOriginSet( );
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
360 MirroredOrigin &at( size_type idx );
361
369 const_iterator findByUrl( const zypp::Url &url ) const;
370
378 iterator findByUrl( const zypp::Url &url );
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;
436 RWCOW_pointer<Private> _pimpl;
437 };
438
439 ZYPP_API std::ostream & operator<<( std::ostream & str, const MirroredOriginSet & origin );
440
441}
442#endif
zypp::MirroredOriginSet
A smart container that manages a collection of MirroredOrigin objects, automatically grouping endpoin...
Definition MirroredOrigin.h:325
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:331
zypp::MirroredOriginSet::at
const MirroredOrigin & at(size_type idx) const
Accesses the MirroredOrigin at a specific index.
Definition MirroredOrigin.cc:304
zypp::MirroredOriginSet::value_type
MirroredOrigin value_type
Definition MirroredOrigin.h:331
zypp::MirroredOriginSet::MirroredOriginSet
MirroredOriginSet()
Definition MirroredOrigin.cc:279
zypp::MirroredOriginSet::const_iterator
std::vector< MirroredOrigin >::const_iterator const_iterator
Definition MirroredOrigin.h:329
zypp::MirroredOriginSet::_pimpl
RWCOW_pointer< Private > _pimpl
Definition MirroredOrigin.h:436
zypp::MirroredOriginSet::iterator
std::vector< MirroredOrigin >::iterator iterator
Definition MirroredOrigin.h:328
zypp::MirroredOriginSet::size_type
size_t size_type
Definition MirroredOrigin.h:330
zypp::MirroredOriginSet::addEndpoints
void addEndpoints(InputIterator first, InputIterator last)
A convenience method to add multiple endpoints from a range.
Definition MirroredOrigin.h:387
zypp::MirroredOriginSet::addEndpoint
void addEndpoint(OriginEndpoint endpoint)
Adds a single endpoint, routing it to the correct MirroredOrigin.
Definition MirroredOrigin.cc:341
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:288
zypp::MirroredOrigin::mirrors
const std::vector< OriginEndpoint > & mirrors() const
Definition MirroredOrigin.cc:189
zypp::MirroredOrigin::end
endpoint_const_iterator end() const
Definition MirroredOrigin.h:274
zypp::MirroredOrigin::at
const OriginEndpoint & at(uint index) const
Definition MirroredOrigin.cc:241
zypp::MirroredOrigin::end
endpoint_iterator end()
Definition MirroredOrigin.h:266
zypp::MirroredOrigin::_pimpl
RWCOW_pointer< Private > _pimpl
Definition MirroredOrigin.h:298
zypp::MirroredOrigin::endpoint_const_iterator
iter< MirroredOrigin const, OriginEndpoint const > endpoint_const_iterator
Definition MirroredOrigin.h:217
zypp::MirroredOrigin::MirroredOrigin
MirroredOrigin()
Definition MirroredOrigin.cc:151
zypp::MirroredOrigin::begin
endpoint_iterator begin()
Definition MirroredOrigin.h:259
zypp::MirroredOrigin::endpoint_iterator
iter< MirroredOrigin, OriginEndpoint > endpoint_iterator
Definition MirroredOrigin.h:216
zypp::MirroredOrigin::begin
endpoint_const_iterator begin() const
Definition MirroredOrigin.h:270
zypp::MirroredOrigin::authority
const OriginEndpoint & authority() const
Definition MirroredOrigin.cc:184
zypp::MirroredOrigin::operator[]
const OriginEndpoint & operator[](uint index) const
Definition MirroredOrigin.h:287
zypp::MirroredOrigin::endpointCount
uint endpointCount() const
Definition MirroredOrigin.cc:235
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:34
zypp::OriginEndpoint::_pimpl
RWCOW_pointer< Private > _pimpl
Definition MirroredOrigin.h:119
zypp::OriginEndpoint::url
const zypp::Url & url() const
Definition MirroredOrigin.cc:51
zypp::OriginEndpoint::~OriginEndpoint
~OriginEndpoint()=default
zypp::OriginEndpoint::setUrl
void setUrl(const zypp::Url &newUrl)
Definition MirroredOrigin.cc:56
zypp::OriginEndpoint::hasConfig
bool hasConfig(const std::string &key) const
Definition MirroredOrigin.cc:61
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 Application.cc:20
zypp::operator<
bool operator<(const StrMatcher &lhs, const StrMatcher &rhs)
Definition StrMatcher.cc:340
zypp::operator==
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...
Definition SetRelationMixin.h:84
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition SerialNumber.cc:52
zypp::ZYPP_API
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247
zypp::operator!=
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...
Definition SetRelationMixin.h:109
zypp::RWCOW_pointer
RW_pointer supporting 'copy on write' functionality.
Definition PtrTypes.h:469
Url.h
PtrTypes.h