libzypp 17.37.17
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/Globals.h>
18#include <zypp/base/PtrTypes.h>
19#include <zypp/base/Flags.h>
20#include <zypp/base/EnumClass.h>
22
24namespace zypp
25{
33 {
34 public:
36 class Value;
37
38 public:
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:
127 };
128
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
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 {};
178
179 public:
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:
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:
294 };
295
298
300 std::ostream & operator<<( std::ostream & str, const CpeId::Value & obj );
301
302} // namespace zypp
304#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:160
bool isWildcardfree() const
An attribute value string without wildcards ([*?
Definition CpeId.h:249
static const Value ANY
Logical value matching ANY value.
Definition CpeId.h:163
bool isNA() const
Whether value is NA.
Definition CpeId.h:231
static const Value NA
Logical value indicating “not applicable/not used".
Definition CpeId.h:166
bool isWildcarded() const
An attribute value string with wildcards ([*?
Definition CpeId.h:253
RWCOW_pointer< std::string > _value
Definition CpeId.h:293
bool isLogical() const
Whether it's a logical value (ANY|NA).
Definition CpeId.h:235
bool isANY() const
Whether value is ANY.
Definition CpeId.h:227
Value(const char *value_r)
Ctor from char* (WFN format; nullptr or "*" represent ANY; "" represents NA)
Definition CpeId.h:192
static constexpr UriFormatType uriFormat
Indicator argument for ctor arg in URI format.
Definition CpeId.h:177
bool isLogical(Type type_r) const
Definition CpeId.h:238
static constexpr FsFormatType fsFormat
Indicator argument for ctor arg in FS format.
Definition CpeId.h:172
bool isString() const
Whether it's an attribute value string (not logical value).
Definition CpeId.h:242
std::string asString() const
Default string representation [asWfn].
Definition CpeId.h:258
base::EnumClass< ETypeDef > Type
'enum class Type'
Definition CpeId.h:216
Type type() const
Return the Type of this Value.
Definition CpeId.h:219
std::string asFs() const
String representation as in Formated-String (ANY:"*", NA:"-")
Definition CpeId.cc:664
SetCompare setRelationMixinCompare(const Value &trg) const
CPE name matching hook for SetRelationMixin.
Definition CpeId.cc:979
Value()
Default ctor: ANY.
Definition CpeId.h:181
bool containsWildcard() const
HAs unquoted [*?
Definition CpeId.cc:912
bool isString(Type type_r) const
Definition CpeId.h:245
std::string asUri() const
String representation as in URI (ANY:"", NA:"-")
Definition CpeId.cc:710
std::string asWfn() const
String representation as in Well-Formed-Name (ANY:"*", NA:"").
Definition CpeId.cc:651
Common Platform Enumearation (2.3) See http://cpe.mitre.org/ for more information on the Common Platf...
Definition CpeId.h:33
std::ostream & operator<<(std::ostream &str, const CpeId &obj)
Stream output.
Definition CpeId.h:133
static constexpr NoThrowType noThrow
Indicator argument for non-trowing ctor.
Definition CpeId.h:63
base::EnumClass< EAttributeDef > Attribute
'enum class Attribute'
Definition CpeId.h:57
std::string asFs() const
String representation as Formated-String (in/out).
Definition CpeId.cc:403
std::string asString() const
Default string representation [asFS].
Definition CpeId.h:94
CpeId(const char *cpe_r)
Ctor parsing from string representation (empty or URI or FS)
Definition CpeId.h:77
SetCompare setRelationMixinCompare(const CpeId &trg) const
CPE name matching hook for SetRelationMixin.
Definition CpeId.cc:412
CpeId()
Default ctor: ANY-Cpeid, all attribute values are ANY.
Definition CpeId.cc:375
RWCOW_pointer< Impl > _pimpl
Implementation class.
Definition CpeId.h:126
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:364
String related utilities and Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247
WFN attributes (use like 'enum class Attribute')
Definition CpeId.h:40
static const std::string & asString(Enum val_r)
string representantion
Definition CpeId.cc:419
static constexpr unsigned numAttributes
number of attributes
Definition CpeId.h:54
Indicator type for non-trowing ctor.
Definition CpeId.h:61
static std::string lastMalformed
Definition CpeId.h:61
Classification of Value types mostly for match (use like 'enum class Type')
Definition CpeId.h:208
Indicator type for ctor arg in FS format.
Definition CpeId.h:170
Indicator type for ctor arg in URI format.
Definition CpeId.h:175
RW_pointer supporting 'copy on write' functionality.
Definition PtrTypes.h:469