svn-gvsig-desktop / trunk / libraries / libjni-mrsid / include / support / lt_utilStatusData.h @ 8232
History | View | Annotate | Download (5.08 KB)
1 |
/* $Id: lt_utilStatusData.h 3539 2006-01-09 12:23:20Z nacho $ */
|
---|---|
2 |
/* //////////////////////////////////////////////////////////////////////////
|
3 |
// //
|
4 |
// This code is Copyright (c) 2004 LizardTech, Inc, 1008 Western Avenue, //
|
5 |
// Suite 200, Seattle, WA 98104. Unauthorized use or distribution //
|
6 |
// prohibited. Access to and use of this code is permitted only under //
|
7 |
// license from LizardTech, Inc. Portions of the code are protected by //
|
8 |
// US and foreign patents and other filings. All Rights Reserved. //
|
9 |
// //
|
10 |
////////////////////////////////////////////////////////////////////////// */
|
11 |
/* PUBLIC */
|
12 |
|
13 |
#ifndef LT_UTILSTATUSDATA_H
|
14 |
#define LT_UTILSTATUSDATA_H
|
15 |
|
16 |
// lt_lib_base
|
17 |
#include "lt_base.h" |
18 |
|
19 |
// system
|
20 |
#include <stdlib.h> |
21 |
|
22 |
|
23 |
#if defined(LT_COMPILER_MS)
|
24 |
#pragma warning(push,4) |
25 |
#endif
|
26 |
|
27 |
|
28 |
LT_BEGIN_NAMESPACE(LizardTech) |
29 |
|
30 |
class LTFileSpec; |
31 |
|
32 |
|
33 |
/**
|
34 |
* Interface to the error data stack.
|
35 |
*
|
36 |
* This class provides functions for pushing and popping data to and from the
|
37 |
* "error stack", used to pass information to accompany a simple status code.
|
38 |
*
|
39 |
* @note For most users, the functions provided in the file
|
40 |
* lt_utilStatusStrings.h are sufficient for error reporting. Only
|
41 |
* applications which need to add their own error strings or perform
|
42 |
* internationalization need to use this class.
|
43 |
*
|
44 |
* @note This error management system is expected to be substantially changed
|
45 |
* in a future release.
|
46 |
*
|
47 |
* Example usage:
|
48 |
*
|
49 |
* @verbatim
|
50 |
// IN APPLICATION
|
51 |
LTUtilStatus::initialize();
|
52 |
...
|
53 |
|
54 |
// IN SOME LIBRARY
|
55 |
LT_STATUS sts = someFunction("foo.txt",99);
|
56 |
if (!LT_SUCCESS(sts))
|
57 |
{
|
58 |
LTUtilStatusData::pushBegin(sts);
|
59 |
LTUtilStatusData::pushString("foo.txt");
|
60 |
LTUtilStatusData::pushEnd();
|
61 |
return sts;
|
62 |
}
|
63 |
...
|
64 |
|
65 |
// IN LT_LIB_UTILS
|
66 |
LT_STATUS sts;
|
67 |
char* str;
|
68 |
int i;
|
69 |
LTUtilStatusData::popBegin(sts);
|
70 |
// parse string for code sts to determine needed data items...
|
71 |
LTUtilStatusData::popString(str);
|
72 |
LTUtilStatusData::popInt32(i);
|
73 |
LTUtilStatusData::popEnd();
|
74 |
...
|
75 |
|
76 |
// IN APPLICATION
|
77 |
LTUtilStatusData::terminate();
|
78 |
* @endverbatim
|
79 |
*
|
80 |
* To set error data, you must first do pushBegin(), then push zero or
|
81 |
* more other data items (called Records), then do a pushEnd().
|
82 |
*
|
83 |
* To retrieve error data, you must first do a popBegin(), followed by
|
84 |
* pops of whatever you pushed, then do a popEnd().
|
85 |
*
|
86 |
* Note it is assumed the popper knows the order and type of things to be
|
87 |
* popped off. (This is not really a problem, since the status code is
|
88 |
* associated with a string which will contain %d, %s, etc telling him what
|
89 |
* to do. Furthermore, the only person who should ever need to use the pop
|
90 |
* calls will be lt_lib_statusStrings.)
|
91 |
*
|
92 |
* If you do not call initialize(), the push and pop operations will do
|
93 |
* nothing. This way, apps need not use the StatusData system if they do
|
94 |
* not wish to.
|
95 |
*/
|
96 |
class LTUtilStatusData |
97 |
{ |
98 |
public:
|
99 |
/**
|
100 |
* initialize the error stack
|
101 |
*
|
102 |
* Applications should call this once prior to any other LizardTech
|
103 |
* functions, to enable the error reporting system. If not called, then
|
104 |
* any calls to pushData() will be no-ops, and the integral status code
|
105 |
* will map to an unintepretted string.
|
106 |
*
|
107 |
* @return success or failure status code
|
108 |
*/
|
109 |
static LT_STATUS initialize();
|
110 |
|
111 |
/**
|
112 |
* cleanup
|
113 |
*
|
114 |
* Applications should call this once after all other LizardTech functions
|
115 |
* have been called, to clean up memory.
|
116 |
*
|
117 |
* @return success or failure success code
|
118 |
*/
|
119 |
static LT_STATUS terminate();
|
120 |
|
121 |
// returns true iff initialize() was called, e.g. system is being used
|
122 |
static bool isActive(); |
123 |
|
124 |
// push data associated with an error onto the error frame stack
|
125 |
// do begin(), data..., end()
|
126 |
static void pushBegin(LT_STATUS); |
127 |
static void pushUint32(lt_uint32); |
128 |
static void pushInt32(lt_int32); |
129 |
static void pushString(const char*); |
130 |
static void pushDouble(double); |
131 |
static void pushFileSpec(const LTFileSpec&); |
132 |
static void pushEnd(); |
133 |
|
134 |
// get the top data item off the error frame stack
|
135 |
// returns failure if the data itemis not of the specified type
|
136 |
static LT_STATUS popBegin(LT_STATUS&);
|
137 |
static LT_STATUS popUint32(lt_uint32&);
|
138 |
static LT_STATUS popInt32(lt_int32&);
|
139 |
static LT_STATUS popString(char*&); // caller takes ownership of string |
140 |
static LT_STATUS popDouble(double&); |
141 |
static LT_STATUS popFileSpec(LTFileSpec&);
|
142 |
static LT_STATUS popEnd();
|
143 |
|
144 |
// pop off all data items from current frame
|
145 |
// used in an emergency, when the top frame is not the one you want
|
146 |
// (and you have no way of knowing how many data items need to be
|
147 |
// popped off)
|
148 |
static LT_STATUS popRemainder();
|
149 |
|
150 |
// remove the current error frame, if any (this is like doing the pop
|
151 |
// begin/end sequence, if there is an active frame)
|
152 |
static void clear(); |
153 |
|
154 |
private:
|
155 |
// nope
|
156 |
LTUtilStatusData(); |
157 |
~LTUtilStatusData(); |
158 |
LTUtilStatusData(const LTUtilStatusData&);
|
159 |
LTUtilStatusData& operator=(const LTUtilStatusData&);
|
160 |
}; |
161 |
|
162 |
|
163 |
LT_END_NAMESPACE(LizardTech) |
164 |
|
165 |
#if defined(LT_COMPILER_MS)
|
166 |
#pragma warning(pop)
|
167 |
#endif
|
168 |
|
169 |
#endif // LT_UTILSTATUSDATA_H |