/***************************************************************************
                          MELError.h  -  description
                             -------------------
    begin                : Mon Feb 21 2005
    copyright            : (C) 2005 by klaus frieler
    email                : kgf@omniversum.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef _LIBMELODY_MELERROR_H
#define _LIBMELODY_MELERROR_H

#include "types.h"
using namespace std;
typedef long MRESULT;

#define  SUCC_OK      0x00000000
#define  SUCC_FAIL    0x00000001
#define  SUCC_NOTIMPL 0x00000002

#define  SUCCESS(Status) ((MRESULT)(Status)>=0)
#define  FAIL(Status)   ((MRESULT)(Status)<0)

#define  ERR_UNEXPECTED          0x80000FFFL
#define  ERR_FAIL                0x80000000L
#define  ERR_INVALIDARG          0x80000001L
#define  ERR_NOPOINTER           0x80000002L
#define  ERR_OUTOFMEMORY         0x80000003L
#define  ERR_EMPTY               0x80000004L
#define  ERR_INCOMPATIBLE        0x80000005L
#define  ERR_FILE_OPEN           0x80000006L
#define  ERR_FILE_FORMAT         0x80000007L
#define  ERR_FILE_READ           0x80000008L
#define  ERR_FILE_WRITE          0x80000009L
#define  ERR_DATA_MISSING        0x8000000AL
#define  ERR_BAD_DATA            0x8000000BL
#define  ERR_BAD_OBJECT          0x8000000CL
#define  ERR_NOTIMPL             0x8000000DL


class MelError
{
public:
   static string   getErrTextFromCode(const MRESULT mr);

public:
   MelError(const MRESULT mr): m_mr(mr), m_sErrDesc(""){}
   MelError(const MRESULT mr, const string& sErrDesc): m_mr(mr), m_sErrDesc(sErrDesc){}
   MelError(const MRESULT mr, const char  *sErrDesc): m_mr(mr),  m_sErrDesc(sErrDesc){}
   MelError(const MelError& melErr): m_mr(melErr.m_mr), m_sErrDesc(melErr.m_sErrDesc){}
   ~MelError(){}

   void         setErrCode(const MRESULT mr){ m_mr = mr;}
   MRESULT      getErrCode(){ return m_mr;}
   void         setErrDescription(const char*   sErrDesc){ m_sErrDesc = sErrDesc;}
   void         setErrDescription(const string& sErrDesc){ m_sErrDesc = sErrDesc;}
   string       getErrDescription(){ return m_sErrDesc;}
   
   string       getErrText();

protected:
   MRESULT  m_mr;
   string   m_sErrDesc;
};
#endif
