Imported Upstream version 17.10.1
[platform/upstream/libzypp.git] / zypp / TriBool.h
index 64488d1..f2c5cfe 100644 (file)
@@ -13,6 +13,7 @@
 #define ZYPP_TRIBOOL_H
 
 #include <iosfwd>
+#include <string>
 #include <boost/logic/tribool.hpp>
 
 ///////////////////////////////////////////////////////////////////
@@ -40,6 +41,20 @@ namespace zypp
   using   boost::logic::tribool;
   using   boost::logic::indeterminate;
 
+  inline std::string asString( const TriBool & val_r, const std::string & istr_r = std::string(),
+                                                     const std::string & tstr_r = std::string(),
+                                                     const std::string & fstr_r = std::string() )
+  {
+    std::string ret;
+    if (indeterminate(val_r))
+      ret = ( istr_r.empty() ? "indeterminate" : istr_r );
+    else if (val_r)
+      ret = ( tstr_r.empty() ? "true" : tstr_r );
+    else
+      ret = ( fstr_r.empty() ? "false" : fstr_r );
+    return ret;
+  }
+
   /////////////////////////////////////////////////////////////////
 } // namespace zypp
 ///////////////////////////////////////////////////////////////////
@@ -49,15 +64,11 @@ namespace boost
     {
       /** \relates TriBool stream output */
       inline std::ostream & operator<<(std::ostream & s, const tribool & obj)
-      {
-        if (indeterminate(obj))
-          s << "indeterminate";
-        else if (obj)
-          s << "true";
-        else
-          s << "false";
-        return s;
-      }
+      { return s << zypp::asString( obj ); }
+
+      /** \relates TriBool whether 2 tribool have the same state (this is NOT ==) */
+      inline bool sameTriboolState( tribool lhs, tribool rhs )
+      { return( ( indeterminate(lhs) && indeterminate(rhs) ) || ( bool )( lhs == rhs ) ); }
     }
 }
 #endif // ZYPP_TRIBOOL_H