libzypp 17.37.0
MediaUrl.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9#ifndef ZYPP_MEDIA_MEDIAURL_INCLUDED
10#define ZYPP_MEDIA_MEDIAURL_INCLUDED
11
12#include <zypp-core/Url.h>
13#include <any>
14#include <string>
15#include <unordered_map>
16
17namespace zypp::media {
18
23 public:
24
25 using SettingsMap = std::unordered_map<std::string, std::any>;
26
28 std::unordered_map<std::string, std::any> settings = {});
29
30 ~MediaUrl() = default;
31 MediaUrl(const MediaUrl &) = default;
32 MediaUrl(MediaUrl &&) = default;
33 MediaUrl &operator=(const MediaUrl &) = default;
34 MediaUrl &operator=(MediaUrl &&) = default;
35
36 bool hasConfig( const std::string &key ) const;
37 void setConfig( const std::string &key, std::any value );
38 const std::any &getConfig( const std::string &key ) const;
39 const SettingsMap &config() const;
40
41 const zypp::Url &url() const;
42 void setUrl(const zypp::Url &newUrl);
43
44 template <typename T>
45 std::enable_if_t<!std::is_same_v<T, std::any>> setConfig ( const std::string &key, T &&value ) {
46 setConfig( key, std::make_any<T>( std::forward<T>(value) ) );
47 }
48
49 template <typename T>
50 std::enable_if_t<!std::is_same_v<T, std::any>, const T&> getConfig( const std::string &key ) const {
51 const std::any &c = getConfig(key);
52 // use the pointer overloads to get to a const reference of the containing type
53 // we need to throw std::out_of_range manually here
54 const T* ref = std::any_cast<const T>(&c);
55 if ( !ref )
56 throw std::out_of_range("Key was not found in settings map.");
57
58 return *ref;
59 }
60
61 private:
64 };
65
66 std::ostream & operator<<( std::ostream & str, const MediaUrl & url );
67
71 bool operator<( const MediaUrl &lhs, const MediaUrl &rhs );
72
76 bool operator==( const MediaUrl &lhs, const MediaUrl &rhs );
77
78
79 bool operator!=( const MediaUrl &lhs, const MediaUrl &rhs );
80
81}
82
83
84#endif
Url manipulation class.
Definition Url.h:93
MediaUrl & operator=(MediaUrl &&)=default
std::enable_if_t<!std::is_same_v< T, std::any > > setConfig(const std::string &key, T &&value)
Definition MediaUrl.h:45
const std::any & getConfig(const std::string &key) const
Definition MediaUrl.cc:30
std::unordered_map< std::string, std::any > SettingsMap
Definition MediaUrl.h:25
MediaUrl(MediaUrl &&)=default
const zypp::Url & url() const
Definition MediaUrl.cc:40
bool hasConfig(const std::string &key) const
Definition MediaUrl.cc:20
MediaUrl(const MediaUrl &)=default
void setConfig(const std::string &key, std::any value)
Definition MediaUrl.cc:25
SettingsMap _settings
Definition MediaUrl.h:63
MediaUrl(zypp::Url url, std::unordered_map< std::string, std::any > settings={})
Definition MediaUrl.cc:15
MediaUrl & operator=(const MediaUrl &)=default
std::enable_if_t<!std::is_same_v< T, std::any >, const T & > getConfig(const std::string &key) const
Definition MediaUrl.h:50
const SettingsMap & config() const
Definition MediaUrl.cc:35
void setUrl(const zypp::Url &newUrl)
Definition MediaUrl.cc:45
typename enable_if< B, T >::type enable_if_t
Definition TypeTraits.h:45
String related utilities and Regular expression matching.
std::ostream & operator<<(std::ostream &str, const MediaHandler &obj)
bool operator!=(const MediaUrl &lhs, const MediaUrl &rhs)
Definition MediaUrl.cc:65
bool operator==(const MediaUrl &lhs, const MediaUrl &rhs)
needed for find
Definition MediaUrl.cc:60
bool operator<(const MediaUrl &lhs, const MediaUrl &rhs)
needed for std::set
Definition MediaUrl.cc:55
Url details namespace.
Definition UrlBase.cc:58
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247