BaseError.hh 1.47 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
// (C) Copyright 2015 by Autodesk, Inc.
//
// The information contained herein is confidential, proprietary
// to Autodesk,  Inc.,  and considered a trade secret as defined
// in section 499C of the penal code of the State of California.
// Use of  this information  by  anyone  other  than  authorized
// employees of Autodesk, Inc.  is granted  only under a written
// non-disclosure agreement,  expressly  prescribing  the  scope
// and manner of such use.

#ifndef BASE_ERROR_HH_INCLUDED
#define BASE_ERROR_HH_INCLUDED

#include <Base/Utils/ThrowError.hh>

namespace Base {

class Error 
{
public:
  enum Index
  {
  #define DEFINE_ERROR(CODE, MSG) CODE,
  #include <Base/Utils/BaseErrorInc.hh>
  #undef DEFINE_ERROR
  };

public:
  //! Constructor.
  Error(const Index _idx) : idx_((int)_idx) {}

  // ! Get the outcome error index
  int index() const { return (int)idx_; }

  //! Return the error message 
  virtual const char* message() const;

  template <typename IndexT>
  bool operator==(const IndexT _idx) const { return (int)_idx == idx_; }

protected:
  int idx_;

protected:
  //! Constructor.
  Error(const int _idx) : idx_(_idx) {}
};

}//namespace BASE

#define BASE_THROW_ERROR(INDEX) { THROW_ERROR_MODULE(Base, INDEX); }
#define BASE_THROW_ERROR_if(COND, INDEX) { if (COND) THROW_ERROR(INDEX); }

#define BASE_THROW_ERROR_TODO(MSG) { THROW_ERROR_TODO_MODULE(Base, MSG); }
#define BASE_THROW_ERROR_TODO_if(COND, MSG) { if (COND) THROW_ERROR_TODO(MSG); }

#endif//BASE_ERROR_HH_INCLUDED