/* ----------------------------------------------------------------------------
 *
 * Raima Database Manager
 *
 * Copyright (c) 2011 Raima Inc.,  All rights reserved.
 *
 * Use of this software, whether in source code format, or in executable,
 * binary object code form, is governed by the Birdstep LICENSE which
 * is fully described in the LICENSE.TXT file, included within this
 * distribution of files.
 *
 * ----------------------------------------------------------------------------
 */

#ifndef DB_TYPES_H
#define DB_TYPES_H

#include "rdm.h"
#if defined(__cplusplus)
#if defined(RDM_WINDOWS) || defined(RDM_WINCE)
#pragma warning(disable: 4290)
#endif
#include <exception>
extern "C"
{
#include "berror.h"
}
using namespace std;
#if defined(__cplusplus)
namespace RDM_CPP {
#endif
#else
#include "berror.h"
#endif

/*lint -e1550 */

#define INVALID_TYPE -1
#define BEFORE_FIRST_TYPE -2
#define PAST_LAST_TYPE -3
#define MEMBER_TYPE -4

#define CPP_FIRST       -30000    /* first c++ interface err */

#define CPP_INVALID_TRANSACTION  -30004
#define CPP_INVALID_DB           -30003
#define CPP_INVALID_DB_TYPE      -30002
#define CPP_INVALID_CURSOR       -30001

static const RDM_ERROR rdm_cpp_errors [] = 
{
    { CPP_INVALID_TRANSACTION,  "CPP_INVALID_TRANSACTION",  "Invalid transaction status"},
    { CPP_INVALID_DB,           "CPP_INVALID_DB",           "Invalid database connection"},
    { CPP_INVALID_DB_TYPE,      "CPP_INVALID_DB_TYPE",      "Invalid db type"},
    { CPP_INVALID_CURSOR,       "CPP_INVALID_CURSOR",       "Invalid cursor"}
};

#if defined(__cplusplus)
class IDb;
class ICursor;
class Db;
class Cursor;
typedef const void *dbType;
typedef int32_t recordType;
typedef int32_t setType;
typedef int32_t fieldId;
typedef int32_t keyId;

#if defined(RDM_WINCE)
#pragma warning (push)
#pragma warning (disable:4275)
#endif

/*! \brief the rdm_exception class
  This class implements the exception thrown by the RDM CPP API
  */
class PUBLIC_CLASS rdm_exception : public exception 
{
public:
    //! rdm_exception constructor
    rdm_exception (int32_t error);
  
    //! method to get a text description of the error causing the exception to be thrown
    virtual const char* what() const throw();

    //! method to get the RDM error number
    int32_t error (void) const;
protected:
    int32_t m_error;
};

class rdm_invalid_db_exception : public rdm_exception {
public:
    rdm_invalid_db_exception () : rdm_exception (CPP_INVALID_DB) {
    }
};
#if defined(RDM_WINCE)
#pragma warning (pop)
#endif

/*lint -e1549 */

#endif
#if defined(__cplusplus)
}
#endif
#endif
