libzypp  17.6.1
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 
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:
126  };
127 
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:
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 {
210  NA,
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
Value()
Default ctor: ANY.
Definition: CpeId.h:180
RWCOW_pointer< Impl > _pimpl
Implementation class.
Definition: CpeId.h:123
std::string asString(const DefaultIntegral< Tp, TInitial > &obj)
SetCompare setRelationMixinCompare(const CpeId &trg) const
CPE name matching hook for SetRelationMixin.
Definition: CpeId.cc:411
Indicator type for ctor arg in FS format.
Definition: CpeId.h:169
std::ostream & operator<<(std::ostream &str, const CpeId &obj)
Definition: CpeId.h:132
Indicator type for non-trowing ctor.
Definition: CpeId.h:60
WFN attributes (use like &#39;enum class Attribute&#39;)
Definition: CpeId.h:39
CpeId(const char *cpe_r)
Ctor parsing from string representation (empty or URI or FS)
Definition: CpeId.h:76
std::string asFs() const
String representation as in Formated-String (ANY:"*", NA:"-")
Definition: CpeId.cc:660
static constexpr unsigned numAttributes
number of attributes
Definition: CpeId.h:53
std::string asUri() const
String representation as in URI (ANY:"", NA:"-")
Definition: CpeId.cc:706
static constexpr FsFormatType fsFormat
Indicator argument for ctor arg in FS format.
Definition: CpeId.h:171
static const Value NA
Logical value indicating “not applicable/not used".
Definition: CpeId.h:165
bool isString(Type type_r) const
Definition: CpeId.h:244
RWCOW_pointer< std::string > _value
Definition: CpeId.h:292
Type type() const
Return the Type of this Value.
Definition: CpeId.h:218
String related utilities and Regular expression matching.
bool isLogical() const
Whether it&#39;s a logical value (ANY|NA).
Definition: CpeId.h:234
Definition: Arch.h:344
~CpeId()
Dtor.
Definition: CpeId.cc:396
Value(const char *value_r)
Ctor from char* (WFN format; nullptr or "*" represent ANY; "" represents NA)
Definition: CpeId.h:191
Common Platform Enumearation (2.3) See http://cpe.mitre.org/ for more information on the Common Platf...
Definition: CpeId.h:31
bool isANY() const
Whether value is ANY.
Definition: CpeId.h:226
static std::string lastMalformed
Definition: CpeId.h:60
bool isNA() const
Whether value is NA.
Definition: CpeId.h:230
CpeId()
Default ctor: ANY-Cpeid, all attribute values are ANY.
Definition: CpeId.cc:374
static const Value ANY
Logical value matching ANY value.
Definition: CpeId.h:162
bool isLogical(Type type_r) const
Definition: CpeId.h:237
bool isString() const
Whether it&#39;s an attribute value string (not logical value).
Definition: CpeId.h:241
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:147
base::EnumClass< ETypeDef > Type
&#39;enum class Type&#39;
Definition: CpeId.h:215
base::EnumClass< EAttributeDef > Attribute
&#39;enum class Attribute&#39;
Definition: CpeId.h:56
Indicator type for ctor arg in URI format.
Definition: CpeId.h:174
Classification of Value types mostly for match (use like &#39;enum class Type&#39;)
Definition: CpeId.h:207
std::string asString() const
Default string representation [asWfn].
Definition: CpeId.h:257
std::string asString() const
Default string representation [asFS].
Definition: CpeId.h:93
WFN attribute value.
Definition: CpeId.h:158
static constexpr NoThrowType noThrow
Indicator argument for non-trowing ctor.
Definition: CpeId.h:62
SetCompare compare(const Derived &trg) const
Compare sets.
bool containsWildcard() const
HAs unquoted [*?] at begin and/or end of value.
Definition: CpeId.cc:908
bool isWildcardfree() const
An attribute value string without wildcards ([*?] at begin and/or end)
Definition: CpeId.h:248
std::string asWfn() const
String representation as in Well-Formed-Name (ANY:"*", NA:"").
Definition: CpeId.cc:647
SETRELATIONMIXIN_DEFINE_COMPARE_BETWEEN(CpeId, const char *)
SetCompare setRelationMixinCompare(const Value &trg) const
CPE name matching hook for SetRelationMixin.
Definition: CpeId.cc:975
std::string asUri() const
String representation as URI (in/out).
Definition: CpeId.cc:405
Provide set relation methods based on Derived::setRelationMixinCompare A class using this mixin must ...
CpeId implementation.
Definition: CpeId.cc:82
static constexpr UriFormatType uriFormat
Indicator argument for ctor arg in URI format.
Definition: CpeId.h:176
std::string asWfn() const
String representation as Well-Formed-Name (internal format, out only).
Definition: CpeId.cc:408
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
bool isWildcarded() const
An attribute value string with wildcards ([*?] at begin and/or end)
Definition: CpeId.h:252
std::string asFs() const
String representation as Formated-String (in/out).
Definition: CpeId.cc:402
static const std::string & asString(Enum val_r)
string representantion
Definition: CpeId.cc:418