Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / zypp / Patch.h
index 253d5c0..b3d240b 100644 (file)
@@ -45,13 +45,14 @@ namespace zypp
       typedef sat::SolvableSet Contents;
 
       enum Category {
-        CAT_OTHER,
-        CAT_YAST,
-        CAT_SECURITY,
-        CAT_RECOMMENDED,
-        CAT_OPTIONAL,
-        CAT_DOCUMENT
+        CAT_OTHER      = 1,    //!< unknown value specified
+        CAT_YAST       = 1<<1, //!<
+        CAT_SECURITY   = 1<<2, //!<
+        CAT_RECOMMENDED        = 1<<3, //!<
+        CAT_OPTIONAL   = 1<<4, //!<
+        CAT_DOCUMENT   = 1<<5  //!<
       };
+      ZYPP_DECLARE_FLAGS(Categories, Category);
 
       /**
        * Flags defining if and why this
@@ -72,12 +73,12 @@ namespace zypp
        * \ref asSring( const Patch::SeverityFlag & ).
        */
       enum SeverityFlag {
-       SEV_NONE        = 0,    //!< no value specified
        SEV_OTHER       = 1,    //!< unknown value specified
-       SEV_LOW         = 1<<1, //!< Low
-       SEV_MODERATE    = 1<<2, //!< Moderate
-       SEV_IMPORTANT   = 1<<3, //!< Important
-       SEV_CRITICAL    = 1<<4  //!< Critical
+       SEV_NONE        = 1<<1, //!< no value specified
+       SEV_LOW         = 1<<2, //!< Low
+       SEV_MODERATE    = 1<<3, //!< Moderate
+       SEV_IMPORTANT   = 1<<4, //!< Important
+       SEV_CRITICAL    = 1<<5  //!< Critical
       };
       ZYPP_DECLARE_FLAGS(SeverityFlags, SeverityFlag);
 
@@ -89,16 +90,42 @@ namespace zypp
       Date timestamp() const
       { return buildtime(); }
 
+      /** \name Patch Category */
+      //@{
       /**
        * Patch category (recommended, security,...)
        */
       std::string category() const;
 
-      /** Patch category as enum of wellknown categories.
+      /** This patch's category as enum of wellknown categories.
        * Unknown values are mapped to \ref CAT_OTHER.
        */
       Category categoryEnum() const;
 
+      /** Whether this patch's category matches \a category_r */
+      bool isCategory( const std::string & category_r ) const;
+      /** \overload taking OR'ed \ref Categories */
+      bool isCategory( Categories category_r ) const;
+#ifndef SWIG // Swig treats it as syntax error
+      /** \overload taking container of category strings
+       * 2nd template arg just to prevent instantiation for Category
+       */
+      template <class TContainer, typename = typename TContainer::value_type>
+      bool isCategory( const TContainer & categories_r ) const
+      {
+       for ( const std::string & el : categories_r )
+       { if ( isCategory( el ) ) return true; }
+       return false;
+      }
+#endif
+      /** Patch category as enum of wellknown categories.
+       * Unknown values are mapped to \ref CAT_OTHER.
+       */
+      static Category categoryEnum( const std::string & category_r );
+      //@}
+
+      /** \name Patch Severity */
+      //@{
       /**
        * Severity string as specified in metadata.
        * For use in computaions see \ref severityFlag.
@@ -111,6 +138,28 @@ namespace zypp
        */
       SeverityFlag severityFlag() const;
 
+      /** Whether this patch's severity matches \a severity_r */
+      bool isSeverity( const std::string & severity_r ) const;
+      /** \overload taking OR'ed \ref SeverityFlags */
+      bool isSeverity( SeverityFlags severity_r ) const;
+#ifndef SWIG // Swig treats it as syntax error
+      /** \overload taking container of severity strings
+       * 2nd template arg just to prevent instantiation for SeverityFlag
+       */
+      template <class TContainer, typename = typename TContainer::value_type>
+      bool isSeverity( const TContainer & severities_r ) const
+      {
+       for ( const std::string & el : severities_r )
+       { if ( isSeverity( el ) ) return true; }
+       return false;
+      }
+#endif
+      /** Severity string mapped to an enum.
+       * Unknown string values are mapped to \ref SEV_OTHER
+       */
+      static SeverityFlag severityFlag( const std::string & category_r );
+      //@}
+
       /**
        * Does the system need to reboot to finish the update process?
        */
@@ -183,9 +232,16 @@ namespace zypp
       /** Dtor */
       virtual ~Patch();
   };
+  ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Patch::Categories);
   ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Patch::InteractiveFlags);
   ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Patch::SeverityFlags);
 
+  /** \relates Patch::Category string representation.*/
+  std::string asString( const Patch::Category & obj );
+
+  /** \relates Patch::InteractiveFlag string representation.*/
+  std::string asString( const Patch::InteractiveFlag & obj );
+
   /** \relates Patch::SeverityFlag string representation.*/
   std::string asString( const Patch::SeverityFlag & obj );