1/*
2 * PROGRAM: Firebird exceptions classes
3 * MODULE: StatusArg.h
4 * DESCRIPTION: Build status vector with variable number of elements
5 *
6 * The contents of this file are subject to the Initial
7 * Developer's Public License Version 1.0 (the "License");
8 * you may not use this file except in compliance with the
9 * License. You may obtain a copy of the License at
10 * http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
11 *
12 * Software distributed under the License is distributed AS IS,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied.
14 * See the License for the specific language governing rights
15 * and limitations under the License.
16 *
17 * The Original Code was created by Alex Peshkov
18 * for the Firebird Open Source RDBMS project.
19 *
20 * Copyright (c) 2008 Alex Peshkov <peshkoff at mail.ru>
21 * and all contributors signed below.
22 *
23 * All Rights Reserved.
24 * Contributor(s): ______________________________________.
25 *
26 *
27 */
28
29#ifndef FB_STATUS_ARG
30#define FB_STATUS_ARG
31
32namespace Firebird {
33
34class IStatus;
35class AbstractString;
36class MetaName;
37class Exception;
38
39namespace Arg {
40
41// forward
42class Warning;
43class StatusVector;
44
45class Base
46{
47#ifdef __HP_aCC
48// aCC gives error, cannot access protected member class ImplBase
49public:
50#else
51protected:
52#endif
53 class ImplBase
54 {
55 private:
56 ISC_STATUS kind, code;
57
58 public:
59 ISC_STATUS getKind() const throw() { return kind; }
60 ISC_STATUS getCode() const throw() { return code; }
61
62 virtual const ISC_STATUS* value() const throw() { return NULL; }
63 virtual unsigned int length() const throw() { return 0; }
64 virtual unsigned int firstWarning() const throw() { return 0; }
65 virtual bool hasData() const throw() { return false; }
66 virtual void clear() throw() { }
67 virtual void makePermanent() throw() { }
68 virtual void append(const StatusVector&) throw() { }
69 virtual void assign(const Exception& ex) throw() { }
70 virtual ISC_STATUS copyTo(ISC_STATUS*) const throw() { return 0; }
71 virtual ISC_STATUS copyTo(IStatus*) const throw() { return 0; }
72
73 virtual void shiftLeft(const Base&) throw() { }
74 virtual void shiftLeft(const Warning&) throw() { }
75 virtual void shiftLeft(const char*) throw() { }
76 virtual void shiftLeft(const AbstractString&) throw() { }
77 virtual void shiftLeft(const MetaName&) throw() { }
78
79 virtual bool compare(const StatusVector& /*v*/) const throw() { return false; }
80
81 ImplBase(ISC_STATUS k, ISC_STATUS c) throw() : kind(k), code(c) { }
82 virtual ~ImplBase() { }
83 };
84
85 Base(ISC_STATUS k, ISC_STATUS c);// : implementation(new ImplBase(k, c)) { }
86 explicit Base(ImplBase* i) throw() : implementation(i) { }
87 ~Base() { delete implementation; }
88
89 ImplBase* const implementation;
90
91public:
92 ISC_STATUS getKind() const throw() { return implementation->getKind(); }
93 ISC_STATUS getCode() const throw() { return implementation->getCode(); }
94};
95
96class StatusVector : public Base
97{
98protected:
99 class ImplStatusVector : public ImplBase
100 {
101 private:
102 ISC_STATUS_ARRAY m_status_vector;
103 unsigned int m_length, m_warning;
104
105 bool appendErrors(const ImplBase* const v) throw();
106 bool appendWarnings(const ImplBase* const v) throw();
107 bool append(const ISC_STATUS* const from, const unsigned int count) throw();
108
109 public:
110 virtual const ISC_STATUS* value() const throw() { return m_status_vector; }
111 virtual unsigned int length() const throw() { return m_length; }
112 virtual unsigned int firstWarning() const throw() { return m_warning; }
113 virtual bool hasData() const throw() { return m_length > 0; }
114 virtual void clear() throw();
115 virtual void makePermanent() throw();
116 virtual void append(const StatusVector& v) throw();
117 virtual void assign(const Exception& ex) throw();
118 virtual ISC_STATUS copyTo(ISC_STATUS* dest) const throw();
119 virtual ISC_STATUS copyTo(IStatus* dest) const throw();
120 virtual void shiftLeft(const Base& arg) throw();
121 virtual void shiftLeft(const Warning& arg) throw();
122 virtual void shiftLeft(const char* text) throw();
123 virtual void shiftLeft(const AbstractString& text) throw();
124 virtual void shiftLeft(const MetaName& text) throw();
125 virtual bool compare(const StatusVector& v) const throw();
126
127 ImplStatusVector(ISC_STATUS k, ISC_STATUS c) throw() : ImplBase(k, c)
128 {
129 clear();
130 }
131
132 explicit ImplStatusVector(const ISC_STATUS* s) throw();
133 };
134
135 StatusVector(ISC_STATUS k, ISC_STATUS v);
136
137public:
138 explicit StatusVector(const ISC_STATUS* s);
139 StatusVector();
140 ~StatusVector() { }
141
142 const ISC_STATUS* value() const throw() { return implementation->value(); }
143 unsigned int length() const throw() { return implementation->length(); }
144 bool hasData() const throw() { return implementation->hasData(); }
145 bool isEmpty() const throw() { return !implementation->hasData(); }
146
147 void clear() throw() { implementation->clear(); }
148 void makePermanent() throw() { implementation->makePermanent(); }
149 void append(const StatusVector& v) throw() { implementation->append(v); }
150 void assign(const Exception& ex) throw() { implementation->assign(ex); }
151 void raise() const;
152 ISC_STATUS copyTo(ISC_STATUS* dest) const throw() { return implementation->copyTo(dest); }
153 ISC_STATUS copyTo(IStatus* dest) const throw() { return implementation->copyTo(dest); }
154
155 // generic argument insert
156 StatusVector& operator<<(const Base& arg) throw()
157 {
158 implementation->shiftLeft(arg);
159 return *this;
160 }
161
162 // StatusVector case - append multiple args
163 StatusVector& operator<<(const StatusVector& arg) throw()
164 {
165 implementation->append(arg);
166 return *this;
167 }
168
169 // warning special case - to setup first warning location
170 StatusVector& operator<<(const Warning& arg) throw()
171 {
172 implementation->shiftLeft(arg);
173 return *this;
174 }
175
176 // Str special case - make the code simpler & better readable
177 StatusVector& operator<<(const char* text) throw()
178 {
179 implementation->shiftLeft(text);
180 return *this;
181 }
182
183 StatusVector& operator<<(const AbstractString& text) throw()
184 {
185 implementation->shiftLeft(text);
186 return *this;
187 }
188
189 StatusVector& operator<<(const MetaName& text) throw()
190 {
191 implementation->shiftLeft(text);
192 return *this;
193 }
194
195 bool operator==(const StatusVector& arg) const throw()
196 {
197 return implementation->compare(arg);
198 }
199
200 bool operator!=(const StatusVector& arg) const throw()
201 {
202 return !(*this == arg);
203 }
204};
205
206
207class Gds : public StatusVector
208{
209public:
210 explicit Gds(ISC_STATUS s) throw();
211};
212
213// To simplify calls to DYN messages from DSQL, only for private DYN messages
214// that do not have presence in system_errors2.sql, when you have to call ENCODE_ISC_MSG.
215class PrivateDyn : public Gds
216{
217public:
218 explicit PrivateDyn(ISC_STATUS codeWithoutFacility) throw();
219};
220
221class Str : public Base
222{
223public:
224 explicit Str(const char* text) throw();
225 explicit Str(const AbstractString& text) throw();
226 explicit Str(const MetaName& text) throw();
227};
228
229class Num : public Base
230{
231public:
232 explicit Num(ISC_STATUS s) throw();
233};
234
235class Interpreted : public StatusVector
236{
237public:
238 explicit Interpreted(const char* text) throw();
239 explicit Interpreted(const AbstractString& text) throw();
240};
241
242class Unix : public Base
243{
244public:
245 explicit Unix(ISC_STATUS s) throw();
246};
247
248class Mach : public Base
249{
250public:
251 explicit Mach(ISC_STATUS s) throw();
252};
253
254class Windows : public Base
255{
256public:
257 explicit Windows(ISC_STATUS s) throw();
258};
259
260class Warning : public StatusVector
261{
262public:
263 explicit Warning(ISC_STATUS s) throw();
264};
265
266class SqlState : public Base
267{
268public:
269 explicit SqlState(const char* text) throw();
270 explicit SqlState(const AbstractString& text) throw();
271};
272
273class OsError : public Base
274{
275public:
276 OsError() throw();
277};
278
279} // namespace Arg
280
281} // namespace Firebird
282
283
284#endif // FB_STATUS_ARG
285