8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-31 09:23:03 +01:00
firebird-mirror/src/common/StatusArg.h

291 lines
7.6 KiB
C
Raw Normal View History

/*
* PROGRAM: Firebird exceptions classes
* MODULE: StatusArg.h
* DESCRIPTION: Build status vector with variable number of elements
*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
*
* Software distributed under the License is distributed AS IS,
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
* See the License for the specific language governing rights
* and limitations under the License.
*
* The Original Code was created by Alex Peshkov
* for the Firebird Open Source RDBMS project.
*
* Copyright (c) 2008 Alex Peshkov <peshkoff at mail.ru>
* and all contributors signed below.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*
*
*/
#ifndef FB_STATUS_ARG
#define FB_STATUS_ARG
namespace Firebird {
class IStatus;
class AbstractString;
class MetaName;
class QualifiedName;
namespace Arg {
2008-07-10 17:46:41 +02:00
// forward
class Warning;
class StatusVector;
2008-07-10 17:46:41 +02:00
class Base
{
#ifdef __HP_aCC
// aCC gives error, cannot access protected member class ImplBase
public:
#else
protected:
#endif
class ImplBase
{
private:
ISC_STATUS kind, code;
public:
ISC_STATUS getKind() const throw() { return kind; }
ISC_STATUS getCode() const throw() { return code; }
virtual const ISC_STATUS* value() const throw() { return NULL; }
virtual unsigned int length() const throw() { return 0; }
virtual unsigned int firstWarning() const throw() { return 0; }
virtual bool hasData() const throw() { return false; }
virtual void clear() throw() { }
virtual void makePermanent() throw() { }
2009-04-26 12:24:44 +02:00
virtual void append(const StatusVector&) throw() { }
virtual ISC_STATUS copyTo(ISC_STATUS*) const throw() { return 0; }
virtual ISC_STATUS copyTo(IStatus*) const throw() { return 0; }
2009-04-26 12:24:44 +02:00
virtual void shiftLeft(const Base&) throw() { }
virtual void shiftLeft(const Warning&) throw() { }
virtual void shiftLeft(const char*) throw() { }
virtual void shiftLeft(const AbstractString&) throw() { }
virtual void shiftLeft(const MetaName&) throw() { }
virtual void shiftLeft(const QualifiedName&) throw() { }
virtual bool compare(const StatusVector& v) const throw() { return false; }
ImplBase(ISC_STATUS k, ISC_STATUS c) throw() : kind(k), code(c) { }
virtual ~ImplBase() { }
};
Base(ISC_STATUS k, ISC_STATUS c);// : implementation(new ImplBase(k, c)) { }
2008-12-01 10:21:31 +01:00
explicit Base(ImplBase* i) throw() : implementation(i) { }
~Base() { delete implementation; }
ImplBase* const implementation;
2009-07-25 02:48:46 +02:00
public:
ISC_STATUS getKind() const throw() { return implementation->getKind(); }
ISC_STATUS getCode() const throw() { return implementation->getCode(); }
};
class StatusVector : public Base
{
2008-07-10 17:46:41 +02:00
protected:
class ImplStatusVector : public ImplBase
{
private:
ISC_STATUS_ARRAY m_status_vector;
unsigned int m_length, m_warning;
bool appendErrors(const ImplBase* const v) throw();
bool appendWarnings(const ImplBase* const v) throw();
bool append(const ISC_STATUS* const from, const unsigned int count) throw();
public:
virtual const ISC_STATUS* value() const throw() { return m_status_vector; }
virtual unsigned int length() const throw() { return m_length; }
virtual unsigned int firstWarning() const throw() { return m_warning; }
virtual bool hasData() const throw() { return m_length > 0; }
virtual void clear() throw();
virtual void makePermanent() throw();
virtual void append(const StatusVector& v) throw();
virtual ISC_STATUS copyTo(ISC_STATUS* dest) const throw();
virtual ISC_STATUS copyTo(IStatus* dest) const throw();
virtual void shiftLeft(const Base& arg) throw();
virtual void shiftLeft(const Warning& arg) throw();
virtual void shiftLeft(const char* text) throw();
virtual void shiftLeft(const AbstractString& text) throw();
virtual void shiftLeft(const MetaName& text) throw();
virtual void shiftLeft(const QualifiedName& text) throw();
virtual bool compare(const StatusVector& v) const throw();
2008-12-05 01:56:15 +01:00
ImplStatusVector(ISC_STATUS k, ISC_STATUS c) throw() : ImplBase(k, c)
{
clear();
}
2008-12-01 10:21:31 +01:00
explicit ImplStatusVector(const ISC_STATUS* s) throw();
};
2008-10-31 12:14:37 +01:00
StatusVector(ISC_STATUS k, ISC_STATUS v);
public:
2008-10-31 12:14:37 +01:00
explicit StatusVector(const ISC_STATUS* s);
StatusVector();
~StatusVector() { }
const ISC_STATUS* value() const throw() { return implementation->value(); }
unsigned int length() const throw() { return implementation->length(); }
bool hasData() const throw() { return implementation->hasData(); }
bool isEmpty() const throw() { return !implementation->hasData(); }
void clear() throw() { implementation->clear(); }
void makePermanent() throw() { implementation->makePermanent(); }
void append(const StatusVector& v) throw() { implementation->append(v); }
void raise() const;
ISC_STATUS copyTo(ISC_STATUS* dest) const throw() { return implementation->copyTo(dest); }
ISC_STATUS copyTo(IStatus* dest) const throw() { return implementation->copyTo(dest); }
2008-07-10 17:46:41 +02:00
// generic argument insert
2009-08-05 08:35:01 +02:00
StatusVector& operator<<(const Base& arg) throw()
{
implementation->shiftLeft(arg);
return *this;
}
2009-08-06 03:06:05 +02:00
// StatusVector case - append multiple args
StatusVector& operator<<(const StatusVector& arg) throw()
{
implementation->append(arg);
return *this;
}
2008-07-10 17:46:41 +02:00
// warning special case - to setup first warning location
2009-08-05 08:35:01 +02:00
StatusVector& operator<<(const Warning& arg) throw()
{
implementation->shiftLeft(arg);
return *this;
}
2009-08-06 03:06:05 +02:00
2008-07-10 17:46:41 +02:00
// Str special case - make the code simpler & better readable
2009-08-05 08:35:01 +02:00
StatusVector& operator<<(const char* text) throw()
{
implementation->shiftLeft(text);
return *this;
}
2009-08-06 03:06:05 +02:00
2009-08-05 08:35:01 +02:00
StatusVector& operator<<(const AbstractString& text) throw()
{
implementation->shiftLeft(text);
return *this;
}
2009-08-06 03:06:05 +02:00
2009-08-05 08:35:01 +02:00
StatusVector& operator<<(const MetaName& text) throw()
{
implementation->shiftLeft(text);
return *this;
}
StatusVector& operator<<(const QualifiedName& text) throw()
{
implementation->shiftLeft(text);
return *this;
}
bool operator==(const StatusVector& arg) const throw()
{
return implementation->compare(arg);
}
bool operator!=(const StatusVector& arg) const throw()
{
return !(*this == arg);
}
};
class Gds : public StatusVector
{
public:
explicit Gds(ISC_STATUS s) throw();
};
2012-01-19 06:42:04 +01:00
// To simplify calls to DYN messages from DSQL, only for private DYN messages
// that do not have presence in system_errors2.sql, when you have to call ENCODE_ISC_MSG
class PrivateDyn : public Gds
{
public:
explicit PrivateDyn(ISC_STATUS codeWithoutFacility) throw();
};
class Str : public Base
{
public:
explicit Str(const char* text) throw();
explicit Str(const AbstractString& text) throw();
explicit Str(const MetaName& text) throw();
explicit Str(const QualifiedName& text) throw();
};
class Num : public Base
{
public:
explicit Num(ISC_STATUS s) throw();
};
class Interpreted : public StatusVector
{
public:
explicit Interpreted(const char* text) throw();
explicit Interpreted(const AbstractString& text) throw();
};
class Unix : public Base
{
public:
explicit Unix(ISC_STATUS s) throw();
};
class Mach : public Base
{
public:
explicit Mach(ISC_STATUS s) throw();
};
class Windows : public Base
{
public:
explicit Windows(ISC_STATUS s) throw();
};
class Warning : public StatusVector
{
public:
explicit Warning(ISC_STATUS s) throw();
};
class SqlState : public Base
{
public:
explicit SqlState(const char* text) throw();
explicit SqlState(const AbstractString& text) throw();
};
class OsError : public Base
{
public:
OsError() throw();
};
} // namespace Arg
} // namespace Firebird
#endif // FB_STATUS_ARG