libzypp: zypp/CpeId.h Source File

libzypp 17.38.14

CpeId.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
11#ifndef ZYPP_CPEID_H
12#define ZYPP_CPEID_H
13
14#include <iosfwd>
15#include <string>
16
17#include <zypp-core/Globals.h>
18#include <zypp-core/base/PtrTypes.h>
19#include <zypp-core/base/Flags.h>
20#include <zypp-core/base/EnumClass.h>
21#include <zypp/base/SetRelationMixin.h>
22
24namespace zypp
25{
32 class ZYPP_API CpeId : public base::SetRelationMixin<CpeId>
33 {
34 public:
36 class Value;
37
38 public:
40 struct EAttributeDef {
41 enum Enum {
42 part, //< attribute (2.2)
43 vendor, //< attribute (2.2)
44 product, //< attribute (2.2)
45 version, //< attribute (2.2)
46 update, //< attribute (2.2)
47 edition, //< attribute (2.2)
48 language, //< attribute (2.2)
49 sw_edition, //< extended attribute (2.3)
50 target_sw, //< extended attribute (2.3)
51 target_hw, //< extended attribute (2.3)
52 other //< extended attribute (2.3)
53 };
54 static constexpr unsigned numAttributes = other+1;
55 static const std::string & asString( Enum val_r );
56 };
57 using Attribute = base::EnumClass<EAttributeDef>;
58
59 public:
61 struct NoThrowType { static std::string lastMalformed; };
63 static constexpr NoThrowType noThrow = NoThrowType();
64
65 public:
67 CpeId();
68
72 explicit CpeId( const std::string & cpe_r );
73
77 explicit CpeId( const char * cpe_r )
78 : CpeId( std::string( cpe_r ? cpe_r : "" ) )
79 {}
80
84 CpeId( const std::string & cpe_r, NoThrowType );
85
87 ~CpeId();
88
89 public:
91 explicit operator bool() const;
92
94 std::string asString() const
95 { return asFs(); }
96
102 std::string asFs() const;
103
109 std::string asUri() const;
110
116 std::string asWfn() const;
117
118 private:
119 friend SetCompare base::SetRelationMixin<CpeId>::compare( const CpeId & ) const;
121 SetCompare setRelationMixinCompare( const CpeId & trg ) const;
122
123 public:
124 class Impl;
125 private:
126 RWCOW_pointer<Impl> _pimpl;
127 };
128
129 SETRELATIONMIXIN_DEFINE_COMPARE_BETWEEN( CpeId, const char * );
130 SETRELATIONMIXIN_DEFINE_COMPARE_BETWEEN( CpeId, const std::string & );
131
133 inline std::ostream & operator<<( std::ostream & str, const CpeId & obj )
134 { return str << obj.asString(); }
135
137 inline std::ostream & operator<<( std::ostream & str, const CpeId::Attribute & obj )
138 { return str << CpeId::Attribute::asString( obj.asEnum() ); }
139
140
159 class CpeId::Value : public base::SetRelationMixin<Value>
160 {
161 public:
163 static const Value ANY;
164
166 static const Value NA;
167
168 public:
170 struct FsFormatType {};
172 static constexpr FsFormatType fsFormat = FsFormatType();
173
175 struct UriFormatType {};
177 static constexpr UriFormatType uriFormat = UriFormatType();
178
179 public:
181 Value()
182 {}
183
187 explicit Value( const std::string & value_r );
188
192 explicit Value( const char * value_r )
193 : Value( std::string( value_r ? value_r : "*" ) )
194 {}
195
199 Value( const std::string & encoded_r, FsFormatType );
200
204 Value( const std::string & encoded_r, UriFormatType );
205
206 public:
208 struct ETypeDef {
209 enum Enum {
210 ANY,
211 NA,
212 wildcardfree,
213 wildcarded,
214 };
215 };
216 using Type = base::EnumClass<ETypeDef>;
217
219 Type type() const
220 {
221 if ( !_value ) return Type::ANY;
222 if ( _value->empty() ) return Type::NA;
223 return( isWildcarded() ? Type::wildcarded : Type::wildcardfree );
224 }
225
227 bool isANY() const
228 { return !_value; }
229
231 bool isNA() const
232 { return _value && _value->empty(); }
233
235 bool isLogical() const
236 { return !_value || _value->empty(); }
237
238 bool isLogical( Type type_r ) const
239 { return( type_r == Type::ANY || type_r == Type::NA ); }
240
242 bool isString() const
243 { return _value && !_value->empty(); }
244
245 bool isString( Type type_r ) const
246 { return( type_r == Type::wildcardfree || type_r == Type::wildcarded ); }
247
249 bool isWildcardfree() const
250 { return isString() && ! containsWildcard(); }
251
253 bool isWildcarded() const
254 { return isString() && containsWildcard(); }
255
256 public:
258 std::string asString() const
259 { return asWfn(); }
260
266 std::string asWfn() const;
267
273 std::string asFs() const;
274
280 std::string asUri() const;
281
282 private:
283 friend SetCompare base::SetRelationMixin<Value>::compare( const Value & ) const;
285 SetCompare setRelationMixinCompare( const Value & trg ) const;
286
290 bool containsWildcard() const;
291
292 private:
293 RWCOW_pointer<std::string> _value;
294 };
295
296 SETRELATIONMIXIN_DEFINE_COMPARE_BETWEEN( CpeId::Value, const char * );
297 SETRELATIONMIXIN_DEFINE_COMPARE_BETWEEN( CpeId::Value, const std::string & );
298
300 std::ostream & operator<<( std::ostream & str, const CpeId::Value & obj );
301
302} // namespace zypp
304#endif // ZYPP_CPEID_H
EnumClass.h
Flags.h
Globals.h
Provides API related macros.
PtrTypes.h
SetRelationMixin.h
SETRELATIONMIXIN_DEFINE_COMPARE_BETWEEN
#define SETRELATIONMIXIN_DEFINE_COMPARE_BETWEEN(DERIVED_TYPE, OTHER_TYPE)
relates: SetRelationMixin Define compare between Derived and some other type (e.g.
Definition SetRelationMixin.h:212
bool
zypp::CpeId::Impl
CpeId implementation.
Definition CpeId.cc:85
zypp::CpeId::Value
WFN attribute value.
Definition CpeId.h:160
zypp::CpeId::Value::isWildcardfree
bool isWildcardfree() const
An attribute value string without wildcards ([*?
Definition CpeId.h:249
zypp::CpeId::Value::ANY
static const Value ANY
Logical value matching ANY value.
Definition CpeId.h:163
zypp::CpeId::Value::isNA
bool isNA() const
Whether value is NA.
Definition CpeId.h:231
zypp::CpeId::Value::NA
static const Value NA
Logical value indicating “not applicable/not used".
Definition CpeId.h:166
zypp::CpeId::Value::isWildcarded
bool isWildcarded() const
An attribute value string with wildcards ([*?
Definition CpeId.h:253
zypp::CpeId::Value::_value
RWCOW_pointer< std::string > _value
Definition CpeId.h:293
zypp::CpeId::Value::isLogical
bool isLogical() const
Whether it's a logical value (ANY|NA).
Definition CpeId.h:235
zypp::CpeId::Value::isANY
bool isANY() const
Whether value is ANY.
Definition CpeId.h:227
zypp::CpeId::Value::Value
Value(const char *value_r)
Ctor from char* (WFN format; nullptr or "*" represent ANY; "" represents NA).
Definition CpeId.h:192
zypp::CpeId::Value::uriFormat
static constexpr UriFormatType uriFormat
Indicator argument for ctor arg in URI format.
Definition CpeId.h:177
zypp::CpeId::Value::isLogical
bool isLogical(Type type_r) const
Definition CpeId.h:238
zypp::CpeId::Value::fsFormat
static constexpr FsFormatType fsFormat
Indicator argument for ctor arg in FS format.
Definition CpeId.h:172
zypp::CpeId::Value::isString
bool isString() const
Whether it's an attribute value string (not logical value).
Definition CpeId.h:242
zypp::CpeId::Value::asString
std::string asString() const
Default string representation [asWfn].
Definition CpeId.h:258
zypp::CpeId::Value::Type
base::EnumClass< ETypeDef > Type
'enum class Type'
Definition CpeId.h:216
zypp::CpeId::Value::type
Type type() const
Return the Type of this Value.
Definition CpeId.h:219
zypp::CpeId::Value::asFs
std::string asFs() const
String representation as in Formated-String (ANY:"*", NA:"-").
Definition CpeId.cc:664
zypp::CpeId::Value::setRelationMixinCompare
SetCompare setRelationMixinCompare(const Value &trg) const
CPE name matching hook for SetRelationMixin.
Definition CpeId.cc:979
zypp::CpeId::Value::Value
Value()
Default ctor: ANY.
Definition CpeId.h:181
zypp::CpeId::Value::containsWildcard
bool containsWildcard() const
HAs unquoted [*?
Definition CpeId.cc:912
zypp::CpeId::Value::isString
bool isString(Type type_r) const
Definition CpeId.h:245
zypp::CpeId::Value::asUri
std::string asUri() const
String representation as in URI (ANY:"", NA:"-").
Definition CpeId.cc:710
zypp::CpeId::Value::asWfn
std::string asWfn() const
String representation as in Well-Formed-Name (ANY:"*", NA:"").
Definition CpeId.cc:651
zypp::CpeId
Common Platform Enumearation (2.3) See http://cpe.mitre.org/ for more information on the Common Platf...
Definition CpeId.h:33
zypp::CpeId::noThrow
static constexpr NoThrowType noThrow
Indicator argument for non-trowing ctor.
Definition CpeId.h:63
zypp::CpeId::Attribute
base::EnumClass< EAttributeDef > Attribute
'enum class Attribute'
Definition CpeId.h:57
zypp::CpeId::asFs
std::string asFs() const
String representation as Formated-String (in/out).
Definition CpeId.cc:403
zypp::CpeId::asString
std::string asString() const
Default string representation [asFS].
Definition CpeId.h:94
zypp::CpeId::CpeId
CpeId(const char *cpe_r)
Ctor parsing from string representation (empty or URI or FS).
Definition CpeId.h:77
zypp::CpeId::setRelationMixinCompare
SetCompare setRelationMixinCompare(const CpeId &trg) const
CPE name matching hook for SetRelationMixin.
Definition CpeId.cc:412
zypp::CpeId::CpeId
CpeId()
Default ctor: ANY-Cpeid, all attribute values are ANY.
Definition CpeId.cc:375
zypp::CpeId::_pimpl
RWCOW_pointer< Impl > _pimpl
Implementation class.
Definition CpeId.h:126
zypp::base::SetRelationMixin
Provide set relation methods based on Derived::setRelationMixinCompare A class using this mixin must ...
Definition SetRelationMixin.h:145
zypp::base::SetRelationMixin::compare
SetCompare compare(const Derived &trg) const
Compare sets.
Definition SetRelationMixin.h:148
std
Definition ansi.h:855
str
String related utilities and Regular expression matching.
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::SetCompare
base::EnumClass< ESetCompareDef > SetCompare
relates: ESetCompareDef typedef 'enum class SetCompare'
Definition SetRelationMixin.h:40
zypp::ZYPP_API
const Arch Arch_empty ZYPP_API
relates: Arch This is an empty Arch represented by an empty string.
Definition Arch.h:173
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const Capabilities &obj)
relates: Capabilities Stream output
Definition Capabilities.cc:65
zypp::CpeId::EAttributeDef
WFN attributes (use like 'enum class Attribute').
Definition CpeId.h:40
zypp::CpeId::EAttributeDef::asString
static const std::string & asString(Enum val_r)
string representantion
Definition CpeId.cc:419
zypp::CpeId::EAttributeDef::Enum
Enum
Definition CpeId.h:41
zypp::CpeId::EAttributeDef::version
@ version
Definition CpeId.h:45
zypp::CpeId::EAttributeDef::sw_edition
@ sw_edition
Definition CpeId.h:49
zypp::CpeId::EAttributeDef::target_sw
@ target_sw
Definition CpeId.h:50
zypp::CpeId::EAttributeDef::vendor
@ vendor
Definition CpeId.h:43
zypp::CpeId::EAttributeDef::update
@ update
Definition CpeId.h:46
zypp::CpeId::EAttributeDef::other
@ other
Definition CpeId.h:52
zypp::CpeId::EAttributeDef::product
@ product
Definition CpeId.h:44
zypp::CpeId::EAttributeDef::edition
@ edition
Definition CpeId.h:47
zypp::CpeId::EAttributeDef::part
@ part
Definition CpeId.h:42
zypp::CpeId::EAttributeDef::target_hw
@ target_hw
Definition CpeId.h:51
zypp::CpeId::EAttributeDef::language
@ language
Definition CpeId.h:48
zypp::CpeId::EAttributeDef::numAttributes
static constexpr unsigned numAttributes
number of attributes
Definition CpeId.h:54
zypp::CpeId::NoThrowType
Indicator type for non-trowing ctor.
Definition CpeId.h:61
zypp::CpeId::NoThrowType::lastMalformed
static std::string lastMalformed
Definition CpeId.h:61
zypp::CpeId::Value::ETypeDef
Classification of Value types mostly for match (use like 'enum class Type').
Definition CpeId.h:208
zypp::CpeId::Value::ETypeDef::Enum
Enum
Definition CpeId.h:209
zypp::CpeId::Value::ETypeDef::wildcardfree
@ wildcardfree
Definition CpeId.h:212
zypp::CpeId::Value::ETypeDef::wildcarded
@ wildcarded
Definition CpeId.h:213
zypp::CpeId::Value::ETypeDef::ANY
@ ANY
Definition CpeId.h:210
zypp::CpeId::Value::ETypeDef::NA
@ NA
Definition CpeId.h:211
zypp::CpeId::Value::FsFormatType
Indicator type for ctor arg in FS format.
Definition CpeId.h:170
zypp::CpeId::Value::UriFormatType
Indicator type for ctor arg in URI format.
Definition CpeId.h:175
zypp::RWCOW_pointer
RW_pointer supporting 'copy on write' functionality.
Definition PtrTypes.h:469