libzypp: zypp-media/ng/lazymediahandle.h Source File

libzypp 17.36.6

lazymediahandle.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9#ifndef ZYPP_MEDIA_NG_LAZYMEDIAHANDLE_H
10#define ZYPP_MEDIA_NG_LAZYMEDIAHANDLE_H
11
12#include <zypp-media/ng/ProvideSpec>
13#include <optional>
14
15
16namespace zyppng
17{
18 template < class ProvideType >
19 class LazyMediaHandle {
20 public:
21 using MediaHandle = typename ProvideType::MediaHandle;
22 using ParentType = ProvideType;
23
24 friend ProvideType;
25
26 LazyMediaHandle( Ref<ProvideType> provider, std::vector<zypp::Url> urls, ProvideMediaSpec spec )
27 : _sharedData(
28 std::make_shared<Data>(
29 std::move(provider)
30 ,std::move(urls)
31 ,std::move(spec)
32 ))
33 { }
34
35 LazyMediaHandle(const LazyMediaHandle &) = default;
36 LazyMediaHandle(LazyMediaHandle &&) = default;
37 LazyMediaHandle &operator=(const LazyMediaHandle &) = default;
38 LazyMediaHandle &operator=(LazyMediaHandle &&) = default;
39
40 const Ref<ProvideType> &parent () const {
41 return _sharedData->_provider.lock();
42 }
43
48 const zypp::Url &baseUrl() const {
49 if ( !_sharedData->_mediaHandle ) {
50 static zypp::Url invalidHandle;
51 if ( _sharedData->_urls.empty() )
52 return invalidHandle;
53 return _sharedData->_urls.front();
54 } else {
55 return _sharedData->_mediaHandle->baseUrl();
56 }
57 }
58
59 const std::vector<zypp::Url> &urls() const {
60 return _sharedData->_urls;
61 }
62
63 std::optional<MediaHandle> handle () const {
64 return _sharedData->_mediaHandle;
65 }
66
67 const ProvideMediaSpec &spec() const {
68 return _sharedData->_spec;
69 }
70
71 const std::optional<zypp::Pathname> &localPath() const
72 {
73 static std::optional<zypp::Pathname> noHandle;
74 if ( !attached() )
75 return noHandle;
76 return _sharedData->_mediaHandle.localPath();
77 }
78
79 bool attached() const {
80 return _sharedData->_mediaHandle.has_value();
81 }
82
83 private:
84
85 struct Data {
86 Data(Ref<ProvideType> &&provider, std::vector<zypp::Url> &&urls,
87 ProvideMediaSpec &&spec)
88 : _provider(std::move(provider)), _urls(std::move(urls)),
89 _spec(std::move(spec)) {}
90
91 Data(const Data &) = delete;
92 Data(Data &&) = delete;
93 Data &operator=(const Data &) = delete;
94 Data &operator=(Data &&) = delete;
95
96 WeakRef<ProvideType> _provider;
97 std::vector<zypp::Url> _urls;
98 ProvideMediaSpec _spec;
99 std::optional<MediaHandle> _mediaHandle;
100 };
101 Ref<Data> _sharedData;
102 };
103}
104
105#endif // ZYPP_MEDIA_NG_LAZYMEDIAHANDLE_H
zypp::Url
Url manipulation class.
Definition Url.h:93
zyppng::LazyMediaHandle< Provide >::urls
const std::vector< zypp::Url > & urls() const
Definition lazymediahandle.h:59
zyppng::LazyMediaHandle< Provide >::ParentType
Provide ParentType
Definition lazymediahandle.h:22
zyppng::LazyMediaHandle::localPath
const std::optional< zypp::Pathname > & localPath() const
Definition lazymediahandle.h:71
zyppng::LazyMediaHandle::operator=
LazyMediaHandle & operator=(LazyMediaHandle &&)=default
zyppng::LazyMediaHandle< Provide >::_sharedData
Ref< Data > _sharedData
Definition lazymediahandle.h:101
zyppng::LazyMediaHandle< Provide >::spec
const ProvideMediaSpec & spec() const
Definition lazymediahandle.h:67
zyppng::LazyMediaHandle< Provide >::MediaHandle
typename Provide::MediaHandle MediaHandle
Definition lazymediahandle.h:21
zyppng::LazyMediaHandle< Provide >::ProvideType
friend ProvideType
Definition lazymediahandle.h:24
zyppng::LazyMediaHandle::operator=
LazyMediaHandle & operator=(const LazyMediaHandle &)=default
zyppng::LazyMediaHandle::baseUrl
const zypp::Url & baseUrl() const
Definition lazymediahandle.h:48
zyppng::LazyMediaHandle::LazyMediaHandle
LazyMediaHandle(const LazyMediaHandle &)=default
zyppng::LazyMediaHandle::parent
const Ref< ProvideType > & parent() const
Definition lazymediahandle.h:40
zyppng::LazyMediaHandle::LazyMediaHandle
LazyMediaHandle(LazyMediaHandle &&)=default
zyppng::LazyMediaHandle::attached
bool attached() const
Definition lazymediahandle.h:79
zyppng::LazyMediaHandle::handle
std::optional< MediaHandle > handle() const
Definition lazymediahandle.h:63
zyppng::LazyMediaHandle::LazyMediaHandle
LazyMediaHandle(Ref< ProvideType > provider, std::vector< zypp::Url > urls, ProvideMediaSpec spec)
Definition lazymediahandle.h:26
zyppng::ProvideMediaSpec
Definition providespec.h:29
std
Definition Arch.h:364
zyppng
Definition MediaCurl2.h:22
zyppng::Ref
std::shared_ptr< T > Ref
Definition zyppglobal.h:110
zyppng::WeakRef
std::weak_ptr< T > WeakRef
Definition zyppglobal.h:113
zyppng::LazyMediaHandle::Data::Data
Data(Data &&)=delete
zyppng::LazyMediaHandle::Data::_mediaHandle
std::optional< MediaHandle > _mediaHandle
Definition lazymediahandle.h:99
zyppng::LazyMediaHandle::Data::operator=
Data & operator=(Data &&)=delete
zyppng::LazyMediaHandle::Data::operator=
Data & operator=(const Data &)=delete
zyppng::LazyMediaHandle::Data::Data
Data(const Data &)=delete
zyppng::LazyMediaHandle::Data::_spec
ProvideMediaSpec _spec
Definition lazymediahandle.h:98
zyppng::LazyMediaHandle::Data::_provider
WeakRef< ProvideType > _provider
Definition lazymediahandle.h:96
zyppng::LazyMediaHandle::Data::_urls
std::vector< zypp::Url > _urls
Definition lazymediahandle.h:97
zyppng::LazyMediaHandle::Data::Data
Data(Ref< ProvideType > &&provider, std::vector< zypp::Url > &&urls, ProvideMediaSpec &&spec)
Definition lazymediahandle.h:86