libzypp: zypp/base/ValueTransform.h Source File

libzypp 17.38.9

ValueTransform.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
11#ifndef ZYPP_BASE_VALUETRANSFORM_H
12#define ZYPP_BASE_VALUETRANSFORM_H
13
14#include <iosfwd>
15
16#include <zypp-core/base/Iterator.h>
17
19namespace zypp
20{
22 namespace base
23 {
34 template<class Tp, class TUnaryFunction>
35 struct ValueTransform
36 {
37 using RawType = Tp;
38 using Transformator = TUnaryFunction;
39#if __cplusplus < 201703L
40 using TransformedType = std::result_of_t<Transformator (RawType)>; // yast in 15.[23] uses c++11
41#else
42 using TransformedType = std::invoke_result_t<Transformator, RawType>;
43#endif
44
45 public:
46 ValueTransform()
47 {}
48
49 explicit ValueTransform( RawType raw_r )
50 : _raw( std::move(raw_r) )
51 {}
52
53 ValueTransform( RawType raw_r, Transformator transform_r )
54 : _raw( std::move(raw_r) ), _transform( std::move(transform_r) )
55 {}
56
57 public:
59 const RawType & raw() const
60 { return _raw; }
61
63 RawType & raw()
64 { return _raw; }
65
66 public:
68 TransformedType transformed() const
69 { return _transform( _raw ); }
70
72 TransformedType transformed( const RawType & raw_r ) const
73 { return _transform( raw_r ); }
74
76 const Transformator & transformator() const
77 { return _transform; }
78
79 private:
80 RawType _raw;
81 Transformator _transform;
82 };
83
94 template<class TContainer, class TUnaryFunction>
95 struct ContainerTransform
96 {
97 using Container = TContainer;
98 using Transformator = TUnaryFunction;
99 using size_type = typename Container::size_type;
100 using RawType = typename Container::value_type;
101#if __cplusplus < 201703L
102 using TransformedType = std::result_of_t<Transformator (RawType)>; // yast in 15.[23] uses c++11
103#else
104 using TransformedType = std::invoke_result_t<Transformator, RawType>;
105#endif
106 public:
107 ContainerTransform()
108 {}
109
110 explicit ContainerTransform( Container raw_r )
111 : _raw( std::move(raw_r) )
112 {}
113
114 ContainerTransform( Container raw_r, Transformator transform_r )
115 : _raw( std::move(raw_r) ), _transform( std::move(transform_r) )
116 {}
117
118 public:
119 bool empty() const
120 { return _raw.empty(); }
121
122 size_type size() const
123 { return _raw.size(); }
124
125 using RawConstIterator = typename Container::const_iterator;
126
127 RawConstIterator rawBegin() const
128 { return _raw.begin(); }
129
130 RawConstIterator rawEnd() const
131 { return _raw.end(); }
132
134 const Container & raw() const
135 { return _raw; }
136
138 Container & raw()
139 { return _raw; }
140
142 void clear()
143 { _raw.clear(); }
144
145 public:
146 using TransformedConstIterator = transform_iterator<Transformator, typename Container::const_iterator>;
147
148 TransformedConstIterator transformedBegin() const
149 { return make_transform_iterator( _raw.begin(), _transform ); }
150
151 TransformedConstIterator transformedEnd() const
152 { return make_transform_iterator( _raw.end(), _transform ); }
153
155 Container transformed() const
156 { return Container( transformedBegin(), transformedEnd() ); }
157
159 TransformedType transformed( const RawType & raw_r ) const
160 { return _transform( raw_r ); }
161
163 TransformedType transformed( const RawConstIterator & rawIter_r ) const
164 { return _transform( *rawIter_r ); }
165
167 const Transformator & transformator() const
168 { return _transform; }
169
170 private:
171 Container _raw;
172 Transformator _transform;
173 };
174
175 } // namespace base
177} // namespace zypp
179#endif // ZYPP_BASE_VALUETRANSFORM_H
Iterator.h
transform_iterator
An iterator over elements which are the result of applying some functional transformation to the elem...
std
Definition ansi.h:855
std::result_of_t
typename result_of< T >::type result_of_t
Definition TypeTraits.h:51
zypp::base
Definition Random.cc:7
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::base::ContainerTransform::transformed
TransformedType transformed(const RawConstIterator &rawIter_r) const
Return a transformed copy of a RawConstIterator raw value.
Definition ValueTransform.h:163
zypp::base::ContainerTransform::transformedBegin
TransformedConstIterator transformedBegin() const
Definition ValueTransform.h:148
zypp::base::ContainerTransform::ContainerTransform
ContainerTransform(Container raw_r)
Definition ValueTransform.h:110
zypp::base::ContainerTransform::transformed
Container transformed() const
Return copy with transformed variables (expensive).
Definition ValueTransform.h:155
zypp::base::ContainerTransform::raw
const Container & raw() const
Get the raw value.
Definition ValueTransform.h:134
zypp::base::ContainerTransform::empty
bool empty() const
Definition ValueTransform.h:119
zypp::base::ContainerTransform< std::list< std::string >, repo::RepoVariablesStringReplacer >::_raw
Container _raw
Definition ValueTransform.h:171
zypp::base::ContainerTransform::TransformedType
std::result_of_t< Transformator(RawType)> TransformedType
Definition ValueTransform.h:102
zypp::base::ContainerTransform::size_type
typename Container::size_type size_type
Definition ValueTransform.h:99
zypp::base::ContainerTransform::rawBegin
RawConstIterator rawBegin() const
Definition ValueTransform.h:127
zypp::base::ContainerTransform::Container
TContainer Container
Definition ValueTransform.h:97
zypp::base::ContainerTransform::ContainerTransform
ContainerTransform()
Definition ValueTransform.h:107
zypp::base::ContainerTransform::rawEnd
RawConstIterator rawEnd() const
Definition ValueTransform.h:130
zypp::base::ContainerTransform< std::list< std::string >, repo::RepoVariablesStringReplacer >::_transform
Transformator _transform
Definition ValueTransform.h:172
zypp::base::ContainerTransform::RawType
typename Container::value_type RawType
Definition ValueTransform.h:100
zypp::base::ContainerTransform::transformator
const Transformator & transformator() const
Return the transformator.
Definition ValueTransform.h:167
zypp::base::ContainerTransform::clear
void clear()
Clear the container.
Definition ValueTransform.h:142
zypp::base::ContainerTransform::size
size_type size() const
Definition ValueTransform.h:122
zypp::base::ContainerTransform::transformed
TransformedType transformed(const RawType &raw_r) const
Return a transformed copy of an arbitrary RawType.
Definition ValueTransform.h:159
zypp::base::ContainerTransform::Transformator
TUnaryFunction Transformator
Definition ValueTransform.h:98
zypp::base::ContainerTransform::RawConstIterator
typename Container::const_iterator RawConstIterator
Definition ValueTransform.h:125
zypp::base::ContainerTransform::TransformedConstIterator
transform_iterator< Transformator, typename Container::const_iterator > TransformedConstIterator
Definition ValueTransform.h:146
zypp::base::ContainerTransform::transformedEnd
TransformedConstIterator transformedEnd() const
Definition ValueTransform.h:151
zypp::base::ContainerTransform::raw
Container & raw()
Set the raw value.
Definition ValueTransform.h:138
zypp::base::ContainerTransform::ContainerTransform
ContainerTransform(Container raw_r, Transformator transform_r)
Definition ValueTransform.h:114
zypp::base::ValueTransform::ValueTransform
ValueTransform(RawType raw_r, Transformator transform_r)
Definition ValueTransform.h:53
zypp::base::ValueTransform::TransformedType
std::result_of_t< Transformator(RawType)> TransformedType
Definition ValueTransform.h:40
zypp::base::ValueTransform::Transformator
TUnaryFunction Transformator
Definition ValueTransform.h:38
zypp::base::ValueTransform::raw
const RawType & raw() const
Get the raw value.
Definition ValueTransform.h:59
zypp::base::ValueTransform::transformed
TransformedType transformed() const
Return a transformed copy of the raw value.
Definition ValueTransform.h:68
zypp::base::ValueTransform::raw
RawType & raw()
Set the raw value.
Definition ValueTransform.h:63
zypp::base::ValueTransform::transformator
const Transformator & transformator() const
Return the transformator.
Definition ValueTransform.h:76
zypp::base::ValueTransform::transformed
TransformedType transformed(const RawType &raw_r) const
Return a transformed copy of an arbitrary RawType.
Definition ValueTransform.h:72
zypp::base::ValueTransform< std::string, repo::RepoVariablesStringReplacer >::_raw
RawType _raw
Definition ValueTransform.h:80
zypp::base::ValueTransform< std::string, repo::RepoVariablesStringReplacer >::_transform
Transformator _transform
Definition ValueTransform.h:81
zypp::base::ValueTransform::RawType
Tp RawType
Definition ValueTransform.h:37
zypp::base::ValueTransform::ValueTransform
ValueTransform(RawType raw_r)
Definition ValueTransform.h:49
zypp::base::ValueTransform::ValueTransform
ValueTransform()
Definition ValueTransform.h:46