From 54782139c74c93f3915acfff23c434a5f37d9dae Mon Sep 17 00:00:00 2001 From: Marty Kraimer Date: Thu, 10 Feb 2011 07:46:38 -0500 Subject: [PATCH] simplified definition and implementation of PVAuxInfo. --- pvDataApp/factory/PVAuxInfoImpl.cpp | 92 +++++++++++------------ pvDataApp/factory/PVDataCreateFactory.cpp | 34 ++++----- pvDataApp/pv/pvData.h | 13 ++-- test/testPVAuxInfo | 14 +++- test/testPVAuxInfoGold | 14 +++- testApp/pv/testPVAuxInfo.cpp | 2 +- 6 files changed, 93 insertions(+), 76 deletions(-) diff --git a/pvDataApp/factory/PVAuxInfoImpl.cpp b/pvDataApp/factory/PVAuxInfoImpl.cpp index 57f9148..1aac070 100644 --- a/pvDataApp/factory/PVAuxInfoImpl.cpp +++ b/pvDataApp/factory/PVAuxInfoImpl.cpp @@ -19,68 +19,69 @@ namespace epics { namespace pvData { PVDATA_REFCOUNT_MONITOR_DEFINE(pvAuxInfo); -typedef std::map::const_iterator map_iterator; - -class PVAuxInfoPvt { -public: - PVAuxInfoPvt(PVField *pvField) - : pvField(pvField), - theMap(std::map()) - {} - PVField *pvField; - std::map theMap; -}; - PVAuxInfo::PVAuxInfo(PVField *pvField) -: pImpl(new PVAuxInfoPvt(pvField)) + : pvField(pvField),lengthInfo(1),numberInfo(0), + pvInfos(new PVScalar *[1]) { PVDATA_REFCOUNT_MONITOR_CONSTRUCT(pvAuxInfo); +} + +PVAuxInfo::~PVAuxInfo() +{ + PVDATA_REFCOUNT_MONITOR_DESTRUCT(pvAuxInfo); + for(int i=0; itheMap.begin(); - while(i!=pImpl->theMap.end()) { - PVScalar *value = i->second; - delete value; - i++; - } - delete pImpl; -} PVField * PVAuxInfo::getPVField() { - return pImpl->pvField; + return pvField; } PVScalar * PVAuxInfo::createInfo(String key,ScalarType scalarType) { - map_iterator i = pImpl->theMap.find(key); - while(i!=pImpl->theMap.end()) { - String message("AuxoInfo:create key "); - message += key.c_str(); - message += " already exists with scalarType "; - ScalarTypeFunc::toString(&message,scalarType); - pImpl->pvField->message(message,errorMessage); - i++; + for(int i=0; igetField()->getFieldName())==0) { + String message("AuxoInfo:create key "); + message += key.c_str(); + message += " already exists with scalarType "; + ScalarTypeFunc::toString(&message,scalarType); + pvField->message(message,errorMessage); + return 0; + } + } + if(lengthInfo==numberInfo) { + int newLength = lengthInfo+4; + PVScalar ** newInfos = new PVScalar *[newLength]; + lengthInfo = newLength; + for(int i=0; icreatePVScalar(0,key,scalarType); - pImpl->theMap.insert(std::pair(key, pvScalar)); + pvInfos[numberInfo++] = pvScalar; return pvScalar; - -} - -PVScalarMap PVAuxInfo::getInfos() -{ - return pImpl->theMap; } PVScalar * PVAuxInfo::getInfo(String key) { - map_iterator i = pImpl->theMap.find(key); - if(i!=pImpl->theMap.end()) return i->second; + for(int i=0; igetField()->getFieldName())==0) return pvScalar; + } return 0; } +PVScalar * PVAuxInfo::getInfo(int index) +{ + if(index<0 || index>=numberInfo) return 0; + return pvInfos[index]; +} + +int PVAuxInfo::getNumberInfo() { return numberInfo;} + void PVAuxInfo::toString(StringBuilder buf) { PVAuxInfo::toString(buf,0); @@ -88,17 +89,14 @@ void PVAuxInfo::toString(StringBuilder buf) void PVAuxInfo::toString(StringBuilder buf,int indentLevel) { - if(pImpl->theMap.empty()) return; + if(numberInfo==0) return; Convert *convert = getConvert(); convert->newLine(buf,indentLevel); *buf += "auxInfo"; - map_iterator i = pImpl->theMap.begin(); - while(i!=pImpl->theMap.end()) { + for(int i=0; inewLine(buf,indentLevel+1); - String key = i->first; - PVScalar *value = i->second; + PVScalar *value = pvInfos[i]; value->toString(buf,indentLevel + 1); - i++; } } }} diff --git a/pvDataApp/factory/PVDataCreateFactory.cpp b/pvDataApp/factory/PVDataCreateFactory.cpp index 15d648f..afb3721 100644 --- a/pvDataApp/factory/PVDataCreateFactory.cpp +++ b/pvDataApp/factory/PVDataCreateFactory.cpp @@ -437,15 +437,14 @@ PVScalar *PVDataCreate::createPVScalar(PVStructure *parent, PVScalar *pvScalar = createPVScalar(parent,fieldName, scalarToClone->getScalar()->getScalarType()); convert->copyScalar(scalarToClone, pvScalar); - PVScalarMap attributes = scalarToClone->getPVAuxInfo()->getInfos(); - PVAuxInfo *pvAttribute = pvScalar->getPVAuxInfo(); - PVScalarMapIter p; - for(p=attributes.begin(); p!=attributes.end(); p++) { - String key = p->first; - PVScalar *fromAttribute = p->second; - PVScalar *toAttribute = pvAttribute->createInfo(key, - fromAttribute->getScalar()->getScalarType()); - convert->copyScalar(fromAttribute,toAttribute); + PVAuxInfo *from = scalarToClone->getPVAuxInfo(); + PVAuxInfo *to = pvScalar->getPVAuxInfo(); + int numberInfo = from->getNumberInfo(); + for(int i=0; igetInfo(i); + ScalarConstPtr scalar = pvFrom->getScalar(); + PVScalar *pvTo = to->createInfo(scalar->getFieldName(),scalar->getScalarType()); + convert->copyScalar(pvFrom,pvTo); } return pvScalar; } @@ -490,15 +489,14 @@ PVScalarArray *PVDataCreate::createPVScalarArray(PVStructure *parent, PVScalarArray *pvArray = createPVScalarArray(parent,fieldName, arrayToClone->getScalarArray()->getElementType()); convert->copyScalarArray(arrayToClone,0, pvArray,0,arrayToClone->getLength()); - PVScalarMap attributes = arrayToClone->getPVAuxInfo()->getInfos(); - PVAuxInfo *pvAttribute = pvArray->getPVAuxInfo(); - PVScalarMapIter p; - for(p=attributes.begin(); p!=attributes.end(); p++) { - String key = p->first; - PVScalar *fromAttribute = p->second; - PVScalar *toAttribute = pvAttribute->createInfo(key, - fromAttribute->getScalar()->getScalarType()); - convert->copyScalar(fromAttribute,toAttribute); + PVAuxInfo *from = arrayToClone->getPVAuxInfo(); + PVAuxInfo *to = pvArray->getPVAuxInfo(); + int numberInfo = from->getNumberInfo(); + for(int i=0; igetInfo(i); + ScalarConstPtr scalar = pvFrom->getScalar(); + PVScalar *pvTo = to->createInfo(scalar->getFieldName(),scalar->getScalarType()); + convert->copyScalar(pvFrom,pvTo); } return pvArray; } diff --git a/pvDataApp/pv/pvData.h b/pvDataApp/pv/pvData.h index e001156..1e840cd 100644 --- a/pvDataApp/pv/pvData.h +++ b/pvDataApp/pv/pvData.h @@ -6,7 +6,6 @@ */ #include #include -#include #ifndef PVDATA_H #define PVDATA_H #include "pvType.h" @@ -28,8 +27,6 @@ class PVScalarArray; class PVStructure; class PVStructureArray; -typedef std::map PVScalarMap; -typedef PVScalarMap::const_iterator PVScalarMapIter; typedef PVStructure * PVStructurePtr; typedef PVStructurePtr* PVStructurePtrArray; typedef PVField* PVFieldPtr; @@ -41,12 +38,16 @@ public: ~PVAuxInfo(); PVField * getPVField(); PVScalar * createInfo(String key,ScalarType scalarType); - PVScalarMap getInfos(); - PVScalar * getInfo(String key); + int getNumberInfo(); + PVScalar * getInfo(String name); + PVScalar * getInfo(int index); void toString(StringBuilder buf); void toString(StringBuilder buf,int indentLevel); private: - class PVAuxInfoPvt *pImpl; + PVField *pvField; + int lengthInfo; + int numberInfo; + PVScalar **pvInfos; // ptr to array of PVscalar * friend class PVDataCreate; }; diff --git a/test/testPVAuxInfo b/test/testPVAuxInfo index 88b107a..1c4b375 100644 --- a/test/testPVAuxInfo +++ b/test/testPVAuxInfo @@ -18,7 +18,12 @@ structure value auxInfo string factory factoryName double junk 3 -value offset 0 next 15 number 15 + control control + structure limit + double low 0 + double high 0 + double minStep 0 +value offset 0 next 20 number 20 value offset 1 next 2 number 1 alarm offset 2 next 5 number 3 severity offset 3 next 4 number 1 @@ -33,6 +38,11 @@ units offset 11 next 12 number 1 limit offset 12 next 15 number 3 low offset 13 next 14 number 1 high offset 14 next 15 number 1 +control offset 15 next 20 number 5 +limit offset 16 next 19 number 3 +low offset 17 next 18 number 1 +high offset 18 next 19 number 1 +minStep offset 19 next 20 number 1 pvAuxInfo: totalConstruct 1 totalDestruct 1 -pvField: totalConstruct 17 totalDestruct 17 +pvField: totalConstruct 22 totalDestruct 22 field: totalConstruct 97 totalDestruct 97 diff --git a/test/testPVAuxInfoGold b/test/testPVAuxInfoGold index 88b107a..1c4b375 100644 --- a/test/testPVAuxInfoGold +++ b/test/testPVAuxInfoGold @@ -18,7 +18,12 @@ structure value auxInfo string factory factoryName double junk 3 -value offset 0 next 15 number 15 + control control + structure limit + double low 0 + double high 0 + double minStep 0 +value offset 0 next 20 number 20 value offset 1 next 2 number 1 alarm offset 2 next 5 number 3 severity offset 3 next 4 number 1 @@ -33,6 +38,11 @@ units offset 11 next 12 number 1 limit offset 12 next 15 number 3 low offset 13 next 14 number 1 high offset 14 next 15 number 1 +control offset 15 next 20 number 5 +limit offset 16 next 19 number 3 +low offset 17 next 18 number 1 +high offset 18 next 19 number 1 +minStep offset 19 next 20 number 1 pvAuxInfo: totalConstruct 1 totalDestruct 1 -pvField: totalConstruct 17 totalDestruct 17 +pvField: totalConstruct 22 totalDestruct 22 field: totalConstruct 97 totalDestruct 97 diff --git a/testApp/pv/testPVAuxInfo.cpp b/testApp/pv/testPVAuxInfo.cpp index f4913cc..40f3bff 100644 --- a/testApp/pv/testPVAuxInfo.cpp +++ b/testApp/pv/testPVAuxInfo.cpp @@ -58,7 +58,7 @@ static void printOffsets(PVStructure *pvStructure,FILE *fd) static void testPVAuxInfo(FILE * fd) { fprintf(fd,"\ntestPVAuxInfo\n"); PVStructure * pvStructure = standardPVField->scalar( - 0,String("value"),pvDouble,String("alarm,timeStamp,display,conytrol")); + 0,String("value"),pvDouble,String("alarm,timeStamp,display,control")); PVStructure *displayLimit = pvStructure->getStructureField( String("display.limit")); assert(displayLimit!=0);