Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libjni-ecwcompress / include / NCSError.h @ 1937

History | View | Annotate | Download (5.62 KB)

1
/********************************************************
2
** Copyright 2001 Earth Resource Mapping Pty Ltd.
3
** This document contains unpublished source code of
4
** Earth Resource Mapping Pty Ltd. This notice does
5
** not indicate any intention to publish the source
6
** code contained herein.
7
**
8
** FILE:     $Archive: /NCS/Source/C/NCSServerUtil/NCSError.h $
9
** CREATED:  28/08/2001 3:27:34 PM
10
** AUTHOR:   Simon Cope
11
** PURPOSE:  CNCSError class header
12
** EDITS:    [xx] ddMmmyy NAME COMMENTS
13
 *******************************************************/
14

    
15
#ifndef NCSERROR_H
16
#define NCSERROR_H
17

    
18
#ifndef NCSLOG_H
19
#include "NCSLog.h"
20
#endif // NCSLOG_H
21

    
22
#ifndef NCSERRORS_H
23
#include "NCSErrors.h"
24
#endif // NCSERRORS_H
25

    
26
#ifndef NCSTYPES_H
27
#include "NCSTypes.h"
28
#endif // NCSTYPES_H
29

    
30
/**
31
 * NCSError wrapper class.
32
 * 
33
 * @author       Simon Cope
34
 * @version      $Revision: 1937 $ $Author: igbrotru $ $Date: 2005-05-16 08:56:31 +0200 (Mon, 16 May 2005) $ 
35
 */
36
class NCS_EXPORT CNCSError {
37
public:
38
        /**
39
         * Overloaded constructor with a heap of parameters (with defaults).
40
         * 
41
         * @param        eError                NCSError enum value
42
         * @param                 pFile                Source file name where object is constructed (usually __FILE__ is used)
43
         * @param                 nLine                Source file line # where object is constructed (usually __LINE__ is used)
44
         * @param                 eLevel                Logging level to log error to log file
45
         * @param                 pText                Optional text to append to error & log message
46
         */
47
        CNCSError(const NCSError eError = NCS_SUCCESS, char *pFile = __FILE__, int nLine = __LINE__, CNCSLog::NCSLogLevel eLevel = CNCSLog::LOG_LEVEL1, const char *pText = (char*)NULL);
48
        /**
49
         * Copy constructor.
50
         * 
51
         * @param        Error                Reference to error to construct from
52
         */
53
        CNCSError(const CNCSError &Error);
54
        /**
55
         * Destructor.
56
         */
57
        ~CNCSError();
58

    
59
        /**
60
         * Get an error message for the error object, optionally with a formatted error string included..
61
         * 
62
         * @param        pFormat        Optional printf() style format string
63
         * @param                 ...                Optional args to match pFormat
64
         * @return       char *                Formatted error string.  Should be freed with NCSFree().
65
         * @see          #GetErrorNumber()
66
         */
67
        char *GetErrorMessage(char *pFormat = NULL, ...);
68
        /**
69
         * Get the NCSError enum for this error object.
70
         * 
71
         * @return       NCSError        Enum value of error
72
         * @see          #GetErrorMessage(char *pFormat = NULL, ...)
73
         */
74
        NCSError GetErrorNumber(void) { return(m_eError); }
75
        /**
76
         * Log the error to the log file, if logging is >= the specified log level.
77
         * 
78
         * @param        eLevel                Log level required before the error should be logged.
79
         */
80
        void Log(CNCSLog::NCSLogLevel eLevel);
81

    
82
        /**
83
         * Assign an error to the error object.
84
         * 
85
         * @param        Error                Reference to error enum to assign to object
86
         * @return                                        Reference to the error object
87
         */
88
        CNCSError& operator =(const CNCSError &Error);
89
        /**
90
         * Compare the errors.
91
         * 
92
         * @param        Error                Error object to compare to.  Comparison is on error enum alone.
93
         * @return                                        Boolean value informing whether the two errors are the same type
94
         */
95
        inline bool operator ==( const CNCSError &Error ) {
96
                        return(m_eError == Error.m_eError);
97
                };
98
        /**
99
         * Compare the errors.
100
         * 
101
         * @param        eError                Error enum value to compare to.  Comparison is on error enum alone.
102
         * @return                                        Boolean value informing whether the two errors are the same type
103
         */
104
        inline bool operator ==( const NCSError eError ) {
105
                        return(m_eError == eError);
106
                };
107
        /**
108
         * Compare the errors.
109
         * 
110
         * @param        Error                Error object to compare to.  Comparison is on error enum alone.
111
         * @return                                        Boolean value informing whether the two errors are not the same type
112
         */
113
        inline bool operator !=( const CNCSError &Error ) {
114
                        return(m_eError != Error.m_eError);
115
                };
116
        /**
117
         * Compare the errors.
118
         * 
119
         * @param        eError                Error enum value to compare to.  Comparison is on error enum alone.
120
         * @return                                        Boolean value informing whether the two errors are not the same type
121
         */
122
        inline bool operator !=( const NCSError eError ) {
123
                        return(m_eError != eError);
124
                };
125
private:
126
        /**
127
         * NCSError enum value for this error.
128
         */
129
        NCSError        m_eError;
130
        /**
131
         * Optional formatted test message for this error.
132
         */
133
        char                *m_pText;
134
        /**
135
         * File this object was created in (overloaded constructor only).
136
         * 
137
         * @see     #CNCSError(NCSError eError = NCS_SUCCESS, char *pFile = __FILE__, int nLine = __LINE__, CNCSLog::NCSLogLevel eLevel = CNCSLog::LOG_LEVEL1, char *pText = (char*)NULL)
138
         */
139
        const char        *m_pFile;
140
        /**
141
         * Line number 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
        int                        m_nLine;
146
};
147

    
148
/**
149
 * Create a CNCSError instance for the specified error enum, setting the file & line values.
150
 * 
151
 * @param        e                                NCSError enum value
152
 */
153
#define NCSERROR(e)                                CNCSError(e, __FILE__, __LINE__)
154
/**
155
 * Create a CNCSError instance for the specified error enum, setting the file & line values, and write it to the log.
156
 * 
157
 * @param        e                                NCSError enum value
158
 */
159
#define NCSERRORLOG(e)                        CNCSError(e, __FILE__, __LINE__, CNCSLog::LOG_LEVEL0)
160
/**
161
 * Create a CNCSError instance for the specified error enum, setting the file & line values, with some additional text.
162
 * 
163
 * @param        e                                NCSError enum value
164
 */
165
#define NCSERRORTXT(e, t)                CNCSError(e, __FILE__, __LINE__, CNCSLog::LOG_LEVEL1, t)
166
/**
167
 * Create a CNCSError instance for the specified error enum, setting the file & line values, with some additional text, and write it to the log.
168
 * 
169
 * @param        e                                NCSError enum value
170
 */
171
#define NCSERRORLOGTXT(e, t)        CNCSError(e, __FILE__, __LINE__, CNCSLog::LOG_LEVEL0, t)
172

    
173
#endif // NCSERROR_H