Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. #ifndef __yacasbase_h__
  2. #define __yacasbase_h__
  3. #include "yacasprivate.h"
  4.  
  5. /* /class YacasBase. All other objects should derive from YacasBase so that they use the correct
  6.  * operators new and delete. This ensures a Yacas-specific memory manager is used.
  7.  */
  8.  
  9. class YacasBase
  10. {
  11. public:
  12.   inline YacasBase() {};
  13. #ifdef YACAS_DEBUG
  14.   // New operators with additional debug arguments need to be handled differently
  15.   static inline void* operator new(size_t size, char* aFile, int aLine)
  16.     { return YacasMallocPrivate(size,aFile,aLine); }
  17.   static inline void* operator new[](size_t size, char* aFile, int aLine)
  18.     { return YacasMallocPrivate(size,aFile,aLine); }
  19. #else
  20.   // Normal versions of operator new
  21.   static inline void* operator new(size_t size)
  22.     { return PlatAlloc(size); }
  23.   static inline void* operator new[](size_t size)
  24.     { return PlatAlloc(size); }
  25. #endif
  26.   /* Operators delete are shared, they behave the same whether in debug or release (as
  27.      PlatFree is mapped to the debug version of freeing memory any way)
  28.    */
  29.   static inline void operator delete(void* object)
  30.     { PlatFree(object); }
  31.   static inline void operator delete[](void* object)
  32.     { PlatFree(object); }
  33.   // Placement form of new and delete.
  34.   static inline void* operator new(size_t, void* where) { return where; }
  35.   static inline void operator delete(void*, void*) {}
  36.  
  37.   /** If we don't want to force vtables, we can make the destructor inline and protected.
  38.    *  The following might cause a little bit of overhead but has the advantage that even
  39.    *  the compiler can see that this is safe (thus no unnecessary warnings). Preferrably
  40.    *  though this class has a protected inline destructor.
  41.    *
  42.    *  When I use Xcode on the MacOSX, I would prefer to not see the warnings that the
  43.    *  destructor of this class is not virtual, and speed is not the primary concern in
  44.    *  that build (as that build is used mostly for debugging).
  45.    *
  46.    *  HIDE_UNIMPORTANT_COMPILER_WARNINGS can be defined in case one wants to get rid of
  47.    *  compiler warnings, as opposed to having maximum running speed.
  48.    */
  49. protected:
  50. #ifdef HIDE_UNIMPORTANT_COMPILER_WARNINGS
  51.   virtual
  52. #else // HIDE_UNIMPORTANT_COMPILER_WARNINGS
  53.   inline
  54. #endif // HIDE_UNIMPORTANT_COMPILER_WARNINGS
  55.      ~YacasBase() {};
  56. };
  57.  
  58. #endif
  59.