libzypp  17.35.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/Globals.h>
18 #include <zypp/base/PtrTypes.h>
19 #include <zypp/base/Flags.h>
20 #include <zypp/base/EnumClass.h>
22 
24 namespace 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:
127  };
128 
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:
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 {
211  NA,
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(); }
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(); }
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
std::string asString(const Patch::Category &obj)
Definition: Patch.cc:122
Value()
Default ctor: ANY.
Definition: CpeId.h:181
RWCOW_pointer< Impl > _pimpl
Implementation class.
Definition: CpeId.h:124
Indicator type for ctor arg in FS format.
Definition: CpeId.h:170
std::ostream & operator<<(std::ostream &str, const CpeId &obj)
Definition: CpeId.h:133
Indicator type for non-trowing ctor.
Definition: CpeId.h:61
WFN attributes (use like &#39;enum class Attribute&#39;)
Definition: CpeId.h:40
CpeId(const char *cpe_r)
Ctor parsing from string representation (empty or URI or FS)
Definition: CpeId.h:77
std::string asFs() const
String representation as in Formated-String (ANY:"*", NA:"-")
Definition: CpeId.cc:664
std::string asUri() const
String representation as in URI (ANY:"", NA:"-")
Definition: CpeId.cc:710
static const Value NA
Logical value indicating “not applicable/not used".
Definition: CpeId.h:166
bool isString(Type type_r) const
Definition: CpeId.h:245
RWCOW_pointer< std::string > _value
Definition: CpeId.h:293
Type type() const
Return the Type of this Value.
Definition: CpeId.h:219
String related utilities and Regular expression matching.
bool isLogical() const
Whether it&#39;s a logical value (ANY|NA).
Definition: CpeId.h:235
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition: SerialNumber.cc:52
Definition: Arch.h:363
Value(const char *value_r)
Ctor from char* (WFN format; nullptr or "*" represent ANY; "" represents NA)
Definition: CpeId.h:192
Common Platform Enumearation (2.3) See http://cpe.mitre.org/ for more information on the Common Platf...
Definition: CpeId.h:32
base::EnumClass< EAttributeDef > Attribute
&#39;enum class Attribute&#39;
Definition: CpeId.h:57
bool isANY() const
Whether value is ANY.
Definition: CpeId.h:227
static std::string lastMalformed
Definition: CpeId.h:61
bool isNA() const
Whether value is NA.
Definition: CpeId.h:231
static const Value ANY
Logical value matching ANY value.
Definition: CpeId.h:163
std::string asString(TInt val, char zero='0', char one='1')
For printing bits.
Definition: Bit.h:57
bool isLogical(Type type_r) const
Definition: CpeId.h:238
bool isString() const
Whether it&#39;s an attribute value string (not logical value).
Definition: CpeId.h:242
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition: ResTraits.h:93
Indicator type for ctor arg in URI format.
Definition: CpeId.h:175
Classification of Value types mostly for match (use like &#39;enum class Type&#39;)
Definition: CpeId.h:208
std::string asString() const
Default string representation [asWfn].
Definition: CpeId.h:258
std::string asString() const
Default string representation [asFS].
Definition: CpeId.h:94
WFN attribute value.
Definition: CpeId.h:159
static constexpr FsFormatType fsFormat
Indicator argument for ctor arg in FS format.
Definition: CpeId.h:172
SetCompare compare(const Derived &trg) const
Compare sets.
bool containsWildcard() const
HAs unquoted [*?] at begin and/or end of value.
Definition: CpeId.cc:912
bool isWildcardfree() const
An attribute value string without wildcards ([*?] at begin and/or end)
Definition: CpeId.h:249
std::string asWfn() const
String representation as in Well-Formed-Name (ANY:"*", NA:"").
Definition: CpeId.cc:651
base::EnumClass< ETypeDef > Type
&#39;enum class Type&#39;
Definition: CpeId.h:216
SETRELATIONMIXIN_DEFINE_COMPARE_BETWEEN(CpeId, const char *)
SetCompare setRelationMixinCompare(const Value &trg) const
CPE name matching hook for SetRelationMixin.
Definition: CpeId.cc:979
Provide set relation methods based on Derived::setRelationMixinCompare A class using this mixin must ...
CpeId implementation.
Definition: CpeId.cc:84
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
bool isWildcarded() const
An attribute value string with wildcards ([*?] at begin and/or end)
Definition: CpeId.h:253
static constexpr UriFormatType uriFormat
Indicator argument for ctor arg in URI format.
Definition: CpeId.h:177