#ifndef ZMENVIRONMENT_H #include "ZMutility/ZMenvironment.h" #endif #include "jlist.hh" #include "tag.hh" USING( namespace std ) JList::JList() : headPtr(NULL), total(0) { } void JList::add(HepHist* h, histType htype) { if (NULL == headPtr) { headPtr = new li(h, htype); total++; return; } li* currentPtr = headPtr; li* tmpPtr = 0; while (NULL != currentPtr) { tmpPtr = currentPtr; currentPtr = currentPtr->nextPtr; } currentPtr = new li(h, htype); tmpPtr->nextPtr = currentPtr; total++; return; } void JList::del(int id) { bool deleted = false; li* currentPtr = headPtr; li* tmpPtr = NULL; if (NULL == currentPtr) return; // empty list // check head of list if (currentPtr->index == id) { headPtr = currentPtr->nextPtr; delete currentPtr; deleted = true; } // check the rest of the list while (NULL != currentPtr->nextPtr) { if ((currentPtr->nextPtr)->index == id) { tmpPtr = (currentPtr->nextPtr)->nextPtr; delete currentPtr->nextPtr; currentPtr->nextPtr = tmpPtr; deleted = true; } currentPtr = (currentPtr->nextPtr); } if (deleted) total--; return; } JList::~JList() { li* currentPtr = headPtr; li** array = new li*[total]; for (int i = 0; i < total; i++) { array[i] = currentPtr; currentPtr = currentPtr->nextPtr; } for (int j = 0; j < total; j++) { delete array[j]; } delete [] array; } void JList::print() { cout << total << " Histograms listed by ID number:" << endl; li* currentPtr = headPtr; while (NULL != currentPtr) { cout << "\t" << currentPtr->index << "\t" << (currentPtr->h)->title(); if (currentPtr->htype == HEPHIST1D) cout << "\t" << "HepHist1D"; if (currentPtr->htype == HEPHIST2D) cout << "\t" << "HepHist2D"; if (currentPtr->htype == HEPHISTPROF) cout << "\t" << "HepHistProf"; cout << endl; currentPtr = currentPtr->nextPtr; } cout << endl; return; } li::li(HepHist* hist, histType t) : h(hist), index(hist->id()), nextPtr(NULL), htype(t) { } li::~li() { cout << "~li() called. Release histogram 0x" << hex << (long int)h << ". "; h->release(); cout << "Done." << endl; } HepHist* JList::getPtr(int id) { HepHist* h = NULL; li* currentPtr = headPtr; while (NULL != currentPtr) { if (currentPtr->index == id) { return currentPtr->h; } currentPtr = currentPtr->nextPtr; } return h; } histType JList::getType(int id) { li* currentPtr = headPtr; while (NULL != currentPtr) { if (currentPtr->index == id) { return currentPtr->htype; } currentPtr = currentPtr->nextPtr; } return (histType)OTHER; }