[SCM] exiv2 packaging branch, master, updated. debian/0.25-3.1-3734-gdcbc29a

Maximiliano Curia maxy at moszumanska.debian.org
Thu Jul 13 17:38:21 UTC 2017


Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/exiv2.git;a=commitdiff;h=c661381

The following commit has been merged in the master branch:
commit c6613812b3ab99bfb67090d942da4cef2c2ca368
Author: Andreas Huggel <ahuggel at gmx.net>
Date:   Mon Mar 12 16:44:43 2007 +0000

    Changed AnyError to inherit from std::exception, required a change of the signature of AnyError::what()
---
 src/error.cpp | 21 ++++++++++-----------
 src/error.hpp | 41 ++++++++++++++++++++++++++++-------------
 2 files changed, 38 insertions(+), 24 deletions(-)

diff --git a/src/error.cpp b/src/error.cpp
index 7c48a05..e22d8c8 100644
--- a/src/error.cpp
+++ b/src/error.cpp
@@ -94,34 +94,33 @@ namespace Exiv2 {
         return idx;
     }
 
-    std::string Error::what() const
+    void Error::setMsg()
     {
         int idx = errorIdx(code_);
-        std::string msg = std::string(_(errMsg_[idx].message_));
+        msg_ = std::string(_(errMsg_[idx].message_));
         std::string::size_type pos;
-        pos = msg.find("%0");
+        pos = msg_.find("%0");
         if (pos != std::string::npos) {
-            msg.replace(pos, 2, toString(code_));
+            msg_.replace(pos, 2, toString(code_));
         }
         if (count_ > 0) {
-            pos = msg.find("%1");
+            pos = msg_.find("%1");
             if (pos != std::string::npos) {
-                msg.replace(pos, 2, arg1_);
+                msg_.replace(pos, 2, arg1_);
             }
         }
         if (count_ > 1) {
-            pos = msg.find("%2");
+            pos = msg_.find("%2");
             if (pos != std::string::npos) {
-                msg.replace(pos, 2, arg2_);
+                msg_.replace(pos, 2, arg2_);
             }
         }
         if (count_ > 2) {
-            pos = msg.find("%3");
+            pos = msg_.find("%3");
             if (pos != std::string::npos) {
-                msg.replace(pos, 2, arg3_);
+                msg_.replace(pos, 2, arg3_);
             }
         }
-        return msg;
     }
 
 }                                       // namespace Exiv2
diff --git a/src/error.hpp b/src/error.hpp
index 6e5178d..3218fea 100644
--- a/src/error.hpp
+++ b/src/error.hpp
@@ -35,6 +35,7 @@
 #include "types.hpp"
 
 // + standard includes
+#include <exception>
 #include <string>
 #include <iosfwd>
 
@@ -52,20 +53,23 @@ namespace Exiv2 {
             : code_(code), message_(message)
         {
         }
-        int code_;                             //!< Error code
+        int code_;                              //!< Error code
         const char* message_;                   //!< Error message
     };
 
     /*!
       @brief Error class interface. Allows the definition and use of a hierarchy
              of error classes which can all be handled in one catch block.
+             Inherits from the standard exception base-class, to make life
+             easier for library users (they have the option of catching most
+             things via std::exception).
      */
-    class AnyError {
+    class AnyError : public std::exception {
     public:
         //! @name Creators
         //@{
         //! Virtual destructor.
-        virtual ~AnyError()
+        virtual ~AnyError() throw()
         {
         }
         //@}
@@ -73,14 +77,7 @@ namespace Exiv2 {
         //! @name Accessors
         //@{
         //! Return the error code.
-        virtual int code() const =0;
-        /*!
-          @brief Return the error message. Consider using the output operator
-                 operator<<(std::ostream &os, const AnyError& error) instead.
-          @note  Unlike std::exception::what(), this function returns an
-                 std::string.
-         */
-        virtual std::string what() const =0;
+        virtual int code() const throw() =0;
     }; // AnyError
 
     //! %AnyBase output operator
@@ -101,12 +98,14 @@ namespace Exiv2 {
         explicit Error(int code)
             : code_(code), count_(0)
         {
+            setMsg();
         }
         //! Constructor taking an error code and one argument
         template<typename A>
         Error(int code, const A& arg1)
             : code_(code), count_(1), arg1_(toString(arg1))
         {
+            setMsg();
         }
         //! Constructor taking an error code and two arguments
         template<typename A, typename B>
@@ -114,6 +113,7 @@ namespace Exiv2 {
             : code_(code), count_(2),
               arg1_(toString(arg1)), arg2_(toString(arg2))
         {
+            setMsg();
         }
         //! Constructor taking an error code and three arguments
         template<typename A, typename B, typename C>
@@ -121,16 +121,30 @@ namespace Exiv2 {
             : code_(code), count_(3),
               arg1_(toString(arg1)), arg2_(toString(arg2)), arg3_(toString(arg3))
         {
+            setMsg();
+        }
+        //! Virtual destructor.
+        virtual ~Error() throw()
+        {
         }
         //@}
 
         //! @name Accessors
         //@{
-        virtual int code() const { return code_; }
-        virtual std::string what() const;
+        virtual int code() const throw() { return code_; }
+        /*!
+          @brief Return the error message. The pointer returned by what()
+                 is valid only as long as the Error object exists.
+         */
+        virtual const char* what() const throw() { return msg_.c_str(); }
         //@}
 
     private:
+        //! @name Manipulators
+        //@{
+        void setMsg();
+        //@}
+
         static int errorIdx(int code);
 
         // DATA
@@ -139,6 +153,7 @@ namespace Exiv2 {
         std::string arg1_;                      //!< First argument
         std::string arg2_;                      //!< Second argument
         std::string arg3_;                      //!< Third argument
+        std::string msg_;                       //!< Complete error message
 
         static const ErrMsg errMsg_[];          //!< List of error messages
     }; // class Error

-- 
exiv2 packaging



More information about the pkg-kde-commits mailing list