diff --git a/src/gdd/gddAppFuncTable.h b/src/gdd/gddAppFuncTable.h index ddb5b3df4..175744919 100644 --- a/src/gdd/gddAppFuncTable.h +++ b/src/gdd/gddAppFuncTable.h @@ -29,6 +29,9 @@ * * History * $Log$ + * Revision 1.2 1996/08/13 23:13:35 jhill + * win NT changes + * * Revision 1.1 1996/07/10 23:44:12 jhill * moved here from src/cas/generic * @@ -67,7 +70,13 @@ template class gddAppFuncTable { public: - gddAppFuncTable(); + gddAppFuncTable() : pMFuncRead(NULL), appTableNElem(0u) {} + ~gddAppFuncTable() + { + if (this->pMFuncRead) { + delete [] this->pMFuncRead; + } + } // // typedef for the app read function to be called @@ -76,23 +85,28 @@ public: // // installReadFunc() - // (g++ gags when these are coded outside the class def?) // - gddAppFuncTableStatus installReadFunc(const unsigned type, gddAppReadFunc pMFuncIn) + gddAppFuncTableStatus installReadFunc(const unsigned type, + gddAppReadFunc pMFuncIn) { // // Attempt to expand the table if the app type will not fit // - if (type>=this->maxAppType) { + if (type>=this->appTableNElem) { this->newTbl(type); - if (type>=this->maxAppType) { + if (type>=this->appTableNElem) { return S_gddAppFuncTable_noMemory; } } this->pMFuncRead[type]=pMFuncIn; return S_gddAppFuncTable_Success; } - gddAppFuncTableStatus installReadFunc(const char * const pName, gddAppReadFunc pMFuncIn) + + // + // installReadFunc() + // + gddAppFuncTableStatus installReadFunc(const char * const pName, + gddAppReadFunc pMFuncIn) { aitUint32 type; gddStatus rc; @@ -114,6 +128,7 @@ public: // // gddAppFuncTableStatus read(PV &pv, gdd &value); + gddAppFuncTableStatus callReadFunc (PV &pv, gdd &value); private: // @@ -122,23 +137,11 @@ private: // expansion of the table) // gddAppReadFunc *pMFuncRead; - unsigned maxAppType; + unsigned appTableNElem; void newTbl(unsigned neMaxType); }; -// -// gddAppFuncTable::gddAppFuncTable() -// -// The total number of application tags to manage should be -// hidden from the application -// -template -inline gddAppFuncTable::gddAppFuncTable() : - pMFuncRead(NULL), - maxAppType(0u) -{ -} // // gddAppFuncTable::newTbl() @@ -151,35 +154,46 @@ inline void gddAppFuncTable::newTbl(unsigned newApplTypeMax) { gddAppReadFunc *pMNewFuncTbl; unsigned maxApp; + unsigned i; - if(this->maxAppType>=newApplTypeMax) { + if (this->appTableNElem>newApplTypeMax) { return; } maxApp = newApplTypeMax+(1u<<6u); - pMNewFuncTbl = new gddAppReadFunc[maxApp]; +#ifdef _MSC_VER +// +// Right now all MS Visual C++ compilers allocate the +// wrong amount of memory (i.e. too little) +// for member function pointers, +// only explicit calculation via sizeof() works. +// For future versions this may become "if _MSC_VER < ???"... +// + pMNewFuncTbl = (gddAppReadFunc *) + new char[sizeof(gddAppReadFunc) * maxApp]; +#else + pMNewFuncTbl = new gddAppReadFunc[maxApp]; +#endif if (pMNewFuncTbl) { - if (this->pMFuncRead) { - memcpy( pMNewFuncTbl, - this->pMFuncRead, - this->maxAppType*sizeof(*pMNewFuncTbl)); - delete [] this->pMFuncRead; - memset(&pMNewFuncTbl[this->maxAppType], 0, - (maxApp-this->maxAppType) * - sizeof(*pMNewFuncTbl)); + for (i=0u; iappTableNElem) { + pMNewFuncTbl[i] = this->pMFuncRead[i]; + } + else { + // + // some versions of NULL include (void *) cast + // (so I am using vanilla zero here) + // + pMNewFuncTbl[i] = 0; + } } - else { - memset(pMNewFuncTbl, 0, - maxApp * sizeof(*pMNewFuncTbl)); + if (this->pMFuncRead) { + delete [] this->pMFuncRead; } this->pMFuncRead = pMNewFuncTbl; - this->maxAppType = maxApp; + this->appTableNElem = maxApp; } } -// -// gddAppFuncTable::installReadFunc() -// - // // gddAppFuncTable::read() @@ -191,8 +205,6 @@ template inline gddAppFuncTableStatus gddAppFuncTable::read(PV &pv, gdd &value) { gddAppFuncTableStatus status; - gddAppReadFunc pFunc; - unsigned type; // // if this gdd is a container then step through it @@ -213,13 +225,24 @@ inline gddAppFuncTableStatus gddAppFuncTable::read(PV &pv, gdd &value) } return status; } + return callReadFunc(pv, value); +} + +// +// gddAppFuncTable::callReadFunc() +// +template +inline gddAppFuncTableStatus gddAppFuncTable::callReadFunc (PV &pv, gdd &value) +{ + unsigned type = value.applicationType(); + gddAppReadFunc pFunc; // // otherwise call the function associated // with this application type // type = value.applicationType(); - if (type>=this->maxAppType) { + if (type>=this->appTableNElem) { errPrintf (S_gddAppFuncTable_badType, __FILE__, __LINE__, "- large appl type code = %u\n", type); @@ -232,7 +255,6 @@ inline gddAppFuncTableStatus gddAppFuncTable::read(PV &pv, gdd &value) type); return S_gddAppFuncTable_badType; } - status = (pv.*pFunc)(value); - return status; + return (pv.*pFunc)(value); }