libzypp 17.31.23
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/base/PtrTypes.h>
18#include <zypp/base/Flags.h>
19#include <zypp/base/EnumClass.h>
21
23namespace zypp
24{
31 class CpeId : public base::SetRelationMixin<CpeId>
32 {
33 public:
35 class Value;
36
37 public:
40 enum Enum {
41 part, //< attribute (2.2)
42 vendor, //< attribute (2.2)
43 product, //< attribute (2.2)
44 version, //< attribute (2.2)
45 update, //< attribute (2.2)
46 edition, //< attribute (2.2)
47 language, //< attribute (2.2)
48 sw_edition, //< extended attribute (2.3)
49 target_sw, //< extended attribute (2.3)
50 target_hw, //< extended attribute (2.3)
51 other //< extended attribute (2.3)
52 };
53 static constexpr unsigned numAttributes = other+1;
54 static const std::string & asString( Enum val_r );
55 };
56 typedef base::EnumClass<EAttributeDef> Attribute;
57
58 public:
60 struct NoThrowType { static std::string lastMalformed; };
62 static constexpr NoThrowType noThrow = NoThrowType();
63
64 public:
66 CpeId();
67
71 explicit CpeId( const std::string & cpe_r );
72
76 explicit CpeId( const char * cpe_r )
77 : CpeId( std::string( cpe_r ? cpe_r : "" ) )
78 {}
79
83 CpeId( const std::string & cpe_r, NoThrowType );
84
86 ~CpeId();
87
88 public:
90 explicit operator bool() const;
91
93 std::string asString() const
94 { return asFs(); }
95
101 std::string asFs() const;
102
108 std::string asUri() const;
109
115 std::string asWfn() const;
116
117 private:
118 friend SetCompare base::SetRelationMixin<CpeId>::compare( const CpeId & ) const;
120 SetCompare setRelationMixinCompare( const CpeId & trg ) const;
121
122 public:
123 class Impl;
124 private:
126 };
127
130
132 inline std::ostream & operator<<( std::ostream & str, const CpeId & obj )
133 { return str << obj.asString(); }
134
136 inline std::ostream & operator<<( std::ostream & str, const CpeId::Attribute & obj )
137 { return str << CpeId::Attribute::asString( obj.asEnum() ); }
138
139
159 {
160 public:
162 static const Value ANY;
163
165 static const Value NA;
166
167 public:
169 struct FsFormatType {};
171 static constexpr FsFormatType fsFormat = FsFormatType();
172
174 struct UriFormatType {};
177
178 public:
181 {}
182
186 explicit Value( const std::string & value_r );
187
191 explicit Value( const char * value_r )
192 : Value( std::string( value_r ? value_r : "*" ) )
193 {}
194
198 Value( const std::string & encoded_r, FsFormatType );
199
203 Value( const std::string & encoded_r, UriFormatType );
204
205 public:
207 struct ETypeDef {
208 enum Enum {
213 };
214 };
215 typedef base::EnumClass<ETypeDef> Type;
216
218 Type type() const
219 {
220 if ( !_value ) return Type::ANY;
221 if ( _value->empty() ) return Type::NA;
222 return( isWildcarded() ? Type::wildcarded : Type::wildcardfree );
223 }
224
226 bool isANY() const
227 { return !_value; }
228
230 bool isNA() const
231 { return _value && _value->empty(); }
232
234 bool isLogical() const
235 { return !_value || _value->empty(); }
237 bool isLogical( Type type_r ) const
238 { return( type_r == Type::ANY || type_r == Type::NA ); }
239
241 bool isString() const
242 { return _value && !_value->empty(); }
244 bool isString( Type type_r ) const
245 { return( type_r == Type::wildcardfree || type_r == Type::wildcarded ); }
246
248 bool isWildcardfree() const
249 { return isString() && ! containsWildcard(); }
250
252 bool isWildcarded() const
253 { return isString() && containsWildcard(); }
254
255 public:
257 std::string asString() const
258 { return asWfn(); }
259
265 std::string asWfn() const;
266
272 std::string asFs() const;
273
279 std::string asUri() const;
280
281 private:
282 friend SetCompare base::SetRelationMixin<Value>::compare( const Value & ) const;
284 SetCompare setRelationMixinCompare( const Value & trg ) const;
285
289 bool containsWildcard() const;
290
291 private:
293 };
294
297
299 std::ostream & operator<<( std::ostream & str, const CpeId::Value & obj );
300
301} // namespace zypp
303#endif // ZYPP_CPEID_H
#define SETRELATIONMIXIN_DEFINE_COMPARE_BETWEEN(DERIVED_TYPE, OTHER_TYPE)
Define compare between Derived and some other type (e.g.
CpeId implementation.
Definition: CpeId.cc:85
WFN attribute value.
Definition: CpeId.h:159
bool isWildcardfree() const
An attribute value string without wildcards ([*?] at begin and/or end)
Definition: CpeId.h:248
static const Value ANY
Logical value matching ANY value.
Definition: CpeId.h:162
bool isNA() const
Whether value is NA.
Definition: CpeId.h:230
static const Value NA
Logical value indicating “not applicable/not used".
Definition: CpeId.h:165
bool isWildcarded() const
An attribute value string with wildcards ([*?] at begin and/or end)
Definition: CpeId.h:252
RWCOW_pointer< std::string > _value
Definition: CpeId.h:292
bool isLogical() const
Whether it's a logical value (ANY|NA).
Definition: CpeId.h:234
base::EnumClass< ETypeDef > Type
'enum class Type'
Definition: CpeId.h:215
bool isANY() const
Whether value is ANY.
Definition: CpeId.h:226
Value(const char *value_r)
Ctor from char* (WFN format; nullptr or "*" represent ANY; "" represents NA)
Definition: CpeId.h:191
static constexpr UriFormatType uriFormat
Indicator argument for ctor arg in URI format.
Definition: CpeId.h:176
bool isLogical(Type type_r) const
Definition: CpeId.h:237
static constexpr FsFormatType fsFormat
Indicator argument for ctor arg in FS format.
Definition: CpeId.h:171
bool isString() const
Whether it's an attribute value string (not logical value).
Definition: CpeId.h:241
std::string asString() const
Default string representation [asWfn].
Definition: CpeId.h:257
Type type() const
Return the Type of this Value.
Definition: CpeId.h:218
std::string asFs() const
String representation as in Formated-String (ANY:"*", NA:"-")
Definition: CpeId.cc:665
SetCompare setRelationMixinCompare(const Value &trg) const
CPE name matching hook for SetRelationMixin.
Definition: CpeId.cc:980
Value()
Default ctor: ANY.
Definition: CpeId.h:180
bool containsWildcard() const
HAs unquoted [*?] at begin and/or end of value.
Definition: CpeId.cc:913
bool isString(Type type_r) const
Definition: CpeId.h:244
std::string asUri() const
String representation as in URI (ANY:"", NA:"-")
Definition: CpeId.cc:711
std::string asWfn() const
String representation as in Well-Formed-Name (ANY:"*", NA:"").
Definition: CpeId.cc:652
Common Platform Enumearation (2.3) See http://cpe.mitre.org/ for more information on the Common Platf...
Definition: CpeId.h:32
std::string asUri() const
String representation as URI (in/out).
Definition: CpeId.cc:407
base::EnumClass< EAttributeDef > Attribute
'enum class Attribute'
Definition: CpeId.h:56
~CpeId()
Dtor.
Definition: CpeId.cc:398
std::ostream & operator<<(std::ostream &str, const CpeId &obj)
Stream output.
Definition: CpeId.h:132
static constexpr NoThrowType noThrow
Indicator argument for non-trowing ctor.
Definition: CpeId.h:62
std::string asWfn() const
String representation as Well-Formed-Name (internal format, out only).
Definition: CpeId.cc:410
std::string asFs() const
String representation as Formated-String (in/out).
Definition: CpeId.cc:404
std::string asString() const
Default string representation [asFS].
Definition: CpeId.h:93
CpeId(const char *cpe_r)
Ctor parsing from string representation (empty or URI or FS)
Definition: CpeId.h:76
SetCompare setRelationMixinCompare(const CpeId &trg) const
CPE name matching hook for SetRelationMixin.
Definition: CpeId.cc:413
CpeId()
Default ctor: ANY-Cpeid, all attribute values are ANY.
Definition: CpeId.cc:376
RWCOW_pointer< Impl > _pimpl
Implementation class.
Definition: CpeId.h:125
Provide set relation methods based on Derived::setRelationMixinCompare A class using this mixin must ...
SetCompare compare(const Derived &trg) const
Compare sets.
Definition: Arch.h:361
String related utilities and Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition: SerialNumber.cc:52
WFN attributes (use like 'enum class Attribute')
Definition: CpeId.h:39
static constexpr unsigned numAttributes
number of attributes
Definition: CpeId.h:53
Indicator type for non-trowing ctor.
Definition: CpeId.h:60
static std::string lastMalformed
Definition: CpeId.h:60
Classification of Value types mostly for match (use like 'enum class Type')
Definition: CpeId.h:207
Indicator type for ctor arg in FS format.
Definition: CpeId.h:169
Indicator type for ctor arg in URI format.
Definition: CpeId.h:174
RW_pointer supporting 'copy on write' functionality.
Definition: PtrTypes.h:459