Statistics
| Revision:

svn-gvsig-desktop / tags / v1_0_2_Build_906 / libraries / libjni-ecw / include / NCSError.h @ 18485

History | View | Annotate | Download (5.87 KB)

1 3538 nacho
/********************************************************
2
** Copyright 2001 Earth Resource Mapping Ltd.
3
** This document contains proprietary source code of
4
** Earth Resource Mapping Ltd, and can only be used under
5
** one of the three licenses as described in the
6
** license.txt file supplied with this distribution.
7
** See separate license.txt file for license details
8
** and conditions.
9
**
10
** This software is covered by US patent #6,442,298,
11
** #6,102,897 and #6,633,688.  Rights to use these patents
12
** is included in the license agreements.
13
**
14
** FILE:     $Archive: /NCS/Source/C/NCSServerUtil/NCSError.h $
15
** CREATED:  28/08/2001 3:27:34 PM
16
** AUTHOR:   Simon Cope
17
** PURPOSE:  CNCSError class header
18
** EDITS:    [xx] ddMmmyy NAME COMMENTS
19
 *******************************************************/
20
21
#ifndef NCSERROR_H
22
#define NCSERROR_H
23
24
#ifndef NCSLOG_H
25
#include "NCSLog.h"
26
#endif // NCSLOG_H
27
28
#ifndef NCSERRORS_H
29
#include "NCSErrors.h"
30
#endif // NCSERRORS_H
31
32
#ifndef NCSTYPES_H
33
#include "NCSTypes.h"
34
#endif // NCSTYPES_H
35
36
/**
37
 * NCSError wrapper class.
38
 *
39
 * @author       Simon Cope
40
 * @version      $Revision$ $Author$ $Date$
41
 */
42
class NCS_EXPORT CNCSError {
43
public:
44
        /**
45
         * Overloaded constructor with a heap of parameters (with defaults).
46
         *
47
         * @param        eError                NCSError enum value
48
         * @param                 pFile                Source file name where object is constructed (usually __FILE__ is used)
49
         * @param                 nLine                Source file line # where object is constructed (usually __LINE__ is used)
50
         * @param                 eLevel                Logging level to log error to log file
51
         * @param                 pText                Optional text to append to error & log message
52
         */
53
        CNCSError(const NCSError eError = NCS_SUCCESS, char *pFile = __FILE__, int nLine = __LINE__, CNCSLog::NCSLogLevel eLevel = CNCSLog::LOG_LEVEL1, const char *pText = (char*)NULL);
54
        /**
55
         * Copy constructor.
56
         *
57
         * @param        Error                Reference to error to construct from
58
         */
59
        CNCSError(const CNCSError &Error);
60
        /**
61
         * Destructor.
62
         */
63
        ~CNCSError();
64
65
        /**
66
         * Get an error message for the error object, optionally with a formatted error string included..
67
         *
68
         * @param        pFormat        Optional printf() style format string
69
         * @param                 ...                Optional args to match pFormat
70
         * @return       char *                Formatted error string.  Should be freed with NCSFree().
71
         * @see          #GetErrorNumber()
72
         */
73
        char *GetErrorMessage(char *pFormat = NULL, ...);
74
        /**
75
         * Get the NCSError enum for this error object.
76
         *
77
         * @return       NCSError        Enum value of error
78
         * @see          #GetErrorMessage(char *pFormat = NULL, ...)
79
         */
80
        NCSError GetErrorNumber(void) { return(m_eError); }
81
        /**
82
         * Log the error to the log file, if logging is >= the specified log level.
83
         *
84
         * @param        eLevel                Log level required before the error should be logged.
85
         */
86
        void Log(CNCSLog::NCSLogLevel eLevel);
87
88
        /**
89
         * Assign an error to the error object.
90
         *
91
         * @param        Error                Reference to error enum to assign to object
92
         * @return                                        Reference to the error object
93
         */
94
        CNCSError& operator =(const CNCSError &Error);
95
        /**
96
         * Compare the errors.
97
         *
98
         * @param        Error                Error object to compare to.  Comparison is on error enum alone.
99
         * @return                                        Boolean value informing whether the two errors are the same type
100
         */
101
        inline bool operator ==( const CNCSError &Error ) {
102
                        return(m_eError == Error.m_eError);
103
                };
104
        /**
105
         * Compare the errors.
106
         *
107
         * @param        eError                Error enum value to compare to.  Comparison is on error enum alone.
108
         * @return                                        Boolean value informing whether the two errors are the same type
109
         */
110
        inline bool operator ==( const NCSError eError ) {
111
                        return(m_eError == eError);
112
                };
113
        /**
114
         * Compare the errors.
115
         *
116
         * @param        Error                Error object to compare to.  Comparison is on error enum alone.
117
         * @return                                        Boolean value informing whether the two errors are not the same type
118
         */
119
        inline bool operator !=( const CNCSError &Error ) {
120
                        return(m_eError != Error.m_eError);
121
                };
122
        /**
123
         * Compare the errors.
124
         *
125
         * @param        eError                Error enum value to compare to.  Comparison is on error enum alone.
126
         * @return                                        Boolean value informing whether the two errors are not the same type
127
         */
128
        inline bool operator !=( const NCSError eError ) {
129
                        return(m_eError != eError);
130
                };
131
private:
132
        /**
133
         * NCSError enum value for this error.
134
         */
135
        NCSError        m_eError;
136
        /**
137
         * Optional formatted test message for this error.
138
         */
139
        char                *m_pText;
140
        /**
141
         * File this object was created in (overloaded constructor only).
142
         *
143
         * @see     #CNCSError(NCSError eError = NCS_SUCCESS, char *pFile = __FILE__, int nLine = __LINE__, CNCSLog::NCSLogLevel eLevel = CNCSLog::LOG_LEVEL1, char *pText = (char*)NULL)
144
         */
145
        const char        *m_pFile;
146
        /**
147
         * Line number this object was created in (overloaded constructor only).
148
         *
149
         * @see     #CNCSError(NCSError eError = NCS_SUCCESS, char *pFile = __FILE__, int nLine = __LINE__, CNCSLog::NCSLogLevel eLevel = CNCSLog::LOG_LEVEL1, char *pText = (char*)NULL)
150
         */
151
        int                        m_nLine;
152
};
153
154
/**
155
 * Create a CNCSError instance for the specified error enum, setting the file & line values.
156
 *
157
 * @param        e                                NCSError enum value
158
 */
159
#define NCSERROR(e)                                CNCSError(e, __FILE__, __LINE__)
160
/**
161
 * Create a CNCSError instance for the specified error enum, setting the file & line values, and write it to the log.
162
 *
163
 * @param        e                                NCSError enum value
164
 */
165
#define NCSERRORLOG(e)                        CNCSError(e, __FILE__, __LINE__, CNCSLog::LOG_LEVEL0)
166
/**
167
 * Create a CNCSError instance for the specified error enum, setting the file & line values, with some additional text.
168
 *
169
 * @param        e                                NCSError enum value
170
 */
171
#define NCSERRORTXT(e, t)                CNCSError(e, __FILE__, __LINE__, CNCSLog::LOG_LEVEL1, t)
172
/**
173
 * Create a CNCSError instance for the specified error enum, setting the file & line values, with some additional text, and write it to the log.
174
 *
175
 * @param        e                                NCSError enum value
176
 */
177
#define NCSERRORLOGTXT(e, t)        CNCSError(e, __FILE__, __LINE__, CNCSLog::LOG_LEVEL0, t)
178
179
#endif // NCSERROR_H