libzypp: zypp/CpeId.h Source File

libzypp 17.25.10

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>
20 #include <zypp/base/SetRelationMixin.h>
21
23 namespace zypp
24 {
31 class CpeId : public base::SetRelationMixin<CpeId>
32 {
33 public:
35 class Value;
36
37 public:
39 struct EAttributeDef {
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:
125 RWCOW_pointer<Impl> _pimpl;
126 };
127
128 SETRELATIONMIXIN_DEFINE_COMPARE_BETWEEN( CpeId, const char * );
129 SETRELATIONMIXIN_DEFINE_COMPARE_BETWEEN( CpeId, const std::string & );
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
158 class CpeId::Value : public base::SetRelationMixin<Value>
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 {};
176 static constexpr UriFormatType uriFormat = UriFormatType();
177
178 public:
180 Value()
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 {
209 ANY,
210 NA,
211 wildcardfree,
212 wildcarded,
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:
292 RWCOW_pointer<std::string> _value;
293 };
294
295 SETRELATIONMIXIN_DEFINE_COMPARE_BETWEEN( CpeId::Value, const char * );
296 SETRELATIONMIXIN_DEFINE_COMPARE_BETWEEN( CpeId::Value, const std::string & );
297
299 std::ostream & operator<<( std::ostream & str, const CpeId::Value & obj );
300
301 } // namespace zypp
303 #endif // ZYPP_CPEID_H
EnumClass.h
Flags.h
PtrTypes.h
SetRelationMixin.h
zypp::CpeId::Impl
CpeId implementation.
Definition: CpeId.cc:85
zypp::CpeId::Value
WFN attribute value.
Definition: CpeId.h:159
zypp::CpeId::Value::isWildcardfree
bool isWildcardfree() const
An attribute value string without wildcards ([*?] at begin and/or end)
Definition: CpeId.h:248
zypp::CpeId::Value::ANY
static const Value ANY
Logical value matching ANY value.
Definition: CpeId.h:162
zypp::CpeId::Value::isNA
bool isNA() const
Whether value is NA.
Definition: CpeId.h:230
zypp::CpeId::Value::NA
static const Value NA
Logical value indicating “not applicable/not used".
Definition: CpeId.h:165
zypp::CpeId::Value::isWildcarded
bool isWildcarded() const
An attribute value string with wildcards ([*?] at begin and/or end)
Definition: CpeId.h:252
zypp::CpeId::Value::_value
RWCOW_pointer< std::string > _value
Definition: CpeId.h:292
zypp::CpeId::Value::isLogical
bool isLogical() const
Whether it's a logical value (ANY|NA).
Definition: CpeId.h:234
zypp::CpeId::Value::Type
base::EnumClass< ETypeDef > Type
'enum class Type'
Definition: CpeId.h:215
zypp::CpeId::Value::isANY
bool isANY() const
Whether value is ANY.
Definition: CpeId.h:226
zypp::CpeId::Value::Value
Value(const char *value_r)
Ctor from char* (WFN format; nullptr or "*" represent ANY; "" represents NA)
Definition: CpeId.h:191
zypp::CpeId::Value::uriFormat
static constexpr UriFormatType uriFormat
Indicator argument for ctor arg in URI format.
Definition: CpeId.h:176
zypp::CpeId::Value::isLogical
bool isLogical(Type type_r) const
Definition: CpeId.h:237
zypp::CpeId::Value::fsFormat
static constexpr FsFormatType fsFormat
Indicator argument for ctor arg in FS format.
Definition: CpeId.h:171
zypp::CpeId::Value::isString
bool isString() const
Whether it's an attribute value string (not logical value).
Definition: CpeId.h:241
zypp::CpeId::Value::asString
std::string asString() const
Default string representation [asWfn].
Definition: CpeId.h:257
zypp::CpeId::Value::type
Type type() const
Return the Type of this Value.
Definition: CpeId.h:218
zypp::CpeId::Value::asFs
std::string asFs() const
String representation as in Formated-String (ANY:"*", NA:"-")
Definition: CpeId.cc:665
zypp::CpeId::Value::setRelationMixinCompare
SetCompare setRelationMixinCompare(const Value &trg) const
CPE name matching hook for SetRelationMixin.
Definition: CpeId.cc:980
zypp::CpeId::Value::Value
Value()
Default ctor: ANY.
Definition: CpeId.h:180
zypp::CpeId::Value::containsWildcard
bool containsWildcard() const
HAs unquoted [*?] at begin and/or end of value.
Definition: CpeId.cc:913
zypp::CpeId::Value::isString
bool isString(Type type_r) const
Definition: CpeId.h:244
zypp::CpeId::Value::asUri
std::string asUri() const
String representation as in URI (ANY:"", NA:"-")
Definition: CpeId.cc:711
zypp::CpeId::Value::asWfn
std::string asWfn() const
String representation as in Well-Formed-Name (ANY:"*", NA:"").
Definition: CpeId.cc:652
zypp::CpeId
Common Platform Enumearation (2.3) See http://cpe.mitre.org/ for more information on the Common Platf...
Definition: CpeId.h:32
zypp::CpeId::asUri
std::string asUri() const
String representation as URI (in/out).
Definition: CpeId.cc:407
zypp::CpeId::Attribute
base::EnumClass< EAttributeDef > Attribute
'enum class Attribute'
Definition: CpeId.h:56
zypp::CpeId::~CpeId
~CpeId()
Dtor.
Definition: CpeId.cc:398
zypp::CpeId::operator<<
std::ostream & operator<<(std::ostream &str, const CpeId &obj)
Stream output.
Definition: CpeId.h:132
zypp::CpeId::noThrow
static constexpr NoThrowType noThrow
Indicator argument for non-trowing ctor.
Definition: CpeId.h:62
zypp::CpeId::asWfn
std::string asWfn() const
String representation as Well-Formed-Name (internal format, out only).
Definition: CpeId.cc:410
zypp::CpeId::asFs
std::string asFs() const
String representation as Formated-String (in/out).
Definition: CpeId.cc:404
zypp::CpeId::asString
std::string asString() const
Default string representation [asFS].
Definition: CpeId.h:93
zypp::CpeId::CpeId
CpeId(const char *cpe_r)
Ctor parsing from string representation (empty or URI or FS)
Definition: CpeId.h:76
zypp::CpeId::setRelationMixinCompare
SetCompare setRelationMixinCompare(const CpeId &trg) const
CPE name matching hook for SetRelationMixin.
Definition: CpeId.cc:413
zypp::CpeId::CpeId
CpeId()
Default ctor: ANY-Cpeid, all attribute values are ANY.
Definition: CpeId.cc:376
zypp::CpeId::_pimpl
RWCOW_pointer< Impl > _pimpl
Implementation class.
Definition: CpeId.h:123
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: Arch.h:348
str
String related utilities and Regular expression matching.
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
zypp::asString
std::string asString(const DefaultIntegral< Tp, TInitial > &obj)
Definition: DefaultIntegral.h:98
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:147
zypp::SETRELATIONMIXIN_DEFINE_COMPARE_BETWEEN
SETRELATIONMIXIN_DEFINE_COMPARE_BETWEEN(CpeId, const char *)
zypp::CpeId::EAttributeDef
WFN attributes (use like 'enum class Attribute')
Definition: CpeId.h:39
zypp::CpeId::EAttributeDef::asString
static const std::string & asString(Enum val_r)
string representantion
Definition: CpeId.cc:420
zypp::CpeId::EAttributeDef::Enum
Enum
Definition: CpeId.h:40
zypp::CpeId::EAttributeDef::version
@ version
Definition: CpeId.h:44
zypp::CpeId::EAttributeDef::sw_edition
@ sw_edition
Definition: CpeId.h:48
zypp::CpeId::EAttributeDef::target_sw
@ target_sw
Definition: CpeId.h:49
zypp::CpeId::EAttributeDef::vendor
@ vendor
Definition: CpeId.h:42
zypp::CpeId::EAttributeDef::update
@ update
Definition: CpeId.h:45
zypp::CpeId::EAttributeDef::other
@ other
Definition: CpeId.h:51
zypp::CpeId::EAttributeDef::product
@ product
Definition: CpeId.h:43
zypp::CpeId::EAttributeDef::edition
@ edition
Definition: CpeId.h:46
zypp::CpeId::EAttributeDef::part
@ part
Definition: CpeId.h:41
zypp::CpeId::EAttributeDef::target_hw
@ target_hw
Definition: CpeId.h:50
zypp::CpeId::EAttributeDef::language
@ language
Definition: CpeId.h:47
zypp::CpeId::EAttributeDef::numAttributes
static constexpr unsigned numAttributes
number of attributes
Definition: CpeId.h:53
zypp::CpeId::NoThrowType
Indicator type for non-trowing ctor.
Definition: CpeId.h:60
zypp::CpeId::NoThrowType::lastMalformed
static std::string lastMalformed
Definition: CpeId.h:60
zypp::CpeId::Value::ETypeDef
Classification of Value types mostly for match (use like 'enum class Type')
Definition: CpeId.h:207
zypp::CpeId::Value::ETypeDef::Enum
Enum
Definition: CpeId.h:208
zypp::CpeId::Value::ETypeDef::wildcardfree
@ wildcardfree
Definition: CpeId.h:211
zypp::CpeId::Value::ETypeDef::wildcarded
@ wildcarded
Definition: CpeId.h:212
zypp::CpeId::Value::ETypeDef::ANY
@ ANY
Definition: CpeId.h:209
zypp::CpeId::Value::ETypeDef::NA
@ NA
Definition: CpeId.h:210
zypp::CpeId::Value::FsFormatType
Indicator type for ctor arg in FS format.
Definition: CpeId.h:169
zypp::CpeId::Value::UriFormatType
Indicator type for ctor arg in URI format.
Definition: CpeId.h:174
zypp::RWCOW_pointer
RW_pointer supporting 'copy on write' functionality.
Definition: PtrTypes.h:459