~noskcaj/ubuntu/trusty/libextractor/merge

« back to all changes in this revision

Viewing changes to src/plugins/exiv2/error.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-11-17 20:27:32 UTC
  • mfrom: (1.10.4 upstream) (5.2.5 sid)
  • Revision ID: james.westby@ubuntu.com-20091117202732-ipm2h3gks5bdw2vx
Tags: 0.5.23+dfsg-3
* Building against libltdl7.
* Updating to standards version 3.8.3.
* Adding maintainer homepage field to control.
* Marking maintainer homepage field to be also included in binary
  packages and changelog.
* Adding README.source.
* Simplifying autotools handling in rules.
* Updating README.source.
* Moving maintainer homepage field from control to copyright.
* Dropping la files.
* Simplyfing debhelper install files.
* Bumping versioned build-depends on debhelper.
* Adding depends to dpkg install info.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// ***************************************************************** -*- C++ -*-
2
 
/*
3
 
 * Copyright (C) 2004, 2005 Andreas Huggel <ahuggel@gmx.net>
4
 
 *
5
 
 * This program is part of the Exiv2 distribution.
6
 
 *
7
 
 * This program is free software; you can redistribute it and/or
8
 
 * modify it under the terms of the GNU General Public License
9
 
 * as published by the Free Software Foundation; either version 2
10
 
 * of the License, or (at your option) any later version.
11
 
 *
12
 
 * This program is distributed in the hope that it will be useful,
13
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
 * GNU General Public License for more details.
16
 
 *
17
 
 * You should have received a copy of the GNU General Public License
18
 
 * along with this program; if not, write to the Free Software
19
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
 
 */
21
 
/*!
22
 
  @file    error.hpp
23
 
  @brief   Error class for exceptions
24
 
  @version $Rev: 560 $
25
 
  @author  Andreas Huggel (ahu)
26
 
           <a href="mailto:ahuggel@gmx.net">ahuggel@gmx.net</a>
27
 
  @date    15-Jan-04, ahu: created<BR>
28
 
           11-Feb-04, ahu: isolated as a component
29
 
 */
30
 
#ifndef ERROR_HPP_
31
 
#define ERROR_HPP_
32
 
 
33
 
// *****************************************************************************
34
 
// included header files
35
 
#include "types.hpp"
36
 
 
37
 
// + standard includes
38
 
#include <string>
39
 
#include <iosfwd>
40
 
 
41
 
// *****************************************************************************
42
 
// namespace extensions
43
 
namespace Exiv2 {
44
 
 
45
 
// *****************************************************************************
46
 
// class definitions
47
 
 
48
 
    //! Helper structure defining an error message
49
 
    struct ErrMsg {
50
 
        //! Constructor
51
 
        ErrMsg(int code, const char* message)
52
 
            : code_(code), message_(message)
53
 
        {
54
 
        }
55
 
        int code_;                             //!< Error code
56
 
        const char* message_;                   //!< Error message
57
 
    };
58
 
 
59
 
    /*!
60
 
      @brief Error class interface. Allows the definition and use of a hierarchy
61
 
             of error classes which can all be handled in one catch block.
62
 
     */
63
 
    class AnyError {
64
 
    public:
65
 
        //! @name Creators
66
 
        //@{
67
 
        //! Virtual destructor.
68
 
        virtual ~AnyError()
69
 
        {
70
 
        }
71
 
        //@}
72
 
 
73
 
        //! @name Accessors
74
 
        //@{
75
 
        //! Return the error code.
76
 
        virtual int code() const =0;
77
 
        /*!
78
 
          @brief Return the error message. Consider using the output operator
79
 
                 operator<<(std::ostream &os, const AnyError& error) instead.
80
 
          @note  Unlike std::exception::what(), this function returns an
81
 
                 std::string.
82
 
         */
83
 
        virtual std::string what() const =0;
84
 
    }; // AnyError
85
 
 
86
 
    //! %AnyBase output operator
87
 
    inline std::ostream& operator<<(std::ostream& os, const AnyError& error)
88
 
    {
89
 
        return os << error.what();
90
 
    }
91
 
 
92
 
    /*!
93
 
      @brief Simple error class used for exceptions. An output operator is
94
 
             provided to print errors to a stream.
95
 
     */
96
 
    class Error : public AnyError {
97
 
    public:
98
 
        //! @name Creators
99
 
        //@{
100
 
        //! Constructor taking only an error code
101
 
        explicit Error(int code)
102
 
            : code_(code), count_(0)
103
 
        {
104
 
        }
105
 
        //! Constructor taking an error code and one argument
106
 
        template<typename A>
107
 
        Error(int code, const A& arg1)
108
 
            : code_(code), count_(1), arg1_(toString(arg1))
109
 
        {
110
 
        }
111
 
        //! Constructor taking an error code and two arguments
112
 
        template<typename A, typename B>
113
 
        Error(int code, const A& arg1, const B& arg2)
114
 
            : code_(code), count_(2),
115
 
              arg1_(toString(arg1)), arg2_(toString(arg2))
116
 
        {
117
 
        }
118
 
        //! Constructor taking an error code and three arguments
119
 
        template<typename A, typename B, typename C>
120
 
        Error(int code, const A& arg1, const B& arg2, const C& arg3)
121
 
            : code_(code), count_(3),
122
 
              arg1_(toString(arg1)), arg2_(toString(arg2)), arg3_(toString(arg3))
123
 
        {
124
 
        }
125
 
        //@}
126
 
 
127
 
        //! @name Accessors
128
 
        //@{
129
 
        virtual int code() const { return code_; }
130
 
        virtual std::string what() const;
131
 
        //@}
132
 
 
133
 
    private:
134
 
        static int errorIdx(int code);
135
 
 
136
 
        // DATA
137
 
        int code_;                              //!< Error code
138
 
        int count_;                             //!< Number of arguments
139
 
        std::string arg1_;                      //!< First argument
140
 
        std::string arg2_;                      //!< Second argument
141
 
        std::string arg3_;                      //!< Third argument
142
 
 
143
 
        static const ErrMsg errMsg_[];          //!< List of error messages
144
 
    }; // class Error
145
 
 
146
 
}                                       // namespace Exiv2
147
 
 
148
 
#endif                                  // #ifndef ERROR_HPP_