Heap.cc

Go to the documentation of this file.
00001 #include <esg/spacesorting/Heap.h>
00002 #include <esg/iterator/Iterator.h>
00003 #include <esg/iterator/IteratorHeap.h>
00004 
00005 using namespace esg;
00006 
00007 void Heap::_duplicate_attributes(const SDS& src)
00008 {
00009     SDS::_duplicate_attributes(src);
00010 }
00011 
00012 //----------- public --------------
00013 
00014 Heap::~Heap()
00015 {
00016     /*
00017     SceneGraphObject* pObj = _list.firstItem();
00018     while (pObj) {
00019         _list.remove(pObj);
00020         delete pObj;
00021         pObj = _list.firstItem();
00022     }
00023     */ // non-destructive delete of the list
00024 }
00025 
00026 SDS* Heap::clone() const
00027 {
00028     Heap* pRet = new Heap();
00029     pRet->_duplicate_attributes(*this);
00030     return pRet;
00031 }
00032 
00033 Iterator* Heap::createIterator()
00034 {
00035   return (Iterator*) new IteratorHeap(this);
00036 }
00037 
00038 int Heap::append(SceneGraphObject* pObj)
00039 {
00040     if (pObj) {
00041         if (pObj->tangible()) _list.append(pObj);
00042         else _intangibleChildren.append(pObj);
00043         return 1;
00044     } else
00045         return 0;
00046 }
00047 
00048 SceneGraphObject* Heap::detach(SceneGraphObject::OID oid)
00049 {
00050     for (SceneGraphObject* pObj=_list.firstItem();pObj;pObj=_list.nextItem())
00051         if (pObj->getOID() == oid) return pObj;
00052     return NULL;
00053 }
00054 
00055 void Heap::dump(const char* intent, const char* tab) 
00056 {
00057     char* newIntent = new char [strlen(intent) + strlen(tab) + 2];
00058     newIntent = strcpy(newIntent, intent);
00059     newIntent = strcat(newIntent, " ");
00060     newIntent = strcat(newIntent, tab);
00061     
00062     printf("%s spacialDataStructure Heap {\n", intent);
00063     printf("%s %s numObjects  %d\n", intent, tab, _list.length());
00064     for (SceneGraphObject* pObj = _list.firstItem();
00065          pObj;
00066          pObj = _list.nextItem())
00067     {
00068         if (pObj->geometry()) pObj->geometry()->dump(newIntent, tab);
00069     }
00070     printf("%s }\n", intent);
00071     
00072     delete [] newIntent;
00073 }
00074 
00075 
00076 
00077 
00078 
00079 

Generated on Wed Jun 28 12:24:31 2006 for esg by  doxygen 1.4.6