diff --git a/src/gdd/gdd.cc b/src/gdd/gdd.cc index e27e10ed9..73f16d41d 100644 --- a/src/gdd/gdd.cc +++ b/src/gdd/gdd.cc @@ -4,6 +4,9 @@ // $Id$ // // $Log$ +// Revision 1.23 1997/08/05 00:51:11 jhill +// fixed problems in aitString and the conversion matrix +// // Revision 1.22 1997/06/25 06:17:34 jhill // fixed warnings // @@ -138,7 +141,14 @@ gdd::gdd(int app, aitEnum prim, int dimen, aitUint32* val) void gdd::init(int app, aitEnum prim, int dimen) { setApplType(app); - setPrimType(prim); + // + // joh - we intentionally dont call setPrimType() + // here because the assumption is that init() is only + // called from the constructor, and we dont want + // to destroy a non-existent string if the uninitialized + // prim type is a string + // + this->prim_type = prim; dim=(aitUint8)dimen; destruct=NULL; ref_cnt=1; @@ -162,6 +172,11 @@ void gdd::init(int app, aitEnum prim, int dimen) aitString* str=(aitString*)dataAddress(); str->init(); } + else if (primitiveType()==aitEnumFixedString) + { + this->data.FString = new aitFixedString; + memset (this->data.FString, '\0', sizeof(aitFixedString)); + } } gdd::gdd(gdd* dd) @@ -177,31 +192,7 @@ gdd::~gdd(void) // fprintf(stderr,"A gdd is really being deleted %8.8x!!\n",this); - // this function need to be corrected for use of aitEnumString! - - if(isScalar()) - { - if(primitiveType()==aitEnumFixedString) - { - // aitString type could have destructors - if(destruct) - destruct->destroy(dataPointer()); - else - if(data.FString) delete [] data.FString; - } - else if(primitiveType()==aitEnumString) - { - // aitString type could have destructors - if(destruct) - destruct->destroy(dataAddress()); - else - { - aitString* s = (aitString*)dataAddress(); - s->clear(); - } - } - } - else if(isContainer()) + if(isContainer()) { if(destruct) destruct->destroy(dataPointer()); @@ -221,8 +212,11 @@ gdd::~gdd(void) if(destruct) destruct->destroy(dataPointer()); if(bounds) freeBounds(); } - setPrimType(aitEnumInvalid); - setApplType(0); + // + // this destroys any scalar string data that may be present + // + this->setPrimType (aitEnumInvalid); + this->setApplType (0); } void gdd::freeBounds(void) @@ -419,6 +413,10 @@ gddStatus gdd::copyStuff(gdd* dd,int ctype) } else { + // + // OK to use init here because the clear() above set the + // scalar prim type to invalid and frees the old scalar strings + // init(dd->applicationType(),dd->primitiveType(),dd->dimension()); if(dd->isScalar()) @@ -1047,6 +1045,10 @@ gddStatus gdd::reset(aitEnum prim, int dimen, aitIndex* cnt) if((rc=clear())==0) { + // + // ok to use init here because the clear above frees + // all allocated resources + // init(app,prim,dimen); for(i=0;isetPrimType(aitEnumFixedString); + + if (data.FString!=NULL) + memcpy (data.FString->fixed_string, d.fixed_string, sizeof(d.fixed_string)); } else { - // this is so bad, like the other put() functions, need fixen - setPrimType(aitEnumFixedString); - data.FString=new aitFixedString; + gddAutoPrint("gdd::put(aitString&)",gddErrorNotAllowed); + rc=gddErrorNotAllowed; } - - memcpy(data.FString->fixed_string,d.fixed_string,sizeof(d.fixed_string)); return rc; } void gdd::putConvert(const aitString& d) { - if(primitiveType()==aitEnumInt8 && dim==1) - { - aitUint32 len = getDataSizeElements(); - char* cp = (char*)dataPointer(); - if(d.length()primitiveType()); - //setDimension(dd->dimension(),dd->getBounds()); - //} if(isScalar() && dd->isScalar()) { // this is the simple case - just make this scaler look like the other - set(dd->primitiveType(),dd->dataVoid()); + this->set(dd->primitiveType(),dd->dataVoid()); } else if(isScalar()) // dd must be atomic if this is true { - if((primitiveType()==aitEnumString || - primitiveType()==aitEnumFixedString) && - dd->primitiveType()==aitEnumInt8) - { - // special case for aitInt8--->aitString (hate this) - aitInt8* i1=(aitInt8*)dd->dataPointer(); - put(i1); - } - else - set(dd->primitiveType(),dd->dataPointer()); + this->set(dd->primitiveType(),dd->dataPointer()); } else if(dd->isScalar()) // this must be atomic if true { - if(primitiveType()==aitEnumInt8 && dd->primitiveType()==aitEnumString) - { - // special case for aitString--->aitInt8 - aitString* s1=(aitString*)dd->dataAddress(); - put(*s1); - } - else if(primitiveType()==aitEnumInt8 && - dd->primitiveType()==aitEnumFixedString) - { - // special case for aitFixedString--->aitInt8 - aitFixedString* s2=data.FString; - if(s2) put(*s2); - } + if(getDataSizeElements()>0) + aitConvert(primitiveType(),dataPointer(), + dd->primitiveType(),dd->dataVoid(),1); else { - if(getDataSizeElements()>0) - aitConvert(primitiveType(),dataPointer(), - dd->primitiveType(),dd->dataVoid(),1); + // this may expose an inconsistancy in the library. + // you can register a gdd with bounds and no data + // which marks it flat + + if(isFlat() || isManaged()) + { + gddAutoPrint("gdd::put(const gdd*)",gddErrorNotAllowed); + rc=gddErrorNotAllowed; + } else { - // this may expose an inconsistancy in the library. - // you can register a gdd with bounds and no data - // which marks it flat - - if(isFlat() || isManaged()) - { - gddAutoPrint("gdd::put(const gdd*)",gddErrorNotAllowed); - rc=gddErrorNotAllowed; - } - else - { - destroyData(); - set(dd->primitiveType(),dd->dataVoid()); - } + destroyData(); + set(dd->primitiveType(),dd->dataVoid()); } } } @@ -1298,7 +1223,7 @@ gddStatus gdd::put(const gdd* dd) // carefully place values from dd into this if(dataPointer()==NULL) { - if(isFlat() || isManaged() || isContainer()) + if(isFlat() || isManaged()) { gddAutoPrint("gdd::put(const gdd*)",gddErrorNotAllowed); rc=gddErrorNotAllowed; @@ -1549,3 +1474,78 @@ size_t gdd::in(void* buf, aitDataFormat f) } +// +// rewrote this to properly construct/destruct +// scalar string types when the prim type changes +// joh 05-22-98 +// +// +void gdd::setPrimType (aitEnum t) +{ + // + // NOOP if there is no change + // + if (this->prim_type == t) { + return; + } + + // + // run constructors/destructors for string data + // if it is scalar + // + if (isScalar()) + { + // + // run destructors for existing string data + // + if(primitiveType()==aitEnumFixedString) + { + // aitString type could have destructors + if(destruct) + destruct->destroy(dataPointer()); + else + if (data.FString) delete [] data.FString; + } + else if(primitiveType()==aitEnumString) + { + // aitString type could have destructors + if(destruct) + destruct->destroy(dataAddress()); + else + { + aitString* s = (aitString*)dataAddress(); + s->clear(); + } + } + + // + // run constructers for new string data types + // + if (t==aitEnumString) { + aitString* str=(aitString*)dataAddress(); + str->init(); + } + else if (t==aitEnumFixedString) { + this->data.FString = new aitFixedString; + memset (this->data.FString, '\0', sizeof(aitFixedString)); + } + } + + // + // I (joh) assume that Jim intended that + // calling of the destructors for arrays of string + // data when the primitive type changes is handled + // by the application. Not sure - nothing was done + // by Jim to take care of this as far as I can tell. + // + else if(isAtomic()) + { + } + + // + // I (joh) assume that nothing needs to be done when + // the primative type of a container changes + // + + this->prim_type = t; +} diff --git a/src/gdd/gddI.h b/src/gdd/gddI.h index d878c46ad..06b2c47dd 100644 --- a/src/gdd/gddI.h +++ b/src/gdd/gddI.h @@ -8,6 +8,9 @@ * $Id$ * * $Log$ + * Revision 1.2 1997/08/05 00:51:15 jhill + * fixed problems in aitString and the conversion matrix + * * Revision 1.1 1997/03/21 01:56:08 jbk * *** empty log message *** * @@ -30,7 +33,6 @@ inline void gdd::setNext(gdd* n) { nextgdd=n; } inline unsigned gdd::dimension(void) const { return dim; } inline aitType& gdd::getData(void) { return data; } inline aitType* gdd::dataUnion(void) { return &data; } -inline void gdd::setPrimType(aitEnum t) { prim_type=(aitUint8)t; } inline void gdd::setApplType(int t) { appl_type=(aitUint16)t; } inline gddStatus gdd::copyInfo(gdd* dd) { return copyStuff(dd,0); } inline gddStatus gdd::copy(gdd* dd) { return copyStuff(dd,1); } @@ -173,13 +175,12 @@ inline void gdd::destroyData(void) destruct=NULL; setData(NULL); } - else + else if (isScalar()) { - if(primitiveType()==aitEnumString && isScalar()) - { - aitString* str = (aitString*)dataAddress(); - str->clear(); - } + // + // this destroys the string types + // + this->setPrimType (aitEnumInvalid); } } @@ -225,14 +226,7 @@ inline void gdd::set(aitEnum t,const void* v,aitDataFormat) #endif { if (primitiveType()==aitEnumInvalid) { - this->prim_type = t; - if(t==aitEnumFixedString) - { - if(dataPointer()==NULL) - { - data.FString = new aitFixedString; - } - } + this->setPrimType (t); } #if aitLocalNetworkDataFormatSame == AIT_FALSE @@ -364,49 +358,49 @@ inline gddStatus gdd::put(const aitInt8* const d) // ----------------put(scalar) functions---------------- inline gddStatus gdd::put(aitFloat64 d) { gddStatus rc=0; - if(isScalar()) { data.Float64=d; setPrimType(aitEnumFloat64); } + if(isScalar()) { setPrimType(aitEnumFloat64); data.Float64=d; } else { rc=gddErrorNotAllowed; gddAutoPrint("gdd:put()",rc); } return rc; } inline gddStatus gdd::put(aitFloat32 d) { gddStatus rc=0; - if(isScalar()) { data.Float32=d;setPrimType(aitEnumFloat32); } + if(isScalar()) { setPrimType(aitEnumFloat32); data.Float32=d;} else { rc=gddErrorNotAllowed; gddAutoPrint("gdd:put()",rc); } return rc; } inline gddStatus gdd::put(aitUint32 d) { gddStatus rc=0; - if(isScalar()) { data.Uint32=d; setPrimType(aitEnumUint32); } + if(isScalar()) { setPrimType(aitEnumUint32); data.Uint32=d; } else { rc=gddErrorNotAllowed; gddAutoPrint("gdd:put()",rc); } return rc; } inline gddStatus gdd::put(aitInt32 d) { gddStatus rc=0; - if(isScalar()) { data.Int32=d; setPrimType(aitEnumInt32); } + if(isScalar()) { setPrimType(aitEnumInt32); data.Int32=d; } else { rc=gddErrorNotAllowed; gddAutoPrint("gdd:put()",rc); } return rc; } inline gddStatus gdd::put(aitUint16 d) { gddStatus rc=0; - if(isScalar()) { data.Uint16=d; setPrimType(aitEnumUint16); } + if(isScalar()) { setPrimType(aitEnumUint16); data.Uint16=d; } else { rc=gddErrorNotAllowed; gddAutoPrint("gdd:put()",rc); } return rc; } inline gddStatus gdd::put(aitInt16 d) { gddStatus rc=0; - if(isScalar()) { data.Int16=d; setPrimType(aitEnumInt16); } + if(isScalar()) { setPrimType(aitEnumInt16); data.Int16=d; } else { rc=gddErrorNotAllowed; gddAutoPrint("gdd:put()",rc); } return rc; } inline gddStatus gdd::put(aitUint8 d) { gddStatus rc=0; - if(isScalar()) { data.Uint8=d; setPrimType(aitEnumUint8); } + if(isScalar()) { setPrimType(aitEnumUint8); data.Uint8=d; } else { rc=gddErrorNotAllowed; gddAutoPrint("gdd:put()",rc); } return rc; } inline gddStatus gdd::put(aitInt8 d) { gddStatus rc=0; - if(isScalar()) { data.Int8=d; setPrimType(aitEnumInt8); } + if(isScalar()) { setPrimType(aitEnumInt8); data.Int8=d; } else { rc=gddErrorNotAllowed; gddAutoPrint("gdd:put()",rc); } return rc; } @@ -560,21 +554,21 @@ inline gdd& gdd::operator=(aitFixedString* v){ putRef(v); return *this;} // ----------------- gdd x = primitive data type functions---------------- inline gdd& gdd::operator=(aitFloat64 d) - { data.Float64=d; setPrimType(aitEnumFloat64); return *this; } + { setPrimType(aitEnumFloat64); data.Float64=d; return *this; } inline gdd& gdd::operator=(aitFloat32 d) - { data.Float32=d;setPrimType(aitEnumFloat32); return *this; } + { setPrimType(aitEnumFloat32); data.Float32=d;return *this; } inline gdd& gdd::operator=(aitUint32 d) - { data.Uint32=d; setPrimType(aitEnumUint32); return *this; } + { setPrimType(aitEnumUint32); data.Uint32=d; return *this; } inline gdd& gdd::operator=(aitInt32 d) - { data.Int32=d; setPrimType(aitEnumInt32); return *this; } + { setPrimType(aitEnumInt32); data.Int32=d; return *this; } inline gdd& gdd::operator=(aitUint16 d) - { data.Uint16=d; setPrimType(aitEnumUint16); return *this; } + { setPrimType(aitEnumUint16); data.Uint16=d; return *this; } inline gdd& gdd::operator=(aitInt16 d) - { data.Int16=d; setPrimType(aitEnumInt16); return *this; } + { setPrimType(aitEnumInt16); data.Int16=d; return *this; } inline gdd& gdd::operator=(aitUint8 d) - { data.Uint8=d; setPrimType(aitEnumUint8); return *this; } + { setPrimType(aitEnumUint8); data.Uint8=d; return *this; } inline gdd& gdd::operator=(aitInt8 d) - { data.Int8=d; setPrimType(aitEnumInt8); return *this; } + { setPrimType(aitEnumInt8); data.Int8=d; return *this; } inline gdd& gdd::operator=(const aitString& d) { put(d); return *this; }