#ifndef _IMGNODEBSP_H #define _IMGNODEBSP_H #include "IMGPrerequisites.h" #include "IMGBox2d.h" namespace IMG { // Fordward declaration... class _IMGExport NodeBsp; typedef ::boost::intrusive_ptr NodeBspPtr; namespace boost { void intrusive_ptr_add_ref(NodeBsp * p); void intrusive_ptr_release(NodeBsp * p); }; class NodeBsp { public: NodeBsp(); virtual ~NodeBsp(); Box2d* getBound(); void setBound(Box2d *box); NodeBspPtr getChild(int i); void setId(int id_); unsigned int getId() const; void setChild(NodeBspPtr node, int i); void print(); NodeBspPtr insert(int w, int h); NodeBspPtr get(NodeBspPtr node, int i); protected: bool fit; Box2d bound; NodeBspPtr child[2]; static unsigned int ID; int id; private: long references; friend void boost::intrusive_ptr_add_ref(NodeBsp * p); friend void boost::intrusive_ptr_release(NodeBsp * p); }; // class specific addref/release implementation // the two function overloads must be in the boost namespace on most compilers: namespace boost { inline void intrusive_ptr_add_ref(NodeBsp * p) { // increment reference count of object *p ++(p->references); } inline void intrusive_ptr_release(NodeBsp * p) { // decrement reference count, and delete object when reference count reaches 0 if (--(p->references) == 0) delete p; } } // namespace boost } #endif