// __author__ = Juan Carlos De Abreu (jcabreur@gmail.com)
//

#ifndef BASE_MEMORY_MM_OBJECT_H__
#define BASE_MEMORY_MM_OBJECT_H__

#include "../../global.h"
#include "../../Includes/Basic.h"

BEGIN_TEG_NAMESPACE();

#define COLLECT_GARBAGE() IMMObject::CollectGarbage()
#define COLLECT_REMAINING_OBJECTS() IMMObject::CollectRemainingObjects()

// Interface Memory Managemer Object
class IMMObject {
 public:
  // Methods
  void AddRef();
  void Release();
  int getRefCount();
  static void CollectGarbage();
  static void CollectRemainingObjects();
  virtual int size() const = 0;

 protected:
  // IMMObject constructor and destructor.
  IMMObject();
  virtual ~IMMObject();

 private:
  // IMMObject attributes, lists with the live objects and dead obejects and
  // reference count to an object.
  static std::list<IMMObject *> liveObjects;
  static std::list<IMMObject *> deadObjects;
  int refCount;
};

// Define a quick macro to make things easier on derived classes.
#define AUTO_SIZE int size() const { return sizeof(*this); }

END_TEG_NAMESPACE();

#endif  // BASE_MEMORY_MM_OBJECT_H__
