diff --git a/pvDataApp/Makefile b/pvDataApp/Makefile index d8c4d1e..947e9c0 100644 --- a/pvDataApp/Makefile +++ b/pvDataApp/Makefile @@ -6,8 +6,6 @@ PVDATA = $(TOP)/pvDataApp/ SRC_DIRS += $(PVDATA)/misc INC += noDefaultMethods.h -INC += linkedListVoid.h -INC += linkedList.h INC += lock.h INC += requester.h INC += serialize.h @@ -18,10 +16,11 @@ INC += serializeHelper.h INC += event.h INC += thread.h INC += executor.h +INC += linkedList.h +INC += linkedListVoid.h INC += CDRMonitor.h INC += timeFunction.h INC += timer.h -INC += queueVoid.h INC += queue.h INC += messageQueue.h INC += destroyable.h @@ -29,7 +28,7 @@ INC += status.h INC += sharedPtr.h LIBSRCS += CDRMonitor.cpp -#LIBSRCS += byteBuffer.cpp +LIBSRCS += byteBuffer.cpp LIBSRCS += bitSet.cpp LIBSRCS += epicsException.cpp LIBSRCS += requester.cpp @@ -39,8 +38,6 @@ LIBSRCS += event.cpp LIBSRCS += executor.cpp LIBSRCS += timeFunction.cpp LIBSRCS += timer.cpp -LIBSRCS += queueVoid.cpp -LIBSRCS += messageQueue.cpp LIBSRCS += status.cpp SRC_DIRS += $(PVDATA)/pv @@ -56,14 +53,14 @@ SRC_DIRS += $(PVDATA)/factory INC += factory.h LIBSRCS += TypeFunc.cpp -LIBSRCS += PVAuxInfoImpl.cpp LIBSRCS += FieldCreateFactory.cpp +LIBSRCS += PVAuxInfoImpl.cpp LIBSRCS += PVField.cpp LIBSRCS += PVScalar.cpp LIBSRCS += PVArray.cpp LIBSRCS += PVScalarArray.cpp LIBSRCS += PVStructure.cpp -LIBSRCS += DefaultPVStructureArray.cpp +LIBSRCS += PVStructureArray.cpp LIBSRCS += PVDataCreateFactory.cpp LIBSRCS += Convert.cpp LIBSRCS += Compare.cpp @@ -97,7 +94,7 @@ LIBSRCS += bitSetUtil.cpp SRC_DIRS += $(PVDATA)/monitor INC += monitor.h INC += monitorQueue.h -LIBSRCS += monitorQueue.cpp +#LIBSRCS += monitorQueue.cpp LIBRARY=pvData diff --git a/pvDataApp/factory/Compare.cpp b/pvDataApp/factory/Compare.cpp index 01dcaa9..25b1e0f 100644 --- a/pvDataApp/factory/Compare.cpp +++ b/pvDataApp/factory/Compare.cpp @@ -56,30 +56,28 @@ bool operator==(const Scalar& a, const Scalar& b) { if(&a==&b) return true; - return a.getScalarType()==b.getScalarType() && a.getFieldName()==b.getFieldName(); + return a.getScalarType()==b.getScalarType(); } bool operator==(const ScalarArray& a, const ScalarArray& b) { if(&a==&b) return true; - return a.getElementType()==b.getElementType() && a.getFieldName()==b.getFieldName(); + return a.getElementType()==b.getElementType(); } bool operator==(const Structure& a, const Structure& b) { if(&a==&b) return true; - int nflds=a.getNumberFields(); + size_t nflds=a.getNumberFields(); if (b.getNumberFields()!=nflds) return false; - if (a.getFieldName()!=b.getFieldName()) - return false; // std::equals does not work, since FieldConstPtrArray is an array of shared_pointers FieldConstPtrArray af = a.getFields(); FieldConstPtrArray bf = b.getFields(); - for (int i = 0; i < nflds; i++) + for (size_t i = 0; i < nflds; i++) if (*(af[i].get()) != *(bf[i].get())) return false; return true; diff --git a/pvDataApp/factory/Convert.cpp b/pvDataApp/factory/Convert.cpp index 0491dbd..23ae619 100644 --- a/pvDataApp/factory/Convert.cpp +++ b/pvDataApp/factory/Convert.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -15,58 +16,377 @@ using std::tr1::static_pointer_cast; using std::tr1::const_pointer_cast; +using std::size_t; namespace epics { namespace pvData { -static Convert* convert = 0; -static PVDataCreate* pvDataCreate = 0; +static PVDataCreatePtr pvDataCreate; static String trueString("true"); static String falseString("false"); static String logicError("Logic error. Should never get here."); static String illegalScalarType("Illegal ScalarType"); +static ConvertPtr convert; + +template +T toScalar(PVScalarPtr &pv) +{ + ScalarConstPtr scalar = pv->getScalar(); + ScalarType scalarType = scalar->getScalarType(); + switch(scalarType) { + case pvBoolean: + throw std::logic_error(String("boolean can not be converted to scalar")); + case pvByte: { + PVBytePtr value = static_pointer_cast(pv); + return value->get(); + } + case pvShort: { + PVShortPtr value = static_pointer_cast(pv); + return value->get(); + } + case pvInt: { + PVIntPtr value = static_pointer_cast(pv); + return value->get(); + } + case pvLong: { + PVLongPtr value = static_pointer_cast(pv); + return value->get(); + } + case pvUByte: { + PVUBytePtr value = static_pointer_cast(pv); + return value->get(); + } + case pvUShort: { + PVUShortPtr value = static_pointer_cast(pv); + return value->get(); + } + case pvUInt: { + PVUIntPtr value = static_pointer_cast(pv); + return value->get(); + } + case pvULong: { + PVULongPtr value = static_pointer_cast(pv); + return value->get(); + } + case pvFloat: { + PVFloatPtr value = static_pointer_cast(pv); + return static_cast(value->get()); + } + case pvDouble: { + PVDoublePtr value = static_pointer_cast(pv); + return static_cast(value->get()); + } + case pvString: + throw std::logic_error(String("string can not be converted to byte")); + } + throw std::logic_error(logicError); +} + +int8 Convert::toByte(PVScalarPtr & pv) +{ + return toScalar(pv); +} + +int16 Convert::toShort(PVScalarPtr & pv) +{ + return toScalar(pv); +} + +int32 Convert::toInt(PVScalarPtr & pv) +{ + return toScalar(pv); +} + +int64 Convert::toLong(PVScalarPtr & pv) +{ + return toScalar(pv); +} + +uint8 Convert::toUByte(PVScalarPtr & pv) +{ + return toScalar(pv); +} + +uint16 Convert::toUShort(PVScalarPtr & pv) +{ + return toScalar(pv); +} + +uint32 Convert::toUInt(PVScalarPtr & pv) +{ + return toScalar(pv); +} + +uint64 Convert::toULong(PVScalarPtr &pv) +{ + return toScalar(pv); +} + +float Convert::toFloat(PVScalarPtr &pv) +{ + return toScalar(pv); +} + +double Convert::toDouble(PVScalarPtr& pv) +{ + return toScalar(pv); +} + +template +String scalarToString(T); + +template<> +String scalarToString(int8 value) +{ + char buffer[20]; + int ival = value; + sprintf(buffer,"%d",ival); + return String(buffer); +} + +template<> +String scalarToString(int16 value) +{ + char buffer[20]; + int ival = value; + sprintf(buffer,"%d",ival); + return String(buffer); +} + +template<> +String scalarToString(int32 value) +{ + char buffer[20]; + int ival = value; + sprintf(buffer,"%d",ival); + return String(buffer); +} + +template<> +String scalarToString(int64 value) +{ + char buffer[30]; + sprintf(buffer,"%lld",(long long)value); + return String(buffer); +} + +template<> +String scalarToString(uint8 value) +{ + char buffer[20]; + unsigned int ival = value; + sprintf(buffer,"%ud",ival); + return String(buffer); +} + +template<> +String scalarToString(uint16 value) +{ + char buffer[20]; + unsigned int ival = value; + sprintf(buffer,"%iud",ival); + return String(buffer); +} + +template<> +String scalarToString(uint32 value) +{ + char buffer[20]; + sprintf(buffer,"%ud",value); + return String(buffer); +} + +template<> +String scalarToString(uint64 value) +{ + char buffer[30]; + sprintf(buffer,"%llu",(unsigned long long)value); + return String(buffer); +} + +template<> +String scalarToString(float value) +{ + char buffer[40]; + sprintf(buffer,"%g",value); + return String(buffer); +} + +template<> +String scalarToString(double value) +{ + char buffer[40]; + sprintf(buffer,"%g",value); + return String(buffer); +} + +template +void fromScalar(PVScalarPtr &pv,T from) +{ + ScalarConstPtr scalar = pv->getScalar(); + ScalarType scalarType = scalar->getScalarType(); + switch(scalarType) { + case pvBoolean: + throw std::logic_error("byte can not be converted to boolean"); + case pvByte: { + PVBytePtr value = static_pointer_cast(pv); + value->put(from); return; + } + case pvShort: { + PVShortPtr value = static_pointer_cast(pv); + value->put(from); return; + } + case pvInt: { + PVIntPtr value = static_pointer_cast(pv); + value->put(from); return; + } + case pvLong: { + PVLongPtr value = static_pointer_cast(pv); + value->put(from); return; + } + case pvUByte: { + PVUBytePtr value = static_pointer_cast(pv); + value->put(from); return; + } + case pvUShort: { + PVUShortPtr value = static_pointer_cast(pv); + value->put(from); return; + } + case pvUInt: { + PVUIntPtr value = static_pointer_cast(pv); + value->put(from); return; + } + case pvULong: { + PVULongPtr value = static_pointer_cast(pv); + value->put(from); return; + } + case pvFloat: { + PVFloatPtr value = static_pointer_cast(pv); + value->put(from); return; + } + case pvDouble: { + PVDoublePtr value = static_pointer_cast(pv); + value->put(from); return; + } + case pvString: { + PVStringPtr pvvalue = static_pointer_cast(pv); + String value = scalarToString(from); + pvvalue->put(value); + return; + } + } + throw std::logic_error(logicError); +} + +void Convert::fromByte(PVScalarPtr &pv,int8 from) +{ + fromScalar(pv,from); +} + +void Convert::fromShort(PVScalarPtr &pv,int16 from) +{ + fromScalar(pv,from); +} + +void Convert::fromInt(PVScalarPtr &pv, int32 from) +{ + fromScalar(pv,from); +} + +void Convert::fromLong(PVScalarPtr &pv, int64 from) +{ + fromScalar(pv,from); +} + +void Convert::fromUByte(PVScalarPtr &pv,uint8 from) +{ + fromScalar(pv,from); +} + +void Convert::fromUShort(PVScalarPtr &pv,uint16 from) +{ + fromScalar(pv,from); +} + +void Convert::fromUInt(PVScalarPtr &pv, uint32 from) +{ + fromScalar(pv,from); +} + +void Convert::fromULong(PVScalarPtr &pv, uint64 from) +{ + fromScalar(pv,from); +} + +void Convert::fromFloat(PVScalarPtr &pv, float from) +{ + fromScalar(pv,from); +} + +void Convert::fromDouble(PVScalarPtr &pv, double from) +{ + fromScalar(pv,from); +} + + static bool convertEquals(PVField *a,PVField *b); -static int convertFromByteArray(PVScalarArray *pv, int offset, - int len,int8 from[], int fromOffset); -static int convertToByteArray(PVScalarArray *pv, int offset, - int len,int8 to[], int toOffset); -static int convertFromShortArray(PVScalarArray *pv, int offset, - int len,int16 from[], int fromOffset); -static int convertToShortArray(PVScalarArray *pv, int offset, - int len,int16 to[], int toOffset); -static int convertFromIntArray(PVScalarArray *pv, int offset, - int len,int32 from[], int fromOffset); -static int convertToIntArray(PVScalarArray *pv, int offset, - int len,int32 to[], int toOffset); -static int convertFromLongArray(PVScalarArray *pv, int offset, - int len,int64 from[], int fromOffset); -static int convertToLongArray(PVScalarArray * pv, int offset, - int len,int64 to[], int toOffset); -static int convertFromFloatArray(PVScalarArray *pv, int offset, - int len,float from[], int fromOffset); -static int convertToFloatArray(PVScalarArray * pv, int offset, - int len,float to[], int toOffset); -static int convertFromDoubleArray(PVScalarArray *pv, int offset, - int len,double from[], int fromOffset); -static int convertToDoubleArray(PVScalarArray * pv, int offset, - int len,double to[], int toOffset); -static int convertFromStringArray(PVScalarArray *pv, int offset, - int len,String from[], int fromOffset); -static int convertToStringArray(PVScalarArray * pv, int offset, - int len,String to[], int toOffset); +static size_t convertFromByteArray(PVScalarArray * pv, size_t offset, + size_t len,int8 from[], size_t fromOffset); +static size_t convertToByteArray(PVScalarArray *pv, size_t offset, + size_t len,int8 to[], size_t toOffset); +static size_t convertFromShortArray(PVScalarArray *pv, size_t offset, + size_t len,int16 from[], size_t fromOffset); +static size_t convertToShortArray(PVScalarArray *pv, size_t offset, + size_t len,int16 to[], size_t toOffset); +static size_t convertFromIntArray(PVScalarArray *pv, size_t offset, + size_t len,int32 from[], size_t fromOffset); +static size_t convertToIntArray(PVScalarArray *pv, size_t offset, + size_t len,int32 to[], size_t toOffset); +static size_t convertFromLongArray(PVScalarArray *pv, size_t offset, + size_t len,int64 from[], size_t fromOffset); +static size_t convertToLongArray(PVScalarArray * pv, size_t offset, + size_t len,int64 to[], size_t toOffset); +static size_t convertFromUByteArray(PVScalarArray * pv, size_t offset, + size_t len,uint8 from[], size_t fromOffset); +static size_t convertToUByteArray(PVScalarArray *pv, size_t offset, + size_t len,uint8 to[], size_t toOffset); +static size_t convertFromUShortArray(PVScalarArray *pv, size_t offset, + size_t len,uint16 from[], size_t fromOffset); +static size_t convertToUShortArray(PVScalarArray *pv, size_t offset, + size_t len,uint16 to[], size_t toOffset); +static size_t convertFromUIntArray(PVScalarArray *pv, size_t offset, + size_t len,uint32 from[], size_t fromOffset); +static size_t convertToUIntArray(PVScalarArray *pv, size_t offset, + size_t len,uint32 to[], size_t toOffset); +static size_t convertFromULongArray(PVScalarArray *pv, size_t offset, + size_t len,uint64 from[], size_t fromOffset); +static size_t convertToULongArray(PVScalarArray * pv, size_t offset, + size_t len,uint64 to[], size_t toOffset); +static size_t convertFromFloatArray(PVScalarArray *pv, size_t offset, + size_t len,float from[], size_t fromOffset); +static size_t convertToFloatArray(PVScalarArray * pv, size_t offset, + size_t len,float to[], size_t toOffset); +static size_t convertFromDoubleArray(PVScalarArray *pv, size_t offset, + size_t len,double from[], size_t fromOffset); +static size_t convertToDoubleArray(PVScalarArray *pv, size_t offset, + size_t len,double to[], size_t toOffset); +static size_t convertFromStringArray(PVScalarArray *pv, size_t offset, + size_t len,StringArray const & from, size_t fromOffset); +static size_t convertToStringArray(PVScalarArray *pv, size_t offset, + size_t len,StringArray const & to, size_t toOffset); static void convertToString(StringBuilder buffer, - PVField * pv,int indentLevel); + PVField *pv,int indentLevel); static void convertStructure(StringBuilder buffer, PVStructure *data,int indentLevel); static void convertArray(StringBuilder buffer, PVScalarArray * pv,int indentLevel); static void convertStructureArray(StringBuilder buffer, PVStructureArray * pvdata,int indentLevel); -static int copyArrayDataReference(PVScalarArray *from,PVArray *to); -static int copyNumericArray(PVScalarArray *from, - int offset, PVScalarArray *to, int toOffset, int len); +static size_t copyArrayDataReference(PVScalarArray *from,PVArray *to); +static size_t copyNumericArray(PVScalarArray *from, + size_t offset, PVScalarArray *to, size_t toOffset, size_t len); static std::vector split(String commaSeparatedList); @@ -82,7 +402,7 @@ static std::vector split(String commaSeparatedList) { std::vector valueList(numValues,""); index=0; for(size_t i=0; iempty(); - *buf += pvField->getField()->getFieldName(); + *buf += pvField->getFieldName(); PVStructure *parent; while((parent=pvField->getParent())!=0) { - pvField = pvField->getParent(); - String name = pvField->getField()->getFieldName(); + parent = pvField->getParent(); + String name = parent->getFieldName(); if(name.length()>0) { buf->insert(0,"."); buf->insert(0,name); @@ -109,44 +429,62 @@ void Convert::getFullName(StringBuilder buf,PVField * pvField) } } +bool Convert::equals(PVFieldPtr &a,PVFieldPtr &b) +{ + return convertEquals(a.get(),b.get()); +} + bool Convert::equals(PVField &a,PVField &b) { return convertEquals(&a,&b); } -void Convert::getString(StringBuilder buf,PVField * pvField,int indentLevel) +void Convert::getString(StringBuilder buf,PVFieldPtr & pvField,int indentLevel) +{ + convertToString(buf,pvField.get(),indentLevel); +} + +void Convert::getString(StringBuilder buf,PVFieldPtr & pvField) +{ + convertToString(buf,pvField.get(),0); +} + +void Convert::getString(StringBuilder buf,PVField *pvField,int indentLevel) { convertToString(buf,pvField,indentLevel); } -void Convert::getString(StringBuilder buf,PVField * pvField) +void Convert::getString(StringBuilder buf,PVField *pvField) { convertToString(buf,pvField,0); } -int Convert::fromString(PVStructure *pvStructure, std::vector& from, int fromStartIndex) +size_t Convert::fromString(PVStructurePtr &pvStructure, StringArray const & from, size_t fromStartIndex) { - int processed = 0; + size_t processed = 0; - PVFieldPtrArray fieldsData = pvStructure->getPVFields(); - if (fieldsData != 0) { - int length = pvStructure->getStructure()->getNumberFields(); - for(int i=0; igetPVFields(); + if (fieldsData.size() != 0) { + size_t length = pvStructure->getStructure()->getNumberFields(); + for(size_t i=0; igetField()->getType(); if(type==structure) { - int count = fromString(static_cast(fieldField), from, fromStartIndex); + PVStructurePtr pv = static_pointer_cast(fieldField); + size_t count = fromString(pv, from, fromStartIndex); processed += count; fromStartIndex += count; } else if(type==scalarArray) { - int count = fromString(static_cast(fieldField), from.at(fromStartIndex)); + PVScalarArrayPtr pv = static_pointer_cast(fieldField); + size_t count = fromString(pv, from.at(fromStartIndex)); processed += count; fromStartIndex += count; } else if(type==scalar) { - fromString(static_cast(fieldField), from.at(fromStartIndex++)); + PVScalarPtr pv = static_pointer_cast(fieldField); + fromString(pv, from.at(fromStartIndex++)); processed++; } else { @@ -162,20 +500,20 @@ int Convert::fromString(PVStructure *pvStructure, std::vector& from, int } -void Convert::fromString(PVScalar *pvScalar, String from) +void Convert::fromString(PVScalarPtr &pvScalar, String from) { ScalarConstPtr scalar = pvScalar->getScalar(); ScalarType scalarType = scalar->getScalarType(); switch(scalarType) { case pvBoolean: { - PVBoolean *pv = static_cast(pvScalar); + PVBooleanPtr pv = static_pointer_cast(pvScalar); bool value = ((from.compare("true")==0) ? true : false); pv->put(value); return; } case pvByte : { - PVByte *pv = static_cast(pvScalar); + PVBytePtr pv = static_pointer_cast(pvScalar); int ival; sscanf(from.c_str(),"%d",&ival); int8 value = ival; @@ -183,7 +521,7 @@ void Convert::fromString(PVScalar *pvScalar, String from) return; } case pvShort : { - PVShort *pv = static_cast(pvScalar); + PVShortPtr pv = static_pointer_cast(pvScalar); int ival; sscanf(from.c_str(),"%d",&ival); int16 value = ival; @@ -191,7 +529,7 @@ void Convert::fromString(PVScalar *pvScalar, String from) return; } case pvInt : { - PVInt *pv = static_cast(pvScalar); + PVIntPtr pv = static_pointer_cast(pvScalar); int ival; sscanf(from.c_str(),"%d",&ival); int32 value = ival; @@ -199,29 +537,61 @@ void Convert::fromString(PVScalar *pvScalar, String from) return; } case pvLong : { - PVLong *pv = static_cast(pvScalar); + PVLongPtr pv = static_pointer_cast(pvScalar); int64 ival; - sscanf(from.c_str(),"%lld",&ival); + sscanf(from.c_str(),"%lld",(long long *)&ival); int64 value = ival; pv->put(value); return; } + case pvUByte : { + PVUBytePtr pv = static_pointer_cast(pvScalar); + unsigned int ival; + sscanf(from.c_str(),"%u",&ival); + uint8 value = ival; + pv->put(value); + return; + } + case pvUShort : { + PVUShortPtr pv = static_pointer_cast(pvScalar); + unsigned int ival; + sscanf(from.c_str(),"%u",&ival); + uint16 value = ival; + pv->put(value); + return; + } + case pvUInt : { + PVUIntPtr pv = static_pointer_cast(pvScalar); + unsigned int ival; + sscanf(from.c_str(),"%u",&ival); + uint32 value = ival; + pv->put(value); + return; + } + case pvULong : { + PVULongPtr pv = static_pointer_cast(pvScalar); + unsigned long long ival; + sscanf(from.c_str(),"%llu",(long long unsigned int *)&ival); + uint64 value = ival; + pv->put(value); + return; + } case pvFloat : { - PVFloat *pv = static_cast(pvScalar); + PVFloatPtr pv = static_pointer_cast(pvScalar); float value; sscanf(from.c_str(),"%f",&value); pv->put(value); return; } case pvDouble : { - PVDouble*pv = static_cast(pvScalar); + PVDoublePtr pv = static_pointer_cast(pvScalar); double value; sscanf(from.c_str(),"%lf",&value); pv->put(value); return; } case pvString: { - PVString *value = static_cast(pvScalar); + PVStringPtr value = static_pointer_cast(pvScalar); value->put(from); return; } @@ -231,92 +601,106 @@ void Convert::fromString(PVScalar *pvScalar, String from) throw std::logic_error(message); } -int Convert::fromString(PVScalarArray *pv, String from) +size_t Convert::fromString(PVScalarArrayPtr &pv, String from) { if(from[0]=='[' && from[from.length()]==']') { - int offset = from.rfind(']'); + size_t offset = from.rfind(']'); from = from.substr(1, offset); } std::vector valueList = split(from); - int length = valueList.size(); - StringArray valueArray = new String[length]; - for(int i=0; isetLength(length); - delete[] valueArray; return length; } -int Convert::fromStringArray(PVScalarArray *pv, int offset, int length, - String from[], int fromOffset) +size_t Convert::fromStringArray(PVScalarArrayPtr &pv, size_t offset, size_t length, + StringArray const & from, size_t fromOffset) { - return convertFromStringArray(pv,offset,length,from,fromOffset); + return convertFromStringArray(pv.get(),offset,length,from,fromOffset); } -int Convert::toStringArray(PVScalarArray * pv, int offset, int length, - String to[], int toOffset) +size_t Convert::toStringArray(PVScalarArrayPtr & pv, size_t offset, size_t length, + StringArray const &to, size_t toOffset) { - return convertToStringArray(pv,offset,length,to,toOffset); + return convertToStringArray(pv.get(),offset,length,to,toOffset); } -bool Convert::isCopyCompatible(FieldConstPtr from, FieldConstPtr to) +bool Convert::isCopyCompatible(FieldConstPtr &from, FieldConstPtr &to) { if(from->getType()!=to->getType()) return false; switch(from->getType()) { - case scalar: - return isCopyScalarCompatible( - static_pointer_cast(from), - static_pointer_cast(to)); + case scalar: + { + ScalarConstPtr xxx = static_pointer_cast(from); + ScalarConstPtr yyy = static_pointer_cast(to); + return isCopyScalarCompatible(xxx,yyy); + } case scalarArray: - return isCopyScalarArrayCompatible( - static_pointer_cast(from), - static_pointer_cast(to)); + { + ScalarArrayConstPtr xxx = static_pointer_cast(from); + ScalarArrayConstPtr yyy = static_pointer_cast(to); + return isCopyScalarArrayCompatible(xxx,yyy); + } case structure: - return isCopyStructureCompatible( - static_pointer_cast(from), - static_pointer_cast(to)); + { + StructureConstPtr xxx = static_pointer_cast(from); + StructureConstPtr yyy = static_pointer_cast(to); + return isCopyStructureCompatible(xxx,yyy); + } case structureArray: - return isCopyStructureArrayCompatible( - static_pointer_cast(from), - static_pointer_cast(to)); + { + StructureArrayConstPtr xxx = static_pointer_cast(from); + StructureArrayConstPtr yyy = static_pointer_cast(to); + return isCopyStructureArrayCompatible(xxx,yyy); + } } String message("Convert::isCopyCompatible should never get here"); throw std::logic_error(message); } -void Convert::copy(PVField *from,PVField *to) +void Convert::copy(PVFieldPtr &from,PVFieldPtr &to) { switch(from->getField()->getType()) { case scalar: - copyScalar( - static_cast(from),static_cast(to)); - return; - case scalarArray: { - PVScalarArray *fromArray = static_cast(from); - PVScalarArray *toArray = static_cast(to); - int length = copyScalarArray(fromArray,0,toArray,0,fromArray->getLength()); - if(toArray->getLength()!=length) toArray->setLength(length); - return; - } + { + PVScalarPtr xxx = static_pointer_cast(from); + PVScalarPtr yyy = static_pointer_cast(to); + copyScalar(xxx,yyy); + return; + } + case scalarArray: + { + PVScalarArrayPtr fromArray = static_pointer_cast(from); + PVScalarArrayPtr toArray = static_pointer_cast(to); + size_t length = copyScalarArray(fromArray,0,toArray,0,fromArray->getLength()); + if(toArray->getLength()!=length) toArray->setLength(length); + return; + } case structure: - copyStructure(static_cast(from) , - static_cast(to)); - return; + { + PVStructurePtr xxx = static_pointer_cast(from); + PVStructurePtr yyy = static_pointer_cast(to); + copyStructure(xxx,yyy); + return; + } case structureArray: { - PVStructureArray *fromArray = static_cast(from); - PVStructureArray *toArray = static_cast(to); - copyStructureArray(fromArray,toArray); - return; - } + PVStructureArrayPtr fromArray = static_pointer_cast(from); + PVStructureArrayPtr toArray = static_pointer_cast(to); + copyStructureArray(fromArray,toArray); + return; + } } } bool Convert::isCopyScalarCompatible( - ScalarConstPtr fromField, ScalarConstPtr toField) + ScalarConstPtr& fromField, ScalarConstPtr& toField) { ScalarType fromScalarType = fromField->getScalarType(); ScalarType toScalarType = toField->getScalarType(); @@ -328,7 +712,7 @@ bool Convert::isCopyScalarCompatible( return false; } -void Convert::copyScalar(PVScalar *from, PVScalar *to) +void Convert::copyScalar(PVScalarPtr &from, PVScalarPtr &to) { if(to->isImmutable()) { if(from==to) return; @@ -345,59 +729,83 @@ void Convert::copyScalar(PVScalar *from, PVScalar *to) throw std::invalid_argument(message); } } - PVBoolean *data = static_cast(from); + PVBooleanPtr data = static_pointer_cast(from); if(toType==pvString) { - PVString *dataTo = static_cast(to); + PVStringPtr dataTo = static_pointer_cast(to); String buf(""); data->toString(&buf); dataTo->put(buf); } else { bool value = data->get(); - PVBoolean *dataTo = static_cast(to); + PVBooleanPtr dataTo = static_pointer_cast(to); dataTo->put(value); } return; } case pvByte : { - PVByte *data = static_cast(from); + PVBytePtr data = static_pointer_cast(from); int8 value = data->get(); - convert->fromByte(to,value); + fromByte(to,value); return; } case pvShort : { - PVShort *data = static_cast(from); - short value = data->get(); - convert->fromShort(to,value); + PVShortPtr data = static_pointer_cast(from); + int16 value = data->get(); + fromShort(to,value); return; } case pvInt :{ - PVInt *data = static_cast(from); - int value = data->get(); - convert->fromInt(to,value); + PVIntPtr data = static_pointer_cast(from); + int32 value = data->get(); + fromInt(to,value); return; } case pvLong : { - PVLong *data = static_cast(from); - long value = data->get(); - convert->fromLong(to,value); + PVLongPtr data = static_pointer_cast(from); + int64 value = data->get(); + fromLong(to,value); + return; + } + case pvUByte : { + PVUBytePtr data = static_pointer_cast(from); + uint8 value = data->get(); + fromUByte(to,value); + return; + } + case pvUShort : { + PVUShortPtr data = static_pointer_cast(from); + uint16 value = data->get(); + fromUShort(to,value); + return; + } + case pvUInt :{ + PVUIntPtr data = static_pointer_cast(from); + uint32 value = data->get(); + fromUInt(to,value); + return; + } + case pvULong : { + PVULongPtr data = static_pointer_cast(from); + uint64 value = data->get(); + fromULong(to,value); return; } case pvFloat : { - PVFloat *data = static_cast(from); + PVFloatPtr data = static_pointer_cast(from); float value = data->get(); - convert->fromFloat(to,value); + fromFloat(to,value); return; } case pvDouble : { - PVDouble *data = static_cast(from); + PVDoublePtr data = static_pointer_cast(from); double value = data->get(); - convert->fromDouble(to,value); + fromDouble(to,value); return; } case pvString: { - PVString *data = static_cast(from); + PVStringPtr data = static_pointer_cast(from); String value = data->get(); - convert->fromString(to,value); + fromString(to,value); return; } } @@ -405,8 +813,8 @@ void Convert::copyScalar(PVScalar *from, PVScalar *to) throw std::logic_error(message); } -bool Convert::isCopyScalarArrayCompatible(ScalarArrayConstPtr fromArray, - ScalarArrayConstPtr toArray) +bool Convert::isCopyScalarArrayCompatible(ScalarArrayConstPtr &fromArray, + ScalarArrayConstPtr &toArray) { ScalarType fromType = fromArray->getElementType(); ScalarType toType = toArray->getElementType(); @@ -418,9 +826,10 @@ bool Convert::isCopyScalarArrayCompatible(ScalarArrayConstPtr fromArray, return false; } -int Convert::copyScalarArray(PVScalarArray *from, int offset, - PVScalarArray *to, int toOffset, int length) +size_t Convert::copyScalarArray(PVScalarArrayPtr &from, size_t offset, + PVScalarArrayPtr &to, size_t toOffset, size_t length) { + if(to->isImmutable()) { if(from==to) return from->getLength(); String message("Convert.copyArray destination is immutable"); @@ -431,77 +840,75 @@ int Convert::copyScalarArray(PVScalarArray *from, int offset, if(from->isImmutable() && (fromElementType==toElementType)) { if(offset==0 && toOffset==0 && length==from->getLength()) { - return copyArrayDataReference(from,to); + return copyArrayDataReference(from.get(),to.get()); } } - int ncopy = 0; + size_t ncopy = 0; if(ScalarTypeFunc::isNumeric(fromElementType) && ScalarTypeFunc::isNumeric(toElementType)) { - return copyNumericArray(from,offset,to,toOffset,length); + return copyNumericArray(from.get(),offset,to.get(),toOffset,length); } else if(toElementType==pvBoolean && fromElementType==pvBoolean) { - PVBooleanArray *pvfrom = static_cast(from); - PVBooleanArray *pvto = static_cast(to); + PVBooleanArray *pvfrom = static_cast(from.get()); + PVBooleanArray *pvto = static_cast(to.get()); while(length>0) { - int num = 0; - BooleanArray data = 0; - int fromOffset = 0; - BooleanArrayData booleanArrayData = BooleanArrayData(); - num = pvfrom->get(offset,length,&booleanArrayData); - data = booleanArrayData.data; + size_t num = 0; + size_t fromOffset = 0; + BooleanArrayData booleanArrayData; + num = pvfrom->get(offset,length,booleanArrayData); + boolean * data = pvfrom->get(); fromOffset = booleanArrayData.offset; if(num<=0) return ncopy; while(num>0) { - int n = pvto->put(toOffset,num,data,fromOffset); + size_t n = pvto->put(toOffset,num,data,fromOffset); if(n<=0) return ncopy; length -= n; num -= n; ncopy+=n; offset += n; toOffset += n; } } return ncopy; } else if(toElementType==pvString && fromElementType==pvString) { - PVStringArray *pvfrom = static_cast(from); - PVStringArray *pvto = static_cast(to); + PVStringArray *pvfrom = static_cast(from.get()); + PVStringArray *pvto = static_cast(to.get()); while(length>0) { - int num = 0; + size_t num = 0; String *data; - int fromOffset = 0; - StringArrayData stringArrayData = StringArrayData(); - num = pvfrom->get(offset,length,&stringArrayData); - data = stringArrayData.data; + size_t fromOffset = 0; + StringArrayData stringArrayData; + num = pvfrom->get(offset,length,stringArrayData); + data = pvfrom->get(); fromOffset = stringArrayData.offset; if(num<=0) return ncopy; while(num>0) { - int n = pvto->put(toOffset,num,data,fromOffset); + size_t n = pvto->put(toOffset,num,data,fromOffset); if(n<=0) return ncopy; length -= n; num -= n; ncopy+=n; offset += n; toOffset += n; } } return ncopy; } else if(toElementType==pvString) { - PVStringArray *pvto = static_cast(to); + PVStringArray *pvto = static_cast(to.get()); ncopy = from->getLength(); if(ncopy>length) ncopy = length; - int num = ncopy; - String toData[1]; + size_t num = ncopy; + StringArray toData(1); while(num>0) { - convert->toStringArray(from,offset,1,toData,0); - if(pvto->put(toOffset,1,toData,0)<=0) break; + toStringArray(from,offset,1,toData,0); + if(pvto->put(toOffset,1,&toData[0],0)<=0) break; num--; offset++; toOffset++; } return ncopy; } else if(fromElementType==pvString) { - PVStringArray *pvfrom = static_cast(from); + PVStringArray *pvfrom = static_cast(from.get()); while(length>0) { - int num = 0; - String *data = 0; - int fromOffset = 0; - StringArrayData stringArrayData = StringArrayData(); - num = pvfrom->get(offset,length,&stringArrayData); - data = stringArrayData.data; + size_t num = 0; + size_t fromOffset = 0; + StringArrayData stringArrayData; + num = pvfrom->get(offset,length,stringArrayData); + StringArray const & data = stringArrayData.data; fromOffset = stringArrayData.offset; if(num<=0) return ncopy; while(num>0) { - int n = fromStringArray(to,toOffset,num,data,fromOffset); + size_t n = fromStringArray(to,toOffset,num,data,fromOffset); if(n<=0) return ncopy; length -= n; num -= n; ncopy+=n; offset += n; toOffset += n; } @@ -513,13 +920,13 @@ int Convert::copyScalarArray(PVScalarArray *from, int offset, } bool Convert::isCopyStructureCompatible( - StructureConstPtr fromStruct, StructureConstPtr toStruct) + StructureConstPtr &fromStruct, StructureConstPtr &toStruct) { FieldConstPtrArray fromFields = fromStruct->getFields(); FieldConstPtrArray toFields = toStruct->getFields(); - int length = fromStruct->getNumberFields(); + size_t length = fromStruct->getNumberFields(); if(length!=toStruct->getNumberFields()) return false; - for(int i=0; igetType(); @@ -527,34 +934,39 @@ bool Convert::isCopyStructureCompatible( if(fromType!=toType) return false; switch(fromType) { case scalar: - if(!convert->isCopyScalarCompatible( - static_pointer_cast(from), - static_pointer_cast(to))) - return false; + { + ScalarConstPtr xxx = static_pointer_cast(from); + ScalarConstPtr yyy = static_pointer_cast(to); + if(!isCopyScalarCompatible(xxx,yyy)) return false; + } break; case scalarArray: - if(!isCopyScalarArrayCompatible( - static_pointer_cast(from), - static_pointer_cast(to))) - return false; + { + ScalarArrayConstPtr xxx = static_pointer_cast(from); + ScalarArrayConstPtr yyy = static_pointer_cast(to); + if(!isCopyScalarArrayCompatible(xxx,yyy)) return false; + } break; case structure: - if(!isCopyStructureCompatible( - static_pointer_cast(from), - static_pointer_cast(to))) - return false; + { + StructureConstPtr xxx = static_pointer_cast(from); + StructureConstPtr yyy = static_pointer_cast(to); + if(!isCopyStructureCompatible(xxx,yyy)) return false; + } break; case structureArray: - if(!isCopyStructureArrayCompatible( - static_pointer_cast(from), - static_pointer_cast(to))) - return false; + { + StructureArrayConstPtr xxx = static_pointer_cast(from); + StructureArrayConstPtr yyy = static_pointer_cast(to); + if(!isCopyStructureArrayCompatible(xxx,yyy)) return false; + } + break; } } return true; } -void Convert::copyStructure(PVStructure *from, PVStructure *to) +void Convert::copyStructure(PVStructurePtr &from, PVStructurePtr &to) { if(to->isImmutable()) { if(from==to) return; @@ -562,41 +974,41 @@ void Convert::copyStructure(PVStructure *from, PVStructure *to) throw std::invalid_argument(message); } if(from==to) return; - PVFieldPtrArray fromDatas = from->getPVFields(); - PVFieldPtrArray toDatas = to->getPVFields(); + PVFieldPtrArray const & fromDatas = from->getPVFields(); + PVFieldPtrArray const & toDatas = to->getPVFields(); if(from->getStructure()->getNumberFields() != to->getStructure()->getNumberFields()) { String message("Convert.copyStructure Illegal copyStructure"); throw std::invalid_argument(message); } - int numberFields = from->getStructure()->getNumberFields(); - if(numberFields==2) { + size_t numberFields = from->getStructure()->getNumberFields(); + if(numberFields>=2) { + String name0 = fromDatas[0]->getFieldName(); + String name1 = fromDatas[1]->getFieldName(); // look for enumerated structure and copy choices first - String fieldName = fromDatas[0]->getField()->getFieldName(); - if(fieldName.compare("index")==0) { + if(name0.compare("index")==0 && name1.compare("choices")==0) { FieldConstPtr fieldIndex = fromDatas[0]->getField(); FieldConstPtr fieldChoices = fromDatas[1]->getField(); if(fieldIndex->getType()==scalar - && (fieldChoices->getFieldName().compare("choices")==0) && fieldChoices->getType()==scalarArray) { - PVScalar *pvScalar = static_cast(fromDatas[0]); - PVScalarArray *pvArray = - static_cast(fromDatas[1]); + PVScalarPtr pvScalar = static_pointer_cast(fromDatas[0]); + PVScalarArrayPtr pvArray = + static_pointer_cast(fromDatas[1]); if((pvScalar->getScalar()->getScalarType()==pvInt) && (pvArray->getScalarArray()->getElementType()==pvString)) { - PVScalarArray* toArray = - static_cast(toDatas[1]); + PVScalarArrayPtr toArray = + static_pointer_cast(toDatas[1]); copyScalarArray(pvArray,0,toArray,0,pvArray->getLength()); - PVScalar *toScalar = static_cast(toDatas[0]); + PVScalarPtr toScalar = static_pointer_cast(toDatas[0]); copyScalar(pvScalar,toScalar); return; } } } } - for(int i=0; i < numberFields; i++) { - PVField *fromData = fromDatas[i]; - PVField *toData = toDatas[i]; + for(size_t i=0; i < numberFields; i++) { + PVFieldPtr fromData = fromDatas[i]; + PVFieldPtr toData = toDatas[i]; Type fromType = fromData->getField()->getType(); Type toType = toData->getField()->getType(); if(fromType!=toType) { @@ -605,72 +1017,74 @@ void Convert::copyStructure(PVStructure *from, PVStructure *to) } switch(fromType) { case scalar: - copyScalar( - static_cast(fromData), - static_cast(toData)); - break; - case scalarArray: { - PVScalarArray *fromArray = static_cast(fromData); - PVScalarArray *toArray = static_cast(toData); - int length = copyScalarArray( - fromArray,0,toArray,0,fromArray->getLength()); - if(toArray->getLength()!=length) toArray->setLength(length); - break; - } + { + PVScalarPtr xxx = static_pointer_cast(fromData); + PVScalarPtr yyy = static_pointer_cast(toData); + copyScalar(xxx,yyy); + break; + } + case scalarArray: + { + PVScalarArrayPtr fromArray = static_pointer_cast(fromData); + PVScalarArrayPtr toArray = static_pointer_cast(toData); + size_t length = copyScalarArray( + fromArray,0,toArray,0,fromArray->getLength()); + if(toArray->getLength()!=length) toArray->setLength(length); + break; + } case structure: - copyStructure( - static_cast(fromData), - static_cast(toData)); - break; - case structureArray: { - PVStructureArray *fromArray = - static_cast(fromData); - PVStructureArray *toArray = - static_cast(toData); - copyStructureArray(fromArray,toArray); - break; - } + { + PVStructurePtr xxx = static_pointer_cast(fromData); + PVStructurePtr yyy = static_pointer_cast(toData); + copyStructure(xxx,yyy); + break; + } + case structureArray: + { + PVStructureArrayPtr fromArray = + static_pointer_cast(fromData); + PVStructureArrayPtr toArray = + static_pointer_cast(toData); + copyStructureArray(fromArray,toArray); + break; + } } } } bool Convert::isCopyStructureArrayCompatible( - StructureArrayConstPtr from, StructureArrayConstPtr to) + StructureArrayConstPtr &from, StructureArrayConstPtr &to) { - return isCopyStructureCompatible(from->getStructure(),to->getStructure()); + StructureConstPtr xxx = from->getStructure(); + StructureConstPtr yyy = to->getStructure(); + return isCopyStructureCompatible(xxx,yyy); } void Convert::copyStructureArray( - PVStructureArray *from, PVStructureArray *to) + PVStructureArrayPtr &from, PVStructureArrayPtr &to) { if(to->isImmutable()) { if(from==to) return; String message("Convert.copyStructureArray destination is immutable"); throw std::invalid_argument(message); } - if(!isCopyStructureCompatible( - from->getStructureArray()->getStructure(), - to->getStructureArray()->getStructure())) { + StructureConstPtr xxx = from->getStructureArray()->getStructure(); + StructureConstPtr yyy = to->getStructureArray()->getStructure(); + if(!isCopyStructureCompatible(xxx,yyy)) { String message("Convert.copyStructureArray from and to are not compatible"); throw std::invalid_argument(message); } - PVStructurePtrArray fromArray = 0; - int length = from->getLength(); - StructureArrayData structureArrayData = StructureArrayData(); - from->get(0, length,&structureArrayData); - fromArray = structureArrayData.data; - PVStructurePtrArray toArray = 0; + size_t length = from->getLength(); if(to->getCapacity()setCapacity(length); - to->get(0, length,&structureArrayData); - toArray = structureArrayData.data; - for(int i=0; iget(); + PVStructurePtr * toArray = to->get(); + for(size_t i=0; igetStructureArray()->getStructure(); - toArray[i] = pvDataCreate->createPVStructure(0,structure); + toArray[i] = pvDataCreate->createPVStructure(structure); } copyStructure(fromArray[i],toArray[i]); } @@ -679,229 +1093,7 @@ void Convert::copyStructureArray( to->postPut(); } -int8 Convert::toByte(PVScalar * pv) -{ - ScalarConstPtr scalar = pv->getScalar(); - ScalarType scalarType = scalar->getScalarType(); - switch(scalarType) { - case pvBoolean: - throw std::logic_error(String("boolean can not be converted to byte")); - case pvByte: { - PVByte *value = static_cast(pv); - return value->get(); - } - case pvShort: { - PVShort *value = static_cast(pv); - return value->get(); - } - case pvInt: { - PVInt *value = static_cast(pv); - return value->get(); - } - case pvLong: { - PVLong *value = static_cast(pv); - return value->get(); - } - case pvFloat: { - PVFloat *value = static_cast(pv); - return static_cast(value->get()); - } - case pvDouble: { - PVDouble *value = static_cast(pv); - return static_cast(value->get()); - } - case pvString: - throw std::logic_error(String("string can not be converted to byte")); - } - throw std::logic_error(logicError); -} - -int16 Convert::toShort(PVScalar * pv) -{ - ScalarConstPtr scalar = pv->getScalar(); - ScalarType scalarType = scalar->getScalarType(); - switch(scalarType) { - case pvBoolean: - throw std::logic_error(String("boolean can not be converted to short")); - case pvByte: { - PVByte *value = static_cast(pv); - return value->get(); - } - case pvShort: { - PVShort *value = static_cast(pv); - return value->get(); - } - case pvInt: { - PVInt *value = static_cast(pv); - return value->get(); - } - case pvLong: { - PVLong *value = static_cast(pv); - return value->get(); - } - case pvFloat: { - PVFloat *value = static_cast(pv); - return static_cast(value->get()); - } - case pvDouble: { - PVDouble *value = static_cast(pv); - return static_cast(value->get()); - } - case pvString: - throw std::logic_error(String("string can not be converted to short")); - } - throw std::logic_error(logicError); -} - -int32 Convert::toInt(PVScalar * pv) -{ - ScalarConstPtr scalar = pv->getScalar(); - ScalarType scalarType = scalar->getScalarType(); - switch(scalarType) { - case pvBoolean: - throw std::logic_error(String("boolean can not be converted to int")); - case pvByte: { - PVByte *value = static_cast(pv); - return value->get(); - } - case pvShort: { - PVShort *value = static_cast(pv); - return value->get(); - } - case pvInt: { - PVInt *value = static_cast(pv); - return value->get(); - } - case pvLong: { - PVLong *value = static_cast(pv); - return value->get(); - } - case pvFloat: { - PVFloat *value = static_cast(pv); - return static_cast(value->get()); - } - case pvDouble: { - PVDouble *value = static_cast(pv); - return static_cast(value->get()); - } - case pvString: - throw std::logic_error(String("string can not be converted to int")); - } - throw std::logic_error(logicError); -} - -int64 Convert::toLong(PVScalar * pv) -{ - ScalarConstPtr scalar = pv->getScalar(); - ScalarType scalarType = scalar->getScalarType(); - switch(scalarType) { - case pvBoolean: - throw std::logic_error(String("boolean can not be converted to long")); - case pvByte: { - PVByte *value = static_cast(pv); - return value->get(); - } - case pvShort: { - PVShort *value = static_cast(pv); - return value->get(); - } - case pvInt: { - PVInt *value = static_cast(pv); - return value->get(); - } - case pvLong: { - PVLong *value = static_cast(pv); - return value->get(); - } - case pvFloat: { - PVFloat *value = static_cast(pv); - return static_cast(value->get()); - } - case pvDouble: { - PVDouble *value = static_cast(pv); - return static_cast(value->get()); - } - case pvString: - throw std::logic_error(String("string can not be converted to long")); - } - throw std::logic_error(logicError); -} - -float Convert::toFloat(PVScalar * pv) -{ - ScalarConstPtr scalar = pv->getScalar(); - ScalarType scalarType = scalar->getScalarType(); - switch(scalarType) { - case pvBoolean: - throw std::logic_error(String("boolean can not be converted to float")); - case pvByte: { - PVByte *value = static_cast(pv); - return value->get(); - } - case pvShort: { - PVShort *value = static_cast(pv); - return value->get(); - } - case pvInt: { - PVInt *value = static_cast(pv); - return value->get(); - } - case pvLong: { - PVLong *value = static_cast(pv); - return value->get(); - } - case pvFloat: { - PVFloat *value = static_cast(pv); - return value->get(); - } - case pvDouble: { - PVDouble *value = static_cast(pv); - return value->get(); - } - case pvString: - throw std::logic_error(String("string can not be converted to float")); - } - throw std::logic_error(logicError); -} - -double Convert::toDouble(PVScalar * pv) -{ - ScalarConstPtr scalar = pv->getScalar(); - ScalarType scalarType = scalar->getScalarType(); - switch(scalarType) { - case pvBoolean: - throw std::logic_error(String("boolean can not be converted to double")); - case pvByte: { - PVByte *value = static_cast(pv); - return value->get(); - } - case pvShort: { - PVShort *value = static_cast(pv); - return value->get(); - } - case pvInt: { - PVInt *value = static_cast(pv); - return value->get(); - } - case pvLong: { - PVLong *value = static_cast(pv); - return value->get(); - } - case pvFloat: { - PVFloat *value = static_cast(pv); - return value->get(); - } - case pvDouble: { - PVDouble *value = static_cast(pv); - return value->get(); - } - case pvString: - throw std::logic_error(String("string can not be converted to double")); - } - throw std::logic_error(logicError); -} - -String Convert::toString(PVScalar * pv) +String Convert::toString(PVScalarPtr & pv) { static String trueString("true"); static String falseString("false"); @@ -910,388 +1102,196 @@ String Convert::toString(PVScalar * pv) ScalarType scalarType = scalar->getScalarType(); switch(scalarType) { case pvBoolean: { - PVBoolean *pvalue = static_cast(pv); - bool value = pvalue->get(); + PVBooleanPtr pvalue = static_pointer_cast(pv); + boolean value = pvalue->get(); return value ? trueString : falseString; } case pvByte: { - PVByte *value = static_cast(pv); + PVBytePtr value = static_pointer_cast(pv); char buffer[30]; - sprintf(buffer,"%d",(int)value->get()); + sprintf(buffer,"%d",(int32)value->get()); return String(buffer); } case pvShort: { - PVShort *value = static_cast(pv); + PVShortPtr value = static_pointer_cast(pv); char buffer[30]; - sprintf(buffer,"%d",(int)value->get()); + sprintf(buffer,"%d",(int32)value->get()); return String(buffer); } case pvInt: { - PVInt *value = static_cast(pv); + PVIntPtr value = static_pointer_cast(pv); char buffer[30]; - sprintf(buffer,"%d",value->get()); + sprintf(buffer,"%d",(int32)value->get()); return String(buffer); } case pvLong: { - PVLong *value = static_cast(pv); + PVLongPtr value = static_pointer_cast(pv); char buffer[30]; - sprintf(buffer,"%lli",value->get()); + sprintf(buffer,"%lli",(long long int)value->get()); + return String(buffer); + } + case pvUByte: { + PVUBytePtr value = static_pointer_cast(pv); + char buffer[30]; + sprintf(buffer,"%u",(uint32)value->get()); + return String(buffer); + } + case pvUShort: { + PVUShortPtr value = static_pointer_cast(pv); + char buffer[30]; + sprintf(buffer,"%u",(uint32)value->get()); + return String(buffer); + } + case pvUInt: { + PVUIntPtr value = static_pointer_cast(pv); + char buffer[30]; + sprintf(buffer,"%u",value->get()); + return String(buffer); + } + case pvULong: { + PVULongPtr value = static_pointer_cast(pv); + char buffer[30]; + sprintf(buffer,"%llu",(unsigned long long int)value->get()); return String(buffer); } case pvFloat: { - PVFloat *value = static_cast(pv); + PVFloatPtr value = static_pointer_cast(pv); char buffer[30]; sprintf(buffer,"%g",value->get()); return String(buffer); } case pvDouble: { - PVDouble *value = static_cast(pv); + PVDoublePtr value = static_pointer_cast(pv); char buffer[30]; sprintf(buffer,"%lg",value->get()); return String(buffer); } case pvString: { - PVString *value = static_cast(pv); + PVStringPtr value = static_pointer_cast(pv); return value->get(); } } throw std::logic_error(logicError); } -void Convert::fromByte(PVScalar *pv,int8 from) +size_t Convert::toByteArray(PVScalarArrayPtr &pv, size_t offset, size_t length, + int8 to[], size_t toOffset) { - ScalarConstPtr scalar = pv->getScalar(); - ScalarType scalarType = scalar->getScalarType(); - switch(scalarType) { - case pvBoolean: - throw std::logic_error(String("byte can not be converted to boolean")); - case pvByte: { - PVByte *value = static_cast(pv); - value->put(from); return; - } - case pvShort: { - PVShort *value = static_cast(pv); - value->put(from); return; - } - case pvInt: { - PVInt *value = static_cast(pv); - value->put(from); return; - } - case pvLong: { - PVLong *value = static_cast(pv); - value->put(from); return; - } - case pvFloat: { - PVFloat *value = static_cast(pv); - value->put(from); return; - } - case pvDouble: { - PVDouble *value = static_cast(pv); - value->put(from); return; - } - case pvString: { - PVString *value = static_cast(pv); - char buffer[20]; - int ival = from; - sprintf(buffer,"%d",ival); - String xxx(buffer); - value->put(xxx); - return; - } - } - throw std::logic_error(logicError); + return convertToByteArray(pv.get(), offset, length, to, toOffset); } -void Convert::fromShort(PVScalar *pv,int16 from) +size_t Convert::toShortArray(PVScalarArrayPtr &pv, size_t offset, size_t length, + int16 to[], size_t toOffset) { - ScalarConstPtr scalar = pv->getScalar(); - ScalarType scalarType = scalar->getScalarType(); - switch(scalarType) { - case pvBoolean: - throw std::logic_error(String("short can not be converted to boolean")); - case pvByte: { - PVByte *value = static_cast(pv); - value->put(from); return; - } - case pvShort: { - PVShort *value = static_cast(pv); - value->put(from); return; - } - case pvInt: { - PVInt *value = static_cast(pv); - value->put(from); return; - } - case pvLong: { - PVLong *value = static_cast(pv); - value->put(from); return; - } - case pvFloat: { - PVFloat *value = static_cast(pv); - value->put(from); return; - } - case pvDouble: { - PVDouble *value = static_cast(pv); - value->put(from); return; - } - case pvString: { - PVString *value = static_cast(pv); - char buffer[20]; - int ival = from; - sprintf(buffer,"%d",ival); - String xxx(buffer); - value->put(xxx); - return; - } - } - throw std::logic_error(logicError); + return convertToShortArray(pv.get(), offset, length, to, toOffset); } -void Convert::fromInt(PVScalar *pv, int32 from) +size_t Convert::toIntArray(PVScalarArrayPtr &pv, size_t offset, size_t length, + int32 to[], size_t toOffset) { - ScalarConstPtr scalar = pv->getScalar(); - ScalarType scalarType = scalar->getScalarType(); - switch(scalarType) { - case pvBoolean: - throw std::logic_error(String("int can not be converted to boolean")); - case pvByte: { - PVByte *value = static_cast(pv); - value->put(from); return; - } - case pvShort: { - PVShort *value = static_cast(pv); - value->put(from); return; - } - case pvInt: { - PVInt *value = static_cast(pv); - value->put(from); return; - } - case pvLong: { - PVLong *value = static_cast(pv); - value->put(from); return; - } - case pvFloat: { - PVFloat *value = static_cast(pv); - value->put(from); return; - } - case pvDouble: { - PVDouble *value = static_cast(pv); - value->put(from); return; - } - case pvString: { - PVString *value = static_cast(pv); - char buffer[20]; - int ival = from; - sprintf(buffer,"%d",ival); - String xxx(buffer); - value->put(xxx); - return; - } - } - throw std::logic_error(logicError); + return convertToIntArray(pv.get(), offset, length, to, toOffset); } -void Convert::fromLong(PVScalar *pv, int64 from) +size_t Convert::toLongArray(PVScalarArrayPtr &pv, size_t offset, size_t length, + int64 to[], size_t toOffset) { - ScalarConstPtr scalar = pv->getScalar(); - ScalarType scalarType = scalar->getScalarType(); - switch(scalarType) { - case pvBoolean: - throw std::logic_error(String("long can not be converted to boolean")); - case pvByte: { - PVByte *value = static_cast(pv); - value->put(from); return; - } - case pvShort: { - PVShort *value = static_cast(pv); - value->put(from); return; - } - case pvInt: { - PVInt *value = static_cast(pv); - value->put(from); return; - } - case pvLong: { - PVLong *value = static_cast(pv); - value->put(from); return; - } - case pvFloat: { - PVFloat *value = static_cast(pv); - value->put(from); return; - } - case pvDouble: { - PVDouble *value = static_cast(pv); - value->put(from); return; - } - case pvString: { - PVString *value = static_cast(pv); - char buffer[20]; - int64 ival = from; - sprintf(buffer,"%lld",ival); - String xxx(buffer); - value->put(xxx); - return; - } - } - throw std::logic_error(logicError); + return convertToLongArray(pv.get(), offset, length, to, toOffset); } -void Convert::fromFloat(PVScalar* pv, float from) +size_t Convert::toUByteArray(PVScalarArrayPtr &pv, size_t offset, size_t length, + uint8 to[], size_t toOffset) { - ScalarConstPtr scalar = pv->getScalar(); - ScalarType scalarType = scalar->getScalarType(); - switch(scalarType) { - case pvBoolean: - throw std::logic_error(String("float can not be converted to boolean")); - case pvByte: { - PVByte *value = static_cast(pv); - value->put(static_cast(from)); return; - } - case pvShort: { - PVShort *value = static_cast(pv); - value->put(static_cast(from)); return; - } - case pvInt: { - PVInt *value = static_cast(pv); - value->put(static_cast(from)); return; - } - case pvLong: { - PVLong *value = static_cast(pv); - value->put(static_cast(from)); return; - } - case pvFloat: { - PVFloat *value = static_cast(pv); - value->put(from); return; - } - case pvDouble: { - PVDouble *value = static_cast(pv); - value->put(from); return; - } - case pvString: { - PVString *value = static_cast(pv); - char buffer[20]; - double dval = from; - sprintf(buffer,"%g",dval); - String xxx(buffer); - value->put(xxx); - return; - } - } - throw std::logic_error(logicError); + return convertToUByteArray(pv.get(), offset, length, to, toOffset); } -void Convert::fromDouble(PVScalar *pv, double from) +size_t Convert::toUShortArray(PVScalarArrayPtr &pv, size_t offset, size_t length, + uint16 to[], size_t toOffset) { - ScalarConstPtr scalar = pv->getScalar(); - ScalarType scalarType = scalar->getScalarType(); - switch(scalarType) { - case pvBoolean: - throw std::logic_error(String("double can not be converted to boolean")); - case pvByte: { - PVByte *value = static_cast(pv); - value->put(static_cast(from)); return; - } - case pvShort: { - PVShort *value = static_cast(pv); - value->put(static_cast(from)); return; - } - case pvInt: { - PVInt *value = static_cast(pv); - value->put(static_cast(from)); return; - } - case pvLong: { - PVLong *value = static_cast(pv); - value->put(static_cast(from)); return; - } - case pvFloat: { - PVFloat *value = static_cast(pv); - value->put(from); return; - } - case pvDouble: { - PVDouble *value = static_cast(pv); - value->put(from); return; - } - case pvString: { - PVString *value = static_cast(pv); - char buffer[20]; - double dval = from; - sprintf(buffer,"%g",dval); - String xxx(buffer); - value->put(xxx); - return; - } - } - throw std::logic_error(logicError); + return convertToUShortArray(pv.get(), offset, length, to, toOffset); } -int Convert::toByteArray(PVScalarArray * pv, int offset, int length, - int8 to[], int toOffset) +size_t Convert::toUIntArray(PVScalarArrayPtr &pv, size_t offset, size_t length, + uint32 to[], size_t toOffset) { - return convertToByteArray(pv, offset, length, to, toOffset); + return convertToUIntArray(pv.get(), offset, length, to, toOffset); } -int Convert::toShortArray(PVScalarArray * pv, int offset, int length, - int16 to[], int toOffset) +size_t Convert::toULongArray(PVScalarArrayPtr &pv, size_t offset, size_t length, + uint64 to[], size_t toOffset) { - return convertToShortArray(pv, offset, length, to, toOffset); + return convertToULongArray(pv.get(), offset, length, to, toOffset); } -int Convert::toIntArray(PVScalarArray * pv, int offset, int length, - int32 to[], int toOffset) +size_t Convert::toFloatArray(PVScalarArrayPtr &pv, size_t offset, size_t length, + float to[], size_t toOffset) { - return convertToIntArray(pv, offset, length, to, toOffset); + return convertToFloatArray(pv.get(), offset, length, to, toOffset); } -int Convert::toLongArray(PVScalarArray * pv, int offset, int length, - int64 to[], int toOffset) +size_t Convert::toDoubleArray(PVScalarArrayPtr &pv, size_t offset, size_t length, + double to[], size_t toOffset) { - return convertToLongArray(pv, offset, length, to, toOffset); + return convertToDoubleArray(pv.get(), offset, length, to, toOffset); } -int Convert::toFloatArray(PVScalarArray * pv, int offset, int length, - float to[], int toOffset) +size_t Convert::fromByteArray(PVScalarArrayPtr &pv, size_t offset, size_t length, + int8 from[], size_t fromOffset) { - return convertToFloatArray(pv, offset, length, to, toOffset); + return convertFromByteArray(pv.get(), offset, length, from, fromOffset); } -int Convert::toDoubleArray(PVScalarArray * pv, int offset, int length, - double to[], int toOffset) +size_t Convert::fromShortArray(PVScalarArrayPtr &pv, size_t offset, size_t length, + int16 from[], size_t fromOffset) { - return convertToDoubleArray(pv, offset, length, to, toOffset); + return convertFromShortArray(pv.get(), offset, length, from, fromOffset); } -int Convert::fromByteArray(PVScalarArray *pv, int offset, int length, - int8 from[], int fromOffset) +size_t Convert::fromIntArray(PVScalarArrayPtr &pv, size_t offset, size_t length, + int32 from[], size_t fromOffset) { - return convertFromByteArray(pv, offset, length, from, fromOffset); + return convertFromIntArray(pv.get(), offset, length, from, fromOffset); } -int Convert::fromShortArray(PVScalarArray *pv, int offset, int length, - int16 from[], int fromOffset) +size_t Convert::fromLongArray(PVScalarArrayPtr &pv, size_t offset, size_t length, + int64 from[], size_t fromOffset) { - return convertFromShortArray(pv, offset, length, from, fromOffset); + return convertFromLongArray(pv.get(), offset, length, from, fromOffset); } -int Convert::fromIntArray(PVScalarArray *pv, int offset, int length, - int32 from[], int fromOffset) +size_t Convert::fromUByteArray(PVScalarArrayPtr &pv, size_t offset, size_t length, + uint8 from[], size_t fromOffset) { - return convertFromIntArray(pv, offset, length, from, fromOffset); + return convertFromUByteArray(pv.get(), offset, length, from, fromOffset); } -int Convert::fromLongArray(PVScalarArray *pv, int offset, int length, - int64 from[], int fromOffset) +size_t Convert::fromUShortArray(PVScalarArrayPtr &pv, size_t offset, size_t length, + uint16 from[], size_t fromOffset) { - return convertFromLongArray(pv, offset, length, from, fromOffset); + return convertFromUShortArray(pv.get(), offset, length, from, fromOffset); } -int Convert::fromFloatArray(PVScalarArray *pv, int offset, int length, - float from[], int fromOffset) +size_t Convert::fromUIntArray(PVScalarArrayPtr &pv, size_t offset, size_t length, + uint32 from[], size_t fromOffset) { - return convertFromFloatArray(pv, offset, length, from, fromOffset); + return convertFromUIntArray(pv.get(), offset, length, from, fromOffset); } -int Convert::fromDoubleArray(PVScalarArray *pv, int offset, int length, - double from[], int fromOffset) +size_t Convert::fromULongArray(PVScalarArrayPtr &pv, size_t offset, size_t length, + uint64 from[], size_t fromOffset) { - return convertFromDoubleArray(pv, offset, length, from, fromOffset); + return convertFromULongArray(pv.get(), offset, length, from, fromOffset); +} + +size_t Convert::fromFloatArray(PVScalarArrayPtr &pv, size_t offset, size_t length, + float from[], size_t fromOffset) +{ + return convertFromFloatArray(pv.get(), offset, length, from, fromOffset); +} + +size_t Convert::fromDoubleArray(PVScalarArrayPtr &pv, size_t offset, size_t length, + double from[], size_t fromOffset) +{ + return convertFromDoubleArray(pv.get(), offset, length, from, fromOffset); } void Convert::newLine(StringBuilder buffer, int indentLevel) @@ -1341,6 +1341,34 @@ static bool scalarEquals(PVScalar *a,PVScalar *b) int64 bvalue = pb->get(); return ((avalue==bvalue) ? true : false); } + case pvUByte: { + PVUByte *pa = static_cast(a); + PVUByte *pb = static_cast(b); + uint8 avalue = pa->get(); + uint8 bvalue = pb->get(); + return ((avalue==bvalue) ? true : false); + } + case pvUShort: { + PVUShort *pa = static_cast(a); + PVUShort *pb = static_cast(b); + uint16 avalue = pa->get(); + uint16 bvalue = pb->get(); + return ((avalue==bvalue) ? true : false); + } + case pvUInt: { + PVUInt *pa = static_cast(a); + PVUInt *pb = static_cast(b); + uint32 avalue = pa->get(); + uint32 bvalue = pb->get(); + return ((avalue==bvalue) ? true : false); + } + case pvULong: { + PVULong *pa = static_cast(a); + PVULong *pb = static_cast(b); + uint64 avalue = pa->get(); + uint64 bvalue = pb->get(); + return ((avalue==bvalue) ? true : false); + } case pvFloat: { PVFloat *pa = static_cast(a); PVFloat *pb = static_cast(b); @@ -1374,18 +1402,18 @@ static bool arrayEquals(PVScalarArray *a,PVScalarArray *b) ScalarType bType = b->getScalarArray()->getElementType(); if(aType!=bType) return false; if(a->getLength()!=b->getLength()) return false; - int length = a->getLength(); + size_t length = a->getLength(); switch(aType) { case pvBoolean: { PVBooleanArray *aarray = static_cast(a); PVBooleanArray *barray = static_cast(b); - BooleanArrayData adata = BooleanArrayData(); - BooleanArrayData bdata = BooleanArrayData(); - aarray->get(0,length,&adata); - barray->get(0,length,&bdata); + BooleanArrayData adata; + BooleanArrayData bdata; + aarray->get(0,length,adata); + barray->get(0,length,bdata); BooleanArray avalue = adata.data; BooleanArray bvalue = bdata.data; - for(int i=0; i(a); PVByteArray *barray = static_cast(b); - ByteArrayData adata = ByteArrayData(); - ByteArrayData bdata = ByteArrayData(); - aarray->get(0,length,&adata); - barray->get(0,length,&bdata); + ByteArrayData adata; + ByteArrayData bdata; + aarray->get(0,length,adata); + barray->get(0,length,bdata); ByteArray avalue = adata.data; ByteArray bvalue = bdata.data; - for(int i=0; i(a); PVShortArray *barray = static_cast(b); - ShortArrayData adata = ShortArrayData(); - ShortArrayData bdata = ShortArrayData(); - aarray->get(0,length,&adata); - barray->get(0,length,&bdata); + ShortArrayData adata; + ShortArrayData bdata; + aarray->get(0,length,adata); + barray->get(0,length,bdata); ShortArray avalue = adata.data; ShortArray bvalue = bdata.data; - for(int i=0; i(a); PVIntArray *barray = static_cast(b); - IntArrayData adata = IntArrayData(); - IntArrayData bdata = IntArrayData(); - aarray->get(0,length,&adata); - barray->get(0,length,&bdata); + IntArrayData adata; + IntArrayData bdata; + aarray->get(0,length,adata); + barray->get(0,length,bdata); IntArray avalue = adata.data; IntArray bvalue = bdata.data; - for(int i=0; i(a); PVLongArray *barray = static_cast(b); - LongArrayData adata = LongArrayData(); - LongArrayData bdata = LongArrayData(); - aarray->get(0,length,&adata); - barray->get(0,length,&bdata); + LongArrayData adata; + LongArrayData bdata; + aarray->get(0,length,adata); + barray->get(0,length,bdata); LongArray avalue = adata.data; LongArray bvalue = bdata.data; - for(int i=0; i(a); + PVUByteArray *barray = static_cast(b); + UByteArrayData adata; + UByteArrayData bdata; + aarray->get(0,length,adata); + barray->get(0,length,bdata); + UByteArray avalue = adata.data; + UByteArray bvalue = bdata.data; + for(size_t i=0; i(a); + PVUShortArray *barray = static_cast(b); + UShortArrayData adata; + UShortArrayData bdata; + aarray->get(0,length,adata); + barray->get(0,length,bdata); + UShortArray avalue = adata.data; + UShortArray bvalue = bdata.data; + for(size_t i=0; i(a); + PVUIntArray *barray = static_cast(b); + UIntArrayData adata; + UIntArrayData bdata; + aarray->get(0,length,adata); + barray->get(0,length,bdata); + UIntArray avalue = adata.data; + UIntArray bvalue = bdata.data; + for(size_t i=0; i(a); + PVULongArray *barray = static_cast(b); + ULongArrayData adata; + ULongArrayData bdata; + aarray->get(0,length,adata); + barray->get(0,length,bdata); + ULongArray avalue = adata.data; + ULongArray bvalue = bdata.data; + for(size_t i=0; i(a); PVFloatArray *barray = static_cast(b); - FloatArrayData adata = FloatArrayData(); - FloatArrayData bdata = FloatArrayData(); - aarray->get(0,length,&adata); - barray->get(0,length,&bdata); + FloatArrayData adata; + FloatArrayData bdata; + aarray->get(0,length,adata); + barray->get(0,length,bdata); FloatArray avalue = adata.data; FloatArray bvalue = bdata.data; - for(int i=0; i(a); PVDoubleArray *barray = static_cast(b); - DoubleArrayData adata = DoubleArrayData(); - DoubleArrayData bdata = DoubleArrayData(); - aarray->get(0,length,&adata); - barray->get(0,length,&bdata); + DoubleArrayData adata; + DoubleArrayData bdata; + aarray->get(0,length,adata); + barray->get(0,length,bdata); DoubleArray avalue = adata.data; DoubleArray bvalue = bdata.data; - for(int i=0; i(a); PVStringArray *barray = static_cast(b); - StringArrayData adata = StringArrayData(); - StringArrayData bdata = StringArrayData(); - aarray->get(0,length,&adata); - barray->get(0,length,&bdata); - String *avalue = adata.data; - String *bvalue = bdata.data; - for(int i=0; iget(0,length,adata); + barray->get(0,length,bdata); + StringArray avalue = adata.data; + StringArray bvalue = bdata.data; + for(size_t i=0; igetLength()!=b->getLength()) return false; StructureArrayData aData = StructureArrayData(); StructureArrayData bData = StructureArrayData(); - int length = a->getLength(); + size_t length = a->getLength(); PVStructurePtrArray aArray = aData.data; PVStructurePtrArray bArray = bData.data; if(aArray==bArray) return true; - for(int i=0; igetStructure(); StructureConstPtr bStructure = a->getStructure(); - int length = aStructure->getNumberFields(); + size_t length = aStructure->getNumberFields(); if(length!=bStructure->getNumberFields()) return false; - PVFieldPtrArray aFields = a->getPVFields(); - PVFieldPtrArray bFields = b->getPVFields(); - for(int i=0; igetPVFields(); + PVFieldPtrArray const & bFields = b->getPVFields(); + for(size_t i=0; i(a),static_cast(b)); if(atype==scalarArray) return arrayEquals( - static_cast(a),static_cast(b)); + static_cast(a),static_cast(b)); if(atype==structureArray) return structureArrayEquals( static_cast(a),static_cast(b)); if(atype==structure) return structureEquals( @@ -1551,19 +1635,18 @@ bool convertEquals(PVField *a,PVField *b) throw std::logic_error(message); } -int convertFromByteArray(PVScalarArray *pv, int offset, int len,int8 from[], int fromOffset) +template +size_t convertFromScalarArray(PVScalarArray *pv, + size_t offset, size_t len,T from[], size_t fromOffset) { ScalarType elemType = pv->getScalarArray()->getElementType(); - int ntransfered = 0; - switch (elemType) { - case pvBoolean: { - String message("convert from byte[] to BooleanArray not legal"); - throw std::invalid_argument(message); - } - case pvByte: { - PVByteArray *pvdata = static_cast(pv); + size_t ntransfered = 0; + String xx = typeid(PVT).name(); + String yy = typeid(T).name(); + if(xx.compare(yy)== 0) { + PVT *pvdata = static_cast(pv); while (len > 0) { - int n = pvdata->put(offset, len, from, fromOffset); + size_t n = pvdata->put(offset, len, from, fromOffset); if (n == 0) break; len -= n; @@ -1573,6 +1656,25 @@ int convertFromByteArray(PVScalarArray *pv, int offset, int len,int8 from[], int } return ntransfered; } + switch (elemType) { + case pvBoolean: { + String message("convert from numeric array to BooleanArray not legal"); + throw std::invalid_argument(message); + } + case pvByte: { + PVByteArray *pvdata = static_cast(pv); + int8 data[1]; + while (len > 0) { + data[0] = from[fromOffset]; + if (pvdata->put(offset, 1, data, 0) == 0) + return ntransfered; + --len; + ++ntransfered; + ++offset; + ++fromOffset; + } + return ntransfered; + } case pvShort: { PVShortArray *pvdata = static_cast(pv); int16 data[1]; @@ -1615,6 +1717,62 @@ int convertFromByteArray(PVScalarArray *pv, int offset, int len,int8 from[], int } return ntransfered; } + case pvUByte: { + PVUByteArray *pvdata = static_cast(pv); + uint8 data[1]; + while (len > 0) { + data[0] = from[fromOffset]; + if (pvdata->put(offset, 1, data, 0) == 0) + return ntransfered; + --len; + ++ntransfered; + ++offset; + ++fromOffset; + } + return ntransfered; + } + case pvUShort: { + PVUShortArray *pvdata = static_cast(pv); + uint16 data[1]; + while (len > 0) { + data[0] = from[fromOffset]; + if (pvdata->put(offset, 1, data, 0) == 0) + return ntransfered; + --len; + ++ntransfered; + ++offset; + ++fromOffset; + } + return ntransfered; + } + case pvUInt: { + PVUIntArray *pvdata = static_cast(pv); + uint32 data[1]; + while (len > 0) { + data[0] = from[fromOffset]; + if (pvdata->put(offset, 1, data, 0) == 0) + return ntransfered; + --len; + ++ntransfered; + ++offset; + ++fromOffset; + } + return ntransfered; + } + case pvULong: { + PVULongArray *pvdata = static_cast(pv); + uint64 data[1]; + while (len > 0) { + data[0] = from[fromOffset]; + if (pvdata->put(offset, 1, data, 0) == 0) + return ntransfered; + --len; + ++ntransfered; + ++offset; + ++fromOffset; + } + return ntransfered; + } case pvFloat: { PVFloatArray *pvdata = static_cast(pv); float data[1]; @@ -1652,10 +1810,12 @@ int convertFromByteArray(PVScalarArray *pv, int offset, int len,int8 from[], int throw std::logic_error(message); } -int convertToByteArray(PVScalarArray * pv, int offset, int len,int8 to[], int toOffset) +template +size_t convertToScalarArray(PVScalarArray *pv, + size_t offset, size_t len,T to[], size_t toOffset) { ScalarType elemType = pv->getScalarArray()->getElementType(); - int ntransfered = 0; + size_t ntransfered = 0; switch (elemType) { case pvBoolean: { String message("convert BooleanArray to byte[]] not legal"); @@ -1663,14 +1823,14 @@ int convertToByteArray(PVScalarArray * pv, int offset, int len,int8 to[], int to } case pvByte: { PVByteArray *pvdata = static_cast(pv); - ByteArrayData data = ByteArrayData(); + ByteArrayData data; while (len > 0) { - int num = 0; - num = pvdata->get(offset,len,&data); + size_t num = 0; + num = pvdata->get(offset,len,data); if (num <= 0) break; ByteArray dataArray = data.data; - int dataOffset = data.offset; - for(int i=0;i(pv); - ShortArrayData data = ShortArrayData(); + ShortArrayData data; while (len > 0) { - int num = pvdata->get(offset, len, &data); + size_t num = pvdata->get(offset, len, data); if (num == 0) break; ShortArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) + size_t dataOffset = data.offset; + for (size_t i = 0; i < num; i++) to[i + toOffset] = dataArray[i + dataOffset]; len -= num; offset += num; @@ -1697,13 +1857,13 @@ int convertToByteArray(PVScalarArray * pv, int offset, int len,int8 to[], int to } case pvInt: { PVIntArray *pvdata = static_cast(pv); - IntArrayData data = IntArrayData(); + IntArrayData data; while (len > 0) { - int num = pvdata->get(offset, len, &data); + size_t num = pvdata->get(offset, len, data); if (num == 0) break; IntArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) + size_t dataOffset = data.offset; + for (size_t i = 0; i < num; i++) to[i + toOffset] = dataArray[i + dataOffset]; len -= num; offset += num; @@ -1714,14 +1874,14 @@ int convertToByteArray(PVScalarArray * pv, int offset, int len,int8 to[], int to } case pvLong: { PVLongArray *pvdata = static_cast(pv); - LongArrayData data = LongArrayData(); + LongArrayData data; while (len > 0) { - int num = pvdata->get(offset, len, &data); + size_t num = pvdata->get(offset, len, data); if (num == 0) break; LongArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) + size_t dataOffset = data.offset; + for (size_t i = 0; i < num; i++) to[i + toOffset] = dataArray[i + dataOffset]; len -= num; offset += num; @@ -1730,170 +1890,16 @@ int convertToByteArray(PVScalarArray * pv, int offset, int len,int8 to[], int to } return ntransfered; } - case pvFloat: { - PVFloatArray *pvdata = static_cast(pv); - FloatArrayData data = FloatArrayData(); + case pvUByte: { + PVUByteArray *pvdata = static_cast(pv); + UByteArrayData data; while (len > 0) { - int num = pvdata->get(offset, len, &data); - if (num == 0) break; - FloatArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) - to[i + toOffset] = static_cast(dataArray[i + dataOffset]); - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = static_cast(pv); - DoubleArrayData data = DoubleArrayData(); - while (len > 0) { - int num = pvdata->get(offset, len, &data); - if (num == 0) - break; - DoubleArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) - to[i + toOffset] = static_cast(dataArray[i + dataOffset]); - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvString: { - String message("convert StringArray to byte[]] not legal"); - throw std::invalid_argument(message); - } - } - String message("Convert::convertToByteArray should never get here"); - throw std::logic_error(message); -} - -int convertFromShortArray(PVScalarArray *pv, int offset, int len,int16 from[], int fromOffset) -{ - ScalarType elemType = pv->getScalarArray()->getElementType(); - int ntransfered = 0; - switch (elemType) { - case pvBoolean: { - String message("convert from short[] to BooleanArray not legal"); - throw std::invalid_argument(message); - } - case pvByte: { - PVByteArray *pvdata = static_cast(pv); - int8 data[1]; - while (len > 0) { - data[0] = from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvShort: { - PVShortArray *pvdata = static_cast(pv); - while (len > 0) { - int n = pvdata->put(offset, len, from, fromOffset); - if (n == 0) - break; - len -= n; - offset += n; - fromOffset += n; - ntransfered += n; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = static_cast(pv); - int32 data[1]; - while (len > 0) { - data[0] = from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = static_cast(pv); - int64 data[1]; - while (len > 0) { - data[0] = from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = static_cast(pv); - float data[1]; - while (len > 0) { - data[0] = from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = static_cast(pv); - double data[1]; - while (len > 0) { - data[0] = from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvString: { - String message("convert from short[] to StringArray not legal"); - throw std::invalid_argument(message); - } - } - String message("Convert::convertFromShortArray should never get here"); - throw std::logic_error(message); -} - -int convertToShortArray(PVScalarArray * pv, int offset, int len,int16 to[], int toOffset) -{ - ScalarType elemType = pv->getScalarArray()->getElementType(); - int ntransfered = 0; - switch (elemType) { - case pvBoolean: { - String message("convert BooleanArray to short[]] not legal"); - throw std::invalid_argument(message); - } - case pvByte: { - PVByteArray *pvdata = static_cast(pv); - ByteArrayData data = ByteArrayData(); - while (len > 0) { - int num = 0; - num = pvdata->get(offset,len,&data); + size_t num = 0; + num = pvdata->get(offset,len,data); if (num <= 0) break; - ByteArray dataArray = data.data; - int dataOffset = data.offset; - for(int i=0;i(pv); - ShortArrayData data = ShortArrayData(); + case pvUShort: { + PVUShortArray *pvdata = static_cast(pv); + UShortArrayData data; while (len > 0) { - int num = pvdata->get(offset, len, &data); + size_t num = pvdata->get(offset, len, data); if (num == 0) break; - ShortArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) + UShortArray dataArray = data.data; + size_t dataOffset = data.offset; + for (size_t i = 0; i < num; i++) to[i + toOffset] = dataArray[i + dataOffset]; len -= num; offset += num; @@ -1918,33 +1924,15 @@ int convertToShortArray(PVScalarArray * pv, int offset, int len,int16 to[], int } return ntransfered; } - case pvInt: { - PVIntArray *pvdata = static_cast(pv); - IntArrayData data = IntArrayData(); + case pvUInt: { + PVUIntArray *pvdata = static_cast(pv); + UIntArrayData data; while (len > 0) { - int num = pvdata->get(offset, len, &data); + size_t num = pvdata->get(offset, len, data); if (num == 0) break; - IntArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) - to[i + toOffset] = dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = static_cast(pv); - LongArrayData data = LongArrayData(); - while (len > 0) { - int num = pvdata->get(offset, len, &data); - if (num == 0) - break; - LongArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) + UIntArray dataArray = data.data; + size_t dataOffset = data.offset; + for (size_t i = 0; i < num; i++) to[i + toOffset] = dataArray[i + dataOffset]; len -= num; offset += num; @@ -1953,16 +1941,34 @@ int convertToShortArray(PVScalarArray * pv, int offset, int len,int16 to[], int } return ntransfered; } + case pvULong: { + PVULongArray *pvdata = static_cast(pv); + ULongArrayData data; + while (len > 0) { + size_t num = pvdata->get(offset, len, data); + if (num == 0) + break; + ULongArray dataArray = data.data; + size_t dataOffset = data.offset; + for (size_t i = 0; i < num; i++) + to[i + toOffset] = dataArray[i + dataOffset]; + len -= num; + offset += num; + toOffset += num; + ntransfered += num; + } + return ntransfered; + } case pvFloat: { PVFloatArray *pvdata = static_cast(pv); - FloatArrayData data = FloatArrayData(); + FloatArrayData data; while (len > 0) { - int num = pvdata->get(offset, len, &data); + size_t num = pvdata->get(offset, len, data); if (num == 0) break; FloatArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) - to[i + toOffset] = static_cast(dataArray[i + dataOffset]); + size_t dataOffset = data.offset; + for (size_t i = 0; i < num; i++) + to[i + toOffset] = dataArray[i + dataOffset]; len -= num; offset += num; toOffset += num; @@ -1972,683 +1978,14 @@ int convertToShortArray(PVScalarArray * pv, int offset, int len,int16 to[], int } case pvDouble: { PVDoubleArray *pvdata = static_cast(pv); - DoubleArrayData data = DoubleArrayData(); + DoubleArrayData data; while (len > 0) { - int num = pvdata->get(offset, len, &data); + size_t num = pvdata->get(offset, len, data); if (num == 0) break; DoubleArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) - to[i + toOffset] = static_cast(dataArray[i + dataOffset]); - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvString: { - String message("convert StringArray to short[]] not legal"); - throw std::invalid_argument(message); - } - } - String message("Convert::convertToShortArray should never get here"); - throw std::logic_error(message); -} - -int convertFromIntArray(PVScalarArray *pv, int offset, int len,int32 from[], int fromOffset) -{ - ScalarType elemType = pv->getScalarArray()->getElementType(); - int ntransfered = 0; - switch (elemType) { - case pvBoolean: { - String message("convert from int[] to BooleanArray not legal"); - throw std::invalid_argument(message); - } - case pvByte: { - PVByteArray *pvdata = static_cast(pv); - int8 data[1]; - while (len > 0) { - data[0] = from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvShort: { - PVShortArray *pvdata = static_cast(pv); - int16 data[1]; - while (len > 0) { - data[0] = from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = static_cast(pv); - while (len > 0) { - int n = pvdata->put(offset, len, from, fromOffset); - if (n == 0) - break; - len -= n; - offset += n; - fromOffset += n; - ntransfered += n; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = static_cast(pv); - int64 data[1]; - while (len > 0) { - data[0] = from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = static_cast(pv); - float data[1]; - while (len > 0) { - data[0] = from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = static_cast(pv); - double data[1]; - while (len > 0) { - data[0] = from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvString: { - String message("convert from int[] to StringArray not legal"); - throw std::invalid_argument(message); - } - } - String message("Convert::convertFromIntArray should never get here"); - throw std::logic_error(message); -} - -int convertToIntArray(PVScalarArray * pv, int offset, int len,int32 to[], int toOffset) -{ - ScalarType elemType = pv->getScalarArray()->getElementType(); - int ntransfered = 0; - switch (elemType) { - case pvBoolean: { - String message("convert BooleanArray to byte[]] not legal"); - throw std::invalid_argument(message); - } - case pvByte: { - PVByteArray *pvdata = static_cast(pv); - ByteArrayData data = ByteArrayData(); - while (len > 0) { - int num = 0; - num = pvdata->get(offset,len,&data); - if (num <= 0) break; - ByteArray dataArray = data.data; - int dataOffset = data.offset; - for(int i=0;i(pv); - ShortArrayData data = ShortArrayData(); - while (len > 0) { - int num = pvdata->get(offset, len, &data); - if (num == 0) break; - ShortArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) - to[i + toOffset] = dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = static_cast(pv); - IntArrayData data = IntArrayData(); - while (len > 0) { - int num = pvdata->get(offset, len, &data); - if (num == 0) break; - IntArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) - to[i + toOffset] = dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = static_cast(pv); - LongArrayData data = LongArrayData(); - while (len > 0) { - int num = pvdata->get(offset, len, &data); - if (num == 0) - break; - LongArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) - to[i + toOffset] = dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = static_cast(pv); - FloatArrayData data = FloatArrayData(); - while (len > 0) { - int num = pvdata->get(offset, len, &data); - if (num == 0) break; - FloatArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) - to[i + toOffset] = static_cast(dataArray[i + dataOffset]); - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = static_cast(pv); - DoubleArrayData data = DoubleArrayData(); - while (len > 0) { - int num = pvdata->get(offset, len, &data); - if (num == 0) - break; - DoubleArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) - to[i + toOffset] = static_cast(dataArray[i + dataOffset]); - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvString: { - String message("convert StringArray to int[]] not legal"); - throw std::invalid_argument(message); - } - } - String message("Convert::convertToIntArray should never get here"); - throw std::logic_error(message); -} - -int convertFromLongArray(PVScalarArray *pv, int offset, int len,int64 from[], int fromOffset) -{ - ScalarType elemType = pv->getScalarArray()->getElementType(); - int ntransfered = 0; - switch (elemType) { - case pvBoolean: { - String message("convert from long[] to BooleanArray not legal"); - throw std::invalid_argument(message); - } - case pvByte: { - PVByteArray *pvdata = static_cast(pv); - int8 data[1]; - while (len > 0) { - data[0] = from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvShort: { - PVShortArray *pvdata = static_cast(pv); - int16 data[1]; - while (len > 0) { - data[0] = from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = static_cast(pv); - int32 data[1]; - while (len > 0) { - data[0] = from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = static_cast(pv); - while (len > 0) { - int n = pvdata->put(offset, len, from, fromOffset); - if (n == 0) - break; - len -= n; - offset += n; - fromOffset += n; - ntransfered += n; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = static_cast(pv); - float data[1]; - while (len > 0) { - data[0] = from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = static_cast(pv); - double data[1]; - while (len > 0) { - data[0] = from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvString: { - String message("convert from long[] to StringArray not legal"); - throw std::invalid_argument(message); - } - } - String message("Convert::convertFromLongArray should never get here"); - throw std::logic_error(message); -} - -int convertToLongArray(PVScalarArray * pv, int offset, int len,int64 to[], int toOffset) -{ - ScalarType elemType = pv->getScalarArray()->getElementType(); - int ntransfered = 0; - switch (elemType) { - case pvBoolean: { - String message("convert BooleanArray to long[]] not legal"); - throw std::invalid_argument(message); - } - case pvByte: { - PVByteArray *pvdata = static_cast(pv); - ByteArrayData data = ByteArrayData(); - while (len > 0) { - int num = 0; - num = pvdata->get(offset,len,&data); - if (num <= 0) break; - ByteArray dataArray = data.data; - int dataOffset = data.offset; - for(int i=0;i(pv); - ShortArrayData data = ShortArrayData(); - while (len > 0) { - int num = pvdata->get(offset, len, &data); - if (num == 0) break; - ShortArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) - to[i + toOffset] = dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = static_cast(pv); - IntArrayData data = IntArrayData(); - while (len > 0) { - int num = pvdata->get(offset, len, &data); - if (num == 0) break; - IntArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) - to[i + toOffset] = dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = static_cast(pv); - LongArrayData data = LongArrayData(); - while (len > 0) { - int num = pvdata->get(offset, len, &data); - if (num == 0) - break; - LongArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) - to[i + toOffset] = dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = static_cast(pv); - FloatArrayData data = FloatArrayData(); - while (len > 0) { - int num = pvdata->get(offset, len, &data); - if (num == 0) break; - FloatArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) - to[i + toOffset] = static_cast(dataArray[i + dataOffset]); - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = static_cast(pv); - DoubleArrayData data = DoubleArrayData(); - while (len > 0) { - int num = pvdata->get(offset, len, &data); - if (num == 0) - break; - DoubleArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) - to[i + toOffset] = static_cast(dataArray[i + dataOffset]); - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvString: { - String message("convert StringArray to long[]] not legal"); - throw std::invalid_argument(message); - } - } - String message("Convert::convertToLongArray should never get here"); - throw std::logic_error(message); -} - -int convertFromFloatArray(PVScalarArray *pv, int offset, int len,float from[], int fromOffset) -{ - ScalarType elemType = pv->getScalarArray()->getElementType(); - int ntransfered = 0; - switch (elemType) { - case pvBoolean: { - String message("convert from float[] to BooleanArray not legal"); - throw std::invalid_argument(message); - } - case pvByte: { - PVByteArray *pvdata = static_cast(pv); - int8 data[1]; - while (len > 0) { - data[0] = static_cast(from[fromOffset]); - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvShort: { - PVShortArray *pvdata = static_cast(pv); - int16 data[1]; - while (len > 0) { - data[0] = static_cast(from[fromOffset]); - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = static_cast(pv); - int32 data[1]; - while (len > 0) { - data[0] = static_cast(from[fromOffset]); - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = static_cast(pv); - int64 data[1]; - while (len > 0) { - data[0] = static_cast(from[fromOffset]); - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = static_cast(pv); - while (len > 0) { - int n = pvdata->put(offset, len, from, fromOffset); - if (n == 0) - break; - len -= n; - offset += n; - fromOffset += n; - ntransfered += n; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = static_cast(pv); - double data[1]; - while (len > 0) { - data[0] = from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvString: { - String message("convert from float[] to StringArray not legal"); - throw std::invalid_argument(message); - } - } - String message("Convert::convertFromFloatArray should never get here"); - throw std::logic_error(message); -} - -int convertToFloatArray(PVScalarArray * pv, int offset, int len,float to[], int toOffset) -{ - ScalarType elemType = pv->getScalarArray()->getElementType(); - int ntransfered = 0; - switch (elemType) { - case pvBoolean: { - String message("convert BooleanArray to float[]] not legal"); - throw std::invalid_argument(message); - } - case pvByte: { - PVByteArray *pvdata = static_cast(pv); - ByteArrayData data = ByteArrayData(); - while (len > 0) { - int num = 0; - num = pvdata->get(offset,len,&data); - if (num <= 0) break; - ByteArray dataArray = data.data; - int dataOffset = data.offset; - for(int i=0;i(pv); - ShortArrayData data = ShortArrayData(); - while (len > 0) { - int num = pvdata->get(offset, len, &data); - if (num == 0) break; - ShortArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) - to[i + toOffset] = dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = static_cast(pv); - IntArrayData data = IntArrayData(); - while (len > 0) { - int num = pvdata->get(offset, len, &data); - if (num == 0) break; - IntArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) - to[i + toOffset] = dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = static_cast(pv); - LongArrayData data = LongArrayData(); - while (len > 0) { - int num = pvdata->get(offset, len, &data); - if (num == 0) - break; - LongArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) - to[i + toOffset] = dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = static_cast(pv); - FloatArrayData data = FloatArrayData(); - while (len > 0) { - int num = pvdata->get(offset, len, &data); - if (num == 0) break; - FloatArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) - to[i + toOffset] = dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = static_cast(pv); - DoubleArrayData data = DoubleArrayData(); - while (len > 0) { - int num = pvdata->get(offset, len, &data); - if (num == 0) - break; - DoubleArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) + size_t dataOffset = data.offset; + for (size_t i = 0; i < num; i++) to[i + toOffset] = dataArray[i + dataOffset]; len -= num; offset += num; @@ -2658,245 +1995,143 @@ int convertToFloatArray(PVScalarArray * pv, int offset, int len,float to[], int return ntransfered; } case pvString: { - String message("convert StringArray to float[]] not legal"); + String message("convert StringArray to numeric not legal"); throw std::invalid_argument(message); } } - String message("Convert::convertToFloatArray should never get here"); + String message("Convert::convertToScalarArray should never get here"); throw std::logic_error(message); } -int convertFromDoubleArray(PVScalarArray *pv, int offset, int len,double from[], int fromOffset) +size_t convertFromByteArray(PVScalarArray *pv, + size_t offset, size_t len,int8 from[], size_t fromOffset) { - ScalarType elemType = pv->getScalarArray()->getElementType(); - int ntransfered = 0; - switch (elemType) { - case pvBoolean: { - String message("convert from double[] to BooleanArray not legal"); - throw std::invalid_argument(message); - } - case pvByte: { - PVByteArray *pvdata = static_cast(pv); - int8 data[1]; - while (len > 0) { - data[0] = static_cast(from[fromOffset]); - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvShort: { - PVShortArray *pvdata = static_cast(pv); - int16 data[1]; - while (len > 0) { - data[0] = static_cast(from[fromOffset]); - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = static_cast(pv); - int32 data[1]; - while (len > 0) { - data[0] = static_cast(from[fromOffset]); - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = static_cast(pv); - int64 data[1]; - while (len > 0) { - data[0] = static_cast(from[fromOffset]); - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = static_cast(pv); - float data[1]; - while (len > 0) { - data[0] = from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = static_cast(pv); - while (len > 0) { - int n = pvdata->put(offset, len, from, fromOffset); - if (n == 0) - break; - len -= n; - offset += n; - fromOffset += n; - ntransfered += n; - } - return ntransfered; - } - case pvString: { - String message("convert from double[] to StringArray not legal"); - throw std::invalid_argument(message); - } - } - String message("Convert::convertFromDoubleArray should never get here"); - throw std::logic_error(message); + return convertFromScalarArray(pv,offset,len,from,fromOffset); } -int convertToDoubleArray(PVScalarArray * pv, int offset, int len,double to[], int toOffset) +size_t convertToByteArray(PVScalarArray * pv, + size_t offset, size_t len,int8 to[], size_t toOffset) { - ScalarType elemType = pv->getScalarArray()->getElementType(); - int ntransfered = 0; - switch (elemType) { - case pvBoolean: { - String message("convert BooleanArray to float[]] not legal"); - throw std::invalid_argument(message); - } - case pvByte: { - PVByteArray *pvdata = static_cast(pv); - ByteArrayData data = ByteArrayData(); - while (len > 0) { - int num = 0; - num = pvdata->get(offset,len,&data); - if (num <= 0) break; - ByteArray dataArray = data.data; - int dataOffset = data.offset; - for(int i=0;i(pv); - ShortArrayData data = ShortArrayData(); - while (len > 0) { - int num = pvdata->get(offset, len, &data); - if (num == 0) break; - ShortArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) - to[i + toOffset] = dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = static_cast(pv); - IntArrayData data = IntArrayData(); - while (len > 0) { - int num = pvdata->get(offset, len, &data); - if (num == 0) break; - IntArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) - to[i + toOffset] = dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = static_cast(pv); - LongArrayData data = LongArrayData(); - while (len > 0) { - int num = pvdata->get(offset, len, &data); - if (num == 0) - break; - LongArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) - to[i + toOffset] = dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = static_cast(pv); - FloatArrayData data = FloatArrayData(); - while (len > 0) { - int num = pvdata->get(offset, len, &data); - if (num == 0) break; - FloatArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) - to[i + toOffset] = dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = static_cast(pv); - DoubleArrayData data = DoubleArrayData(); - while (len > 0) { - int num = pvdata->get(offset, len, &data); - if (num == 0) - break; - DoubleArray dataArray = data.data; - int dataOffset = data.offset; - for (int i = 0; i < num; i++) - to[i + toOffset] = dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvString: { - String message("convert StringArray to double[]] not legal"); - throw std::invalid_argument(message); - } - } - String message("Convert::convertToDoubleArray should never get here"); - throw std::logic_error(message); + return convertToScalarArray(pv,offset,len,to,toOffset); } -int convertFromStringArray(PVScalarArray *pv, int offset, int len,String from[], int fromOffset) +size_t convertFromShortArray(PVScalarArray *pv, + size_t offset, size_t len,int16 from[], size_t fromOffset) +{ + return convertFromScalarArray(pv,offset,len,from,fromOffset); +} + +size_t convertToShortArray(PVScalarArray * pv, + size_t offset, size_t len,int16 to[], size_t toOffset) +{ + return convertToScalarArray(pv,offset,len,to,toOffset); +} + +size_t convertFromIntArray(PVScalarArray *pv, + size_t offset, size_t len,int32 from[], size_t fromOffset) +{ + return convertFromScalarArray(pv,offset,len,from,fromOffset); +} + +size_t convertToIntArray(PVScalarArray * pv, + size_t offset, size_t len,int32 to[], size_t toOffset) +{ + return convertToScalarArray(pv,offset,len,to,toOffset); +} + +size_t convertFromLongArray(PVScalarArray *pv, + size_t offset, size_t len,int64 from[], size_t fromOffset) +{ + return convertFromScalarArray(pv,offset,len,from,fromOffset); +} + +size_t convertToLongArray(PVScalarArray * pv, + size_t offset, size_t len,int64 to[], size_t toOffset) +{ + return convertToScalarArray(pv,offset,len,to,toOffset); +} + +size_t convertFromUByteArray(PVScalarArray *pv, + size_t offset, size_t len,uint8 from[], size_t fromOffset) +{ + return convertFromScalarArray(pv,offset,len,from,fromOffset); +} + +size_t convertToUByteArray(PVScalarArray * pv, + size_t offset, size_t len,uint8 to[], size_t toOffset) +{ + return convertToScalarArray(pv,offset,len,to,toOffset); +} + +size_t convertFromUShortArray(PVScalarArray *pv, + size_t offset, size_t len,uint16 from[], size_t fromOffset) +{ + return convertFromScalarArray(pv,offset,len,from,fromOffset); +} + +size_t convertToUShortArray(PVScalarArray * pv, + size_t offset, size_t len,uint16 to[], size_t toOffset) +{ + return convertToScalarArray(pv,offset,len,to,toOffset); +} + +size_t convertFromUIntArray(PVScalarArray *pv, + size_t offset, size_t len,uint32 from[], size_t fromOffset) +{ + return convertFromScalarArray(pv,offset,len,from,fromOffset); +} + +size_t convertToUIntArray(PVScalarArray * pv, + size_t offset, size_t len,uint32 to[], size_t toOffset) +{ + return convertToScalarArray(pv,offset,len,to,toOffset); +} + +size_t convertFromULongArray(PVScalarArray *pv, + size_t offset, size_t len,uint64 from[], size_t fromOffset) +{ + return convertFromScalarArray(pv,offset,len,from,fromOffset); +} + +size_t convertToULongArray(PVScalarArray * pv, + size_t offset, size_t len,uint64 to[], size_t toOffset) +{ + return convertToScalarArray(pv,offset,len,to,toOffset); +} + +size_t convertFromFloatArray(PVScalarArray *pv, + size_t offset, size_t len,float from[], size_t fromOffset) +{ + return convertFromScalarArray(pv,offset,len,from,fromOffset); +} + +size_t convertToFloatArray(PVScalarArray * pv, + size_t offset, size_t len,float to[], size_t toOffset) +{ + return convertToScalarArray(pv,offset,len,to,toOffset); +} + +size_t convertFromDoubleArray(PVScalarArray *pv, + size_t offset, size_t len,double from[], size_t fromOffset) +{ + return convertFromScalarArray(pv,offset,len,from,fromOffset); +} + +size_t convertToDoubleArray(PVScalarArray * pv, + size_t offset, size_t len,double to[], size_t toOffset) +{ + return convertToScalarArray(pv,offset,len,to,toOffset); +} + +size_t convertFromStringArray(PVScalarArray *pv, + size_t offset, size_t len,StringArray const & from, size_t fromOffset) { ScalarType elemType = pv->getScalarArray()->getElementType(); - int ntransfered = 0; + size_t ntransfered = 0; switch (elemType) { case pvBoolean: { PVBooleanArray *pvdata = static_cast(pv); - bool data[1]; + boolean data[1]; while (len > 0) { String fromString = from[fromOffset]; data[0] = (fromString.compare("true")==0) ? true : false; @@ -2966,7 +2201,75 @@ int convertFromStringArray(PVScalarArray *pv, int offset, int len,String from[], while (len > 0) { String fromString = from[fromOffset]; int64 ival; - sscanf(fromString.c_str(),"%lld",&ival); + sscanf(fromString.c_str(),"%lld",(long long int *)&ival); + data[0] = ival; + if (pvdata->put(offset, 1, data, 0) == 0) + return ntransfered; + --len; + ++ntransfered; + ++offset; + ++fromOffset; + } + return ntransfered; + } + case pvUByte: { + PVUByteArray *pvdata = static_cast(pv); + uint8 data[1]; + while (len > 0) { + String fromString = from[fromOffset]; + unsigned int ival; + sscanf(fromString.c_str(),"%u",&ival); + data[0] = ival; + if (pvdata->put(offset, 1, data, 0) == 0) + return ntransfered; + --len; + ++ntransfered; + ++offset; + ++fromOffset; + } + return ntransfered; + } + case pvUShort: { + PVUShortArray *pvdata = static_cast(pv); + uint16 data[1]; + while (len > 0) { + String fromString = from[fromOffset]; + unsigned int ival; + sscanf(fromString.c_str(),"%u",&ival); + data[0] = ival; + if (pvdata->put(offset, 1, data, 0) == 0) + return ntransfered; + --len; + ++ntransfered; + ++offset; + ++fromOffset; + } + return ntransfered; + } + case pvUInt: { + PVUIntArray *pvdata = static_cast(pv); + uint32 data[1]; + while (len > 0) { + String fromString = from[fromOffset]; + unsigned int ival; + sscanf(fromString.c_str(),"%u",&ival); + data[0] = ival; + if (pvdata->put(offset, 1, data, 0) == 0) + return ntransfered; + --len; + ++ntransfered; + ++offset; + ++fromOffset; + } + return ntransfered; + } + case pvULong: { + PVULongArray *pvdata = static_cast(pv); + uint64 data[1]; + while (len > 0) { + String fromString = from[fromOffset]; + uint64 ival; + sscanf(fromString.c_str(),"%lld",(unsigned long long int *)&ival); data[0] = ival; if (pvdata->put(offset, 1, data, 0) == 0) return ntransfered; @@ -3014,7 +2317,7 @@ int convertFromStringArray(PVScalarArray *pv, int offset, int len,String from[], case pvString: PVStringArray *pvdata = static_cast(pv); while (len > 0) { - int n = pvdata->put(offset, len, from, fromOffset); + size_t n = pvdata->put(offset, len, get(from), fromOffset); if (n == 0) break; len -= n; @@ -3028,18 +2331,20 @@ int convertFromStringArray(PVScalarArray *pv, int offset, int len,String from[], throw std::logic_error(message); } -int convertToStringArray(PVScalarArray * pv, int offset, int len,String to[], int toOffset) +size_t convertToStringArray(PVScalarArray *pv, + size_t offset, size_t len,StringArray const & xxx, size_t toOffset) { + String *to = const_cast(&xxx[0]); ScalarType elementType = pv->getScalarArray()->getElementType(); - int ncopy = pv->getLength(); + size_t ncopy = pv->getLength(); if (ncopy > len) ncopy = len; - int num = ncopy; + size_t num = ncopy; switch (elementType) { case pvBoolean: { PVBooleanArray *pvdata = static_cast(pv); - BooleanArrayData data = BooleanArrayData(); - for (int i = 0; i < num; i++) { - if (pvdata->get(offset + i, 1, &data) == 1) { + BooleanArrayData data; + for (size_t i = 0; i < num; i++) { + if (pvdata->get(offset + i, 1, data) == 1) { BooleanArray dataArray = data.data; bool value = dataArray[data.offset]; to[toOffset + i] = value ? trueString : falseString; @@ -3051,10 +2356,10 @@ int convertToStringArray(PVScalarArray * pv, int offset, int len,String to[], in break; case pvByte: { PVByteArray *pvdata = static_cast(pv); - ByteArrayData data = ByteArrayData(); + ByteArrayData data; char cr[30]; - for (int i = 0; i < num; i++) { - if (pvdata->get(offset + i, 1, &data) == 1) { + for (size_t i = 0; i < num; i++) { + if (pvdata->get(offset + i, 1, data) == 1) { ByteArray dataArray = data.data; int ival = dataArray[data.offset]; sprintf(cr,"%d",ival); @@ -3067,10 +2372,10 @@ int convertToStringArray(PVScalarArray * pv, int offset, int len,String to[], in break; case pvShort: { PVShortArray *pvdata = static_cast(pv); - ShortArrayData data = ShortArrayData(); + ShortArrayData data; char cr[30]; - for (int i = 0; i < num; i++) { - if (pvdata->get(offset + i, 1, &data) == 1) { + for (size_t i = 0; i < num; i++) { + if (pvdata->get(offset + i, 1, data) == 1) { ShortArray dataArray = data.data; int ival = dataArray[data.offset]; sprintf(cr,"%d",ival); @@ -3083,10 +2388,10 @@ int convertToStringArray(PVScalarArray * pv, int offset, int len,String to[], in break; case pvInt: { PVIntArray *pvdata = static_cast(pv); - IntArrayData data = IntArrayData(); + IntArrayData data; char cr[30]; - for (int i = 0; i < num; i++) { - if (pvdata->get(offset + i, 1, &data) == 1) { + for (size_t i = 0; i < num; i++) { + if (pvdata->get(offset + i, 1, data) == 1) { IntArray dataArray = data.data; int ival = dataArray[data.offset]; sprintf(cr,"%d",ival); @@ -3101,11 +2406,75 @@ int convertToStringArray(PVScalarArray * pv, int offset, int len,String to[], in PVLongArray *pvdata = static_cast(pv); LongArrayData data = LongArrayData(); char cr[30]; - for (int i = 0; i < num; i++) { - if (pvdata->get(offset + i, 1, &data) == 1) { + for (size_t i = 0; i < num; i++) { + if (pvdata->get(offset + i, 1, data) == 1) { LongArray dataArray = data.data; int64 ival = dataArray[data.offset]; - sprintf(cr,"%lld",ival); + sprintf(cr,"%lld",(long long)ival); + to[toOffset + i] = String(cr); + } else { + to[toOffset + i] = "bad pv"; + } + } + } + break; + case pvUByte: { + PVUByteArray *pvdata = static_cast(pv); + UByteArrayData data; + char cr[30]; + for (size_t i = 0; i < num; i++) { + if (pvdata->get(offset + i, 1, data) == 1) { + UByteArray dataArray = data.data; + unsigned int ival = dataArray[data.offset]; + sprintf(cr,"%u",ival); + to[toOffset + i] = String(cr); + } else { + to[toOffset + i] = "bad pv"; + } + } + } + break; + case pvUShort: { + PVUShortArray *pvdata = static_cast(pv); + UShortArrayData data; + char cr[30]; + for (size_t i = 0; i < num; i++) { + if (pvdata->get(offset + i, 1, data) == 1) { + UShortArray dataArray = data.data; + unsigned int ival = dataArray[data.offset]; + sprintf(cr,"%u",ival); + to[toOffset + i] = String(cr); + } else { + to[toOffset + i] = "bad pv"; + } + } + } + break; + case pvUInt: { + PVUIntArray *pvdata = static_cast(pv); + UIntArrayData data; + char cr[30]; + for (size_t i = 0; i < num; i++) { + if (pvdata->get(offset + i, 1, data) == 1) { + UIntArray dataArray = data.data; + unsigned int ival = dataArray[data.offset]; + sprintf(cr,"%u",ival); + to[toOffset + i] = String(cr); + } else { + to[toOffset + i] = "bad pv"; + } + } + } + break; + case pvULong: { + PVULongArray *pvdata = static_cast(pv); + ULongArrayData data; + char cr[30]; + for (size_t i = 0; i < num; i++) { + if (pvdata->get(offset + i, 1, data) == 1) { + ULongArray dataArray = data.data; + uint64 ival = dataArray[data.offset]; + sprintf(cr,"%llu",(unsigned long long)ival); to[toOffset + i] = String(cr); } else { to[toOffset + i] = "bad pv"; @@ -3115,10 +2484,10 @@ int convertToStringArray(PVScalarArray * pv, int offset, int len,String to[], in break; case pvFloat: { PVFloatArray *pvdata = static_cast(pv); - FloatArrayData data = FloatArrayData(); + FloatArrayData data; char cr[30]; - for (int i = 0; i < num; i++) { - if (pvdata->get(offset + i, 1, &data) == 1) { + for (size_t i = 0; i < num; i++) { + if (pvdata->get(offset + i, 1, data) == 1) { FloatArray dataArray = data.data; float fval = dataArray[data.offset]; sprintf(cr,"%g",fval); @@ -3131,10 +2500,10 @@ int convertToStringArray(PVScalarArray * pv, int offset, int len,String to[], in break; case pvDouble: { PVDoubleArray *pvdata = static_cast(pv); - DoubleArrayData data = DoubleArrayData(); + DoubleArrayData data; char cr[30]; - for (int i = 0; i < num; i++) { - if (pvdata->get(offset + i, 1, &data) == 1) { + for (size_t i = 0; i < num; i++) { + if (pvdata->get(offset + i, 1, data) == 1) { DoubleArray dataArray = data.data; double fval = dataArray[data.offset]; sprintf(cr,"%g",fval); @@ -3148,19 +2517,19 @@ int convertToStringArray(PVScalarArray * pv, int offset, int len,String to[], in case pvString: { PVStringArray *pvdata = static_cast(pv); while (num > 0) { - int numnow = 0; - StringArray dataArray = 0; - int dataOffset = 0; - StringArrayData stringArrayData = StringArrayData(); - numnow = pvdata->get(offset, num, &stringArrayData); - dataArray = stringArrayData.data; + size_t numnow = 0; + size_t dataOffset = 0; + String *dataArray; + StringArrayData stringArrayData; + numnow = pvdata->get(offset, num, stringArrayData); + dataArray = pvdata->get(); dataOffset = stringArrayData.offset; if (numnow <= 0) { - for (int i = 0; i < num; i++) + for (size_t i = 0; i < num; i++) to[toOffset + i] = "bad pv"; break; } - for(int i=0; igetScalarType(); ScalarTypeFunc::toString(buffer,scalarType); *buffer += " "; - *buffer += pscalar->getFieldName(); + *buffer += pv->getFieldName(); *buffer += " "; switch(scalarType) { case pvBoolean: { @@ -3233,7 +2602,35 @@ void convertToString(StringBuilder buffer,PVField * pv,int indentLevel) case pvLong: { PVLong *data = static_cast(pv); char xxx[30]; - sprintf(xxx,"%lld",(int64)data->get()); + sprintf(xxx,"%lld",(long long)data->get()); + *buffer += xxx; + } + return; + case pvUByte: { + PVUByte *data = static_cast(pv); + char xxx[30]; + sprintf(xxx,"%u",(unsigned int)data->get()); + *buffer += xxx; + } + return; + case pvUShort: { + PVUShort *data = static_cast(pv); + char xxx[30]; + sprintf(xxx,"%u",(unsigned int)data->get()); + *buffer += xxx; + } + return; + case pvUInt: { + PVUInt *data = static_cast(pv); + char xxx[30]; + sprintf(xxx,"%u",(unsigned int)data->get()); + *buffer += xxx; + } + return; + case pvULong: { + PVULong *data = static_cast(pv); + char xxx[30]; + sprintf(xxx,"%llu",(unsigned long long)data->get()); *buffer += xxx; } return; @@ -3270,13 +2667,13 @@ void convertStructure(StringBuilder buffer,PVStructure *data,int indentLevel) *buffer += extendsName; *buffer += " "; } - *buffer += data->getField()->getFieldName(); - PVFieldPtrArray fieldsData = data->getPVFields(); - if (fieldsData != 0) { + *buffer += data->getFieldName(); + PVFieldPtrArray const & fieldsData = data->getPVFields(); + if (fieldsData.size() != 0) { int length = data->getStructure()->getNumberFields(); for(int i=0; inewLine(buffer, indentLevel+1); - PVField *fieldField = fieldsData[i]; + PVFieldPtr fieldField = fieldsData[i]; fieldField->toString(buffer,indentLevel + 1); } } @@ -3288,16 +2685,16 @@ void convertArray(StringBuilder buffer,PVScalarArray * pv,int indentLevel) ScalarType type = array->getElementType(); ScalarTypeFunc::toString(buffer,type); *buffer += "[] "; - *buffer += array->getFieldName(); + *buffer += pv->getFieldName(); *buffer += " "; switch(type) { case pvBoolean: { PVBooleanArray *pvdata = static_cast(pv); - BooleanArrayData data = BooleanArrayData(); + BooleanArrayData data; *buffer += "["; - for(int i=0; i < pvdata->getLength(); i++) { + for(size_t i=0; i < pvdata->getLength(); i++) { if(i!=0) *buffer += ","; - int num = pvdata->get(i,1,&data); + size_t num = pvdata->get(i,1,data); if(num==1) { BooleanArray value = data.data; if(value[data.offset]) { @@ -3314,11 +2711,11 @@ void convertArray(StringBuilder buffer,PVScalarArray * pv,int indentLevel) } case pvByte: { PVByteArray *pvdata = static_cast(pv); - ByteArrayData data = ByteArrayData(); + ByteArrayData data; *buffer += "["; - for(int i=0; i < pvdata->getLength(); i++) { + for(size_t i=0; i < pvdata->getLength(); i++) { if(i!=0) *buffer += ","; - int num = pvdata->get(i,1,&data); + size_t num = pvdata->get(i,1,data); if(num==1) { int val = data.data[data.offset]; char buf[16]; @@ -3333,11 +2730,11 @@ void convertArray(StringBuilder buffer,PVScalarArray * pv,int indentLevel) } case pvShort: { PVShortArray *pvdata = static_cast(pv); - ShortArrayData data = ShortArrayData(); + ShortArrayData data; *buffer += "["; - for(int i=0; i < pvdata->getLength(); i++) { + for(size_t i=0; i < pvdata->getLength(); i++) { if(i!=0) *buffer += ','; - int num = pvdata->get(i,1,&data); + size_t num = pvdata->get(i,1,data); if(num==1) { int val = data.data[data.offset]; char buf[16]; @@ -3352,11 +2749,11 @@ void convertArray(StringBuilder buffer,PVScalarArray * pv,int indentLevel) } case pvInt: { PVIntArray *pvdata = static_cast(pv); - IntArrayData data = IntArrayData(); + IntArrayData data; *buffer += "["; - for(int i=0; i < pvdata->getLength(); i++) { + for(size_t i=0; i < pvdata->getLength(); i++) { if(i!=0) *buffer += ','; - int num = pvdata->get(i,1,&data); + size_t num = pvdata->get(i,1,data); if(num==1) { int val = data.data[data.offset]; char buf[16]; @@ -3371,15 +2768,91 @@ void convertArray(StringBuilder buffer,PVScalarArray * pv,int indentLevel) } case pvLong: { PVLongArray *pvdata = static_cast(pv); - LongArrayData data = LongArrayData(); + LongArrayData data; *buffer += "["; - for(int i=0; i < pvdata->getLength(); i++) { + for(size_t i=0; i < pvdata->getLength(); i++) { if(i!=0) *buffer += ','; - int num = pvdata->get(i,1,&data); + size_t num = pvdata->get(i,1,data); if(num==1) { int64 val = data.data[data.offset]; + char buf[32]; + sprintf(buf,"%lld",(long long)val); + *buffer += buf; + } else { + *buffer += "???? "; + } + } + *buffer += "]"; + break; + } + case pvUByte: { + PVUByteArray *pvdata = static_cast(pv); + UByteArrayData data; + *buffer += "["; + for(size_t i=0; i < pvdata->getLength(); i++) { + if(i!=0) *buffer += ","; + size_t num = pvdata->get(i,1,data); + if(num==1) { + unsigned int val = data.data[data.offset]; char buf[16]; - sprintf(buf,"%lld",val); + sprintf(buf,"%u",val); + *buffer += buf; + } else { + *buffer += "???? "; + } + } + *buffer += "]"; + break; + } + case pvUShort: { + PVUShortArray *pvdata = static_cast(pv); + UShortArrayData data; + *buffer += "["; + for(size_t i=0; i < pvdata->getLength(); i++) { + if(i!=0) *buffer += ','; + size_t num = pvdata->get(i,1,data); + if(num==1) { + unsigned int val = data.data[data.offset]; + char buf[16]; + sprintf(buf,"%u",val); + *buffer += buf; + } else { + *buffer += "???? "; + } + } + *buffer += "]"; + break; + } + case pvUInt: { + PVUIntArray *pvdata = static_cast(pv); + UIntArrayData data; + *buffer += "["; + for(size_t i=0; i < pvdata->getLength(); i++) { + if(i!=0) *buffer += ','; + size_t num = pvdata->get(i,1,data); + if(num==1) { + unsigned int val = data.data[data.offset]; + char buf[16]; + sprintf(buf,"%u",val); + *buffer += buf; + } else { + *buffer += "???? "; + } + } + *buffer += "]"; + break; + } + case pvULong: { + PVULongArray *pvdata = static_cast(pv); + ULongArrayData data; + *buffer += "["; + for(size_t i=0; i < pvdata->getLength(); i++) { + if(i!=0) *buffer += ','; + size_t num = pvdata->get(i,1,data); + if(num==1) { + uint64 val = data.data[data.offset]; + char buf[32]; + sprintf(buf,"%llu",(unsigned long long)val); *buffer += buf; } else { *buffer += "???? "; @@ -3390,11 +2863,11 @@ void convertArray(StringBuilder buffer,PVScalarArray * pv,int indentLevel) } case pvFloat: { PVFloatArray *pvdata = static_cast(pv); - FloatArrayData data = FloatArrayData(); + FloatArrayData data; *buffer += "["; - for(int i=0; i < pvdata->getLength(); i++) { + for(size_t i=0; i < pvdata->getLength(); i++) { if(i!=0) *buffer += ','; - int num = pvdata->get(i,1,&data); + size_t num = pvdata->get(i,1,data); if(num==1) { float val = data.data[data.offset]; char buf[16]; @@ -3409,11 +2882,11 @@ void convertArray(StringBuilder buffer,PVScalarArray * pv,int indentLevel) } case pvDouble: { PVDoubleArray *pvdata = static_cast(pv); - DoubleArrayData data = DoubleArrayData(); + DoubleArrayData data; *buffer += "["; - for(int i=0; i < pvdata->getLength(); i++) { + for(size_t i=0; i < pvdata->getLength(); i++) { if(i!=0) *buffer += ','; - int num = pvdata->get(i,1,&data); + size_t num = pvdata->get(i,1,data); if(num==1) { double val = data.data[data.offset]; char buf[16]; @@ -3428,11 +2901,11 @@ void convertArray(StringBuilder buffer,PVScalarArray * pv,int indentLevel) } case pvString: { PVStringArray *pvdata = static_cast(pv); - StringArrayData data = StringArrayData(); + StringArrayData data; *buffer += "["; - for(int i=0; i < pvdata->getLength(); i++) { + for(size_t i=0; i < pvdata->getLength(); i++) { if(i!=0) *buffer += ","; - int num = pvdata->get(i,1,&data); + size_t num = pvdata->get(i,1,data); StringArray value = data.data; if(num==1) { if(value[data.offset].length()>0) { @@ -3459,18 +2932,18 @@ void convertStructureArray(StringBuilder buffer, PVStructureArray * pvdata,int indentLevel) { *buffer += "structure[] "; - *buffer += pvdata->getField()->getFieldName(); + *buffer += pvdata->getFieldName(); *buffer += " "; - int length = pvdata->getLength(); + size_t length = pvdata->getLength(); if(length<=0) { return; } StructureArrayData data = StructureArrayData(); - pvdata->get(0, length, &data); - for (int i = 0; i < length; i++) { + pvdata->get(0, length, data); + for (size_t i = 0; i < length; i++) { convert->newLine(buffer, indentLevel + 1); - PVStructure *pvStructure = data.data[i]; - if (pvStructure == 0) { + PVStructurePtr pvStructure = data.data[i]; + if (pvStructure.get() == 0) { *buffer += "null"; } else { pvStructure->toString(buffer,indentLevel+1); @@ -3478,80 +2951,92 @@ void convertStructureArray(StringBuilder buffer, } } -int copyArrayDataReference(PVScalarArray *from,PVArray *to) +size_t copyArrayDataReference(PVScalarArray *from,PVArray *to) { ScalarType scalarType = from->getScalarArray()->getElementType(); switch (scalarType) { case pvBoolean: { PVBooleanArray *pvfrom = (PVBooleanArray*) from; PVBooleanArray *pvto = (PVBooleanArray*) to; - BooleanArrayData booleanArrayData = BooleanArrayData(); - pvfrom->get(0, pvfrom->getLength(), &booleanArrayData); - BooleanArray booleanArray = booleanArrayData.data; - pvto->shareData(booleanArray,from->getCapacity(),from->getLength()); + pvto->shareData( + pvfrom->getSharedVector(),pvfrom->getCapacity(),pvfrom->getLength()); break; } case pvByte: { PVByteArray *pvfrom = (PVByteArray*) from; PVByteArray *pvto = (PVByteArray*) to; - ByteArrayData byteArrayData = ByteArrayData(); - pvfrom->get(0, pvfrom->getLength(), &byteArrayData); - ByteArray byteArray = byteArrayData.data; - pvto->shareData(byteArray,from->getCapacity(),from->getLength()); + pvto->shareData( + pvfrom->getSharedVector(),pvfrom->getCapacity(),pvfrom->getLength()); break; } case pvShort: { PVShortArray *pvfrom = (PVShortArray*) from; PVShortArray *pvto = (PVShortArray*) to; - ShortArrayData shortArrayData = ShortArrayData(); - pvfrom->get(0, pvfrom->getLength(), &shortArrayData); - ShortArray shortArray = shortArrayData.data; - pvto->shareData(shortArray,from->getCapacity(),from->getLength()); + pvto->shareData( + pvfrom->getSharedVector(),pvfrom->getCapacity(),pvfrom->getLength()); break; } case pvInt: { PVIntArray *pvfrom = (PVIntArray*) from; PVIntArray *pvto = (PVIntArray*) to; - IntArrayData intArrayData = IntArrayData(); - pvfrom->get(0, pvfrom->getLength(), &intArrayData); - IntArray intArray = intArrayData.data; - pvto->shareData(intArray,from->getCapacity(),from->getLength()); + pvto->shareData( + pvfrom->getSharedVector(),pvfrom->getCapacity(),pvfrom->getLength()); break; } case pvLong: { PVLongArray *pvfrom = (PVLongArray*) from; PVLongArray *pvto = (PVLongArray*) to; - LongArrayData longArrayData = LongArrayData(); - pvfrom->get(0, pvfrom->getLength(), &longArrayData); - LongArray longArray = longArrayData.data; - pvto->shareData(longArray,from->getCapacity(),from->getLength()); + pvto->shareData( + pvfrom->getSharedVector(),pvfrom->getCapacity(),pvfrom->getLength()); + break; + } + case pvUByte: { + PVUByteArray *pvfrom = (PVUByteArray*) from; + PVUByteArray *pvto = (PVUByteArray*) to; + pvto->shareData( + pvfrom->getSharedVector(),pvfrom->getCapacity(),pvfrom->getLength()); + break; + } + case pvUShort: { + PVUShortArray *pvfrom = (PVUShortArray*) from; + PVUShortArray *pvto = (PVUShortArray*) to; + pvto->shareData( + pvfrom->getSharedVector(),pvfrom->getCapacity(),pvfrom->getLength()); + break; + } + case pvUInt: { + PVUIntArray *pvfrom = (PVUIntArray*) from; + PVUIntArray *pvto = (PVUIntArray*) to; + pvto->shareData( + pvfrom->getSharedVector(),pvfrom->getCapacity(),pvfrom->getLength()); + break; + } + case pvULong: { + PVULongArray *pvfrom = (PVULongArray*) from; + PVULongArray *pvto = (PVULongArray*) to; + pvto->shareData( + pvfrom->getSharedVector(),pvfrom->getCapacity(),pvfrom->getLength()); break; } case pvFloat: { PVFloatArray *pvfrom = (PVFloatArray*) from; PVFloatArray *pvto = (PVFloatArray*) to; - FloatArrayData longArrayData = FloatArrayData(); - pvfrom->get(0, pvfrom->getLength(), &longArrayData); - FloatArray longArray = longArrayData.data; - pvto->shareData(longArray,from->getCapacity(),from->getLength()); + pvto->shareData( + pvfrom->getSharedVector(),pvfrom->getCapacity(),pvfrom->getLength()); break; } case pvDouble: { PVDoubleArray *pvfrom = (PVDoubleArray*) from; PVDoubleArray *pvto = (PVDoubleArray*) to; - DoubleArrayData doubleArrayData = DoubleArrayData(); - pvfrom->get(0, pvfrom->getLength(), &doubleArrayData); - DoubleArray doubleArray = doubleArrayData.data; - pvto->shareData(doubleArray,from->getCapacity(),from->getLength()); + pvto->shareData( + pvfrom->getSharedVector(),pvfrom->getCapacity(),pvfrom->getLength()); break; } case pvString: { PVStringArray *pvfrom = (PVStringArray*) from; PVStringArray *pvto = (PVStringArray*) to; - StringArrayData stringArrayData = StringArrayData(); - pvfrom->get(0, pvfrom->getLength(), &stringArrayData); - StringArray stringArray = stringArrayData.data; - pvto->shareData(stringArray,from->getCapacity(),from->getLength()); + pvto->shareData( + pvfrom->getSharedVector(),pvfrom->getCapacity(),pvfrom->getLength()); break; } } @@ -3559,24 +3044,24 @@ int copyArrayDataReference(PVScalarArray *from,PVArray *to) return from->getLength(); } -int copyNumericArray(PVScalarArray *from, int offset, PVScalarArray *to, int toOffset, int len) +size_t copyNumericArray(PVScalarArray *from, size_t offset, PVScalarArray *to, size_t toOffset, size_t len) { ScalarType fromElementType = from->getScalarArray()->getElementType(); - int ncopy = 0; + size_t ncopy = 0; switch (fromElementType) { case pvBoolean: throw std::logic_error(String("PVBooleanArray is not a numeric array")); case pvByte: { PVByteArray *pvfrom = (PVByteArray*) from; while (len > 0) { - int num = 0; - ByteArrayData byteArrayData = ByteArrayData(); - num = pvfrom->get(offset, len, &byteArrayData); - ByteArray data = byteArrayData.data; - int dataOffset = byteArrayData.offset; + size_t num = 0; + ByteArrayData arrayData = ByteArrayData(); + num = pvfrom->get(offset, len, arrayData); + int8 * data = get(arrayData.data); + size_t dataOffset = arrayData.offset; if (num <= 0) break; while (num > 0) { - int n = convert->fromByteArray( + size_t n = convertFromByteArray( to, toOffset, num, data, dataOffset); if (n <= 0) break; len -= n; @@ -3591,14 +3076,14 @@ int copyNumericArray(PVScalarArray *from, int offset, PVScalarArray *to, int toO case pvShort: { PVShortArray *pvfrom = (PVShortArray*) from; while (len > 0) { - int num = 0; - ShortArrayData shortArrayData = ShortArrayData(); - num = pvfrom->get(offset, len, &shortArrayData); - ShortArray data = shortArrayData.data; - int dataOffset = shortArrayData.offset; + size_t num = 0; + ShortArrayData arrayData = ShortArrayData(); + num = pvfrom->get(offset, len, arrayData); + int16 * data = get(arrayData.data); + size_t dataOffset = arrayData.offset; if (num <= 0) break; while (num > 0) { - int n = convert->fromShortArray( + size_t n = convertFromShortArray( to, toOffset, num, data, dataOffset); if (n <= 0) break; len -= n; @@ -3613,14 +3098,14 @@ int copyNumericArray(PVScalarArray *from, int offset, PVScalarArray *to, int toO case pvInt: { PVIntArray *pvfrom = (PVIntArray*) from; while (len > 0) { - int num = 0; - IntArrayData shortArrayData = IntArrayData(); - num = pvfrom->get(offset, len, &shortArrayData); - IntArray data = shortArrayData.data; - int dataOffset = shortArrayData.offset; + size_t num = 0; + IntArrayData arrayData = IntArrayData(); + num = pvfrom->get(offset, len, arrayData); + int32 * data = get(arrayData.data); + size_t dataOffset = arrayData.offset; if (num <= 0) break; while (num > 0) { - int n = convert->fromIntArray( + size_t n = convertFromIntArray( to, toOffset, num, data, dataOffset); if (n <= 0) break; len -= n; @@ -3635,14 +3120,102 @@ int copyNumericArray(PVScalarArray *from, int offset, PVScalarArray *to, int toO case pvLong: { PVLongArray *pvfrom = (PVLongArray*) from; while (len > 0) { - int num = 0; - LongArrayData longArrayData = LongArrayData(); - num = pvfrom->get(offset, len, &longArrayData); - LongArray data = longArrayData.data; - int dataOffset = longArrayData.offset; + size_t num = 0; + LongArrayData arrayData = LongArrayData(); + num = pvfrom->get(offset, len, arrayData); + int64 * data = get(arrayData.data); + size_t dataOffset = arrayData.offset; if (num <= 0) break; while (num > 0) { - int n = convert->fromLongArray( + size_t n = convertFromLongArray( + to, toOffset, num, data, dataOffset); + if (n <= 0) break; + len -= n; + num -= n; + ncopy += n; + offset += n; + toOffset += n; + } + } + break; + } + case pvUByte: { + PVUByteArray *pvfrom = (PVUByteArray*) from; + while (len > 0) { + size_t num = 0; + UByteArrayData arrayData = UByteArrayData(); + num = pvfrom->get(offset, len, arrayData); + uint8 * data = get(arrayData.data); + size_t dataOffset = arrayData.offset; + if (num <= 0) break; + while (num > 0) { + size_t n = convertFromUByteArray( + to, toOffset, num, data, dataOffset); + if (n <= 0) break; + len -= n; + num -= n; + ncopy += n; + offset += n; + toOffset += n; + } + } + break; + } + case pvUShort: { + PVUShortArray *pvfrom = (PVUShortArray*) from; + while (len > 0) { + size_t num = 0; + UShortArrayData arrayData = UShortArrayData(); + num = pvfrom->get(offset, len, arrayData); + uint16 * data = get(arrayData.data); + size_t dataOffset = arrayData.offset; + if (num <= 0) break; + while (num > 0) { + size_t n = convertFromUShortArray( + to, toOffset, num, data, dataOffset); + if (n <= 0) break; + len -= n; + num -= n; + ncopy += n; + offset += n; + toOffset += n; + } + } + break; + } + case pvUInt: { + PVUIntArray *pvfrom = (PVUIntArray*) from; + while (len > 0) { + size_t num = 0; + UIntArrayData arrayData = UIntArrayData(); + num = pvfrom->get(offset, len, arrayData); + uint32 * data = get(arrayData.data); + size_t dataOffset = arrayData.offset; + if (num <= 0) break; + while (num > 0) { + size_t n = convertFromUIntArray( + to, toOffset, num, data, dataOffset); + if (n <= 0) break; + len -= n; + num -= n; + ncopy += n; + offset += n; + toOffset += n; + } + } + break; + } + case pvULong: { + PVULongArray *pvfrom = (PVULongArray*) from; + while (len > 0) { + size_t num = 0; + ULongArrayData arrayData = ULongArrayData(); + num = pvfrom->get(offset, len, arrayData); + uint64 * data = get(arrayData.data); + size_t dataOffset = arrayData.offset; + if (num <= 0) break; + while (num > 0) { + size_t n = convertFromULongArray( to, toOffset, num, data, dataOffset); if (n <= 0) break; len -= n; @@ -3657,14 +3230,14 @@ int copyNumericArray(PVScalarArray *from, int offset, PVScalarArray *to, int toO case pvFloat: { PVFloatArray *pvfrom = (PVFloatArray*) from; while (len > 0) { - int num = 0; + size_t num = 0; FloatArrayData floatArrayData = FloatArrayData(); - num = pvfrom->get(offset, len, &floatArrayData); - FloatArray data = floatArrayData.data; - int dataOffset = floatArrayData.offset; + num = pvfrom->get(offset, len, floatArrayData); + float * data = get(floatArrayData.data); + size_t dataOffset = floatArrayData.offset; if (num <= 0) break; while (num > 0) { - int n = convert->fromFloatArray( + size_t n = convertFromFloatArray( to, toOffset, num, data, dataOffset); if (n <= 0) break; len -= n; @@ -3679,14 +3252,14 @@ int copyNumericArray(PVScalarArray *from, int offset, PVScalarArray *to, int toO case pvDouble: { PVDoubleArray *pvfrom = (PVDoubleArray*) from; while (len > 0) { - int num = 0; + size_t num = 0; DoubleArrayData doubleArrayData = DoubleArrayData(); - num = pvfrom->get(offset, len, &doubleArrayData); - DoubleArray data = doubleArrayData.data; - int dataOffset = doubleArrayData.offset; + num = pvfrom->get(offset, len, doubleArrayData); + double * data = get(doubleArrayData.data); + size_t dataOffset = doubleArrayData.offset; if (num <= 0) break; while (num > 0) { - int n = convert->fromDoubleArray( + size_t n = convertFromDoubleArray( to, toOffset, num, data, dataOffset); if (n <= 0) break; len -= n; @@ -3703,21 +3276,24 @@ int copyNumericArray(PVScalarArray *from, int offset, PVScalarArray *to, int toO } return ncopy; } +#ifdef XXXXXXXXX -class ConvertExt : public Convert { -public: - ConvertExt(): Convert(){}; -}; +#endif ///MARTY REMOVE THIS XXXXXXX -Convert * getConvert() { +ConvertPtr Convert::getConvert() +{ static Mutex mutex; Lock xx(mutex); - if(convert==0){ - convert = new ConvertExt(); + if(convert.get()==0) { + convert = ConvertPtr(new Convert()); pvDataCreate = getPVDataCreate(); } return convert; } +ConvertPtr getConvert() { + return Convert::getConvert(); +} + }} diff --git a/pvDataApp/factory/DefaultPVStructureArray.cpp b/pvDataApp/factory/DefaultPVStructureArray.cpp deleted file mode 100644 index 6a516c4..0000000 --- a/pvDataApp/factory/DefaultPVStructureArray.cpp +++ /dev/null @@ -1,251 +0,0 @@ -/*PVStructureArray.cpp*/ -/** - * Copyright - See the COPYRIGHT that is included with this distribution. - * EPICS pvDataCPP is distributed subject to a Software License Agreement found - * in file LICENSE that is included with this distribution. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include "DefaultPVStructureArray.h" - -using std::tr1::static_pointer_cast; -using std::tr1::const_pointer_cast; - -namespace epics { namespace pvData { - - BasePVStructureArray::BasePVStructureArray( - PVStructure *parent,StructureArrayConstPtr structureArray) - : PVStructureArray(parent,structureArray), - structureArray(structureArray), - structureArrayData(new StructureArrayData()), - value(new PVStructurePtr[0]) - { - } - - BasePVStructureArray::~BasePVStructureArray() - { - delete structureArrayData; - int number = getCapacity(); - for(int i=0; igetStructure(); - for(int i=currentLength; icreatePVStructure(0,structure); - } - return newLength; - } - - bool BasePVStructureArray::remove(int offset,int number) - { - int length = getCapacity(); - if(offset+number>length) return false; - for(int i=offset;i0) remove(length,numRemove); - PVStructurePtrArray newValue = new PVStructurePtr[capacity]; - int limit = length; - if(length>capacity) limit = capacity; - for(int i=0; icapacity) length = capacity; - delete[] value; - value = newValue; - setCapacityLength(capacity,length); - } - - - StructureArrayConstPtr BasePVStructureArray::getStructureArray() - { - return structureArray; - } - - int BasePVStructureArray::get( - int offset, int len, StructureArrayData *data) - { - int n = len; - int length = getLength(); - if(offset+len > length) { - n = length - offset; - if(n<0) n = 0; - } - data->data = value; - data->offset = offset; - return n; - } - - int BasePVStructureArray::put(int offset,int len, - PVStructurePtrArray from, int fromOffset) - { - if(isImmutable()) { - message(String("field is immutable"), errorMessage); - return 0; - } - if(from==value) return len; - if(len<1) return 0; - int length = getLength(); - int capacity = getCapacity(); - if(offset+len > length) { - int newlength = offset + len; - if(newlength>capacity) { - setCapacity(newlength); - capacity = getCapacity(); - newlength = capacity; - len = newlength - offset; - if(len<=0) return 0; - } - length = newlength; - setLength(length); - } - StructureConstPtr structure = structureArray->getStructure(); - for(int i=0; igetStructure()!=structure) { - throw std::invalid_argument(String( - "Element is not a compatible structure")); - } - value[i+offset] = frompv; - } - postPut(); - return len; - } - - void BasePVStructureArray::shareData( - PVStructurePtrArray newValue,int capacity,int length) - { - for(int i=0; i=0) { - // prepare array, if necessary - if(size>getCapacity()) setCapacity(size); - for(int i = 0; iensureData(1); - int8 temp = pbuffer->getByte(); - if(temp==0) { - if (value[i]) { - delete value[i]; - value[i] = NULL; - } - } - else { - if(value[i]==NULL) { - value[i] = getPVDataCreate()->createPVStructure( - NULL, structureArray->getStructure()); - } - value[i]->deserialize(pbuffer, pcontrol); - } - } - setLength(size); - postPut(); - } - } - - void BasePVStructureArray::serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher, int offset, int count) const { - // cache - int length = getLength(); - - // check bounds - if(offset<0) - offset = 0; - else if(offset>length) offset = length; - if(count<0) count = length; - - int maxCount = length-offset; - if(count>maxCount) count = maxCount; - - // write - SerializeHelper::writeSize(count, pbuffer, pflusher); - for(int i = 0; igetRemaining()<1) pflusher->flushSerializeBuffer(); - PVStructure* pvStructure = value[i+offset]; - if(pvStructure==NULL) { - pbuffer->putByte(0); - } - else { - pbuffer->putByte(1); - pvStructure->serialize(pbuffer, pflusher); - } - } - } - -}} diff --git a/pvDataApp/factory/DefaultPVStructureArray.h b/pvDataApp/factory/DefaultPVStructureArray.h index 8cfeec2..a34ec3d 100644 --- a/pvDataApp/factory/DefaultPVStructureArray.h +++ b/pvDataApp/factory/DefaultPVStructureArray.h @@ -17,32 +17,44 @@ namespace epics { namespace pvData { - class BasePVStructureArray : public PVStructureArray { - public: - BasePVStructureArray(PVStructure *parent, - StructureArrayConstPtr structureArray); - virtual ~BasePVStructureArray(); - virtual StructureArrayConstPtr getStructureArray(); - virtual int append(int number); - virtual bool remove(int offset,int number); - virtual void compress(); - virtual void setCapacity(int capacity); - virtual int get(int offset, int length, - StructureArrayData *data); - virtual int put(int offset,int length, - PVStructurePtrArray from, int fromOffset); - virtual void shareData( PVStructurePtrArray value,int capacity,int length); - virtual void serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher) const; - virtual void deserialize(ByteBuffer *buffer, - DeserializableControl *pflusher); - virtual void serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher, int offset, int count) const; - private: - StructureArrayConstPtr structureArray; - StructureArrayData *structureArrayData; - PVStructurePtrArray value; - }; +class BasePVStructureArray : public PVStructureArray { +public: + POINTER_DEFINITIONS(PVStructureArray); + typedef PVStructurePtr* pointer; + typedef std::vector vector; + typedef std::tr1::shared_ptr shared_vector; + + BasePVStructureArray(PVStructure *parent, + StructureArrayConstPtr structureArray); + virtual ~BasePVStructureArray(); + virtual StructureArrayConstPtr getStructureArray(); + virtual std::size_t append(std::size_t number); + virtual bool remove(std::size_t offset,std::size_t number); + virtual void compress(); + virtual void setCapacity(std::size_t capacity); + virtual std::size_t get(std::size_t offset, std::size_t length, + StructureArrayData &data); + virtual std::size_t put(std::size_t offset,std::size_t length, + vector const & from, std::size_t fromOffset); + virtual void shareData( + shared_vector const & value, + std::size_t capacity, + std::size_t length); + virtual pointer getRaw(); + virtual pointer getRaw() const; + virtual vector const & getVector(){return *value.get();} + virtual shared_vector const & getSharedVector(){return value;}; + + virtual void serialize(ByteBuffer *pbuffer, + SerializableControl *pflusher) const; + virtual void deserialize(ByteBuffer *buffer, + DeserializableControl *pflusher); + virtual void serialize(ByteBuffer *pbuffer, + SerializableControl *pflusher, std::size_t offset, std::size_t count) const ; +private: + StructureArrayConstPtr structureArray; + shared_vector value; +}; }} #endif /*DEFAULTPVSTRUCTUREARRAY_H*/ diff --git a/pvDataApp/factory/FieldCreateFactory.cpp b/pvDataApp/factory/FieldCreateFactory.cpp index 99fa3b7..da6cfe9 100644 --- a/pvDataApp/factory/FieldCreateFactory.cpp +++ b/pvDataApp/factory/FieldCreateFactory.cpp @@ -12,10 +12,10 @@ #include #include #include -#include #include using std::tr1::static_pointer_cast; +using std::size_t; namespace epics { namespace pvData { @@ -27,54 +27,41 @@ static void newLine(StringBuilder buffer, int indentLevel) for(int i=0; iensureBuffer(1); buffer->putByte((int8)(epics::pvData::scalar << 4 | getScalarType())); SerializeHelper::serializeString(getFieldName(), buffer, control); +*/ } void Scalar::deserialize(ByteBuffer *buffer, DeserializableControl *control) { } - - static void serializeStructureField(const Structure* structure, ByteBuffer* buffer, SerializableControl* control) { +/* SerializeHelper::serializeString(structure->getFieldName(), buffer, control); FieldConstPtrArray fields = structure->getFields(); SerializeHelper::writeSize(structure->getNumberFields(), buffer, control); @@ -82,10 +69,13 @@ static void serializeStructureField(const Structure* structure, ByteBuffer* buff { control->cachedSerialize(fields[i], buffer); } +*/ } static StructureConstPtr deserializeStructureField(const FieldCreate* fieldCreate, ByteBuffer* buffer, DeserializableControl* control) { +throw std::invalid_argument("for Matej to convert"); +/* const String structureFieldName = SerializeHelper::deserializeString(buffer, control); const int32 size = SerializeHelper::readSize(buffer, control); FieldConstPtrArray fields = NULL; @@ -105,33 +95,32 @@ static StructureConstPtr deserializeStructureField(const FieldCreate* fieldCreat StructureConstPtr structure = fieldCreate->createStructure(structureFieldName, size, fields); return structure; +*/ } - - - -ScalarArray::ScalarArray(String fieldName,ScalarType elementType) -: Field(fieldName,scalarArray),elementType(elementType){} +ScalarArray::ScalarArray(ScalarType elementType) +: Field(scalarArray),elementType(elementType){} ScalarArray::~ScalarArray() {} void ScalarArray::toString(StringBuilder buffer,int indentLevel) const{ ScalarTypeFunc::toString(buffer,elementType); *buffer += "[]"; - Field::toString(buffer,indentLevel); } void ScalarArray::serialize(ByteBuffer *buffer, SerializableControl *control) const { +/* control->ensureBuffer(1); buffer->putByte((int8)(epics::pvData::scalarArray << 4 | getElementType())); SerializeHelper::serializeString(getFieldName(), buffer, control); +*/ } void ScalarArray::deserialize(ByteBuffer *buffer, DeserializableControl *control) { } -StructureArray::StructureArray(String fieldName,StructureConstPtr structure) -: Field(fieldName,structureArray),pstructure(structure) +StructureArray::StructureArray(StructureConstPtr structure) +: Field(structureArray),pstructure(structure) { } @@ -140,187 +129,195 @@ StructureArray::~StructureArray() { } void StructureArray::toString(StringBuilder buffer,int indentLevel) const { - *buffer += "structure[]"; - Field::toString(buffer,indentLevel); - newLine(buffer,indentLevel + 1); - pstructure->toString(buffer,indentLevel + 1); + if(indentLevel==0) { + *buffer += "structure[]"; + newLine(buffer,indentLevel + 1); + pstructure->toString(buffer,indentLevel + 1); + return; + } + pstructure->toString(buffer,indentLevel); } void StructureArray::serialize(ByteBuffer *buffer, SerializableControl *control) const { +/* control->ensureBuffer(1); buffer->putByte((int8)(epics::pvData::structureArray << 4)); SerializeHelper::serializeString(getFieldName(), buffer, control); // we also need to serialize structure field... serializeStructureField(getStructure().get(), buffer, control); +*/ } void StructureArray::deserialize(ByteBuffer *buffer, DeserializableControl *control) { } -Structure::Structure (String fieldName, - int numberFields, FieldConstPtrArray infields) -: Field(fieldName,structure), - numberFields(numberFields), +Structure::Structure (StringArray fieldNames,FieldConstPtrArray infields) +: Field(structure), + fieldNames(fieldNames), fields(infields) { - for(int i=0; igetFieldName(); + if(fieldNames.size()!=fields.size()) { + throw std::invalid_argument("fieldNames.size()!=fields.size()"); + } + size_t number = fields.size(); + for(size_t i=0; igetFieldName(); + for(size_t j=i+1; jgetFieldName()); + int result = fieldName.compare(fieldNames[i]); if(result==0) return pfield; } return FieldConstPtr(); } -int Structure::getFieldIndex(String fieldName) const { - for(int i=0; igetFieldName()); + int result = fieldName.compare(fieldNames[i]); if(result==0) return i; } return -1; } -void Structure::appendField(FieldConstPtr field) -{ - FieldConstPtr *newFields = new FieldConstPtr[numberFields+1]; - for(int i=0; i=numberFields) { - throw std::invalid_argument( - String("Structure::removeField index out of bounds")); - } - FieldConstPtr *newFields = new FieldConstPtr[numberFields-1]; - - int ind=0; - for(int i=0; itoString(buffer,indentLevel+1); - if(igetType()) { + case scalar: + case scalarArray: + pfield->toString(buffer, indentLevel); + *buffer += " "; + *buffer += fieldNames[i]; + break; + case structure: + { + Field const *xxx = pfield.get(); + Structure const *pstruct = static_cast(xxx); + *buffer += "structure "; + *buffer += fieldNames[i]; + pstruct->toStringCommon(buffer,indentLevel + 1); + break; + } + case structureArray: + *buffer += "structure[] " + fieldNames[i]; + newLine(buffer,indentLevel +1); + pfield->toString(buffer,indentLevel +1); + break; + } + if(iensureBuffer(1); buffer->putByte((int8)(epics::pvData::structure << 4)); serializeStructureField(this, buffer, control); +*/ } void Structure::deserialize(ByteBuffer *buffer, DeserializableControl *control) { } -ScalarConstPtr FieldCreate::createScalar(String fieldName, - ScalarType scalarType) const +ScalarConstPtr FieldCreate::createScalar(ScalarType scalarType) const { - ScalarConstPtr scalar(new Scalar(fieldName,scalarType), Field::Deleter()); + ScalarConstPtr scalar(new Scalar(scalarType), Field::Deleter()); return scalar; } -ScalarArrayConstPtr FieldCreate::createScalarArray( - String fieldName,ScalarType elementType) const +ScalarArrayConstPtr FieldCreate::createScalarArray(ScalarType elementType) const { - ScalarArrayConstPtr scalarArray(new ScalarArray(fieldName,elementType), Field::Deleter()); + ScalarArrayConstPtr scalarArray(new ScalarArray(elementType), Field::Deleter()); return scalarArray; } + StructureConstPtr FieldCreate::createStructure ( - String fieldName,int numberFields, - FieldConstPtr fields[]) const + StringArray const & fieldNames,FieldConstPtrArray const & fields) const { - StructureConstPtr structure(new Structure( - fieldName,numberFields,fields), Field::Deleter()); + StructureConstPtr structure( + new Structure(fieldNames,fields), Field::Deleter()); return structure; } + StructureArrayConstPtr FieldCreate::createStructureArray( - String fieldName,StructureConstPtr structure) const + StructureConstPtr structure) const { - StructureArrayConstPtr structureArray(new StructureArray(fieldName,structure), Field::Deleter()); + StructureArrayConstPtr structureArray( + new StructureArray(structure), Field::Deleter()); return structureArray; } -FieldConstPtr FieldCreate::create(String fieldName, - FieldConstPtr pfield) const +StructureConstPtr FieldCreate::appendField( + StructureConstPtr structure,String fieldName, FieldConstPtr field) const { - FieldConstPtr ret; - Type type = pfield->getType(); - switch(type) { - case scalar: { - ScalarConstPtr pscalar = static_pointer_cast(pfield); - return createScalar(fieldName,pscalar->getScalarType()); + StringArray oldNames = structure->getFieldNames(); + FieldConstPtrArray oldFields = structure->getFields(); + size_t oldLen = oldNames.size(); + StringArray newNames(oldLen+1); + FieldConstPtrArray newFields(oldLen+1); + for(size_t i = 0; i(pfield); - return createScalarArray(fieldName,pscalarArray->getElementType()); + newNames[oldLen] = fieldName; + newFields[oldLen] = field; + return createStructure(newNames,newFields); +} + +StructureConstPtr FieldCreate::appendFields( + StructureConstPtr structure, + StringArray const & fieldNames, + FieldConstPtrArray const & fields) const +{ + StringArray oldNames = structure->getFieldNames(); + FieldConstPtrArray oldFields = structure->getFields(); + size_t oldLen = oldNames.size(); + size_t extra = fieldNames.size(); + StringArray newNames(oldLen+extra); + FieldConstPtrArray newFields(oldLen+extra); + for(size_t i = 0; i(pfield); - return createStructure(fieldName,pstructure->getNumberFields(),pstructure->getFields()); + for(size_t i = 0; i(pfield); - return createStructureArray(fieldName,pstructureArray->getStructure()); - } - } - String message("field "); - message += fieldName; - THROW_EXCEPTION2(std::logic_error, message); + return createStructure(newNames,newFields); } FieldConstPtr FieldCreate::deserialize(ByteBuffer* buffer, DeserializableControl* control) const { +throw std::invalid_argument("for Matej to convert"); +/* + control->ensureData(1); const int8 typeCode = buffer->getByte(); @@ -356,20 +353,23 @@ FieldConstPtr FieldCreate::deserialize(ByteBuffer* buffer, DeserializableControl return FieldConstPtr(); } } +*/ } -static FieldCreate* fieldCreate = 0; - -FieldCreate::FieldCreate() +FieldCreatePtr FieldCreate::getFieldCreate() { -} - -FieldCreate * getFieldCreate() { + static FieldCreatePtr fieldCreate; static Mutex mutex; Lock xx(mutex); - if(fieldCreate==0) fieldCreate = new FieldCreate(); + if(fieldCreate.get()==0) fieldCreate = FieldCreatePtr(new FieldCreate()); return fieldCreate; } +FieldCreate::FieldCreate(){} + +FieldCreatePtr getFieldCreate() { + return FieldCreate::getFieldCreate(); +} + }} diff --git a/pvDataApp/factory/PVArray.cpp b/pvDataApp/factory/PVArray.cpp index 3755c8e..a7017ec 100644 --- a/pvDataApp/factory/PVArray.cpp +++ b/pvDataApp/factory/PVArray.cpp @@ -12,19 +12,21 @@ #include #include +using std::size_t; + namespace epics { namespace pvData { class PVArrayPvt { public: PVArrayPvt() : length(0),capacity(0),capacityMutable(true) {} - int length; - int capacity; + size_t length; + size_t capacity; bool capacityMutable; }; - PVArray::PVArray(PVStructure *parent,FieldConstPtr field) - : PVField(parent,field),pImpl(new PVArrayPvt()) + PVArray::PVArray(FieldConstPtr field) + : PVField(field),pImpl(new PVArrayPvt()) { } PVArray::~PVArray() @@ -32,13 +34,13 @@ namespace epics { namespace pvData { delete pImpl; } - int PVArray::getLength() const {return pImpl->length;} + size_t PVArray::getLength() const {return pImpl->length;} - int PVArray::getCapacity() const {return pImpl->capacity;} + size_t PVArray::getCapacity() const {return pImpl->capacity;} static String fieldImmutable("field is immutable"); - void PVArray::setLength(int length) { + void PVArray::setLength(size_t length) { if(length==pImpl->length) return; if(PVField::isImmutable()) { PVField::message(fieldImmutable,errorMessage); @@ -49,7 +51,7 @@ namespace epics { namespace pvData { pImpl->length = length; } - void PVArray::setCapacityLength(int capacity,int length) { + void PVArray::setCapacityLength(size_t capacity,size_t length) { pImpl->capacity = capacity; pImpl->length = length; } @@ -74,7 +76,7 @@ namespace epics { namespace pvData { static String capacityImmutable("capacity is immutable"); - void PVArray::setCapacity(int capacity) { + void PVArray::setCapacity(size_t capacity) { if(PVField::isImmutable()) { PVField::message(fieldImmutable,errorMessage); return; diff --git a/pvDataApp/factory/PVAuxInfoImpl.cpp b/pvDataApp/factory/PVAuxInfoImpl.cpp index 35963c2..633b82a 100644 --- a/pvDataApp/factory/PVAuxInfoImpl.cpp +++ b/pvDataApp/factory/PVAuxInfoImpl.cpp @@ -17,11 +17,13 @@ namespace epics { namespace pvData { +static PVScalarPtr nullPVScalar; + PVDATA_REFCOUNT_MONITOR_DEFINE(pvAuxInfo); -PVAuxInfo::PVAuxInfo(PVField *pvField) - : pvField(pvField),lengthInfo(1),numberInfo(0), - pvInfos(new PVScalar *[1]) +PVAuxInfo::PVAuxInfo(PVField * pvField) + : pvField(pvField), + pvInfos(std::map > ()) { PVDATA_REFCOUNT_MONITOR_CONSTRUCT(pvAuxInfo); } @@ -29,8 +31,6 @@ PVAuxInfo::PVAuxInfo(PVField *pvField) PVAuxInfo::~PVAuxInfo() { PVDATA_REFCOUNT_MONITOR_DESTRUCT(pvAuxInfo); - 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; - } + PVInfoIter iter = pvInfos.find(key); + if(iter!=pvInfos.end()) { + String message = key.c_str(); + message += " already exists "; + pvField->message(message,errorMessage); + return nullPVScalar; } - if(lengthInfo==numberInfo) { - int newLength = lengthInfo+4; - PVScalar ** newInfos = new PVScalar *[newLength]; - lengthInfo = newLength; - for(int i=0; icreatePVScalar(0,key,scalarType); - pvInfos[numberInfo++] = pvScalar; + PVScalarPtr pvScalar = getPVDataCreate()->createPVScalar(scalarType); + pvInfos.insert(PVInfoPair(key,pvScalar)); return pvScalar; } -PVScalar * PVAuxInfo::getInfo(String key) +PVScalarPtr& PVAuxInfo::getInfo(String key) { - for(int i=0; igetField()->getFieldName())==0) return pvScalar; - } - return 0; + PVInfoIter iter; + iter = pvInfos.find(key); + if(iter==pvInfos.end()) return nullPVScalar; + return iter->second; } -PVScalar * PVAuxInfo::getInfo(int index) +PVAuxInfo::PVInfoMap & PVAuxInfo::getInfoMap() { - if(index<0 || index>=numberInfo) return 0; - return pvInfos[index]; + return pvInfos; } -int PVAuxInfo::getNumberInfo() { return numberInfo;} void PVAuxInfo::toString(StringBuilder buf) { @@ -89,13 +74,13 @@ void PVAuxInfo::toString(StringBuilder buf) void PVAuxInfo::toString(StringBuilder buf,int indentLevel) { - if(numberInfo==0) return; - Convert *convert = getConvert(); + if(pvInfos.size()<=0) return; + ConvertPtr convert = getConvert(); convert->newLine(buf,indentLevel); *buf += "auxInfo"; - for(int i=0; inewLine(buf,indentLevel+1); - PVScalar *value = pvInfos[i]; + PVFieldPtr value = iter->second; value->toString(buf,indentLevel + 1); } } diff --git a/pvDataApp/factory/PVDataCreateFactory.cpp b/pvDataApp/factory/PVDataCreateFactory.cpp index 2f031d0..915c6b3 100644 --- a/pvDataApp/factory/PVDataCreateFactory.cpp +++ b/pvDataApp/factory/PVDataCreateFactory.cpp @@ -17,16 +17,15 @@ #include #include #include -#include "DefaultPVStructureArray.h" using std::tr1::static_pointer_cast; using std::tr1::const_pointer_cast; +using std::size_t; namespace epics { namespace pvData { static Convert* convert = 0; static FieldCreate * fieldCreate = 0; -static PVDataCreate* pvDataCreate = 0; /** Default storage for scalar values */ @@ -37,7 +36,7 @@ public: typedef T* pointer; typedef const T* const_pointer; - BasePVScalar(PVStructure *parent,ScalarConstPtr scalar); + BasePVScalar(ScalarConstPtr &scalar); virtual ~BasePVScalar(); virtual T get(); virtual void put(T val); @@ -50,8 +49,8 @@ private: }; template -BasePVScalar::BasePVScalar(PVStructure *parent,ScalarConstPtr scalar) - : PVScalarValue(parent,scalar),value(0) +BasePVScalar::BasePVScalar(ScalarConstPtr &scalar) + : PVScalarValue(scalar),value(0) {} //Note: '0' is a suitable default for all POD types (not String) @@ -79,11 +78,15 @@ void BasePVScalar::deserialize(ByteBuffer *pbuffer, value = pbuffer->get(); } -typedef BasePVScalar BasePVBoolean; +typedef BasePVScalar BasePVBoolean; typedef BasePVScalar BasePVByte; typedef BasePVScalar BasePVShort; typedef BasePVScalar BasePVInt; typedef BasePVScalar BasePVLong; +typedef BasePVScalar BasePVUByte; +typedef BasePVScalar BasePVUShort; +typedef BasePVScalar BasePVUInt; +typedef BasePVScalar BasePVULong; typedef BasePVScalar BasePVFloat; typedef BasePVScalar BasePVDouble; @@ -94,7 +97,7 @@ public: typedef String* pointer; typedef const String* const_pointer; - BasePVString(PVStructure *parent,ScalarConstPtr scalar); + BasePVString(ScalarConstPtr &scalar); virtual ~BasePVString(); virtual String get(); virtual void put(String val); @@ -103,13 +106,13 @@ public: virtual void deserialize(ByteBuffer *pbuffer, DeserializableControl *pflusher); virtual void serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher, int offset, int count) const; + SerializableControl *pflusher, size_t offset, size_t count) const; private: String value; }; -BasePVString::BasePVString(PVStructure *parent,ScalarConstPtr scalar) - : PVString(parent,scalar),value() +BasePVString::BasePVString(ScalarConstPtr &scalar) + : PVString(scalar),value() {} BasePVString::~BasePVString() {} @@ -131,15 +134,15 @@ void BasePVString::deserialize(ByteBuffer *pbuffer, } void BasePVString::serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher, int offset, int count) const + SerializableControl *pflusher, size_t offset, size_t count) const { // check bounds - const int length = /*(value == null) ? 0 :*/ value.length(); + const size_t length = /*(value == null) ? 0 :*/ value.length(); if (offset < 0) offset = 0; else if (offset > length) offset = length; if (count < 0) count = length; - const int maxCount = length - offset; + const size_t maxCount = length - offset; if (count > maxCount) count = maxCount; @@ -152,40 +155,63 @@ void BasePVString::serialize(ByteBuffer *pbuffer, template class DefaultPVArray : public PVValueArray { public: - typedef T value_type; typedef T* pointer; - typedef const T* const_pointer; + typedef std::vector vector; + typedef std::tr1::shared_ptr shared_vector; - DefaultPVArray(PVStructure *parent,ScalarArrayConstPtr scalarArray); + DefaultPVArray(ScalarArrayConstPtr &scalarArray); virtual ~DefaultPVArray(); - virtual void setCapacity(int capacity); - virtual int get(int offset, int length, PVArrayData *data) ; - virtual int put(int offset,int length, pointer from, - int fromOffset); - virtual void shareData(pointer value,int capacity,int length); + virtual void setCapacity(size_t capacity); + virtual size_t get(size_t offset, size_t length, PVArrayData &data) ; + virtual size_t put(size_t offset,size_t length, pointer const from, + size_t fromOffset); + virtual void shareData( + std::tr1::shared_ptr > const & value, + std::size_t capacity, + std::size_t length); + virtual pointer get() ; + virtual pointer get() const ; + virtual vector const & getVector() { return *value.get(); } + virtual shared_vector const & getSharedVector(){return value;}; // from Serializable virtual void serialize(ByteBuffer *pbuffer,SerializableControl *pflusher) const; virtual void deserialize(ByteBuffer *pbuffer,DeserializableControl *pflusher); virtual void serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher, int offset, int count) const; + SerializableControl *pflusher, size_t offset, size_t count) const; private: - pointer value; + shared_vector value; }; template -DefaultPVArray::DefaultPVArray(PVStructure *parent, - ScalarArrayConstPtr scalarArray) -: PVValueArray(parent,scalarArray),value(new T[0]) +T *DefaultPVArray::get() +{ + std::vector *vec = value.get(); + T *praw = &((*vec)[0]); + return praw; +} + +template +T *DefaultPVArray::get() const +{ + std::vector *vec = value.get(); + T *praw = &((*vec)[0]); + return praw; +} + + +template +DefaultPVArray::DefaultPVArray(ScalarArrayConstPtr &scalarArray) +: PVValueArray(scalarArray), + value(std::tr1::shared_ptr >(new std::vector())) + { } template DefaultPVArray::~DefaultPVArray() -{ - delete[] value; -} +{ } template -void DefaultPVArray::setCapacity(int capacity) +void DefaultPVArray::setCapacity(size_t capacity) { if(PVArray::getCapacity()==capacity) return; if(!PVArray::isCapacityMutable()) { @@ -193,43 +219,45 @@ void DefaultPVArray::setCapacity(int capacity) PVField::message(message, errorMessage); return; } - int length = PVArray::getLength(); - if(length>capacity) length = capacity; - T *newValue = new T[capacity]; - for(int i=0; i array(capacity); + size_t num = PVArray::getLength(); + if(num>capacity) num = capacity; + T * from = get(); + for (size_t i=0; iswap(array); PVArray::setCapacityLength(capacity,length); } template -int DefaultPVArray::get(int offset, int len, PVArrayData *data) +size_t DefaultPVArray::get(size_t offset, size_t len, PVArrayData &data) { - int n = len; - int length = this->getLength(); + size_t n = len; + size_t length = this->getLength(); if(offset+len > length) { n = length-offset; if(n<0) n = 0; } - data->data = value; - data->offset = offset; + data.data = *value.get(); + data.offset = offset; return n; } template -int DefaultPVArray::put(int offset,int len, - pointer from,int fromOffset) +size_t DefaultPVArray::put(size_t offset,size_t len, + pointer const from,size_t fromOffset) { if(PVField::isImmutable()) { PVField::message("field is immutable",errorMessage); return 0; } - if(from==value) return len; + T * pvalue = get(); + if(from==pvalue) return len; if(len<1) return 0; - int length = this->getLength(); - int capacity = this->getCapacity(); + size_t length = this->getLength(); + size_t capacity = this->getCapacity(); if(offset+len > length) { - int newlength = offset + len; + size_t newlength = offset + len; if(newlength>capacity) { setCapacity(newlength); newlength = this->getCapacity(); @@ -238,8 +266,9 @@ int DefaultPVArray::put(int offset,int len, } length = newlength; } - for(int i=0;isetLength(length); this->postPut(); @@ -247,10 +276,12 @@ int DefaultPVArray::put(int offset,int len, } template -void DefaultPVArray::shareData(pointer shareValue,int capacity,int length) +void DefaultPVArray::shareData( + std::tr1::shared_ptr > const & sharedValue, + std::size_t capacity, + std::size_t length) { - delete[] value; - value = shareValue; + value = sharedValue; PVArray::setCapacityLength(capacity,length); } @@ -263,21 +294,21 @@ void DefaultPVArray::serialize(ByteBuffer *pbuffer, template void DefaultPVArray::deserialize(ByteBuffer *pbuffer, DeserializableControl *pcontrol) { - int size = SerializeHelper::readSize(pbuffer, pcontrol); + size_t size = SerializeHelper::readSize(pbuffer, pcontrol); // if (size>0) { pcontrol->ensureData(sizeof(T)-1); pbuffer->align(sizeof(T)); } if(size>=0) { // prepare array, if necessary if(size>this->getCapacity()) this->setCapacity(size); // retrieve value from the buffer - int i = 0; + size_t i = 0; while(true) { /* - int maxIndex = std::min(size-i, (int)(pbuffer->getRemaining()/sizeof(T)))+i; + size_t maxIndex = std::min(size-i, (int)(pbuffer->getRemaining()/sizeof(T)))+i; for(; iget(); */ - int maxCount = std::min(size-i, (int)(pbuffer->getRemaining()/sizeof(T))); - pbuffer->getArray(&value[i], maxCount); + size_t maxCount = std::min(size-i, (pbuffer->getRemaining()/sizeof(T))); + pbuffer->getArray(get(), maxCount); i += maxCount; if(i::deserialize(ByteBuffer *pbuffer, template void DefaultPVArray::serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher, int offset, int count) const { + SerializableControl *pflusher, size_t offset, size_t count) const { // cache - int length = this->getLength(); + size_t length = this->getLength(); // check bounds if(offset<0) @@ -304,24 +335,25 @@ void DefaultPVArray::serialize(ByteBuffer *pbuffer, else if(offset>length) offset = length; if(count<0) count = length; - int maxCount = length-offset; + size_t maxCount = length-offset; if(count>maxCount) count = maxCount; // write SerializeHelper::writeSize(count, pbuffer, pflusher); //if (count == 0) return; pcontrol->ensureData(sizeof(T)-1); pbuffer->align(sizeof(T)); - int end = offset+count; - int i = offset; + size_t end = offset+count; + size_t i = offset; while(true) { /* - int maxIndex = std::min(end-i, (int)(pbuffer->getRemaining()/sizeof(T)))+i; + size_t maxIndex = std::min(end-i, (int)(pbuffer->getRemaining()/sizeof(T)))+i; for(; iput(value[i]); */ - int maxCount = std::min(end-i, (int)(pbuffer->getRemaining()/sizeof(T))); - pbuffer->putArray(&value[i], maxCount); + size_t maxCount = std::min(end-i, (int)(pbuffer->getRemaining()/sizeof(T))); + T * pvalue = const_cast(get()); + pbuffer->putArray(pvalue, maxCount); i += maxCount; if(i::serialize(ByteBuffer *pbuffer, template<> void DefaultPVArray::deserialize(ByteBuffer *pbuffer, DeserializableControl *pcontrol) { - int size = SerializeHelper::readSize(pbuffer, pcontrol); + size_t size = SerializeHelper::readSize(pbuffer, pcontrol); if(size>=0) { // prepare array, if necessary if(size>getCapacity()) setCapacity(size); // retrieve value from the buffer - for(int i = 0; i::deserialize(ByteBuffer *pbuffer, template<> void DefaultPVArray::serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher, int offset, int count) const { - int length = getLength(); + SerializableControl *pflusher, size_t offset, size_t count) const { + size_t length = getLength(); // check bounds if(offset<0) @@ -362,21 +396,27 @@ void DefaultPVArray::serialize(ByteBuffer *pbuffer, else if(offset>length) offset = length; if(count<0) count = length; - int maxCount = length-offset; + size_t maxCount = length-offset; if(count>maxCount) count = maxCount; // write SerializeHelper::writeSize(count, pbuffer, pflusher); - int end = offset+count; - for(int i = offset; i DefaultPVBooleanArray; +typedef DefaultPVArray DefaultPVBooleanArray; typedef DefaultPVArray BasePVByteArray; typedef DefaultPVArray BasePVShortArray; typedef DefaultPVArray BasePVIntArray; typedef DefaultPVArray BasePVLongArray; +typedef DefaultPVArray BasePVUByteArray; +typedef DefaultPVArray BasePVUShortArray; +typedef DefaultPVArray BasePVUIntArray; +typedef DefaultPVArray BasePVULongArray; typedef DefaultPVArray BasePVFloatArray; typedef DefaultPVArray BasePVDoubleArray; typedef DefaultPVArray BasePVStringArray; @@ -385,217 +425,230 @@ typedef DefaultPVArray BasePVStringArray; PVDataCreate::PVDataCreate(){ } -PVField *PVDataCreate::createPVField(PVStructure *parent, - FieldConstPtr field) +PVFieldPtr PVDataCreate::createPVField(FieldConstPtr & field) { switch(field->getType()) { case scalar: { ScalarConstPtr xx = static_pointer_cast(field); - return createPVScalar(parent,xx); + return createPVScalar(xx); } case scalarArray: { ScalarArrayConstPtr xx = static_pointer_cast(field); - return (PVField *)createPVScalarArray(parent,xx); + return createPVScalarArray(xx); } case structure: { StructureConstPtr xx = static_pointer_cast(field); - return (PVField *)createPVStructure(parent,xx); + return createPVStructure(xx); } case structureArray: { StructureArrayConstPtr xx = static_pointer_cast(field); - return createPVStructureArray(parent,xx); + return createPVStructureArray(xx); } } - String message("PVDataCreate::createPVField should never get here"); - throw std::logic_error(message); + throw std::logic_error("PVDataCreate::createPVField should never get here"); } -PVField *PVDataCreate::createPVField(PVStructure *parent, - String fieldName,PVField * fieldToClone) +PVFieldPtr PVDataCreate::createPVField(PVFieldPtr & fieldToClone) { switch(fieldToClone->getField()->getType()) { case scalar: - return createPVScalar(parent,fieldName,(PVScalar*)fieldToClone); + { + PVScalarPtr pvScalar = static_pointer_cast(fieldToClone); + return createPVScalar(pvScalar); + } case scalarArray: - return (PVField *)createPVScalarArray(parent,fieldName, - (PVScalarArray *)fieldToClone); + { + PVScalarArrayPtr pvScalarArray + = static_pointer_cast(fieldToClone); + return createPVScalarArray(pvScalarArray); + } case structure: - return (PVField *)createPVStructure(parent,fieldName, - (PVStructure *)fieldToClone); + { + PVStructurePtr pvStructure + = static_pointer_cast(fieldToClone); + StringArray fieldNames = pvStructure->getStructure()->getFieldNames(); + PVFieldPtrArray pvFieldPtrArray = pvStructure->getPVFields(); + return createPVStructure(fieldNames,pvFieldPtrArray); + } case structureArray: - String message( - "PVDataCreate::createPVField structureArray not valid fieldToClone"); - throw std::invalid_argument(message); + { + PVStructureArrayPtr from + = static_pointer_cast(fieldToClone); + StructureArrayConstPtr structureArray = from->getStructureArray(); + PVStructureArrayPtr to = createPVStructureArray( + structureArray); + convert->copyStructureArray(from, to); + return to; + } } - String message("PVDataCreate::createPVField should never get here"); - throw std::logic_error(message); + throw std::logic_error("PVDataCreate::createPVField should never get here"); } -PVScalar *PVDataCreate::createPVScalar(PVStructure *parent,ScalarConstPtr scalar) +PVScalarPtr PVDataCreate::createPVScalar(ScalarConstPtr & scalar) { ScalarType scalarType = scalar->getScalarType(); switch(scalarType) { case pvBoolean: - return new BasePVBoolean(parent,scalar); + return PVScalarPtr(new BasePVBoolean(scalar)); case pvByte: - return new BasePVByte(parent,scalar); + return PVScalarPtr(new BasePVByte(scalar)); case pvShort: - return new BasePVShort(parent,scalar); + return PVScalarPtr(new BasePVShort(scalar)); case pvInt: - return new BasePVInt(parent,scalar); + return PVScalarPtr(new BasePVInt(scalar)); case pvLong: - return new BasePVLong(parent,scalar); + return PVScalarPtr(new BasePVLong(scalar)); + case pvUByte: + return PVScalarPtr(new BasePVUByte(scalar)); + case pvUShort: + return PVScalarPtr(new BasePVUShort(scalar)); + case pvUInt: + return PVScalarPtr(new BasePVUInt(scalar)); + case pvULong: + return PVScalarPtr(new BasePVULong(scalar)); case pvFloat: - return new BasePVFloat(parent,scalar); + return PVScalarPtr(new BasePVFloat(scalar)); case pvDouble: - return new BasePVDouble(parent,scalar); + return PVScalarPtr(new BasePVDouble(scalar)); case pvString: - return new BasePVString(parent,scalar); + return PVScalarPtr(new BasePVString(scalar)); } - String message("PVDataCreate::createPVScalar should never get here"); - throw std::logic_error(message); + throw std::logic_error("PVDataCreate::createPVScalar should never get here"); } -PVScalar *PVDataCreate::createPVScalar(PVStructure *parent, - String fieldName,ScalarType scalarType) +PVScalarPtr PVDataCreate::createPVScalar(ScalarType scalarType) { - ScalarConstPtr scalar = fieldCreate->createScalar(fieldName,scalarType); - return createPVScalar(parent,scalar); + ScalarConstPtr scalar = fieldCreate->createScalar(scalarType); + return createPVScalar(scalar); } -PVScalar *PVDataCreate::createPVScalar(PVStructure *parent, - String fieldName,PVScalar * scalarToClone) +PVScalarPtr PVDataCreate::createPVScalar(PVScalarPtr & scalarToClone) { - PVScalar *pvScalar = createPVScalar(parent,fieldName, - scalarToClone->getScalar()->getScalarType()); + ScalarType scalarType = scalarToClone->getScalar()->getScalarType(); + PVScalarPtr pvScalar = createPVScalar(scalarType); convert->copyScalar(scalarToClone, pvScalar); - 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); + PVAuxInfoPtr from = scalarToClone->getPVAuxInfo(); + PVAuxInfoPtr to = pvScalar->getPVAuxInfo(); + PVAuxInfo::PVInfoMap & map = from->getInfoMap(); + for(PVAuxInfo::PVInfoIter iter = map.begin(); iter!= map.end(); ++iter) { + String key = iter->first; + PVScalarPtr pvFrom = iter->second; + ScalarConstPtr scalar = pvFrom->getScalar(); + PVScalarPtr pvTo = to->createInfo(key,scalar->getScalarType()); + convert->copyScalar(pvFrom,pvTo); } return pvScalar; } -PVScalarArray *PVDataCreate::createPVScalarArray(PVStructure *parent, - ScalarArrayConstPtr scalarArray) +PVScalarArrayPtr PVDataCreate::createPVScalarArray( + ScalarArrayConstPtr & scalarArray) { switch(scalarArray->getElementType()) { case pvBoolean: - return new DefaultPVBooleanArray(parent,scalarArray); + return PVScalarArrayPtr(new DefaultPVBooleanArray(scalarArray)); case pvByte: - return new BasePVByteArray(parent,scalarArray); + return PVScalarArrayPtr(new BasePVByteArray(scalarArray)); case pvShort: - return new BasePVShortArray(parent,scalarArray); + return PVScalarArrayPtr(new BasePVShortArray(scalarArray)); case pvInt: - return new BasePVIntArray(parent,scalarArray); + return PVScalarArrayPtr(new BasePVIntArray(scalarArray)); case pvLong: - return new BasePVLongArray(parent,scalarArray); + return PVScalarArrayPtr(new BasePVLongArray(scalarArray)); + case pvUByte: + return PVScalarArrayPtr(new BasePVUByteArray(scalarArray)); + case pvUShort: + return PVScalarArrayPtr(new BasePVUShortArray(scalarArray)); + case pvUInt: + return PVScalarArrayPtr(new BasePVUIntArray(scalarArray)); + case pvULong: + return PVScalarArrayPtr(new BasePVULongArray(scalarArray)); case pvFloat: - return new BasePVFloatArray(parent,scalarArray); + return PVScalarArrayPtr(new BasePVFloatArray(scalarArray)); case pvDouble: - return new BasePVDoubleArray(parent,scalarArray); + return PVScalarArrayPtr(new BasePVDoubleArray(scalarArray)); case pvString: - return new BasePVStringArray(parent,scalarArray); + return PVScalarArrayPtr(new BasePVStringArray(scalarArray)); } - String message("PVDataCreate::createPVScalarArray should never get here"); - throw std::logic_error(message); + throw std::logic_error("PVDataCreate::createPVScalarArray should never get here"); } -PVScalarArray *PVDataCreate::createPVScalarArray(PVStructure *parent, - String fieldName,ScalarType elementType) +PVScalarArrayPtr PVDataCreate::createPVScalarArray( + ScalarType elementType) { - return createPVScalarArray(parent, - fieldCreate->createScalarArray(fieldName, elementType)); + ScalarArrayConstPtr scalarArray = fieldCreate->createScalarArray(elementType); + return createPVScalarArray(scalarArray); } -PVScalarArray *PVDataCreate::createPVScalarArray(PVStructure *parent, - String fieldName,PVScalarArray * arrayToClone) +PVScalarArrayPtr PVDataCreate::createPVScalarArray( + PVScalarArrayPtr &arrayToClone) { - PVScalarArray *pvArray = createPVScalarArray(parent,fieldName, + PVScalarArrayPtr pvArray = createPVScalarArray( arrayToClone->getScalarArray()->getElementType()); convert->copyScalarArray(arrayToClone,0, pvArray,0,arrayToClone->getLength()); - 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); + PVAuxInfoPtr from = arrayToClone->getPVAuxInfo(); + PVAuxInfoPtr to = pvArray->getPVAuxInfo(); + PVAuxInfo::PVInfoMap & map = from->getInfoMap(); + for(PVAuxInfo::PVInfoIter iter = map.begin(); iter!= map.end(); ++iter) { + String key = iter->first; + PVScalarPtr pvFrom = iter->second; + ScalarConstPtr scalar = pvFrom->getScalar(); + PVScalarPtr pvTo = to->createInfo(key,scalar->getScalarType()); + convert->copyScalar(pvFrom,pvTo); } return pvArray; } -PVStructureArray *PVDataCreate::createPVStructureArray(PVStructure *parent, - StructureArrayConstPtr structureArray) +PVStructureArrayPtr PVDataCreate::createPVStructureArray( + StructureArrayConstPtr & structureArray) { - return new BasePVStructureArray(parent,structureArray); + return PVStructureArrayPtr(new PVStructureArray(structureArray)); } -PVStructure *PVDataCreate::createPVStructure(PVStructure *parent, - StructureConstPtr structure) +PVStructurePtr PVDataCreate::createPVStructure( + StructureConstPtr &structure) { - PVStructure *pvStructure = new PVStructure(parent,structure); - return pvStructure; + return PVStructurePtr(new PVStructure(structure)); } -PVStructure *PVDataCreate::createPVStructure(PVStructure *parent, - String fieldName,int numberFields,FieldConstPtrArray fields) +PVStructurePtr PVDataCreate::createPVStructure( + StringArray & fieldNames,PVFieldPtrArray & pvFields) { - StructureConstPtr structure = fieldCreate->createStructure( - fieldName,numberFields, fields); - return new PVStructure(parent,structure); + size_t num = fieldNames.size(); + FieldConstPtrArray fields(num); + for (size_t i=0;igetField(); + StructureConstPtr structure = fieldCreate->createStructure(fieldNames,fields); + return PVStructurePtr(new PVStructure(structure,pvFields)); } -PVStructure *PVDataCreate::createPVStructure(PVStructure *parent, - String fieldName,int numberFields,PVFieldPtrArray pvFields) +PVStructurePtr PVDataCreate::createPVStructure(PVStructurePtr &structToClone) { - FieldConstPtrArray fields = new FieldConstPtr[numberFields]; - for(int i=0; igetField(); - } - StructureConstPtr structure = fieldCreate->createStructure( - fieldName,numberFields,fields); - PVStructure *pvStructure = new PVStructure(parent,structure,pvFields); - return pvStructure; -} - -PVStructure *PVDataCreate::createPVStructure(PVStructure *parent, - String fieldName,PVStructure *structToClone) -{ - FieldConstPtrArray fields = 0; - int numberFields = 0; - PVStructure *pvStructure = 0;; + FieldConstPtrArray field; if(structToClone==0) { - fields = new FieldConstPtr[0]; - StructureConstPtr structure = fieldCreate->createStructure( - fieldName,numberFields,fields); - pvStructure = new PVStructure(parent,structure); - } else { - StructureConstPtr structure = structToClone->getStructure(); - pvStructure = new PVStructure(parent,structure); - convert->copyStructure(structToClone,pvStructure); + FieldConstPtrArray fields(0); + StringArray fieldNames(0); + StructureConstPtr structure = fieldCreate->createStructure(fieldNames,fields); + return PVStructurePtr(new PVStructure(structure)); } + StructureConstPtr structure = structToClone->getStructure(); + PVStructurePtr pvStructure(new PVStructure(structure)); + convert->copyStructure(structToClone,pvStructure); return pvStructure; } -PVDataCreate * getPVDataCreate() { - static Mutex mutex; - Lock xx(mutex); +PVDataCreatePtr PVDataCreate::getPVDataCreate() +{ + static PVDataCreatePtr pvDataCreate; + static Mutex mutex; + Lock xx(mutex); - if(pvDataCreate==0){ - pvDataCreate = new PVDataCreate(); - convert = getConvert(); - fieldCreate = getFieldCreate(); - } - return pvDataCreate; - } + if(pvDataCreate.get()==0) pvDataCreate = PVDataCreatePtr(new PVDataCreate()); + return pvDataCreate; +} + +PVDataCreatePtr getPVDataCreate() { + return PVDataCreate::getPVDataCreate(); +} }} diff --git a/pvDataApp/factory/PVField.cpp b/pvDataApp/factory/PVField.cpp index f23557a..614ceec 100644 --- a/pvDataApp/factory/PVField.cpp +++ b/pvDataApp/factory/PVField.cpp @@ -12,72 +12,39 @@ #include #include #include -#include using std::tr1::const_pointer_cast; +using std::size_t; namespace epics { namespace pvData { static String notImplemented("not implemented"); -PVDATA_REFCOUNT_MONITOR_DEFINE(pvField); -class PVFieldPvt { -public: - PVFieldPvt(PVStructure *parent,FieldConstPtr field); - ~PVFieldPvt(); - PVStructure *parent; - FieldConstPtr field; - int fieldOffset; - int nextFieldOffset; - PVAuxInfo *pvAuxInfo; - bool immutable; - Requester *requester; - PostHandler *postHandler; - Convert *convert; -}; - -PVFieldPvt::PVFieldPvt(PVStructure *parent,FieldConstPtr field) -: parent(parent),field(field), - fieldOffset(0), nextFieldOffset(0), - pvAuxInfo(0), - immutable(false),requester(0),postHandler(0), - convert(getConvert()) +PVField::PVField(FieldConstPtr field) +: parent(NULL),field(field), + fieldOffset(0), nextFieldOffset(0), + immutable(false),requester(0),postHandler(0), + convert(getConvert()) { } -PVFieldPvt::~PVFieldPvt() -{ - if(pvAuxInfo!=0) delete pvAuxInfo; -} - - - -PVField::PVField(PVStructure *parent,FieldConstPtr field) -: pImpl(new PVFieldPvt(parent,field)) -{ - PVDATA_REFCOUNT_MONITOR_CONSTRUCT(pvField); -} - PVField::~PVField() -{ - PVDATA_REFCOUNT_MONITOR_DESTRUCT(pvField); - delete pImpl; -} +{ } void PVField::message(String fieldName,String message,MessageType messageType) { - if(pImpl->parent!=0) { - String parentName = pImpl->parent->getField()->getFieldName(); + if(parent!=NULL) { + String parentName = parent->getFieldName(); if(parentName.length()>0) { fieldName = parentName + "." + fieldName; } - pImpl->parent->message(fieldName,message,messageType); + parent->message(fieldName,message,messageType); return; } - if(pImpl->requester) { + if(requester) { String mess = fieldName + " " + message; - pImpl->requester->message(mess,messageType); + requester->message(mess,messageType); } else { printf("%s %s %s\n", messageTypeName[messageType].c_str(), @@ -88,129 +55,174 @@ void PVField::message(String fieldName,String message,MessageType messageType) void PVField::message(String message,MessageType messageType) { - PVField::message(pImpl->field->getFieldName(),message,messageType); + PVField::message(fieldName,message,messageType); } + +String PVField::getFieldName() +{ + if(parent==NULL) return fieldName; + PVFieldPtrArray pvFields = parent->getPVFields(); + StringArray const & fieldNames = parent->getStructure()->getFieldNames(); + for(size_t i=0; iparent!=0) { - throw std::logic_error(String( - "PVField::setRequester only legal for top level structure")); + if(parent!=NULL) { + throw std::logic_error( + "PVField::setRequester only legal for top level structure"); } - if(pImpl->requester!=0) { - if(pImpl->requester==requester) return; - throw std::logic_error(String( - "PVField::setRequester requester is already present")); + if(requester!=NULL) { + if(requester==requester) return; + throw std::logic_error( + "PVField::setRequester requester is already present"); } - pImpl->requester = requester; + requester = requester; } -int PVField::getFieldOffset() +size_t PVField::getFieldOffset() { - if(pImpl->nextFieldOffset==0) computeOffset(this); - return pImpl->fieldOffset; + if(nextFieldOffset==0) computeOffset(this); + return fieldOffset; } -int PVField::getNextFieldOffset() +size_t PVField::getNextFieldOffset() { - if(pImpl->nextFieldOffset==0) computeOffset(this); - return pImpl->nextFieldOffset; + if(nextFieldOffset==0) computeOffset(this); + return nextFieldOffset; } -int PVField::getNumberFields() +size_t PVField::getNumberFields() { - if(pImpl->nextFieldOffset==0) computeOffset(this); - return (pImpl->nextFieldOffset - pImpl->fieldOffset); + if(nextFieldOffset==0) computeOffset(this); + return (nextFieldOffset - fieldOffset); } -PVAuxInfo * PVField::getPVAuxInfo(){ - if(pImpl->pvAuxInfo==0) { - pImpl->pvAuxInfo = new PVAuxInfo(this); +PVAuxInfoPtr & PVField::getPVAuxInfo(){ + if(pvAuxInfo.get()==NULL) { + pvAuxInfo = PVAuxInfoPtr(new PVAuxInfo(this)); } - return pImpl->pvAuxInfo; + return pvAuxInfo; } -bool PVField::isImmutable() {return pImpl->immutable;} +bool PVField::isImmutable() {return immutable;} -void PVField::setImmutable() {pImpl->immutable = true;} +void PVField::setImmutable() {immutable = true;} -FieldConstPtr PVField::getField() {return pImpl->field;} +FieldConstPtr & PVField::getField() {return field;} -PVStructure * PVField::getParent() {return pImpl->parent;} +PVStructure *PVField::getParent() {return parent;} - -bool PVField::renameField(String newName) +void PVField::replacePVField(PVFieldPtr & newPVField) { - if(pImpl->parent!=0) { - StructureConstPtr structure = pImpl->parent->getStructure(); - int index = structure->getFieldIndex(newName); - if(index>=0) return false; + if(parent==NULL) { + throw std::logic_error("no parent"); } - Field::shared_pointer field(const_pointer_cast(pImpl->field)); - field->renameField(newName); - return true; + PVFieldPtrArray pvFields = parent->getPVFields(); + StructureConstPtr structure = parent->getStructure(); + StringArray fieldNames = structure->getFieldNames(); + for(size_t i=0; igetFieldName().compare(fieldNames[i]) == 0) { + pvFields[i] = newPVField; + return; + } + } + throw std::logic_error("Did not find field in parent"); +} + +void PVField::replaceField(FieldConstPtr &xxx) +{ + field = xxx; +} + +void PVField::renameField(String newName) +{ + if(parent==NULL) { + throw std::logic_error("no parent"); + } + std::tr1::shared_ptr parentStructure = const_pointer_cast( + parent->getStructure()); + StringArray const &fieldNames = parentStructure->getFieldNames(); + FieldConstPtrArray const &fields = parentStructure->getFields(); + for(size_t i=0; irenameField(i,newName); + return; + } + } + throw std::logic_error("Did not find field in parent"); } void PVField::postPut() { - if(pImpl->postHandler!=0) pImpl->postHandler->postPut(); + if(postHandler!=NULL) postHandler->postPut(); } void PVField::setPostHandler(PostHandler *postHandler) { - if(pImpl->postHandler!=0) { - if(postHandler==pImpl->postHandler) return; - String message( + if(postHandler!=NULL) { + if(postHandler==postHandler) return; + throw std::logic_error( "PVField::setPostHandler a postHandler is already registered"); - throw std::logic_error(message); + } - pImpl->postHandler = postHandler; + postHandler = postHandler; } -void PVField::setParent(PVStructure * parent) +void PVField::setParent(PVStructure * xxx) { - pImpl->parent = parent; + parent = xxx; } bool PVField::equals(PVField &pv) { - return pImpl->convert->equals(*this,pv); + return convert->equals(*this,pv); } -void PVField::toString(StringBuilder buf) {toString(buf,0);} +void PVField::toString(StringBuilder buf) +{ + toString(buf,0); +} void PVField::toString(StringBuilder buf,int indentLevel) { - pImpl->convert->getString(buf,this,indentLevel); - if(pImpl->pvAuxInfo==0) return; - pImpl->pvAuxInfo->toString(buf,indentLevel); + static ConvertPtr convert = getConvert(); + convert->getString(buf,this,indentLevel); + if(pvAuxInfo.get()!=NULL) pvAuxInfo->toString(buf,indentLevel); } void PVField::computeOffset(PVField * pvField) { - PVStructure *pvTop = pvField->getParent(); - if(pvTop==0) { + PVStructure * pvTop = pvField->getParent(); + if(pvTop==NULL) { if(pvField->getField()->getType()!=structure) { - pvField->pImpl->fieldOffset = 0; - pvField->pImpl->nextFieldOffset = 1; + pvField->fieldOffset = 0; + pvField->nextFieldOffset = 1; return; } pvTop = static_cast(pvField); } else { - while(pvTop->getParent()!=0) pvTop = pvTop->getParent(); + while(pvTop->getParent()!=NULL) pvTop = pvTop->getParent(); } int offset = 0; int nextOffset = 1; - PVFieldPtrArray pvFields = pvTop->getPVFields(); - for(int i=0; i < pvTop->getStructure()->getNumberFields(); i++) { + PVFieldPtrArray pvFields = pvTop->getPVFields(); + for(size_t i=0; i < pvTop->getStructure()->getNumberFields(); i++) { offset = nextOffset; - PVField *pvField = pvFields[i]; + PVField *pvField = pvFields[i].get(); FieldConstPtr field = pvField->getField(); switch(field->getType()) { case scalar: case scalarArray: case structureArray:{ nextOffset++; - pvField->pImpl->fieldOffset = offset; - pvField->pImpl->nextFieldOffset = nextOffset; + pvField->fieldOffset = offset; + pvField->nextFieldOffset = nextOffset; break; } case structure: { @@ -220,36 +232,36 @@ void PVField::computeOffset(PVField * pvField) { } } PVField *top = (PVField *)pvTop; - top->pImpl->fieldOffset = 0; - top->pImpl->nextFieldOffset = nextOffset; + top->fieldOffset = 0; + top->nextFieldOffset = nextOffset; } -void PVField::computeOffset(PVField * pvField,int offset) { - int beginOffset = offset; - int nextOffset = offset + 1; - PVStructure *pvStructure = static_cast(pvField); - PVFieldPtrArray pvFields = pvStructure->getPVFields(); - for(int i=0; i < pvStructure->getStructure()->getNumberFields(); i++) { - offset = nextOffset; - PVField *pvSubField = pvFields[i]; - FieldConstPtr field = pvSubField->getField(); - switch(field->getType()) { - case scalar: - case scalarArray: - case structureArray: { - nextOffset++; - pvSubField->pImpl->fieldOffset = offset; - pvSubField->pImpl->nextFieldOffset = nextOffset; - break; - } - case structure: { - pvSubField->computeOffset(pvSubField,offset); - nextOffset = pvSubField->getNextFieldOffset(); - } - } - } - pvField->pImpl->fieldOffset = beginOffset; - pvField->pImpl->nextFieldOffset = nextOffset; +void PVField::computeOffset(PVField * pvField,size_t offset) { + int beginOffset = offset; + int nextOffset = offset + 1; + PVStructure *pvStructure = static_cast(pvField); + PVFieldPtrArray pvFields = pvStructure->getPVFields(); + for(size_t i=0; i < pvStructure->getStructure()->getNumberFields(); i++) { + offset = nextOffset; + PVField *pvSubField = pvFields[i].get(); + FieldConstPtr field = pvSubField->getField(); + switch(field->getType()) { + case scalar: + case scalarArray: + case structureArray: { + nextOffset++; + pvSubField->fieldOffset = offset; + pvSubField->nextFieldOffset = nextOffset; + break; + } + case structure: { + pvSubField->computeOffset(pvSubField,offset); + nextOffset = pvSubField->getNextFieldOffset(); + } + } + } + pvField->fieldOffset = beginOffset; + pvField->nextFieldOffset = nextOffset; } }} diff --git a/pvDataApp/factory/PVScalar.cpp b/pvDataApp/factory/PVScalar.cpp index 8111c8e..7c723d7 100644 --- a/pvDataApp/factory/PVScalar.cpp +++ b/pvDataApp/factory/PVScalar.cpp @@ -17,8 +17,8 @@ namespace epics { namespace pvData { PVScalar::~PVScalar() {} - PVScalar::PVScalar(PVStructure *parent,ScalarConstPtr scalar) - : PVField(parent,scalar) {} + PVScalar::PVScalar(ScalarConstPtr scalar) + : PVField(scalar) {} ScalarConstPtr PVScalar::getScalar() { diff --git a/pvDataApp/factory/PVScalarArray.cpp b/pvDataApp/factory/PVScalarArray.cpp index f52f67f..ce218f6 100644 --- a/pvDataApp/factory/PVScalarArray.cpp +++ b/pvDataApp/factory/PVScalarArray.cpp @@ -17,9 +17,8 @@ namespace epics { namespace pvData { PVScalarArray::~PVScalarArray() {} - PVScalarArray::PVScalarArray(PVStructure *parent, - ScalarArrayConstPtr scalarArray) - : PVArray(parent,scalarArray) {} + PVScalarArray::PVScalarArray(ScalarArrayConstPtr scalarArray) + : PVArray(scalarArray) {} ScalarArrayConstPtr PVScalarArray::getScalarArray() { diff --git a/pvDataApp/factory/PVStructure.cpp b/pvDataApp/factory/PVStructure.cpp index 869b69d..79b0b7c 100644 --- a/pvDataApp/factory/PVStructure.cpp +++ b/pvDataApp/factory/PVStructure.cpp @@ -17,551 +17,625 @@ using std::tr1::static_pointer_cast; using std::tr1::const_pointer_cast; +using std::size_t; namespace epics { namespace pvData { - class PVStructurePvt { - public: - PVStructurePvt(); - ~PVStructurePvt(); +static PVFieldPtr nullPVField; +static PVBooleanPtr nullPVBoolean; +static PVBytePtr nullPVByte; +static PVShortPtr nullPVShort; +static PVIntPtr nullPVInt; +static PVLongPtr nullPVLong; +static PVUBytePtr nullPVUByte; +static PVUShortPtr nullPVUShort; +static PVUIntPtr nullPVUInt; +static PVULongPtr nullPVULong; +static PVFloatPtr nullPVFloat; +static PVDoublePtr nullPVDouble; +static PVStringPtr nullPVString; +static PVStructurePtr nullPVStructure; +static PVStructureArrayPtr nullPVStructureArray; +static PVScalarArrayPtr nullPVScalarArray; - int numberFields; - PVFieldPtrArray pvFields; - String extendsStructureName; - }; +static PVFieldPtr &findSubField(String fieldName,PVStructure *pvStructure); - PVStructurePvt::PVStructurePvt() - : numberFields(0), pvFields(0),extendsStructureName("") - { +PVStructure::PVStructure(StructureConstPtr& structurePtr) +: PVField(structurePtr), + structurePtr(structurePtr), + extendsStructureName("") +{ + size_t numberFields = structurePtr->getNumberFields(); + FieldConstPtrArray fields = structurePtr->getFields(); + pvFields.reserve(numberFields); + PVDataCreatePtr pvDataCreate = getPVDataCreate(); + for(size_t i=0; icreatePVField(fields[i])); } - - PVStructurePvt::~PVStructurePvt() - { - for(int i=0; isetParent(this); } +} - static PVField *findSubField(String fieldName,PVStructure *pvStructure); - - PVStructure::PVStructure(PVStructure *parent,StructureConstPtr structurePtr) - : PVField(parent,structurePtr),pImpl(new PVStructurePvt()) - { - int numberFields = structurePtr->getNumberFields(); - FieldConstPtrArray fields = structurePtr->getFields(); - pImpl->numberFields = numberFields; - pImpl->pvFields = new PVFieldPtr[numberFields]; - PVFieldPtrArray pvFields = pImpl->pvFields; - PVDataCreate *pvDataCreate = getPVDataCreate(); - for(int i=0; icreatePVField(this,fields[i]); - } +PVStructure::PVStructure(StructureConstPtr structurePtr, + PVFieldPtrArray & pvs +) +: PVField(structurePtr), + structurePtr(structurePtr), + extendsStructureName("") +{ + size_t numberFields = structurePtr->getNumberFields(); + pvFields = pvs; + for(size_t i=0; isetParent(this); } +} - PVStructure::PVStructure(PVStructure *parent,StructureConstPtr structurePtr, - PVFieldPtrArray pvFields - ) - : PVField(parent,structurePtr),pImpl(new PVStructurePvt()) - { - int numberFields = structurePtr->getNumberFields(); - pImpl->numberFields = numberFields; - pImpl->pvFields = pvFields; - for(int i=0; isetParent(parent); + if(fieldOffset>getNextFieldOffset()) return nullPVField; + size_t numFields = pvFields.size(); + for(size_t i=0; igetFieldOffset()==fieldOffset) return pvFields[i]; + if(pvField->getNextFieldOffset()<=fieldOffset) continue; if(pvField->getField()->getType()==structure) { - PVStructure *subStructure = static_cast(pvField); - PVFieldPtr *subFields = subStructure->getPVFields(); - int numberFields = subStructure->getStructure()->getNumberFields(); - for(int i=0; i(subFields[i]); - setParentPvt(subField,subStructure); - } + PVStructure *pvStructure = static_cast(pvField.get()); + return pvStructure->getSubField(fieldOffset); } } + throw std::logic_error("PVStructure.getSubField: Logic error"); +} - PVStructure::~PVStructure() - { - delete pImpl; +void PVStructure::appendPVField(String fieldName,PVFieldPtr & pvField ) +{ + size_t origLength = pvFields.size(); + size_t newLength = origLength+1; + PVFieldPtrArray newPVFields; + newPVFields.reserve(newLength); + for(size_t i=0; iappendField(structurePtr,fieldName,pvField->getField()); + replaceField(field); + structurePtr = static_pointer_cast(field); + for(size_t i=0; isetParent(this); +} - StructureConstPtr PVStructure::getStructure() - { - return static_pointer_cast(PVField::getField()); +void PVStructure::appendPVFields(StringArray &fieldNames,PVFieldPtrArray &pvFields) +{ + size_t origLength = this->pvFields.size(); + size_t extra = fieldNames.size(); + if(extra==0) return; + size_t newLength = origLength + extra; + PVFieldPtrArray newPVFields; + newPVFields.reserve(newLength); + for(size_t i=0; ipvFields[i]); } - - PVFieldPtrArray PVStructure::getPVFields() - { - return pImpl->pvFields; + for(size_t i=0; ipvFields.swap(newPVFields); + FieldConstPtrArray fields; + fields.reserve(extra); + for(size_t i=0; igetField()); + FieldConstPtr field = getFieldCreate()->appendFields(structurePtr,fieldNames,fields); + replaceField(field); + structurePtr = static_pointer_cast(field); + for(size_t i=0; isetParent(this); +} - PVFieldPtr PVStructure::getSubField(String fieldName) - { - return findSubField(fieldName,this); - } - - PVFieldPtr PVStructure::getSubField(int fieldOffset) - { - if(fieldOffset<=getFieldOffset()) { - if(fieldOffset==getFieldOffset()) return this; - return 0; - } - if(fieldOffset>getNextFieldOffset()) return 0; - int numFields = pImpl->numberFields; - PVFieldPtrArray pvFields = pImpl->pvFields; - for(int i=0; igetFieldOffset()==fieldOffset) return pvField; - if(pvField->getNextFieldOffset()<=fieldOffset) continue; - if(pvField->getField()->getType()==structure) { - return ((PVStructure*)pvField)->getSubField(fieldOffset); - } - } - String message("PVStructure.getSubField: Logic error"); - throw std::logic_error(message); - } - - void PVStructure::appendPVField(PVFieldPtr pvField) - { - Structure::shared_pointer structure = const_pointer_cast(getStructure()); - structure->appendField(pvField->getField()); - int origLength = pImpl->numberFields; - PVFieldPtrArray oldPVFields = pImpl->pvFields; - PVFieldPtrArray newPVFields = new PVFieldPtr[origLength + 1]; - for(int i=0; ipvFields; - pImpl->pvFields = newPVFields; - pImpl->numberFields = origLength + 1; - } - - void PVStructure::appendPVFields(int numberNewFields,PVFieldPtrArray pvFields) - { - if (numberNewFields<0) - throw std::logic_error("Number of fields must be >=0"); - - Structure::shared_pointer structure = const_pointer_cast(getStructure()); - std::vector fields(numberNewFields); - for(int i=0; igetField(); - structure->appendFields(numberNewFields,&fields[0]); - int origLength = pImpl->numberFields; - PVFieldPtrArray oldPVFields = pImpl->pvFields; - int numberFields = origLength + numberNewFields; - PVFieldPtrArray newPVFields = new PVFieldPtr[numberFields]; - for(int i=0; ipvFields; - pImpl->pvFields = newPVFields; - pImpl->numberFields = numberFields; - } - - void PVStructure::removePVField(String fieldName) - { - PVField *pvField = getSubField(fieldName); - if(pvField==0) { - String message("removePVField "); - message += fieldName + " does not exist"; - this->message(message, errorMessage); - return; - } - int origLength = pImpl->numberFields; - int newLength = origLength - 1; - PVFieldPtrArray origPVFields = pImpl->pvFields; - PVFieldPtrArray newPVFields = new PVFieldPtr[newLength]; - int newIndex = 0; - int indRemove = -1; - for(int i=0; i(getStructure().get()); - structure->removeField(indRemove); - delete origPVFields[indRemove]; - delete[] pImpl->pvFields; - pImpl->pvFields = newPVFields; - pImpl->numberFields = newLength; - } - - PVBoolean *PVStructure::getBooleanField(String fieldName) - { - PVField *pvField = findSubField(fieldName,this); - if(pvField==0) { - String message("fieldName "); - message += fieldName + " does not exist"; - this->message(message, errorMessage); - return 0; - } - if(pvField->getField()->getType()==scalar) { - ScalarConstPtr pscalar = static_pointer_cast( - pvField->getField()); - if(pscalar->getScalarType()==pvBoolean) { - return (PVBoolean*)pvField; - } - } - String message("fieldName "); - message += fieldName + " does not have type boolean "; +void PVStructure::removePVField(String fieldName) +{ + PVFieldPtr pvField = getSubField(fieldName); + if(pvField.get()==NULL) { + String message("removePVField "); + message += fieldName + " does not exist"; this->message(message, errorMessage); - return 0; + return; } + size_t origLength = pvFields.size(); + size_t newLength = origLength - 1; + PVFieldPtrArray const & origPVFields = pvFields; + FieldConstPtrArray origFields = structurePtr->getFields(); + PVFieldPtrArray newPVFields; + newPVFields.reserve(newLength); + StringArray newFieldNames; + newFieldNames.reserve(newLength); + FieldConstPtrArray fields; + fields.reserve(newLength); + for(size_t i=0; igetFieldName()); + newPVFields.push_back(origPVFields[i]); + fields.push_back(origFields[i]); + } + } + pvFields.swap(newPVFields); + FieldConstPtr field = getFieldCreate()->createStructure(newFieldNames,fields); + replaceField(field); + structurePtr = static_pointer_cast(field); + for(size_t i=0; isetParent(this); +} - PVByte *PVStructure::getByteField(String fieldName) - { - PVField *pvField = findSubField(fieldName,this); - if(pvField==0) { - String message("fieldName "); - message += fieldName + " does not exist"; - this->message(message, errorMessage); - return 0; - } - if(pvField->getField()->getType()==scalar) { - ScalarConstPtr pscalar = static_pointer_cast( - pvField->getField()); - if(pscalar->getScalarType()==pvByte) { - return (PVByte*)pvField; - } - } +PVBooleanPtr PVStructure::getBooleanField(String fieldName) +{ + PVFieldPtr pvField = findSubField(fieldName,this); + if(pvField.get()==NULL) { String message("fieldName "); - message += fieldName + " does not have type byte "; + message += fieldName + " does not exist"; this->message(message, errorMessage); - return 0; + return nullPVBoolean; } + if(pvField->getField()->getType()==scalar) { + ScalarConstPtr pscalar = static_pointer_cast( + pvField->getField()); + if(pscalar->getScalarType()==pvBoolean) { + return std::tr1::static_pointer_cast(pvField); + } + } + String message("fieldName "); + message += fieldName + " does not have type boolean "; + this->message(message, errorMessage); + return nullPVBoolean; +} - PVShort *PVStructure::getShortField(String fieldName) - { - PVField *pvField = findSubField(fieldName,this); - if(pvField==0) { - String message("fieldName "); - message += fieldName + " does not exist"; - this->message(message, errorMessage); - return 0; - } - if(pvField->getField()->getType()==scalar) { - ScalarConstPtr pscalar = static_pointer_cast( - pvField->getField()); - if(pscalar->getScalarType()==pvShort) { - return (PVShort*)pvField; - } - } +PVBytePtr PVStructure::getByteField(String fieldName) +{ + PVFieldPtr pvField = findSubField(fieldName,this); + if(pvField.get()==NULL) { String message("fieldName "); - message += fieldName + " does not have type short "; + message += fieldName + " does not exist"; this->message(message, errorMessage); - return 0; + return nullPVByte; } + if(pvField->getField()->getType()==scalar) { + ScalarConstPtr pscalar = static_pointer_cast( + pvField->getField()); + if(pscalar->getScalarType()==pvByte) { + return std::tr1::static_pointer_cast(pvField); + } + } + String message("fieldName "); + message += fieldName + " does not have type byte "; + this->message(message, errorMessage); + return nullPVByte; +} - PVInt *PVStructure::getIntField(String fieldName) - { - PVField *pvField = findSubField(fieldName,this); - if(pvField==0) { - String message("fieldName "); - message += fieldName + " does not exist"; - this->message(message, errorMessage); - return 0; - } - if(pvField->getField()->getType()==scalar) { - ScalarConstPtr pscalar = static_pointer_cast( - pvField->getField()); - if(pscalar->getScalarType()==pvInt) { - return (PVInt*)pvField; - } - } +PVShortPtr PVStructure::getShortField(String fieldName) +{ + PVFieldPtr pvField = findSubField(fieldName,this); + if(pvField.get()==NULL) { String message("fieldName "); - message += fieldName + " does not have type int "; + message += fieldName + " does not exist"; this->message(message, errorMessage); - return 0; + return nullPVShort; } + if(pvField->getField()->getType()==scalar) { + ScalarConstPtr pscalar = static_pointer_cast( + pvField->getField()); + if(pscalar->getScalarType()==pvShort) { + return std::tr1::static_pointer_cast(pvField); + } + } + String message("fieldName "); + message += fieldName + " does not have type short "; + this->message(message, errorMessage); + return nullPVShort; +} - PVLong *PVStructure::getLongField(String fieldName) - { - PVField *pvField = findSubField(fieldName,this); - if(pvField==0) { - String message("fieldName "); - message += fieldName + " does not exist"; - this->message(message, errorMessage); - return 0; - } - if(pvField->getField()->getType()==scalar) { - ScalarConstPtr pscalar = static_pointer_cast( - pvField->getField()); - if(pscalar->getScalarType()==pvLong) { - return (PVLong*)pvField; - } - } +PVIntPtr PVStructure::getIntField(String fieldName) +{ + PVFieldPtr pvField = findSubField(fieldName,this); + if(pvField.get()==NULL) { String message("fieldName "); - message += fieldName + " does not have type long "; + message += fieldName + " does not exist"; this->message(message, errorMessage); - return 0; + return nullPVInt; } + if(pvField->getField()->getType()==scalar) { + ScalarConstPtr pscalar = static_pointer_cast( + pvField->getField()); + if(pscalar->getScalarType()==pvInt) { + return std::tr1::static_pointer_cast(pvField); + } + } + String message("fieldName "); + message += fieldName + " does not have type int "; + this->message(message, errorMessage); + return nullPVInt; +} - PVFloat *PVStructure::getFloatField(String fieldName) - { - PVField *pvField = findSubField(fieldName,this); - if(pvField==0) { - String message("fieldName "); - message += fieldName + " does not exist"; - this->message(message, errorMessage); - return 0; - } - if(pvField->getField()->getType()==scalar) { - ScalarConstPtr pscalar = static_pointer_cast( - pvField->getField()); - if(pscalar->getScalarType()==pvFloat) { - return (PVFloat*)pvField; - } - } +PVLongPtr PVStructure::getLongField(String fieldName) +{ + PVFieldPtr pvField = findSubField(fieldName,this); + if(pvField.get()==NULL) { String message("fieldName "); - message += fieldName + " does not have type float "; + message += fieldName + " does not exist"; this->message(message, errorMessage); - return 0; + return nullPVLong; } + if(pvField->getField()->getType()==scalar) { + ScalarConstPtr pscalar = static_pointer_cast( + pvField->getField()); + if(pscalar->getScalarType()==pvLong) { + return std::tr1::static_pointer_cast(pvField); + } + } + String message("fieldName "); + message += fieldName + " does not have type long "; + this->message(message, errorMessage); + return nullPVLong; +} - PVDouble *PVStructure::getDoubleField(String fieldName) - { - PVField *pvField = findSubField(fieldName,this); - if(pvField==0) { - String message("fieldName "); - message += fieldName + " does not exist"; - this->message(message, errorMessage); - return 0; - } - if(pvField->getField()->getType()==scalar) { - ScalarConstPtr pscalar = static_pointer_cast( - pvField->getField()); - if(pscalar->getScalarType()==pvDouble) { - return (PVDouble*)pvField; - } - } +PVUBytePtr PVStructure::getUByteField(String fieldName) +{ + PVFieldPtr pvField = findSubField(fieldName,this); + if(pvField.get()==NULL) { String message("fieldName "); - message += fieldName + " does not have type double "; + message += fieldName + " does not exist"; this->message(message, errorMessage); - return 0; + return nullPVUByte; } + if(pvField->getField()->getType()==scalar) { + ScalarConstPtr pscalar = static_pointer_cast( + pvField->getField()); + if(pscalar->getScalarType()==pvUByte) { + return std::tr1::static_pointer_cast(pvField); + } + } + String message("fieldName "); + message += fieldName + " does not have type byte "; + this->message(message, errorMessage); + return nullPVUByte; +} - PVString *PVStructure::getStringField(String fieldName) - { - PVField *pvField = findSubField(fieldName,this); - if(pvField==0) { - String message("fieldName "); - message += fieldName + " does not exist"; - this->message(message, errorMessage); - return 0; - } - if(pvField->getField()->getType()==scalar) { - ScalarConstPtr pscalar = static_pointer_cast( - pvField->getField()); - if(pscalar->getScalarType()==pvString) { - return (PVString*)pvField; - } - } +PVUShortPtr PVStructure::getUShortField(String fieldName) +{ + PVFieldPtr pvField = findSubField(fieldName,this); + if(pvField.get()==NULL) { String message("fieldName "); - message += fieldName + " does not have type string "; + message += fieldName + " does not exist"; this->message(message, errorMessage); - return 0; + return nullPVUShort; } + if(pvField->getField()->getType()==scalar) { + ScalarConstPtr pscalar = static_pointer_cast( + pvField->getField()); + if(pscalar->getScalarType()==pvUShort) { + return std::tr1::static_pointer_cast(pvField); + } + } + String message("fieldName "); + message += fieldName + " does not have type short "; + this->message(message, errorMessage); + return nullPVUShort; +} - PVStructure *PVStructure::getStructureField(String fieldName) - { - PVField *pvField = findSubField(fieldName,this); - if(pvField==0) { - String message("fieldName "); - message += fieldName + " does not exist"; - this->message(message, errorMessage); - return 0; - } - if(pvField->getField()->getType()==structure) { - return((PVStructure *)pvField); - } +PVUIntPtr PVStructure::getUIntField(String fieldName) +{ + PVFieldPtr pvField = findSubField(fieldName,this); + if(pvField.get()==NULL) { String message("fieldName "); - message += fieldName + " does not have type structure "; + message += fieldName + " does not exist"; this->message(message, errorMessage); - return 0; + return nullPVUInt; } - - PVScalarArray *PVStructure::getScalarArrayField( - String fieldName,ScalarType elementType) - { - PVField *pvField = findSubField(fieldName,this); - if(pvField==0) { - String message("fieldName "); - message += fieldName + " does not exist"; - this->message(message, errorMessage); - return 0; + if(pvField->getField()->getType()==scalar) { + ScalarConstPtr pscalar = static_pointer_cast( + pvField->getField()); + if(pscalar->getScalarType()==pvUInt) { + return std::tr1::static_pointer_cast(pvField); } - FieldConstPtr field = pvField->getField(); - Type type = field->getType(); - if(type!=scalarArray) { - String message("fieldName "); - message += fieldName + " does not have type array "; - this->message(message, errorMessage); - return 0; - } - ScalarArrayConstPtr pscalarArray - = static_pointer_cast(pvField->getField()); - if(pscalarArray->getElementType()!=elementType) { - String message("fieldName "); - message += fieldName + " is array but does not have elementType "; - ScalarTypeFunc::toString(&message,elementType); - this->message(message, errorMessage); - return 0; - } - return (PVScalarArray*)pvField; } + String message("fieldName "); + message += fieldName + " does not have type int "; + this->message(message, errorMessage); + return nullPVUInt; +} - PVStructureArray *PVStructure::getStructureArrayField( - String fieldName) - { - PVField *pvField = findSubField(fieldName,this); - if(pvField==0) { - String message("fieldName "); - message += fieldName + " does not exist"; - this->message(message, errorMessage); - return 0; - } - if(pvField->getField()->getType()==structureArray) { - return((PVStructureArray *)pvField); - } +PVULongPtr PVStructure::getULongField(String fieldName) +{ + PVFieldPtr pvField = findSubField(fieldName,this); + if(pvField.get()==NULL) { String message("fieldName "); - message += fieldName + " does not have type structureArray "; + message += fieldName + " does not exist"; this->message(message, errorMessage); - return 0; + return nullPVULong; } - - String PVStructure::getExtendsStructureName() - { - return pImpl->extendsStructureName; - } - - bool PVStructure::putExtendsStructureName( - String extendsStructureName) - { - if(pImpl->extendsStructureName.length()!=0) return false; - pImpl->extendsStructureName = extendsStructureName; - return true; - } - - void PVStructure::serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher) const { - for(int i = 0; inumberFields; i++) - pImpl->pvFields[i]->serialize(pbuffer, pflusher); - } - - void PVStructure::deserialize(ByteBuffer *pbuffer, - DeserializableControl *pcontrol) { - for(int i = 0; inumberFields; i++) - pImpl->pvFields[i]->deserialize(pbuffer, pcontrol); - - } - - void PVStructure::serialize(ByteBuffer *pbuffer, - SerializableControl *pflusher, BitSet *pbitSet) const { - int offset = const_cast(this)->getFieldOffset(); - int numberFields = const_cast(this)->getNumberFields(); - int next = pbitSet->nextSetBit(offset); - - // no more changes or no changes in this structure - if(next<0||next>=offset+numberFields) return; - - // entire structure - if(offset==next) { - serialize(pbuffer, pflusher); - return; - } - - for(int i = 0; inumberFields; i++) { - PVField* pvField = pImpl->pvFields[i]; - offset = pvField->getFieldOffset(); - numberFields = pvField->getNumberFields(); - next = pbitSet->nextSetBit(offset); - // no more changes - if(next<0) return; - // no change in this pvField - if(next>=offset+numberFields) continue; - - // serialize field or fields - if(numberFields==1) - pvField->serialize(pbuffer, pflusher); - else - ((PVStructure*)pvField)->serialize(pbuffer, pflusher, - pbitSet); + if(pvField->getField()->getType()==scalar) { + ScalarConstPtr pscalar = static_pointer_cast( + pvField->getField()); + if(pscalar->getScalarType()==pvULong) { + return std::tr1::static_pointer_cast(pvField); } } + String message("fieldName "); + message += fieldName + " does not have type long "; + this->message(message, errorMessage); + return nullPVULong; +} - void PVStructure::deserialize(ByteBuffer *pbuffer, - DeserializableControl *pcontrol, BitSet *pbitSet) { - int offset = getFieldOffset(); - int numberFields = getNumberFields(); - int next = pbitSet->nextSetBit(offset); - - // no more changes or no changes in this structure - if(next<0||next>=offset+numberFields) return; - - // entire structure - if(offset==next) { - deserialize(pbuffer, pcontrol); - return; - } - - for(int i = 0; inumberFields; i++) { - PVField* pvField = pImpl->pvFields[i]; - offset = pvField->getFieldOffset(); - numberFields = pvField->getNumberFields(); - next = pbitSet->nextSetBit(offset); - // no more changes - if(next<0) return; - // no change in this pvField - if(next>=offset+numberFields) continue; - - // deserialize field or fields - if(numberFields==1) - pvField->deserialize(pbuffer, pcontrol); - else - ((PVStructure*)pvField)->deserialize(pbuffer, pcontrol, - pbitSet); +PVFloatPtr PVStructure::getFloatField(String fieldName) +{ + PVFieldPtr pvField = findSubField(fieldName,this); + if(pvField.get()==NULL) { + String message("fieldName "); + message += fieldName + " does not exist"; + this->message(message, errorMessage); + return nullPVFloat; + } + if(pvField->getField()->getType()==scalar) { + ScalarConstPtr pscalar = static_pointer_cast( + pvField->getField()); + if(pscalar->getScalarType()==pvFloat) { + return std::tr1::static_pointer_cast(pvField); } } + String message("fieldName "); + message += fieldName + " does not have type float "; + this->message(message, errorMessage); + return nullPVFloat; +} - static PVField *findSubField(String fieldName,PVStructure *pvStructure) { - if( fieldName.length()<1) return 0; - String::size_type index = fieldName.find('.'); - String name = fieldName; - String restOfName = String(); - if(index>0) { - name = fieldName.substr(0, index); - if(fieldName.length()>index) { - restOfName = fieldName.substr(index+1); - } - } - PVFieldPtrArray pvFields = pvStructure->getPVFields(); - PVField *pvField = 0; - int numFields = pvStructure->getStructure()->getNumberFields(); - for(int i=0; igetField()->getFieldName().compare(name); - if(result==0) { - pvField = pvf; - break; - } - } - if(pvField==0) return 0; - if(restOfName.length()==0) return pvField; - if(pvField->getField()->getType()!=structure) return 0; - return findSubField(restOfName,(PVStructure*)pvField); +PVDoublePtr PVStructure::getDoubleField(String fieldName) +{ + PVFieldPtr pvField = findSubField(fieldName,this); + if(pvField.get()==NULL) { + String message("fieldName "); + message += fieldName + " does not exist"; + this->message(message, errorMessage); + return nullPVDouble; } + if(pvField->getField()->getType()==scalar) { + ScalarConstPtr pscalar = static_pointer_cast( + pvField->getField()); + if(pscalar->getScalarType()==pvDouble) { + return std::tr1::static_pointer_cast(pvField); + } + } + String message("fieldName "); + message += fieldName + " does not have type double "; + this->message(message, errorMessage); + return nullPVDouble; +} + +PVStringPtr PVStructure::getStringField(String fieldName) +{ + PVFieldPtr pvField = findSubField(fieldName,this); + if(pvField.get()==NULL) { + String message("fieldName "); + message += fieldName + " does not exist"; + this->message(message, errorMessage); + return nullPVString; + } + if(pvField->getField()->getType()==scalar) { + ScalarConstPtr pscalar = static_pointer_cast( + pvField->getField()); + if(pscalar->getScalarType()==pvString) { + return std::tr1::static_pointer_cast(pvField); + } + } + String message("fieldName "); + message += fieldName + " does not have type string "; + this->message(message, errorMessage); + return nullPVString; +} + +PVStructurePtr PVStructure::getStructureField(String fieldName) +{ + PVFieldPtr pvField = findSubField(fieldName,this); + if(pvField.get()==NULL) { + String message("fieldName "); + message += fieldName + " does not exist"; + this->message(message, errorMessage); + return nullPVStructure; + } + if(pvField->getField()->getType()==structure) { + return std::tr1::static_pointer_cast(pvField); + } + String message("fieldName "); + message += fieldName + " does not have type structure "; + this->message(message, errorMessage); + return nullPVStructure; +} + +PVScalarArrayPtr PVStructure::getScalarArrayField( + String fieldName,ScalarType elementType) +{ + PVFieldPtr pvField = findSubField(fieldName,this); + if(pvField.get()==NULL) { + String message("fieldName "); + message += fieldName + " does not exist"; + this->message(message, errorMessage); + return nullPVScalarArray; + } + FieldConstPtr field = pvField->getField(); + Type type = field->getType(); + if(type!=scalarArray) { + String message("fieldName "); + message += fieldName + " does not have type array "; + this->message(message, errorMessage); + return nullPVScalarArray; + } + ScalarArrayConstPtr pscalarArray + = static_pointer_cast(pvField->getField()); + if(pscalarArray->getElementType()!=elementType) { + String message("fieldName "); + message += fieldName + " is array but does not have elementType "; + ScalarTypeFunc::toString(&message,elementType); + this->message(message, errorMessage); + return nullPVScalarArray; + } + return std::tr1::static_pointer_cast(pvField); +} + +PVStructureArrayPtr PVStructure::getStructureArrayField( + String fieldName) +{ + PVFieldPtr pvField = findSubField(fieldName,this); + if(pvField.get()==NULL) { + String message("fieldName "); + message += fieldName + " does not exist"; + this->message(message, errorMessage); + return nullPVStructureArray; + } + if(pvField->getField()->getType()==structureArray) { + return std::tr1::static_pointer_cast(pvField); + } + String message("fieldName "); + message += fieldName + " does not have type structureArray "; + this->message(message, errorMessage); + return nullPVStructureArray; +} + +String PVStructure::getExtendsStructureName() +{ + return extendsStructureName; +} + +bool PVStructure::putExtendsStructureName( + String extendsStructureName) +{ + if(extendsStructureName.length()!=0) return false; + extendsStructureName = extendsStructureName; + return true; +} + +void PVStructure::serialize(ByteBuffer *pbuffer, + SerializableControl *pflusher) const { + for(size_t i = 0; iserialize(pbuffer, pflusher); +} + +void PVStructure::deserialize(ByteBuffer *pbuffer, + DeserializableControl *pcontrol) { + for(size_t i = 0; ideserialize(pbuffer, pcontrol); + +} + +void PVStructure::serialize(ByteBuffer *pbuffer, + SerializableControl *pflusher, BitSet *pbitSet) const { + size_t offset = const_cast(this)->getFieldOffset(); + size_t numberFields = const_cast(this)->getNumberFields(); + size_t next = pbitSet->nextSetBit(offset); + + // no more changes or no changes in this structure + if(next<0||next>=offset+numberFields) return; + + // entire structure + if(offset==next) { + serialize(pbuffer, pflusher); + return; + } + + for(size_t i = 0; igetFieldOffset(); + numberFields = pvField->getNumberFields(); + next = pbitSet->nextSetBit(offset); + // no more changes + if(next<0) return; + // no change in this pvField + if(next>=offset+numberFields) continue; + + // serialize field or fields + if(numberFields==1) { + pvField->serialize(pbuffer, pflusher); + } else { + PVStructurePtr pvStructure = std::tr1::static_pointer_cast(pvField); + pvStructure->serialize(pbuffer, pflusher, pbitSet); + } + } +} + +void PVStructure::deserialize(ByteBuffer *pbuffer, + DeserializableControl *pcontrol, BitSet *pbitSet) { + size_t offset = getFieldOffset(); + size_t numberFields = getNumberFields(); + size_t next = pbitSet->nextSetBit(offset); + + // no more changes or no changes in this structure + if(next<0||next>=offset+numberFields) return; + + // entire structure + if(offset==next) { + deserialize(pbuffer, pcontrol); + return; + } + + for(size_t i = 0; igetFieldOffset(); + numberFields = pvField->getNumberFields(); + next = pbitSet->nextSetBit(offset); + // no more changes + if(next<0) return; + // no change in this pvField + if(next>=offset+numberFields) continue; + + // deserialize field or fields + if(numberFields==1) { + pvField->deserialize(pbuffer, pcontrol); + } else { + PVStructurePtr pvStructure = std::tr1::static_pointer_cast(pvField); + pvStructure->deserialize(pbuffer, pcontrol, pbitSet); + } + } +} + +static PVFieldPtr &findSubField(String fieldName,PVStructure *pvStructure) { + if( fieldName.length()<1) return nullPVField; + String::size_type index = fieldName.find('.'); + String name = fieldName; + String restOfName = String(); + if(index>0) { + name = fieldName.substr(0, index); + if(fieldName.length()>index) { + restOfName = fieldName.substr(index+1); + } + } + PVFieldPtrArray pvFields = pvStructure->getPVFields(); + PVFieldPtr pvField; + size_t numFields = pvStructure->getStructure()->getNumberFields(); + for(size_t i=0; igetFieldName().compare(name); + if(result==0) { + if(restOfName.length()==0) return pvField; + if(pvField->getField()->getType()!=structure) return nullPVField; + PVStructurePtr pvStructure = std::tr1::static_pointer_cast(pvField); + return findSubField(restOfName,pvStructure.get()); + } + } + return nullPVField; +} }} diff --git a/pvDataApp/factory/PVStructureArray.cpp b/pvDataApp/factory/PVStructureArray.cpp new file mode 100644 index 0000000..456d702 --- /dev/null +++ b/pvDataApp/factory/PVStructureArray.cpp @@ -0,0 +1,227 @@ +/*PVStructureArray.cpp*/ +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * EPICS pvDataCPP is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. + */ +#include +#include +#include +#include +#include +#include +#include +#include + +using std::tr1::static_pointer_cast; +using std::tr1::const_pointer_cast; +using std::size_t; + +namespace epics { namespace pvData { + +PVStructureArray::PVStructureArray(StructureArrayConstPtr structureArray) +: PVArray(structureArray), + structureArray(structureArray), + value(std::tr1::shared_ptr > + (new std::vector())) +{ +} + +size_t PVStructureArray::append(size_t number) +{ + size_t currentLength = getCapacity(); + size_t newLength = currentLength + number; + setCapacity(newLength); + StructureConstPtr structure = structureArray->getStructure(); + for(size_t i=currentLength; icreatePVStructure(structure); + } + return newLength; +} + +bool PVStructureArray::remove(size_t offset,size_t number) +{ + size_t length = getCapacity(); + if(offset+number>length) return false; + value->erase(value->begin()+ offset,value->begin()+number-1); + return true; +} + +void PVStructureArray::compress() { + size_t length = getCapacity(); + size_t newLength = 0; + PVStructurePtrArray vec = *value.get(); + for(size_t i=0; icapacity) num = capacity; + PVStructurePtr * from = get(); + for (size_t i=0; iswap(array); + setCapacityLength(capacity,length); +} + + +StructureArrayConstPtr PVStructureArray::getStructureArray() +{ + return structureArray; +} + +size_t PVStructureArray::get( + size_t offset, size_t len, StructureArrayData &data) +{ + size_t n = len; + size_t length = getLength(); + if(offset+len > length) { + n = length - offset; + if(n<0) n = 0; + } + data.data = *value.get(); + data.offset = offset; + return n; +} + +size_t PVStructureArray::put(size_t offset,size_t len, + PVStructurePtr* const from, size_t fromOffset) +{ + if(isImmutable()) { + message(String("field is immutable"), errorMessage); + return 0; + } + std::vector to = *value.get(); + if(from==&to[0]) return len; + if(len<1) return 0; + size_t length = getLength(); + size_t capacity = getCapacity(); + if(offset+len > length) { + size_t newlength = offset + len; + if(newlength>capacity) { + setCapacity(newlength); + capacity = getCapacity(); + newlength = capacity; + len = newlength - offset; + if(len<=0) return 0; + } + length = newlength; + setLength(length); + } + to = *value.get(); + StructureConstPtr structure = structureArray->getStructure(); + for(size_t i=0; igetStructure()!=structure) { + throw std::invalid_argument(String( + "Element is not a compatible structure")); + } + } + to[i+offset] = frompv; + } + postPut(); + setLength(length); + return len; +} + +void PVStructureArray::shareData( + std::tr1::shared_ptr > const & sharedValue, + std::size_t capacity, + std::size_t length) +{ + value = sharedValue; + setCapacityLength(capacity,length); +} + +void PVStructureArray::serialize(ByteBuffer *pbuffer, + SerializableControl *pflusher) const { + serialize(pbuffer, pflusher, 0, getLength()); +} + +void PVStructureArray::deserialize(ByteBuffer *pbuffer, + DeserializableControl *pcontrol) { + size_t size = SerializeHelper::readSize(pbuffer, pcontrol); + if(size>=0) { + // prepare array, if necessary + if(size>getCapacity()) setCapacity(size); + PVStructurePtrArray pvArray = *value.get(); + for(size_t i = 0; iensureData(1); + size_t temp = pbuffer->getByte(); + if(temp==0) { + pvArray[i].reset(); + } + else { + if(pvArray[i].get()==NULL) { + StructureConstPtr structure = structureArray->getStructure(); + pvArray[i] = getPVDataCreate()->createPVStructure(structure); + } + pvArray[i]->deserialize(pbuffer, pcontrol); + } + } + setLength(size); + postPut(); + } +} + +void PVStructureArray::serialize(ByteBuffer *pbuffer, + SerializableControl *pflusher, size_t offset, size_t count) const { + // cache + size_t length = getLength(); + + // check bounds + if(offset<0) + offset = 0; + else if(offset>length) offset = length; + if(count<0) count = length; + + size_t maxCount = length-offset; + if(count>maxCount) count = maxCount; + + PVStructurePtrArray pvArray = *value.get(); + // write + SerializeHelper::writeSize(count, pbuffer, pflusher); + for(size_t i = 0; igetRemaining()<1) pflusher->flushSerializeBuffer(); + PVStructurePtr pvStructure = pvArray[i+offset]; + if(pvStructure.get()==NULL) { + pbuffer->putByte(0); + } + else { + pbuffer->putByte(1); + pvStructure->serialize(pbuffer, pflusher); + } + } +} + +}} diff --git a/pvDataApp/factory/StandardField.cpp b/pvDataApp/factory/StandardField.cpp index f787823..dc4006b 100644 --- a/pvDataApp/factory/StandardField.cpp +++ b/pvDataApp/factory/StandardField.cpp @@ -12,16 +12,13 @@ #include #include #include -#include using std::tr1::static_pointer_cast; namespace epics { namespace pvData { -static StandardField* standardField = 0; - static String notImplemented("not implemented"); -static FieldCreate* fieldCreate = 0; +static FieldCreatePtr fieldCreate; static String valueFieldName("value"); // following are preallocated structures @@ -41,158 +38,213 @@ static StructureConstPtr enumeratedAlarmField; static void createAlarm() { - FieldConstPtrArray fields = new FieldConstPtr[3]; - fields[0] = fieldCreate->createScalar(String("severity"),pvInt); - fields[1] = fieldCreate->createScalar(String("status"),pvInt); - fields[2] = fieldCreate->createScalar(String("message"),pvString); - alarmField = fieldCreate->createStructure(String("alarm"),3,fields); + size_t num = 3; + FieldConstPtrArray fields(num); + StringArray names(num); + names[0] = "severity"; + names[1] = "status"; + names[2] = "message"; + fields[0] = fieldCreate->createScalar(pvInt); + fields[1] = fieldCreate->createScalar(pvInt); + fields[2] = fieldCreate->createScalar(pvString); + alarmField = fieldCreate->createStructure(names,fields); } static void createTimeStamp() { - FieldConstPtrArray fields = new FieldConstPtr[3]; - fields[0] = fieldCreate->createScalar(String("secondsPastEpoch"),pvLong); - fields[1] = fieldCreate->createScalar(String("nanoSeconds"),pvInt); - fields[2] = fieldCreate->createScalar(String("userTag"),pvInt); - timeStampField = fieldCreate->createStructure(String("timeStamp"),3,fields); + size_t num = 3; + FieldConstPtrArray fields(num); + StringArray names(num); + names[0] = "secondsPastEpoch"; + names[1] = "nanoSeconds"; + names[2] = "userTag"; + fields[0] = fieldCreate->createScalar(pvLong); + fields[1] = fieldCreate->createScalar(pvInt); + fields[2] = fieldCreate->createScalar(pvInt); + timeStampField = fieldCreate->createStructure(names,fields); } static void createDisplay() { - FieldConstPtrArray limitFields = new FieldConstPtr[2]; - limitFields[0] = fieldCreate->createScalar(String("low"),pvDouble); - limitFields[1] = fieldCreate->createScalar(String("high"),pvDouble); - FieldConstPtrArray fields = new FieldConstPtr[4]; - fields[0] = fieldCreate->createScalar(String("description"),pvString); - fields[1] = fieldCreate->createScalar(String("format"),pvString); - fields[2] = fieldCreate->createScalar(String("units"),pvString); - fields[3] = fieldCreate->createStructure(String("limit"),2,limitFields); - displayField = fieldCreate->createStructure(String("display"),4,fields); + size_t num = 5; + FieldConstPtrArray fields(num); + StringArray names(num); + names[0] = "limitLow"; + names[1] = "limitHigh"; + names[2] = "description"; + names[3] = "format"; + names[4] = "units"; + fields[0] = fieldCreate->createScalar(pvDouble); + fields[1] = fieldCreate->createScalar(pvDouble); + fields[2] = fieldCreate->createScalar(pvString); + fields[3] = fieldCreate->createScalar(pvString); + fields[4] = fieldCreate->createScalar(pvString); + displayField = fieldCreate->createStructure(names,fields); } static void createControl() { - FieldConstPtrArray limitFields = new FieldConstPtr[2]; - limitFields[0] = fieldCreate->createScalar(String("low"),pvDouble); - limitFields[1] = fieldCreate->createScalar(String("high"),pvDouble); - FieldConstPtrArray fields = new FieldConstPtr[2]; - fields[0] = fieldCreate->createStructure(String("limit"),2,limitFields); - fields[1] = fieldCreate->createScalar(String("minStep"),pvDouble); - controlField = fieldCreate->createStructure(String("control"),2,fields); + size_t num = 3; + FieldConstPtrArray fields(num); + StringArray names(num); + names[0] = "limitLow"; + names[1] = "limitHigh"; + names[2] = "minStep"; + fields[0] = fieldCreate->createScalar(pvDouble); + fields[1] = fieldCreate->createScalar(pvDouble); + fields[2] = fieldCreate->createScalar(pvDouble); + controlField = fieldCreate->createStructure(names,fields); } static void createBooleanAlarm() { - FieldConstPtrArray fields = new FieldConstPtr[4]; - fields[0] = fieldCreate->createScalar(String("active"),pvBoolean); - fields[1] = fieldCreate->createScalar(String("falseSeverity"),pvInt); - fields[2] = fieldCreate->createScalar(String("trueSeverity"),pvInt); - fields[3] = fieldCreate->createScalar(String("changeStateSeverity"),pvInt); - booleanAlarmField = fieldCreate->createStructure(String("valueAlarm"),4,fields); + size_t num = 4; + FieldConstPtrArray fields(num); + StringArray names(num); + names[0] = "active"; + names[1] = "falseSeverity"; + names[2] = "trueSeverity"; + names[3] = "changeStateSeverity"; + booleanAlarmField = fieldCreate->createStructure(names,fields); } static void createByteAlarm() { - int numFields = 10; - FieldConstPtrArray fields = new FieldConstPtr[numFields]; - fields[0] = fieldCreate->createScalar(String("active"),pvBoolean); - fields[1] = fieldCreate->createScalar(String("lowAlarmLimit"),pvByte); - fields[2] = fieldCreate->createScalar(String("lowWarningLimit"),pvByte); - fields[3] = fieldCreate->createScalar(String("highWarningLimit"),pvByte); - fields[4] = fieldCreate->createScalar(String("highAlarmLimit"),pvByte); - fields[5] = fieldCreate->createScalar(String("lowAlarmSeverity"),pvInt); - fields[6] = fieldCreate->createScalar(String("lowWarningSeverity"),pvInt); - fields[7] = fieldCreate->createScalar(String("highWarningSeverity"),pvInt); - fields[8] = fieldCreate->createScalar(String("highAlarmSeverity"),pvInt); - fields[9] = fieldCreate->createScalar(String("hystersis"),pvByte); - byteAlarmField = fieldCreate->createStructure(String("valueAlarm"),numFields,fields); + size_t numFields = 10; + FieldConstPtrArray fields(numFields); + StringArray names(numFields); + names[0] = "active"; + names[1] = "lowAlarmLimit"; + names[2] = "lowWarningLimit"; + names[3] = "highWarningLimit"; + names[4] = "highAlarmLimit"; + names[5] = "lowAlarmSeverity"; + names[6] = "lowWarningSeverity"; + names[7] = "highWarningSeverity"; + names[8] = "highAlarmSeverity"; + names[9] = "hystersis"; + fields[0] = fieldCreate->createScalar(pvBoolean); + for(size_t i=0; icreateScalar(pvByte); + } + byteAlarmField = fieldCreate->createStructure(names,fields); } static void createShortAlarm() { - int numFields = 10; - FieldConstPtrArray fields = new FieldConstPtr[numFields]; - fields[0] = fieldCreate->createScalar(String("active"),pvBoolean); - fields[1] = fieldCreate->createScalar(String("lowAlarmLimit"),pvShort); - fields[2] = fieldCreate->createScalar(String("lowWarningLimit"),pvShort); - fields[3] = fieldCreate->createScalar(String("highWarningLimit"),pvShort); - fields[4] = fieldCreate->createScalar(String("highAlarmLimit"),pvShort); - fields[5] = fieldCreate->createScalar(String("lowAlarmSeverity"),pvInt); - fields[6] = fieldCreate->createScalar(String("lowWarningSeverity"),pvInt); - fields[7] = fieldCreate->createScalar(String("highWarningSeverity"),pvInt); - fields[8] = fieldCreate->createScalar(String("highAlarmSeverity"),pvInt); - fields[9] = fieldCreate->createScalar(String("hystersis"),pvShort); - shortAlarmField = fieldCreate->createStructure(String("valueAlarm"),numFields,fields); + size_t numFields = 10; + FieldConstPtrArray fields(numFields); + StringArray names(numFields); + names[0] = "active"; + names[1] = "lowAlarmLimit"; + names[2] = "lowWarningLimit"; + names[3] = "highWarningLimit"; + names[4] = "highAlarmLimit"; + names[5] = "lowAlarmSeverity"; + names[6] = "lowWarningSeverity"; + names[7] = "highWarningSeverity"; + names[8] = "highAlarmSeverity"; + names[9] = "hystersis"; + fields[0] = fieldCreate->createScalar(pvBoolean); + for(size_t i=0; icreateScalar(pvShort); + } + shortAlarmField = fieldCreate->createStructure(names,fields); } static void createIntAlarm() { - int numFields = 10; - FieldConstPtrArray fields = new FieldConstPtr[numFields]; - fields[0] = fieldCreate->createScalar(String("active"),pvBoolean); - fields[1] = fieldCreate->createScalar(String("lowAlarmLimit"),pvInt); - fields[2] = fieldCreate->createScalar(String("lowWarningLimit"),pvInt); - fields[3] = fieldCreate->createScalar(String("highWarningLimit"),pvInt); - fields[4] = fieldCreate->createScalar(String("highAlarmLimit"),pvInt); - fields[5] = fieldCreate->createScalar(String("lowAlarmSeverity"),pvInt); - fields[6] = fieldCreate->createScalar(String("lowWarningSeverity"),pvInt); - fields[7] = fieldCreate->createScalar(String("highWarningSeverity"),pvInt); - fields[8] = fieldCreate->createScalar(String("highAlarmSeverity"),pvInt); - fields[9] = fieldCreate->createScalar(String("hystersis"),pvInt); - intAlarmField = fieldCreate->createStructure(String("valueAlarm"),numFields,fields); + size_t numFields = 10; + FieldConstPtrArray fields(numFields); + StringArray names(numFields); + names[0] = "active"; + names[1] = "lowAlarmLimit"; + names[2] = "lowWarningLimit"; + names[3] = "highWarningLimit"; + names[4] = "highAlarmLimit"; + names[5] = "lowAlarmSeverity"; + names[6] = "lowWarningSeverity"; + names[7] = "highWarningSeverity"; + names[8] = "highAlarmSeverity"; + names[9] = "hystersis"; + fields[0] = fieldCreate->createScalar(pvBoolean); + for(size_t i=0; icreateScalar(pvInt); + } + intAlarmField = fieldCreate->createStructure(names,fields); } static void createLongAlarm() { - int numFields = 10; - FieldConstPtrArray fields = new FieldConstPtr[numFields]; - fields[0] = fieldCreate->createScalar(String("active"),pvBoolean); - fields[1] = fieldCreate->createScalar(String("lowAlarmLimit"),pvLong); - fields[2] = fieldCreate->createScalar(String("lowWarningLimit"),pvLong); - fields[3] = fieldCreate->createScalar(String("highWarningLimit"),pvLong); - fields[4] = fieldCreate->createScalar(String("highAlarmLimit"),pvLong); - fields[5] = fieldCreate->createScalar(String("lowAlarmSeverity"),pvInt); - fields[6] = fieldCreate->createScalar(String("lowWarningSeverity"),pvInt); - fields[7] = fieldCreate->createScalar(String("highWarningSeverity"),pvInt); - fields[8] = fieldCreate->createScalar(String("highAlarmSeverity"),pvInt); - fields[9] = fieldCreate->createScalar(String("hystersis"),pvLong); - longAlarmField = fieldCreate->createStructure(String("valueAlarm"),numFields,fields); + size_t numFields = 10; + FieldConstPtrArray fields(numFields); + StringArray names(numFields); + names[0] = "active"; + names[1] = "lowAlarmLimit"; + names[2] = "lowWarningLimit"; + names[3] = "highWarningLimit"; + names[4] = "highAlarmLimit"; + names[5] = "lowAlarmSeverity"; + names[6] = "lowWarningSeverity"; + names[7] = "highWarningSeverity"; + names[8] = "highAlarmSeverity"; + names[9] = "hystersis"; + fields[0] = fieldCreate->createScalar(pvBoolean); + for(size_t i=0; icreateScalar(pvLong); + } + longAlarmField = fieldCreate->createStructure(names,fields); } static void createFloatAlarm() { - int numFields = 10; - FieldConstPtrArray fields = new FieldConstPtr[numFields]; - fields[0] = fieldCreate->createScalar(String("active"),pvBoolean); - fields[1] = fieldCreate->createScalar(String("lowAlarmLimit"),pvFloat); - fields[2] = fieldCreate->createScalar(String("lowWarningLimit"),pvFloat); - fields[3] = fieldCreate->createScalar(String("highWarningLimit"),pvFloat); - fields[4] = fieldCreate->createScalar(String("highAlarmLimit"),pvFloat); - fields[5] = fieldCreate->createScalar(String("lowAlarmSeverity"),pvInt); - fields[6] = fieldCreate->createScalar(String("lowWarningSeverity"),pvInt); - fields[7] = fieldCreate->createScalar(String("highWarningSeverity"),pvInt); - fields[8] = fieldCreate->createScalar(String("highAlarmSeverity"),pvInt); - fields[9] = fieldCreate->createScalar(String("hystersis"),pvFloat); - floatAlarmField = fieldCreate->createStructure(String("valueAlarm"),numFields,fields); + size_t numFields = 10; + FieldConstPtrArray fields(numFields); + StringArray names(numFields); + names[0] = "active"; + names[1] = "lowAlarmLimit"; + names[2] = "lowWarningLimit"; + names[3] = "highWarningLimit"; + names[4] = "highAlarmLimit"; + names[5] = "lowAlarmSeverity"; + names[6] = "lowWarningSeverity"; + names[7] = "highWarningSeverity"; + names[8] = "highAlarmSeverity"; + names[9] = "hystersis"; + fields[0] = fieldCreate->createScalar(pvBoolean); + for(size_t i=0; icreateScalar(pvFloat); + } + floatAlarmField = fieldCreate->createStructure(names,fields); } static void createDoubleAlarm() { - int numFields = 10; - FieldConstPtrArray fields = new FieldConstPtr[numFields]; - fields[0] = fieldCreate->createScalar(String("active"),pvBoolean); - fields[1] = fieldCreate->createScalar(String("lowAlarmLimit"),pvDouble); - fields[2] = fieldCreate->createScalar(String("lowWarningLimit"),pvDouble); - fields[3] = fieldCreate->createScalar(String("highWarningLimit"),pvDouble); - fields[4] = fieldCreate->createScalar(String("highAlarmLimit"),pvDouble); - fields[5] = fieldCreate->createScalar(String("lowAlarmSeverity"),pvInt); - fields[6] = fieldCreate->createScalar(String("lowWarningSeverity"),pvInt); - fields[7] = fieldCreate->createScalar(String("highWarningSeverity"),pvInt); - fields[8] = fieldCreate->createScalar(String("highAlarmSeverity"),pvInt); - fields[9] = fieldCreate->createScalar(String("hystersis"),pvDouble); - doubleAlarmField = fieldCreate->createStructure(String("valueAlarm"),numFields,fields); + size_t numFields = 10; + FieldConstPtrArray fields(numFields); + StringArray names(numFields); + names[0] = "active"; + names[1] = "lowAlarmLimit"; + names[2] = "lowWarningLimit"; + names[3] = "highWarningLimit"; + names[4] = "highAlarmLimit"; + names[5] = "lowAlarmSeverity"; + names[6] = "lowWarningSeverity"; + names[7] = "highWarningSeverity"; + names[8] = "highAlarmSeverity"; + names[9] = "hystersis"; + fields[0] = fieldCreate->createScalar(pvDouble); + for(size_t i=0; icreateScalar(pvByte); + } + doubleAlarmField = fieldCreate->createStructure(names,fields); } static void createEnumeratedAlarm() { - int numFields = 3; - FieldConstPtrArray fields = new FieldConstPtr[numFields]; - fields[0] = fieldCreate->createScalar(String("active"),pvBoolean); - fields[1] = fieldCreate->createScalar(String("stateSeverity"),pvInt); - fields[2] = fieldCreate->createScalar(String("changeStateSeverity"),pvInt); - enumeratedAlarmField = fieldCreate->createStructure(String("valueAlarm"),numFields,fields); + size_t numFields = 3; + FieldConstPtrArray fields(numFields); + StringArray names(numFields); + names[0] = "active"; + names[1] = "stateSeverity"; + names[2] = "changeStateSeverity"; + fields[0] = fieldCreate->createScalar(pvBoolean); + fields[1] = fieldCreate->createScalar(pvInt); + fields[2] = fieldCreate->createScalar(pvInt); + enumeratedAlarmField = fieldCreate->createStructure(names,fields); } -static StructureConstPtr createProperties(String fieldName,FieldConstPtr field,String properties) { +static StructureConstPtr createProperties(FieldConstPtr field,String properties) +{ bool gotAlarm = false; bool gotTimeStamp = false; bool gotDisplay = false; @@ -225,12 +277,13 @@ static StructureConstPtr createProperties(String fieldName,FieldConstPtr field,S } if(type==structure) { StructureConstPtr structurePtr = static_pointer_cast(field); - if(structurePtr->getNumberFields()==2) { + StringArray names = structurePtr->getFieldNames(); + if(names.size()==2) { FieldConstPtrArray fields = structurePtr->getFields(); FieldConstPtr first = fields[0]; FieldConstPtr second = fields[1]; - String nameFirst = first->getFieldName(); - String nameSecond = second->getFieldName(); + String nameFirst = names[0]; + String nameSecond = names[1]; int compareFirst = nameFirst.compare("index"); int compareSecond = nameSecond.compare("choices"); if(compareFirst==0 && compareSecond==0) { @@ -250,138 +303,75 @@ static StructureConstPtr createProperties(String fieldName,FieldConstPtr field,S } throw std::logic_error(String("valueAlarm property for illegal type")); } - int numFields = numProp+1; - FieldConstPtrArray fields = new FieldConstPtr[numFields]; + size_t numFields = numProp+1; + FieldConstPtrArray fields(numFields); + StringArray names(numFields); int next = 0; + names[0] = "value"; fields[next++] = field; - if(gotAlarm) {fields[next++] = alarmField;} - if(gotTimeStamp) {fields[next++] = timeStampField;} - if(gotDisplay) {fields[next++] = displayField;} - if(gotControl) {fields[next++] = controlField;} - if(gotValueAlarm) {fields[next++] = valueAlarm;} - return fieldCreate->createStructure(fieldName,numFields,fields); + if(gotAlarm) { + names[next] = "alarm"; + fields[next++] = alarmField; + } + if(gotTimeStamp) { + names[next] = "timeStamp"; + fields[next++] = timeStampField; + } + if(gotDisplay) { + names[next] = "display"; + fields[next++] = displayField; + } + if(gotControl) { + names[next] = "control"; + fields[next++] = controlField; + } + if(gotValueAlarm) { + names[next] = "valueAlarm"; + fields[next++] = valueAlarm; + } + return fieldCreate->createStructure(names,fields); } -ScalarConstPtr StandardField::scalar(String fieldName,ScalarType type) -{ - return fieldCreate->createScalar(fieldName,type); -} - StructureConstPtr StandardField::scalar( - String fieldName,ScalarType type,String properties) + ScalarType type,String properties) { - ScalarConstPtr field = fieldCreate->createScalar(valueFieldName,type); - return createProperties(fieldName,field,properties); -} - -ScalarArrayConstPtr StandardField::scalarArray( - String fieldName,ScalarType elementType) -{ - return fieldCreate->createScalarArray(fieldName,elementType); + ScalarConstPtr field = fieldCreate->createScalar(type); + return createProperties(field,properties); } StructureConstPtr StandardField::scalarArray( - String fieldName,ScalarType elementType, String properties) -{ - ScalarArrayConstPtr field = fieldCreate->createScalarArray( - valueFieldName,elementType); - return createProperties(fieldName,field,properties); -} - -StructureArrayConstPtr StandardField::structureArray( - String fieldName,StructureConstPtr structure) -{ - return fieldCreate->createStructureArray(fieldName,structure); -} - -StructureConstPtr StandardField::structureArray( - String fieldName,StructureConstPtr structure,String properties) -{ - StructureArrayConstPtr field = fieldCreate->createStructureArray( - valueFieldName,structure); - return createProperties(fieldName,field,properties); -} - -StructureConstPtr StandardField::structure( - String fieldName,int numFields,FieldConstPtrArray fields) -{ - return fieldCreate->createStructure(fieldName,numFields,fields); -} - -StructureConstPtr StandardField::enumerated(String fieldName) -{ - FieldConstPtrArray fields = new FieldConstPtr[2]; - fields[0] = fieldCreate->createScalar(String("index"),pvInt); - fields[1] = fieldCreate->createScalarArray(String("choices"),pvString); - return fieldCreate->createStructure(fieldName,2,fields); -} - -StructureConstPtr StandardField::enumerated( - String fieldName,String properties) -{ - StructureConstPtr field = standardField->enumerated(valueFieldName); - return createProperties(fieldName,field,properties); -} - -ScalarConstPtr StandardField::scalarValue(ScalarType type) -{ - return fieldCreate->createScalar(valueFieldName,type); -} - -StructureConstPtr StandardField::scalarValue(ScalarType type,String properties) -{ - ScalarConstPtr field = fieldCreate->createScalar(valueFieldName,type); - return createProperties(valueFieldName,field,properties); -} - -ScalarArrayConstPtr StandardField::scalarArrayValue(ScalarType elementType) -{ - return fieldCreate->createScalarArray(valueFieldName,elementType); -} - -StructureConstPtr StandardField::scalarArrayValue( ScalarType elementType, String properties) { - ScalarArrayConstPtr field = fieldCreate->createScalarArray( - valueFieldName,elementType); - return createProperties(valueFieldName,field,properties); - + ScalarArrayConstPtr field = fieldCreate->createScalarArray(elementType); + return createProperties(field,properties); } -StructureArrayConstPtr StandardField::structureArrayValue( - StructureConstPtr structure) -{ - return fieldCreate->createStructureArray(valueFieldName,structure); -} -StructureConstPtr StandardField::structureArrayValue( - StructureConstPtr structure,String properties) +StructureConstPtr StandardField::structureArray( + StructureConstPtr &structure,String properties) { StructureArrayConstPtr field = fieldCreate->createStructureArray( - valueFieldName,structure); - return createProperties(valueFieldName,field,properties); - + structure); + return createProperties(field,properties); } -StructureConstPtr StandardField::structureValue( - int numFields,FieldConstPtrArray fields) +StructureConstPtr StandardField::enumerated() { - return fieldCreate->createStructure(valueFieldName,numFields,fields); + size_t num = 2; + FieldConstPtrArray fields(num); + StringArray names(num); + names[0] = "index"; + names[1] = "choices"; + fields[0] = fieldCreate->createScalar(pvInt); + fields[1] = fieldCreate->createScalarArray(pvString); + return fieldCreate->createStructure(names,fields); } -StructureConstPtr StandardField::enumeratedValue() +StructureConstPtr StandardField::enumerated(String properties) { - FieldConstPtrArray fields = new FieldConstPtr[2]; - fields[0] = fieldCreate->createScalar(String("index"),pvInt); - fields[1] = fieldCreate->createScalarArray(String("choices"),pvString); - return fieldCreate->createStructure(valueFieldName,2,fields); -} - -StructureConstPtr StandardField::enumeratedValue( String properties) -{ - StructureConstPtr field = standardField->enumerated(valueFieldName); - return createProperties(valueFieldName,field,properties); + StructureConstPtr field = enumerated(valueFieldName); + return createProperties(field,properties); } StructureConstPtr StandardField::alarm() @@ -444,58 +434,38 @@ StructureConstPtr StandardField::enumeratedAlarm() return enumeratedAlarmField; } -void StandardField::init() +StandardFieldPtr StandardField::getStandardField() { - createAlarm(); - createTimeStamp(); - createDisplay(); - createControl(); - createBooleanAlarm(); - createByteAlarm(); - createShortAlarm(); - createIntAlarm(); - createLongAlarm(); - createFloatAlarm(); - createDoubleAlarm(); - createEnumeratedAlarm(); + static StandardFieldPtr standardFieldCreate; + static Mutex mutex; + Lock xx(mutex); + + if(standardFieldCreate.get()==0) + { + fieldCreate = getFieldCreate(); + createAlarm(); + createTimeStamp(); + createDisplay(); + createControl(); + createBooleanAlarm(); + createByteAlarm(); + createShortAlarm(); + createIntAlarm(); + createLongAlarm(); + createFloatAlarm(); + createDoubleAlarm(); + createEnumeratedAlarm(); + standardFieldCreate = StandardFieldPtr(new StandardField()); + } + return standardFieldCreate; } +StandardField::StandardField(){} +StandardField::~StandardField(){} -StandardField::StandardField(){init();} -StandardField::~StandardField(){ -} - -static void myDeleteStatic(void*) -{ - alarmField.reset(); - timeStampField.reset(); - displayField.reset(); - controlField.reset(); - booleanAlarmField.reset(); - byteAlarmField.reset(); - shortAlarmField.reset(); - intAlarmField.reset(); - longAlarmField.reset(); - floatAlarmField.reset(); - doubleAlarmField.reset(); - enumeratedAlarmField.reset(); - -} - -static void myInitStatic(void*) -{ - standardField = new StandardField(); - fieldCreate = getFieldCreate(); - epicsAtExit(&myDeleteStatic,0); -} - -static -epicsThreadOnceId myInitOnce = EPICS_THREAD_ONCE_INIT; - -StandardField * getStandardField() { - epicsThreadOnce(&myInitOnce,&myInitStatic,0); - return standardField; +StandardFieldPtr getStandardField() { + return StandardField::getStandardField(); } }} diff --git a/pvDataApp/factory/StandardPVField.cpp b/pvDataApp/factory/StandardPVField.cpp index ee39c2a..6bccfa0 100644 --- a/pvDataApp/factory/StandardPVField.cpp +++ b/pvDataApp/factory/StandardPVField.cpp @@ -14,16 +14,15 @@ #include #include #include -#include namespace epics { namespace pvData { -static StandardField *standardField = 0; +static StandardFieldPtr standardField; +static FieldCreatePtr fieldCreate; +static PVDataCreatePtr pvDataCreate; + static String notImplemented("not implemented"); -static FieldCreate* fieldCreate = 0; -static PVDataCreate* pvDataCreate = 0; -static StandardPVField *standardPVField = 0; static void addExtendsStructureName(PVStructure *pvStructure,String properties) { @@ -36,20 +35,20 @@ static void addExtendsStructureName(PVStructure *pvStructure,String properties) if(properties.find("display")!=String::npos) gotDisplay = true; if(properties.find("control")!=String::npos) gotControl = true; if(gotAlarm) { - PVStructure *pv = pvStructure->getStructureField(String("alarm")); - if(pv!=0) pv->putExtendsStructureName(String("alarm")); + PVStructure *pv = pvStructure->getStructureField("alarm").get(); + if(pv!=NULL) pv->putExtendsStructureName("alarm"); } if(gotTimeStamp) { - PVStructure *pv = pvStructure->getStructureField(String("timeStamp")); - if(pv!=0) pv->putExtendsStructureName(String("timeStamp")); + PVStructure *pv = pvStructure->getStructureField("timeStamp").get(); + if(pv!=NULL) pv->putExtendsStructureName("timeStamp"); } if(gotDisplay) { - PVStructure *pv = pvStructure->getStructureField(String("display")); - if(pv!=0) pv->putExtendsStructureName(String("display")); + PVStructure *pv = pvStructure->getStructureField("display").get(); + if(pv!=NULL) pv->putExtendsStructureName("display"); } if(gotControl) { - PVStructure *pv = pvStructure->getStructureField(String("control")); - if(pv!=0) pv->putExtendsStructureName(String("control")); + PVStructure *pv = pvStructure->getStructureField("control").get(); + if(pv!=NULL) pv->putExtendsStructureName(String("control")); } } @@ -57,297 +56,75 @@ StandardPVField::StandardPVField(){} StandardPVField::~StandardPVField(){} - -PVScalar * StandardPVField::scalar(PVStructure *parent, - String fieldName,ScalarType type) +PVStructurePtr StandardPVField::scalar(ScalarType type,String properties) { - ScalarConstPtr field = standardField->scalar(fieldName,type); - return pvDataCreate->createPVScalar(parent,field); -} - -PVStructure * StandardPVField::scalar(PVStructure *parent, - String fieldName,ScalarType type,String properties) -{ - StructureConstPtr field = standardField->scalar(fieldName,type,properties); - PVStructure * pvStructure = pvDataCreate->createPVStructure(parent,field); - addExtendsStructureName(pvStructure,properties); + StructureConstPtr field = standardField->scalar(type,properties); + PVStructurePtr pvStructure = pvDataCreate->createPVStructure(field); + addExtendsStructureName(pvStructure.get(),properties); return pvStructure; } -PVScalarArray * StandardPVField::scalarArray(PVStructure *parent, - String fieldName,ScalarType elementType) +PVStructurePtr StandardPVField::scalarArray(ScalarType elementType, String properties) { - ScalarArrayConstPtr field = standardField->scalarArray( - fieldName,elementType); - return pvDataCreate->createPVScalarArray(parent,field); -} - -PVStructure * StandardPVField::scalarArray(PVStructure *parent, - String fieldName,ScalarType elementType, String properties) -{ - StructureConstPtr field = standardField->scalarArray( - fieldName,elementType,properties); - PVStructure * pvStructure = pvDataCreate->createPVStructure(parent,field); - addExtendsStructureName(pvStructure,properties); + StructureConstPtr field = standardField->scalarArray(elementType,properties); + PVStructurePtr pvStructure = pvDataCreate->createPVStructure(field); + addExtendsStructureName(pvStructure.get(),properties); return pvStructure; } -PVStructureArray * StandardPVField::structureArray(PVStructure *parent, - String fieldName,StructureConstPtr structure) +PVStructurePtr StandardPVField::structureArray(StructureConstPtr structure,String properties) { - StructureArrayConstPtr field = standardField->structureArray( - fieldName,structure); - return pvDataCreate->createPVStructureArray(parent,field); -} - -PVStructure* StandardPVField::structureArray(PVStructure *parent, - String fieldName,StructureConstPtr structure,String properties) -{ - StructureConstPtr field = standardField->structureArray( - fieldName,structure,properties); - PVStructure * pvStructure = pvDataCreate->createPVStructure(parent,field); - addExtendsStructureName(pvStructure,properties); + StructureConstPtr field = standardField->structureArray(structure,properties); + PVStructurePtr pvStructure = pvDataCreate->createPVStructure(field); + addExtendsStructureName(pvStructure.get(),properties); return pvStructure; } -PVStructure * StandardPVField::enumerated(PVStructure *parent, - String fieldName,StringArray choices,int number) +PVStructurePtr StandardPVField::enumerated(StringArray choices) { - StructureConstPtr field = standardField->enumerated(fieldName); - PVStructure *pvStructure = pvDataCreate->createPVStructure(parent,field); - PVScalarArray *pvScalarArray = pvStructure->getScalarArrayField( + StructureConstPtr field = standardField->enumerated(); + PVStructurePtr pvStructure = pvDataCreate->createPVStructure(field); + PVScalarArrayPtr pvScalarArray = pvStructure->getScalarArrayField( "choices",pvString); - if(pvScalarArray==0) { + if(pvScalarArray.get()==NULL) { throw std::logic_error(String("StandardPVField::enumerated")); } - PVStringArray *pvChoices = static_cast(pvScalarArray); - pvChoices->put(0,number,choices,0); + PVStringArray * pvChoices = static_cast(pvScalarArray.get()); + pvChoices->put(0,choices.size(),get(choices),0); return pvStructure; } -PVStructure * StandardPVField::enumerated(PVStructure *parent, - String fieldName,StringArray choices,int number, String properties) +PVStructurePtr StandardPVField::enumerated(StringArray choices,String properties) { - StructureConstPtr field = standardField->enumerated( - fieldName,properties); - PVStructure *pvStructure = pvDataCreate->createPVStructure(parent,field); - addExtendsStructureName(pvStructure,properties); - PVScalarArray *pvScalarArray = pvStructure->getScalarArrayField( - fieldName += ".choices",pvString); - if(pvScalarArray==0) { + StructureConstPtr field = standardField->enumerated(properties); + PVStructurePtr pvStructure = pvDataCreate->createPVStructure(field); + addExtendsStructureName(pvStructure.get(),properties); + PVScalarArrayPtr pvScalarArray = pvStructure->getScalarArrayField("value.choices",pvString); + if(pvScalarArray.get()==NULL) { throw std::logic_error(String("StandardPVField::enumerated")); } - PVStringArray *pvChoices = static_cast(pvScalarArray); - pvChoices->put(0,number,choices,0); + PVStringArray * pvChoices = static_cast(pvScalarArray.get()); + pvChoices->put(0,choices.size(),get(choices),0); return pvStructure; } -PVScalar * StandardPVField::scalarValue(PVStructure *parent, - ScalarType scalarType) +StandardPVFieldPtr StandardPVField::getStandardPVField() { - ScalarConstPtr field = standardField->scalarValue(scalarType); - return pvDataCreate->createPVScalar(parent,field); -} + static StandardPVFieldPtr standardPVField; + static Mutex mutex; + Lock xx(mutex); -PVStructure * StandardPVField::scalarValue(PVStructure *parent, - ScalarType type,String properties) -{ - StructureConstPtr field = standardField->scalarValue(type,properties); - PVStructure * pvStructure = pvDataCreate->createPVStructure(parent,field); - addExtendsStructureName(pvStructure,properties); - return pvStructure; -} - -PVScalarArray * StandardPVField::scalarArrayValue(PVStructure *parent, - ScalarType elementType) -{ - ScalarArrayConstPtr scalarArray = - standardField->scalarArrayValue(elementType); - return pvDataCreate->createPVScalarArray(0,scalarArray); -} - -PVStructure * StandardPVField::scalarArrayValue(PVStructure *parent, - ScalarType elementType, String properties) -{ - StructureConstPtr field = standardField->scalarArrayValue( - elementType,properties); - PVStructure * pvStructure = pvDataCreate->createPVStructure(parent,field); - addExtendsStructureName(pvStructure,properties); - return pvStructure; -} - -PVStructureArray * StandardPVField::structureArrayValue(PVStructure *parent, - StructureConstPtr structure) -{ - StructureArrayConstPtr field = standardField->structureArrayValue( - structure); - return pvDataCreate->createPVStructureArray(parent,field); -} - -PVStructure * StandardPVField::structureArrayValue(PVStructure *parent, - StructureConstPtr structure,String properties) -{ - StructureConstPtr field = standardField->structureArrayValue( - structure,properties); - PVStructure * pvStructure = pvDataCreate->createPVStructure(parent,field); - addExtendsStructureName(pvStructure,properties); - return pvStructure; -} - -PVStructure * StandardPVField::enumeratedValue(PVStructure *parent, - StringArray choices,int number) -{ - StructureConstPtr field = standardField->enumeratedValue(); - PVStructure *pvStructure = pvDataCreate->createPVStructure(parent,field); - PVScalarArray *pvScalarArray = pvStructure->getScalarArrayField( - "choices",pvString); - if(pvScalarArray==0) { - throw std::logic_error(String("StandardPVField::enumerated")); + if(standardPVField.get()==NULL) { + standardField = getStandardField(); + fieldCreate = getFieldCreate(); + pvDataCreate = getPVDataCreate(); + standardPVField= StandardPVFieldPtr(new StandardPVField()); } - PVStringArray *pvChoices = static_cast(pvScalarArray); - pvChoices->put(0,number,choices,0); - return pvStructure; -} - -PVStructure * StandardPVField::enumeratedValue(PVStructure *parent, - StringArray choices, int number,String properties) -{ - StructureConstPtr field = standardField->enumeratedValue( properties); - PVStructure *pvStructure = pvDataCreate->createPVStructure(parent,field); - addExtendsStructureName(pvStructure,properties); - PVScalarArray *pvScalarArray = pvStructure->getScalarArrayField( - String("value.choices"),pvString); - if(pvScalarArray==0) { - throw std::logic_error(String("StandardPVField::enumerated")); - } - PVStringArray *pvChoices = static_cast(pvScalarArray); - pvChoices->put(0,number,choices,0); - return pvStructure; -} - -PVStructure * StandardPVField::alarm(PVStructure *parent) -{ - StructureConstPtr field = standardField->alarm(); - return pvDataCreate->createPVStructure(parent,field); -} - -PVStructure * StandardPVField::timeStamp(PVStructure *parent) -{ - StructureConstPtr field = standardField->timeStamp(); - return pvDataCreate->createPVStructure(parent,field); -} - -PVStructure * StandardPVField::display(PVStructure *parent) -{ - StructureConstPtr field = standardField->display(); - return pvDataCreate->createPVStructure(parent,field); -} - -PVStructure * StandardPVField::control(PVStructure *parent) -{ - StructureConstPtr field = standardField->control(); - return pvDataCreate->createPVStructure(parent,field); -} - -PVStructure * StandardPVField::booleanAlarm(PVStructure *parent) -{ - StructureConstPtr field = standardField->booleanAlarm(); - return pvDataCreate->createPVStructure(parent,field); -} - -PVStructure * StandardPVField::byteAlarm(PVStructure *parent) -{ - StructureConstPtr field = standardField->byteAlarm(); - return pvDataCreate->createPVStructure(parent,field); -} - -PVStructure * StandardPVField::shortAlarm(PVStructure *parent) -{ - StructureConstPtr field = standardField->shortAlarm(); - return pvDataCreate->createPVStructure(parent,field); -} - -PVStructure * StandardPVField::intAlarm(PVStructure *parent) -{ - StructureConstPtr field = standardField->intAlarm(); - return pvDataCreate->createPVStructure(parent,field); -} - -PVStructure * StandardPVField::longAlarm(PVStructure *parent) -{ - StructureConstPtr field = standardField->longAlarm(); - return pvDataCreate->createPVStructure(parent,field); -} - -PVStructure * StandardPVField::floatAlarm(PVStructure *parent) -{ - StructureConstPtr field = standardField->floatAlarm(); - return pvDataCreate->createPVStructure(parent,field); -} - -PVStructure * StandardPVField::doubleAlarm(PVStructure *parent) -{ - StructureConstPtr field = standardField->doubleAlarm(); - return pvDataCreate->createPVStructure(parent,field); -} - -PVStructure * StandardPVField::enumeratedAlarm(PVStructure *parent) -{ - StructureConstPtr field = standardField->enumeratedAlarm(); - return pvDataCreate->createPVStructure(parent,field); -} - -PVStructure * StandardPVField::powerSupply(PVStructure *parent) -{ - StructureConstPtr alarmField = standardField->alarm(); - StructureConstPtr timeStampField = standardField->timeStamp(); - StructureConstPtr voltageField = standardField->scalar( - String("voltage"),pvDouble,String("alarm")); - StructureConstPtr powerField = standardField->scalar( - String("power"),pvDouble,String("alarm")); - StructureConstPtr currentField = standardField->scalar( - String("current"),pvDouble,String("alarm")); - FieldConstPtr fields[3]; - fields[0] = voltageField; - fields[1] = powerField; - fields[2] = currentField; - StructureConstPtr valueField = standardField->structureValue( 3,fields); - fields[0] = alarmField; - fields[1] = timeStampField; - fields[2] = valueField; - StructureConstPtr structureField = standardField->structureValue(3,fields); - return pvDataCreate->createPVStructure(parent,structureField); -} - - - - - -class StandardPVFieldExt : public StandardPVField { -public: - StandardPVFieldExt(): StandardPVField(){}; -}; - -static void myDeleteStatic(void*) -{ - delete standardPVField; -} - -static void myInitStatic(void*) -{ - fieldCreate = getFieldCreate(); - pvDataCreate = getPVDataCreate(); - standardField = getStandardField(); - standardPVField = new StandardPVFieldExt(); - epicsAtExit(&myDeleteStatic, 0); -} - -static -epicsThreadOnceId myInitOnce = EPICS_THREAD_ONCE_INIT; - -StandardPVField * getStandardPVField() { - epicsThreadOnce(&myInitOnce, &myInitStatic, 0); return standardPVField; } +StandardPVFieldPtr getStandardPVField() { + return StandardPVField::getStandardPVField(); +} + }} diff --git a/pvDataApp/factory/TypeFunc.cpp b/pvDataApp/factory/TypeFunc.cpp index a678111..abea7c3 100644 --- a/pvDataApp/factory/TypeFunc.cpp +++ b/pvDataApp/factory/TypeFunc.cpp @@ -33,7 +33,12 @@ namespace TypeFunc { namespace ScalarTypeFunc { bool isInteger(ScalarType type) { - if(type>=pvByte && type<=pvLong) return true; + if(type>=pvByte && type<=pvULong) return true; + return false; + } + + bool isUInteger(ScalarType type) { + if(type>=pvUByte && type<=pvULong) return true; return false; } @@ -48,7 +53,9 @@ namespace ScalarTypeFunc { } static const char* names[] = { - "boolean", "byte", "short", "int", "long", + "boolean", + "byte", "short", "int", "long", + "ubyte", "ushort", "uint", "ulong", "float", "double", "string", }; ScalarType getScalarType(String pvalue) { diff --git a/pvDataApp/misc/byteBuffer.h b/pvDataApp/misc/byteBuffer.h index 149a912..8220cbe 100644 --- a/pvDataApp/misc/byteBuffer.h +++ b/pvDataApp/misc/byteBuffer.h @@ -153,7 +153,7 @@ inline double swap(double val) } #define is_aligned(POINTER, BYTE_COUNT) \ - (((uintptr_t)(const void *)(POINTER)) % (BYTE_COUNT) == 0) + (((std::ptrdiff_t)(const void *)(POINTER)) % (BYTE_COUNT) == 0) /*template - inline void put(uintptr_t index, T value) + inline void put(std::size_t index, T value) { // this avoids int8 specialization, compiler will take care if optimization, -O2 or more if (sizeof(T) == 1) @@ -470,7 +470,7 @@ public: * @return The object. */ template - inline T get(uintptr_t index) + inline T get(std::size_t index) { // this avoids int8 specialization, compiler will take care if optimization, -O2 or more if (sizeof(T) == 1) @@ -525,7 +525,7 @@ public: * @param offset The starting position within src. * @param count The number of bytes to put into the byte buffer, */ - inline void put(const char* src, uintptr_t src_offset, uintptr_t count) { + inline void put(const char* src, std::size_t src_offset, std::size_t count) { //if(count>getRemaining()) THROW_BASE_EXCEPTION("buffer overflow"); memcpy(_position, src + src_offset, count); _position += count; @@ -538,7 +538,7 @@ public: * @param offset The starting position within src. * @param count The number of bytes to put into the byte buffer, */ - inline void get(char* dest, uintptr_t dest_offset, uintptr_t count) { + inline void get(char* dest, std::size_t dest_offset, std::size_t count) { //if(count>getRemaining()) THROW_BASE_EXCEPTION("buffer overflow"); memcpy(dest + dest_offset, _position, count); _position += count; @@ -551,7 +551,7 @@ public: * @param count The number of elements. */ template - inline void putArray(T* values, uintptr_t count) + inline void putArray(T* values, std::size_t count) { // this avoids int8 specialization, compiler will take care if optimization, -O2 or more if (sizeof(T) == 1) @@ -570,7 +570,7 @@ public: // ... so that we can be fast changing endianess if (ENDIANESS_SUPPORT && reverse()) { - for (uintptr_t i = 0; i < count; i++) + for (std::size_t i = 0; i < count; i++) { *start = swap(*start); start++; @@ -585,7 +585,7 @@ public: * @param count The number of elements. */ template - inline void getArray(T* values, uintptr_t count) + inline void getArray(T* values, std::size_t count) { // this avoids int8 specialization, compiler will take care if optimization, -O2 or more if (sizeof(T) == 1) @@ -604,7 +604,7 @@ public: // ... so that we can be fast changing endianess if (ENDIANESS_SUPPORT && reverse()) { - for (uintptr_t i = 0; i < count; i++) + for (std::size_t i = 0; i < count; i++) { *start = swap(*start); start++; @@ -627,8 +627,8 @@ public: */ inline void align(int size) { - const uintptr_t k = size - 1; - _position = (char*)((((uintptr_t)(const void *)_position) + k) & ~(k)); + const std::size_t k = size - 1; + _position = (char*)((((std::ptrdiff_t)(const void *)_position) + k) & ~(k)); } /** * Put a boolean value into the byte buffer. @@ -679,49 +679,49 @@ public: * @param index The offset in the byte buffer, * @param value The value. */ - inline void putBoolean(uintptr_t index, bool value) { put< int8>(index, value); } + inline void putBoolean(std::size_t index, bool value) { put< int8>(index, value); } /** * Put a byte value into the byte buffer at the specified index. * * @param index The offset in the byte buffer, * @param value The value. */ - inline void putByte (uintptr_t index, int8 value) { put< int8>(index, value); } + inline void putByte (std::size_t index, int8 value) { put< int8>(index, value); } /** * Put a short value into the byte buffer at the specified index. * * @param index The offset in the byte buffer, * @param value The value. */ - inline void putShort (uintptr_t index, int16 value) { put< int16>(index, value); } + inline void putShort (std::size_t index, int16 value) { put< int16>(index, value); } /** * Put an int value into the byte buffer at the specified index. * * @param index The offset in the byte buffer, * @param value The value. */ - inline void putInt (uintptr_t index, int32 value) { put< int32>(index, value); } + inline void putInt (std::size_t index, int32 value) { put< int32>(index, value); } /** * Put a long value into the byte buffer at the specified index. * * @param index The offset in the byte buffer, * @param value The value. */ - inline void putLong (uintptr_t index, int64 value) { put< int64>(index, value); } + inline void putLong (std::size_t index, int64 value) { put< int64>(index, value); } /** * Put a float value into the byte buffer at the specified index. * * @param index The offset in the byte buffer, * @param value The value. */ - inline void putFloat (uintptr_t index, float value) { put< float>(index, value); } + inline void putFloat (std::size_t index, float value) { put< float>(index, value); } /** * Put a double value into the byte buffer at the specified index. * * @param index The offset in the byte buffer, * @param value The value. */ - inline void putDouble (uintptr_t index,double value) { put(index, value); } + inline void putDouble (std::size_t index,double value) { put(index, value); } /** * Get a boolean value from the byte buffer. @@ -772,49 +772,49 @@ public: * @param index The offset in the byte buffer. * @return The value. */ - inline bool getBoolean(uintptr_t index) { return get< int8>(index) != 0; } + inline bool getBoolean(std::size_t index) { return get< int8>(index) != 0; } /** * Get a byte value from the byte buffer at the specified index. * * @param index The offset in the byte buffer. * @return The value. */ - inline int8 getByte (uintptr_t index) { return get< int8>(index); } + inline int8 getByte (std::size_t index) { return get< int8>(index); } /** * Get a short value from the byte buffer at the specified index. * * @param index The offset in the byte buffer. * @return The value. */ - inline int16 getShort (uintptr_t index) { return get< int16>(index); } + inline int16 getShort (std::size_t index) { return get< int16>(index); } /** * Get an int value from the byte buffer at the specified index. * * @param index The offset in the byte buffer. * @return The value. */ - inline int32 getInt (uintptr_t index) { return get< int32>(index); } + inline int32 getInt (std::size_t index) { return get< int32>(index); } /** * Get a long value from the byte buffer at the specified index. * * @param index The offset in the byte buffer. * @return The value. */ - inline int64 getLong (uintptr_t index) { return get< int64>(index); } + inline int64 getLong (std::size_t index) { return get< int64>(index); } /** * Get a float value from the byte buffer at the specified index. * * @param index The offset in the byte buffer. * @return The value. */ - inline float getFloat (uintptr_t index) { return get< float>(index); } + inline float getFloat (std::size_t index) { return get< float>(index); } /** * Get a boolean value from the byte buffer at the specified index. * * @param double The offset in the byte buffer. * @return The value. */ - inline double getDouble (uintptr_t index) { return get(index); } + inline double getDouble (std::size_t index) { return get(index); } // TODO remove inline const char* getArray() @@ -827,7 +827,7 @@ private: char* _buffer; char* _position; char* _limit; - uintptr_t _size; + std::size_t _size; bool _reverseEndianess; bool _reverseFloatEndianess; }; diff --git a/pvDataApp/misc/messageQueue.h b/pvDataApp/misc/messageQueue.h index 164f206..19053f9 100644 --- a/pvDataApp/misc/messageQueue.h +++ b/pvDataApp/misc/messageQueue.h @@ -6,17 +6,27 @@ */ #ifndef MESSAGEQUEUE_H #define MESSAGEQUEUE_H +#include +#include +#include +#include + #include #include #include namespace epics { namespace pvData { +class MessageNode; +class MessageQueue; +typedef std::tr1::shared_ptr MessageNodePtr; +typedef std::tr1::shared_ptr MessageQueuePtr; + class MessageNode { public: - String getMessage() const; - MessageType getMessageType() const; - void setMessageNull(); + String getMessage() const { return message;} + MessageType getMessageType() const {return messageType;} + void setMessageNull() {message=String();} private: MessageNode(); ~MessageNode(); @@ -27,7 +37,7 @@ private: class MessageQueue : private NoDefaultMethods { public: - MessageQueue(int size); + static MessageQueuePtr create(int size); ~MessageQueue(); MessageNode *get(); // must call release before next get @@ -38,9 +48,91 @@ public: bool isFull() const; int getClearOverrun(); private: - class MessageQueuePvt *pImpl; + MessageQueue(std::vector > data); + + Queue queue; + MessageNode *lastPut; + MessagreNode *lastGet; + int size; + int overrun; }; +MessageQueuePtr MessageQueue::create(int size) +{ + std::vector > dataArray; + dataArray.reserve(size); + for(int i=0; i(new MessageNode())); + } + return std::tr1::shared_ptr(new MessageQueue(dataArray)); +} + +MessageQueue::MessageQueue(std::vector > data) +: queue(data), + lastPut(NULL), + lastGet(NULL), + size(data.size()), + overrun(0) +{ } + +MessageNode *MessageQueue::get() { + if(lastGet!=NULL) { + throw std::logic_error( + String("MessageQueue::get() but did not release last")); + } + MessageNode node = queue.getUsed(); + if(node==NULL) return NULL; + lastGet = node; + return node; +} + +void MessageQueue::release() { + if(lastGet==NULL) return; + queue.releaseUsed(lastGet); + lastGet = NULL; +} + +bool MessageQueue::put(String message,MessageType messageType,bool replaceLast) +{ + MessageNode node = queue.getFree(); + if(node!= NULL) { + node->message = message; + node->messageType = messageType; + lastPut = node; + queue.setUsed(node); + return true; + } + overrun++; + if(replaceLast) { + node = lastPut; + node->message = message; + node->messageType = messageType; + } + return false; +} + +bool MessageQueue::isEmpty() const +{ + int free = queue.getNumberFree(); + if(free==size) return true; + return false; +} + +bool MessageQueue::isFull() const +{ + if(queue.getNumberFree()==0) return true; + return false; +} + +int MessageQueue::getClearOverrun() +{ + int num = overrun; + overrun = 0; + return num; +} + + }} #endif /* MESSAGEQUEUE_H */ diff --git a/pvDataApp/misc/queue.h b/pvDataApp/misc/queue.h index 013a772..485432e 100644 --- a/pvDataApp/misc/queue.h +++ b/pvDataApp/misc/queue.h @@ -4,47 +4,121 @@ * EPICS pvDataCPP is distributed subject to a Software License Agreement found * in file LICENSE that is included with this distribution. */ +#include +#include +#include +#include #ifndef QUEUE_H #define QUEUE_H -#include namespace epics { namespace pvData { template -class Queue; - -template -class QueueElement; - -template -class QueueElement : private QueueElementVoid { +class Queue +{ public: - T *getObject() { return static_cast(QueueElementVoid::getObject());} -protected: - QueueElement(T *object) : QueueElementVoid(static_cast(object)){} - ~QueueElement() {} - friend class Queue; + typedef std::tr1::shared_ptr queueElementPtr; + Queue(int size); + Queue(std::vector elements); + ~Queue(){} + void clear(); + int capacity(){return size;} + int getNumberFree(){return numberFree;} + int getNumberUsed(){return numberUsed;} + T * getFree(); + void setUsed(T *element); + T * getUsed(); + void releaseUsed(T *element); +private: + std::vector elements; + int size; + int numberFree; + int numberUsed; + int nextGetFree; + int nextSetUsed; + int nextGetUsed; + int nextReleaseUsed; }; template -class Queue : private QueueVoid { -public: - Queue(T *array[],int number) - : QueueVoid((ObjectPtr*)array,number) - //: QueueVoid(static_cast(array),number) - {} - ~Queue() {} - void clear() {QueueVoid::clear();} - int getNumberFree() {return QueueVoid::getNumberFree();} - int capacity() {return QueueVoid::capacity();} - QueueElement *getFree() { - return static_cast *>(QueueVoid::getFree());} - void setUsed(QueueElement *queueElement) { - QueueVoid::setUsed(static_cast(queueElement));} - QueueElement *getUsed() { - return static_cast *>(QueueVoid::getUsed());} - void releaseUsed(QueueElement *queueElement) { - QueueVoid::releaseUsed(static_cast(queueElement));} -}; +Queue::Queue(int size) +: elements(size), + size(size), + numberFree(size), + numberUsed(0), + nextGetFree(0), + nextSetUsed(0), + nextGetUsed(0), + nextReleaseUsed(0) +{ + for(int i=0; i(new T()); + } +} + +template +Queue::Queue(std::vector elements) +: elements(elements), + size(elements.size()), + numberFree(size), + numberUsed(0), + nextGetFree(0), + nextSetUsed(0), + nextGetUsed(0), + nextReleaseUsed(0) +{ } + +template +void Queue::clear() +{ + numberFree = size; + numberUsed = 0; + nextGetFree = 0; + nextSetUsed = 0; + nextGetUsed = 0; + nextReleaseUsed = 0; +} + +template +T * Queue::getFree() +{ + if(numberFree==0) return NULL; + numberFree--; + std::tr1::shared_ptr queueElement = elements[nextGetFree++]; + if(nextGetFree>=size) nextGetFree = 0; + return queueElement.get(); +} + +template +void Queue::setUsed(T *element) +{ + if(element!=elements[nextSetUsed++].get()) { + throw std::logic_error("not correct queueElement"); + } + numberUsed++; + if(nextSetUsed>=size) nextSetUsed = 0; +} + +template +T * Queue::getUsed() +{ + if(numberUsed==0) return 0; + std::tr1::shared_ptr queueElement = elements[nextGetUsed++]; + if(nextGetUsed>=size) nextGetUsed = 0; + return queueElement.get(); +} + +template +void Queue::releaseUsed( T *element) +{ + if(element!=elements[nextReleaseUsed++].get()) { + throw std::logic_error( + "not queueElement returned by last call to getUsed"); + } + if(nextReleaseUsed>=size) nextReleaseUsed = 0; + numberUsed--; + numberFree++; + +} }} diff --git a/pvDataApp/misc/queueVoid.cpp b/pvDataApp/misc/queueVoid.cpp deleted file mode 100644 index 1708606..0000000 --- a/pvDataApp/misc/queueVoid.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* queueVoid.cpp */ -/** - * Copyright - See the COPYRIGHT that is included with this distribution. - * EPICS pvDataCPP is distributed subject to a Software License Agreement found - * in file LICENSE that is included with this distribution. - */ -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -namespace epics { namespace pvData { - -PVDATA_REFCOUNT_MONITOR_DEFINE(queueElement); -PVDATA_REFCOUNT_MONITOR_DEFINE(queue); - -QueueElementVoid::QueueElementVoid(ObjectPtr object) -: object(object) -{ - PVDATA_REFCOUNT_MONITOR_CONSTRUCT(queueElement); -} - - -QueueElementVoid::~QueueElementVoid() -{ - PVDATA_REFCOUNT_MONITOR_DESTRUCT(queueElement); -} - -ObjectPtr QueueElementVoid::getObject() { - return object; -} - - - -QueueVoid::QueueVoid(ObjectPtr object[],int number) -: array(new QueueElementVoidPtr[number]),number(number), - numberFree(number),numberUsed(0), - nextGetFree(0),nextSetUsed(), - nextGetUsed(0),nextReleaseUsed(0) -{ - for(int i=0; i=number) nextGetFree = 0; - return queueElement; -} - -void QueueVoid::setUsed(QueueElementVoid *queueElement) -{ - if(queueElement!=array[nextSetUsed++]) { - throw std::logic_error(String("not correct queueElement")); - } - numberUsed++; - if(nextSetUsed>=number) nextSetUsed = 0; -} - -QueueElementVoid * QueueVoid::getUsed() -{ - if(numberUsed==0) return 0; - QueueElementVoid *queueElement = array[nextGetUsed++]; - if(nextGetUsed>=number) nextGetUsed = 0; - return queueElement; -} - -void QueueVoid::releaseUsed(QueueElementVoid *queueElement) -{ - if(queueElement!=array[nextReleaseUsed++]) { - throw std::logic_error(String( - "not queueElement returned by last call to getUsed")); - } - if(nextReleaseUsed>=number) nextReleaseUsed = 0; - numberUsed--; - numberFree++; -} - -}} diff --git a/pvDataApp/misc/queueVoid.h b/pvDataApp/misc/queueVoid.h deleted file mode 100644 index 6a85dcf..0000000 --- a/pvDataApp/misc/queueVoid.h +++ /dev/null @@ -1,56 +0,0 @@ -/* queueVoid.h */ -/** - * Copyright - See the COPYRIGHT that is included with this distribution. - * EPICS pvDataCPP is distributed subject to a Software License Agreement found - * in file LICENSE that is included with this distribution. - */ -#ifndef QUEUEVOID_H -#define QUEUEVOID_H -namespace epics { namespace pvData { - -class QueueVoid; -class QueueElementVoid; - -typedef void * ObjectPtr; -typedef QueueElementVoid * QueueElementVoidPtr; -typedef QueueElementVoidPtr * QueueElementVoidPtrArray; - -class QueueElementVoid { -protected: - ObjectPtr getObject(); - QueueElementVoid(ObjectPtr object); - ~QueueElementVoid(); - ObjectPtr object; - friend class QueueVoid; -}; - - -class QueueVoid { -protected: - QueueVoid(ObjectPtr array[],int number); - ~QueueVoid(); - void clear(); - int getNumberFree(); - int capacity(); - QueueElementVoidPtr getFree(); - void setUsed(QueueElementVoid *queueElement); - QueueElementVoid *getUsed(); - void releaseUsed(QueueElementVoid *queueElement); -private: - friend class QueueElementVoid; - QueueElementVoidPtrArray array; - int number; - int numberFree; - int numberUsed; - int nextGetFree; - int nextSetUsed; - int nextGetUsed; - int nextReleaseUsed; -}; - - -}} -#endif /* QUEUEVOID_H */ - - - diff --git a/pvDataApp/misc/requester.cpp b/pvDataApp/misc/requester.cpp index 0e1bbaa..2cfa2c3 100644 --- a/pvDataApp/misc/requester.cpp +++ b/pvDataApp/misc/requester.cpp @@ -9,12 +9,14 @@ namespace epics { namespace pvData { const size_t messageTypeCount = 4; -static std::string typeName[messageTypeCount] = { - String("info"), - String("warning"), - String("error"), - String("fatalError") -}; -StringArray messageTypeName = typeName; +StringArray messageTypeName(messageTypeCount); +void Requester::init() +{ + messageTypeName[0] = "info"; + messageTypeName[1] = "warning"; + messageTypeName[2] = "error"; + messageTypeName[3] = "fatalError"; +} + }} diff --git a/pvDataApp/misc/requester.h b/pvDataApp/misc/requester.h index 1add4cc..a7259f6 100644 --- a/pvDataApp/misc/requester.h +++ b/pvDataApp/misc/requester.h @@ -27,6 +27,8 @@ public: virtual ~Requester(){} virtual String getRequesterName() = 0; virtual void message(String message,MessageType messageType) = 0; +private: + static void init(); }; }} diff --git a/pvDataApp/misc/serialize.h b/pvDataApp/misc/serialize.h index 0c3cc82..679e6e0 100644 --- a/pvDataApp/misc/serialize.h +++ b/pvDataApp/misc/serialize.h @@ -22,7 +22,7 @@ namespace epics { namespace pvData { public: virtual ~SerializableControl(){} virtual void flushSerializeBuffer() =0; - virtual void ensureBuffer(int size) =0; + virtual void ensureBuffer(std::size_t size) =0; virtual void alignBuffer(int alignment) =0; virtual void cachedSerialize(std::tr1::shared_ptr const & field, ByteBuffer* buffer) = 0; }; @@ -30,7 +30,7 @@ namespace epics { namespace pvData { class DeserializableControl { public: virtual ~DeserializableControl(){} - virtual void ensureData(int size) =0; + virtual void ensureData(std::size_t size) =0; virtual void alignData(int alignment) =0; virtual std::tr1::shared_ptr cachedDeserialize(ByteBuffer* buffer) = 0; }; @@ -58,7 +58,7 @@ namespace epics { namespace pvData { public: virtual ~SerializableArray(){} virtual void serialize(ByteBuffer *buffer, - SerializableControl *flusher, int offset, int count) const = 0; + SerializableControl *flusher, std::size_t offset, std::size_t count) const = 0; }; }} diff --git a/pvDataApp/misc/serializeHelper.cpp b/pvDataApp/misc/serializeHelper.cpp index 0a69b3a..f02d601 100644 --- a/pvDataApp/misc/serializeHelper.cpp +++ b/pvDataApp/misc/serializeHelper.cpp @@ -23,13 +23,13 @@ using namespace std; namespace epics { namespace pvData { - void SerializeHelper::writeSize(int s, ByteBuffer* buffer, + void SerializeHelper::writeSize(std::size_t s, ByteBuffer* buffer, SerializableControl* flusher) { flusher->ensureBuffer(sizeof(int64)+1); SerializeHelper::writeSize(s, buffer); } - void SerializeHelper::writeSize(int s, ByteBuffer* buffer) { + void SerializeHelper::writeSize(std::size_t s, ByteBuffer* buffer) { if(s==-1) // null buffer->putByte(-1); else if(s<254) @@ -41,7 +41,7 @@ namespace epics { } } - int SerializeHelper::readSize(ByteBuffer* buffer, + std::size_t SerializeHelper::readSize(ByteBuffer* buffer, DeserializableControl* control) { control->ensureData(1); int8 b = buffer->getByte(); @@ -54,17 +54,17 @@ namespace epics { return s; } else - return (int)(b<0 ? b+256 : b); + return (std::size_t)(b<0 ? b+256 : b); } void SerializeHelper::serializeString(const String& value, ByteBuffer* buffer, SerializableControl* flusher) { - int len = value.length(); + std::size_t len = value.length(); SerializeHelper::writeSize(len, buffer, flusher); if (len<=0) return; - int i = 0; + std::size_t i = 0; while(true) { - int maxToWrite = min(len-i, (int)buffer->getRemaining()); + std::size_t maxToWrite = min(len-i, buffer->getRemaining()); buffer->put(value.data(), i, maxToWrite); // ASCII i += maxToWrite; if(i(int)value.length()) offset = value.length(); + else if(offset>(std::size_t)value.length()) offset = value.length(); - if(offset+count>(int)value.length()) count = value.length()-offset; + if(offset+count>(std::size_t)value.length()) count = value.length()-offset; SerializeHelper::writeSize(count, buffer, flusher); if (count<=0) return; - int i = 0; + std::size_t i = 0; while(true) { - int maxToWrite = min(count-i, (int)buffer->getRemaining()); + std::size_t maxToWrite = min(count-i, buffer->getRemaining()); buffer->put(value.data(), offset+i, maxToWrite); // ASCII i += maxToWrite; if(i0) { - if ((int)buffer->getRemaining()>=size) + if (buffer->getRemaining()>=size) { // entire string is in buffer, simply create a string out of it (copy) - int pos = buffer->getPosition(); + std::size_t pos = buffer->getPosition(); String str(buffer->getArray()+pos, size); buffer->setPosition(pos+size); return str; @@ -118,10 +118,10 @@ namespace epics { String str; str.reserve(size); try { - int i = 0; + std::size_t i = 0; while(true) { - int toRead = min(size-i, (int)buffer->getRemaining()); - int pos = buffer->getPosition(); + std::size_t toRead = min(size-i, buffer->getRemaining()); + std::size_t pos = buffer->getPosition(); str.append(buffer->getArray()+pos, toRead); buffer->setPosition(pos+toRead); i += toRead; diff --git a/pvDataApp/misc/serializeHelper.h b/pvDataApp/misc/serializeHelper.h index 6dcdf42..66c22f4 100644 --- a/pvDataApp/misc/serializeHelper.h +++ b/pvDataApp/misc/serializeHelper.h @@ -31,7 +31,7 @@ namespace epics { * @param[in] buffer serialization buffer * @param[in] flusher flusher */ - static void writeSize(int s, ByteBuffer* buffer, + static void writeSize(std::size_t s, ByteBuffer* buffer, SerializableControl* flusher); /** @@ -40,7 +40,7 @@ namespace epics { * @param[in] buffer deserialization buffer. * @returns array size. */ - static int readSize(ByteBuffer* buffer, + static std::size_t readSize(ByteBuffer* buffer, DeserializableControl* control); /** @@ -62,8 +62,8 @@ namespace epics { * @param[in] buffer serialization buffer * @param[in] flusher flusher */ - static void serializeSubstring(const String& value, int offset, - int count, ByteBuffer* buffer, + static void serializeSubstring(const String& value, std::size_t offset, + std::size_t count, ByteBuffer* buffer, SerializableControl* flusher); /** @@ -93,7 +93,7 @@ namespace epics { * @param[in] s size to encode * @param[in] buffer serialization buffer */ - static void writeSize(int s, ByteBuffer* buffer); + static void writeSize(std::size_t s, ByteBuffer* buffer); }; diff --git a/pvDataApp/monitor/monitor.h b/pvDataApp/monitor/monitor.h index 02a1d0f..2ee5488 100644 --- a/pvDataApp/monitor/monitor.h +++ b/pvDataApp/monitor/monitor.h @@ -15,92 +15,102 @@ namespace epics { namespace pvData { +typedef std::tr1::shared_ptr BitSetPtr; + +class MonitorElement; +typedef std::tr1::shared_ptr MonitorElementPtr; +typedef std::vector MonitorElementArray; + +class Monitor; +typedef std::tr1::shared_ptr MonitorPtr; + + +/** + * Class instance representing monitor element. + * @author mrk + */ +class MonitorElement { + public: + POINTER_DEFINITIONS(MonitorElement); + virtual ~MonitorElement(){} /** - * Class instance representing monitor element. - * @author mrk + * Get the PVStructure. + * @return The PVStructure. */ - class MonitorElement { - public: - POINTER_DEFINITIONS(MonitorElement); - virtual ~MonitorElement(){} - /** - * Get the PVStructure. - * @return The PVStructure. - */ - virtual PVStructure::shared_pointer const & getPVStructure() = 0; - /** - * Get the bitSet showing which fields have changed. - * @return The bitSet. - */ - virtual BitSet::shared_pointer const & getChangedBitSet() = 0; - /** - * Get the bitSet showing which fields have been changed more than once. - * @return The bitSet. - */ - virtual BitSet::shared_pointer const & getOverrunBitSet() = 0; - }; - - + virtual PVStructurePtr getPVStructure() = 0; /** - * Interface for Monitor. - * @author mrk + * Get the bitSet showing which fields have changed. + * @return The bitSet. */ - class Monitor : public Destroyable, private NoDefaultMethods { - public: - POINTER_DEFINITIONS(Monitor); - virtual ~Monitor(){} - /** - * Start monitoring. - * @return completion status. - */ - virtual Status start() = 0; - /** - * Stop Monitoring. - * @return completion status. - */ - virtual Status stop() = 0; - /** - * If monitor has occurred return data. - * @return monitorElement for modified data. - * Must call get to determine if data is available. - */ - virtual MonitorElement::shared_pointer const & poll() = 0; - /** - * Release a MonitorElement that was returned by poll. - * @param monitorElement - */ - virtual void release(MonitorElement::shared_pointer const & monitorElement) = 0; - }; - - + virtual BitSetPtr getChangedBitSet() = 0; /** - * Requester for ChannelMonitor. - * @author mrk + * Get the bitSet showing which fields have been changed more than once. + * @return The bitSet. */ - class MonitorRequester : public virtual Requester { - public: - POINTER_DEFINITIONS(MonitorRequester); - virtual ~MonitorRequester(){} - /** - * The client and server have both completed the createMonitor request. - * @param status Completion status. - * @param monitor The monitor - * @param structure The structure defining the data. - */ - virtual void monitorConnect(Status const &status, - Monitor::shared_pointer const & monitor, StructureConstPtr const & structure) = 0; - /** - * A monitor event has occurred. - * The requester must call Monitor.poll to get data. - * @param monitor The monitor. - */ - virtual void monitorEvent(Monitor::shared_pointer const &monitor) = 0; - /** - * The data source is no longer available. - * @param monitor The monitor. - */ - virtual void unlisten(Monitor::shared_pointer const &monitor) = 0; - }; + virtual BitSetPtr getOverrunBitSet() = 0; +}; + + +/** + * Interface for Monitor. + * @author mrk + */ +class Monitor : public Destroyable, private NoDefaultMethods { + public: + POINTER_DEFINITIONS(Monitor); + virtual ~Monitor(){} + /** + * Start monitoring. + * @return completion status. + */ + virtual Status start() = 0; + /** + * Stop Monitoring. + * @return completion status. + */ + virtual Status stop() = 0; + /** + * If monitor has occurred return data. + * @return monitorElement for modified data. + * Must call get to determine if data is available. + */ + virtual MonitorElementPtr poll() = 0; + /** + * Release a MonitorElement that was returned by poll. + * @param monitorElement + */ + virtual void release(MonitorElementPtr & monitorElement) = 0; +}; + + +/** + * Requester for ChannelMonitor. + * @author mrk + */ +class MonitorRequester : public virtual Requester { + public: + POINTER_DEFINITIONS(MonitorRequester); + virtual ~MonitorRequester(){} + /** + * The client and server have both completed the createMonitor request. + * @param status Completion status. + * @param monitor The monitor + * @param structure The structure defining the data. + */ + virtual void monitorConnect(Status const &status, + MonitorPtr & monitor, StructureConstPtr const & structure) = 0; + /** + * A monitor event has occurred. + * The requester must call Monitor.poll to get data. + * @param monitor The monitor. + */ + virtual void monitorEvent(MonitorPtr const &monitor) = 0; + /** + * The data source is no longer available. + * @param monitor The monitor. + */ + virtual void unlisten(MonitorPtr const &monitor) = 0; +}; }} #endif /* MONITOR_H */ diff --git a/pvDataApp/monitor/monitorQueue.h b/pvDataApp/monitor/monitorQueue.h index 83f874f..42930f0 100644 --- a/pvDataApp/monitor/monitorQueue.h +++ b/pvDataApp/monitor/monitorQueue.h @@ -31,16 +31,16 @@ public: void clear(); int getNumberFree(); int capacity(); - MonitorElement::shared_pointer const & getFree(); - void setUsed(MonitorElement::shared_pointer const & element); - MonitorElement::shared_pointer const & getUsed(); - void releaseUsed(MonitorElement::shared_pointer const & element); + MonitorElementPtr & getFree(); + void setUsed(MonitorElementPtr & element); + MonitorElementPtr getUsed(); + void releaseUsed(MonitorElementPtr & element); private: int number; PVStructureSharedPointerPtrArray structures; - Queue *queue; - MonitorElement::shared_pointer **queueElements; - MonitorElement::shared_pointer nullElement; + Queue *queue; + MonitorElementPtr **queueElements; + MonitorElementPtr nullElement; }; }} diff --git a/pvDataApp/property/alarm.cpp b/pvDataApp/property/alarm.cpp index b5e1873..f77be2b 100644 --- a/pvDataApp/property/alarm.cpp +++ b/pvDataApp/property/alarm.cpp @@ -6,21 +6,13 @@ */ #include #include +#include #include #include #include #include namespace epics { namespace pvData { -const size_t severityCount = 5; -static String severityNames[severityCount] = -{ - String("NONE"), - String("MINOR"), - String("MAJOR"), - String("INVALID"), - String("UNDEFINED") -}; AlarmSeverity AlarmSeverityFunc::getSeverity(int value) { @@ -39,6 +31,18 @@ AlarmSeverity AlarmSeverityFunc::getSeverity(int value) StringArray AlarmSeverityFunc::getSeverityNames() { + static size_t severityCount = 5; + static StringArray severityNames; + static Mutex mutex; + Lock xx(mutex); + if(severityNames.size()==0) { + severityNames.reserve(severityCount); + severityNames.push_back("NONE"); + severityNames.push_back("MINOR"); + severityNames.push_back("MAJOR"); + severityNames.push_back("INVALID"); + severityNames.push_back("UNDEFINED"); + } return severityNames; } @@ -54,19 +58,6 @@ AlarmSeverity Alarm::getSeverity() const throw std::logic_error(String("should never get here")); } -const size_t statusCount = 8; -static String statusNames[statusCount] = -{ - String("NONE"), - String("DEVICE"), - String("DRIVER"), - String("RECORD"), - String("DB"), - String("CONF"), - String("UNDEFINED"), - String("CLIENT") -}; - AlarmStatus AlarmStatusFunc::getStatus(int value) { if(value<0 || value>7) { @@ -87,6 +78,21 @@ AlarmStatus AlarmStatusFunc::getStatus(int value) StringArray AlarmStatusFunc::getStatusNames() { + static size_t statusCount = 8; + static StringArray statusNames; + static Mutex mutex; + Lock xx(mutex); + if(statusNames.size()==0) { + statusNames.reserve(statusCount); + statusNames.push_back("NONE"); + statusNames.push_back("DEVICE"); + statusNames.push_back("DRIVER"); + statusNames.push_back("RECORD"); + statusNames.push_back("DB"); + statusNames.push_back("CONF"); + statusNames.push_back("UNDEFINED"); + statusNames.push_back("CLIENT"); + } return statusNames; } diff --git a/pvDataApp/property/pvAlarm.cpp b/pvDataApp/property/pvAlarm.cpp index 4a41e13..202d9ae 100644 --- a/pvDataApp/property/pvAlarm.cpp +++ b/pvDataApp/property/pvAlarm.cpp @@ -12,71 +12,55 @@ #include namespace epics { namespace pvData { +using std::tr1::static_pointer_cast; + static String noAlarmFound("No alarm structure found"); static String notAttached("Not attached to an alarm structure"); -bool PVAlarm::attach(PVField *pvField) +bool PVAlarm::attach(PVFieldPtr pvField) { - PVStructure *pvStructure = 0; - if(pvField->getField()->getFieldName().compare("alarm")!=0) { - if(pvField->getField()->getFieldName().compare("value")!=0) { - pvField->message(noAlarmFound,errorMessage); - return false; - } - PVStructure *pvParent = pvField->getParent(); - if(pvParent==0) { - pvField->message(noAlarmFound,errorMessage); - return false; - } - pvStructure = pvParent->getStructureField(String("alarm")); - if(pvStructure==0) { - pvField->message(noAlarmFound,errorMessage); - return false; - } - } else { - if(pvField->getField()->getType()!=structure) { - pvField->message(noAlarmFound,errorMessage); - return false; - } - pvStructure = static_cast(pvField); - } - PVInt *pvInt = pvStructure->getIntField(String("severity")); - if(pvInt==0) { + if(pvField->getField()->getType()!=structure) { pvField->message(noAlarmFound,errorMessage); return false; } - pvSeverity = pvInt; - pvInt = pvStructure->getIntField(String("status")); - if(pvInt==0) { + PVStructurePtr pvStructure = static_pointer_cast(pvField); + pvSeverity = pvStructure->getIntField("severity"); + if(pvSeverity.get()==NULL) { pvField->message(noAlarmFound,errorMessage); return false; } - pvStatus = pvInt; - PVString *pvString = pvStructure->getStringField(String("message")); - if(pvInt==0) { + pvStatus = pvStructure->getIntField("status"); + if(pvStatus.get()==NULL) { pvField->message(noAlarmFound,errorMessage); + pvSeverity.reset(); + return false; + } + pvMessage = pvStructure->getStringField("message"); + if(pvMessage.get()==NULL) { + pvField->message(noAlarmFound,errorMessage); + pvSeverity.reset(); + pvStatus.reset(); return false; } - pvMessage = pvString; return true; } void PVAlarm::detach() { - pvSeverity = 0; - pvStatus = 0; - pvMessage = 0; + pvSeverity.reset(); + pvStatus.reset(); + pvMessage.reset(); } bool PVAlarm::isAttached() { - if(pvSeverity==0 || pvMessage==0) return false; + if(pvSeverity.get()==NULL) return false; return true; } void PVAlarm::get(Alarm & alarm) const { - if(pvSeverity==0 || pvMessage==0) { + if(pvSeverity.get()==NULL) { throw std::logic_error(notAttached); } alarm.setSeverity(AlarmSeverityFunc::getSeverity(pvSeverity->get())); @@ -86,7 +70,7 @@ void PVAlarm::get(Alarm & alarm) const bool PVAlarm::set(Alarm const & alarm) { - if(pvSeverity==0 || pvMessage==0) { + if(pvSeverity.get()==NULL) { throw std::logic_error(notAttached); } if(pvSeverity->isImmutable() || pvMessage->isImmutable()) return false; diff --git a/pvDataApp/property/pvAlarm.h b/pvDataApp/property/pvAlarm.h index cc58960..7f2b0ee 100644 --- a/pvDataApp/property/pvAlarm.h +++ b/pvDataApp/property/pvAlarm.h @@ -15,11 +15,11 @@ namespace epics { namespace pvData { class PVAlarm { public: - PVAlarm() : pvSeverity(0),pvStatus(0),pvMessage(0) {} + PVAlarm() {} //default constructors and destructor are OK //returns (false,true) if pvField(isNot, is valid enumerated structure //An automatic detach is issued if already attached. - bool attach(PVField *pvField); + bool attach(PVFieldPtr pvField); void detach(); bool isAttached(); // each of the following throws logic_error is not attached to PVField @@ -27,9 +27,9 @@ public: void get(Alarm & alarm) const; bool set(Alarm const & alarm); private: - PVInt *pvSeverity; - PVInt *pvStatus; - PVString *pvMessage; + PVIntPtr pvSeverity; + PVIntPtr pvStatus; + PVStringPtr pvMessage; }; }} diff --git a/pvDataApp/property/pvControl.cpp b/pvDataApp/property/pvControl.cpp index 3196d50..430dae5 100644 --- a/pvDataApp/property/pvControl.cpp +++ b/pvDataApp/property/pvControl.cpp @@ -12,64 +12,46 @@ #include namespace epics { namespace pvData { +using std::tr1::static_pointer_cast; + static String noControlFound("No control structure found"); static String notAttached("Not attached to an control structure"); -bool PVControl::attach(PVField *pvField) +bool PVControl::attach(PVFieldPtr pvField) { - PVStructure *pvStructure = 0; - if(pvField->getField()->getFieldName().compare("control")!=0) { - if(pvField->getField()->getFieldName().compare("value")!=0) { + if(pvField->getField()->getType()!=structure) { pvField->message(noControlFound,errorMessage); return false; - } - PVStructure *pvParent = pvField->getParent(); - if(pvParent==0) { - pvField->message(noControlFound,errorMessage); - return false; - } - pvStructure = pvParent->getStructureField(String("control")); - if(pvStructure==0) { - pvField->message(noControlFound,errorMessage); - return false; - } - } else { - if(pvField->getField()->getType()!=structure) { - pvField->message(noControlFound,errorMessage); - return false; - } - pvStructure = static_cast(pvField); } - PVDouble *pvDouble = pvStructure->getDoubleField(String("limit.low")); - if(pvDouble==0) { + PVStructurePtr pvStructure = static_pointer_cast(pvField); + pvLow = pvStructure->getDoubleField("limitLow"); + if(pvLow.get()==NULL) { pvField->message(noControlFound,errorMessage); return false; } - pvLow = pvDouble; - pvDouble = pvStructure->getDoubleField(String("limit.high")); - if(pvDouble==0) { - pvLow = 0; + pvHigh = pvStructure->getDoubleField(String("limitHigh")); + if(pvHigh.get()==NULL) { + pvLow.reset(); pvField->message(noControlFound,errorMessage); return false; } - pvHigh = pvDouble; return true; } void PVControl::detach() { - pvLow = 0; - pvHigh = 0; + pvLow.reset(); + pvHigh.reset(); } bool PVControl::isAttached(){ - if(pvLow==0 || pvHigh==0) return false; + if(pvLow.get()==NULL) return false; return true; } void PVControl::get(Control &control) const { - if(pvLow==0 || pvHigh==0) { + if(pvLow.get()==NULL) { throw std::logic_error(notAttached); } control.setLow(pvLow->get()); @@ -78,7 +60,7 @@ void PVControl::get(Control &control) const bool PVControl::set(Control const & control) { - if(pvLow==0 || pvHigh==0) { + if(pvLow.get()==NULL) { throw std::logic_error(notAttached); } if(pvLow->isImmutable() || pvHigh->isImmutable()) return false; diff --git a/pvDataApp/property/pvControl.h b/pvDataApp/property/pvControl.h index 530087e..2ff233d 100644 --- a/pvDataApp/property/pvControl.h +++ b/pvDataApp/property/pvControl.h @@ -12,11 +12,11 @@ namespace epics { namespace pvData { class PVControl { public: - PVControl() : pvLow(0),pvHigh(0) {} + PVControl(){} //default constructors and destructor are OK //returns (false,true) if pvField(isNot, is valid enumerated structure //An automatic detach is issued if already attached. - bool attach(PVField *pvField); + bool attach(PVFieldPtr pvField); void detach(); bool isAttached(); // each of the following throws logic_error is not attached to PVField @@ -24,8 +24,8 @@ public: void get(Control &) const; bool set(Control const & control); private: - PVDouble *pvLow; - PVDouble *pvHigh; + PVDoublePtr pvLow; + PVDoublePtr pvHigh; }; }} diff --git a/pvDataApp/property/pvDisplay.cpp b/pvDataApp/property/pvDisplay.cpp index 3903b5c..b39bc8e 100644 --- a/pvDataApp/property/pvDisplay.cpp +++ b/pvDataApp/property/pvDisplay.cpp @@ -12,59 +12,43 @@ #include namespace epics { namespace pvData { +using std::tr1::static_pointer_cast; + static String noDisplayFound("No display structure found"); static String notAttached("Not attached to an display structure"); -bool PVDisplay::attach(PVField *pvField) +bool PVDisplay::attach(PVFieldPtr pvField) { - PVStructure *pvStructure = 0; - if(pvField->getField()->getFieldName().compare("display")!=0) { - if(pvField->getField()->getFieldName().compare("value")!=0) { + if(pvField->getField()->getType()!=structure) { pvField->message(noDisplayFound,errorMessage); return false; - } - PVStructure *pvParent = pvField->getParent(); - if(pvParent==0) { - pvField->message(noDisplayFound,errorMessage); - return false; - } - pvStructure = pvParent->getStructureField(String("display")); - if(pvStructure==0) { - pvField->message(noDisplayFound,errorMessage); - return false; - } - } else { - if(pvField->getField()->getType()!=structure) { - pvField->message(noDisplayFound,errorMessage); - return false; - } - pvStructure = static_cast(pvField); } - pvDescription = pvStructure->getStringField(String("description")); - if(pvDescription==0) { + PVStructurePtr pvStructure = static_pointer_cast(pvField); + pvDescription = pvStructure->getStringField("description"); + if(pvDescription.get()==NULL) { pvField->message(noDisplayFound,errorMessage); return false; } - pvFormat = pvStructure->getStringField(String("format")); - if(pvFormat==0) { + pvFormat = pvStructure->getStringField("format"); + if(pvFormat.get()==NULL) { pvField->message(noDisplayFound,errorMessage); detach(); return false; } - pvUnits = pvStructure->getStringField(String("units")); - if(pvUnits==0) { + pvUnits = pvStructure->getStringField("units"); + if(pvUnits.get()==NULL) { pvField->message(noDisplayFound,errorMessage); detach(); return false; } - pvLow = pvStructure->getDoubleField(String("limit.low")); - if(pvLow==0) { + pvLow = pvStructure->getDoubleField(String("limitLow")); + if(pvLow.get()==NULL) { pvField->message(noDisplayFound,errorMessage); detach(); return false; } - pvHigh = pvStructure->getDoubleField(String("limit.high")); - if(pvHigh==0) { + pvHigh = pvStructure->getDoubleField(String("limitHigh")); + if(pvHigh.get()==NULL) { pvField->message(noDisplayFound,errorMessage); detach(); return false; @@ -74,22 +58,21 @@ bool PVDisplay::attach(PVField *pvField) void PVDisplay::detach() { - pvDescription = 0; - pvFormat = 0; - pvUnits = 0; - pvLow = 0; - pvHigh = 0; + pvDescription.reset(); + pvFormat.reset(); + pvUnits.reset(); + pvLow.reset(); + pvHigh.reset(); } bool PVDisplay::isAttached() { - if(pvDescription==0 || pvFormat==0 || pvUnits==0 || pvLow==0 || pvHigh==0) - return false; + if(pvDescription.get()) return false; return true; } void PVDisplay::get(Display & display) const { - if(pvDescription==0 || pvFormat==0 || pvUnits==0 || pvLow==0 || pvHigh==0) { + if(pvDescription.get()==NULL) { throw std::logic_error(notAttached); } display.setDescription(pvDescription->get()); @@ -101,13 +84,12 @@ void PVDisplay::get(Display & display) const bool PVDisplay::set(Display const & display) { - if(pvDescription==0 || pvFormat==0 || pvUnits==0 || pvLow==0 || pvHigh==0) { + if(pvDescription.get()==NULL) { throw std::logic_error(notAttached); } if(pvDescription->isImmutable() || pvFormat->isImmutable()) return false; if(pvUnits->isImmutable() || pvLow->isImmutable() || pvHigh->isImmutable()) return false; - pvDescription->put(display.getDescription()); pvFormat->put(display.getFormat()); pvUnits->put(display.getUnits()); diff --git a/pvDataApp/property/pvDisplay.h b/pvDataApp/property/pvDisplay.h index 95b199e..f28ca80 100644 --- a/pvDataApp/property/pvDisplay.h +++ b/pvDataApp/property/pvDisplay.h @@ -14,11 +14,10 @@ namespace epics { namespace pvData { class PVDisplay { public: - PVDisplay() - : pvDescription(0),pvFormat(),pvUnits(),pvLow(),pvHigh() {} + PVDisplay() {} //default constructors and destructor are OK //An automatic detach is issued if already attached. - bool attach(PVField *pvField); + bool attach(PVFieldPtr pvField); void detach(); bool isAttached(); // each of the following throws logic_error is not attached to PVField @@ -26,11 +25,11 @@ public: void get(Display &) const; bool set(Display const & display); private: - PVString *pvDescription; - PVString *pvFormat; - PVString *pvUnits; - PVDouble *pvLow; - PVDouble *pvHigh; + PVStringPtr pvDescription; + PVStringPtr pvFormat; + PVStringPtr pvUnits; + PVDoublePtr pvLow; + PVDoublePtr pvHigh; }; }} diff --git a/pvDataApp/property/pvEnumerated.cpp b/pvDataApp/property/pvEnumerated.cpp index 6e0e8fb..a51d9b9 100644 --- a/pvDataApp/property/pvEnumerated.cpp +++ b/pvDataApp/property/pvEnumerated.cpp @@ -12,48 +12,48 @@ #include namespace epics { namespace pvData { +using std::tr1::static_pointer_cast; -static String notStructure("field is not a structure"); -static String notEnumerated("field is not an enumerated structure"); +static String notFound("No enumerated structure found"); static String notAttached("Not attached to an enumerated structure"); -bool PVEnumerated::attach(PVField *pvField) +bool PVEnumerated::attach(PVFieldPtr pvField) { if(pvField->getField()->getType()!=structure) { - pvField->message(notStructure,errorMessage); + pvField->message(notFound,errorMessage); + return false; + } + PVStructurePtr pvStructure = static_pointer_cast(pvField); + pvIndex = pvStructure->getIntField("index"); + if(pvIndex.get()==NULL) { + pvField->message(notFound,errorMessage); return false; } - PVStructure *pvStructure = static_cast(pvField); - PVInt *pvInt = pvStructure->getIntField(String("index")); - if(pvInt==0) { - pvField->message(notEnumerated,errorMessage); + PVScalarArrayPtr pvScalarArray = pvStructure->getScalarArrayField( + "choices",pvString); + if(pvScalarArray.get()==NULL) { + pvIndex.reset(); + pvField->message(notFound,errorMessage); return false; } - PVScalarArray *pvScalarArray = pvStructure->getScalarArrayField( - String("choices"),pvString); - if(pvScalarArray==0) { - pvField->message(notEnumerated,errorMessage); - return false; - } - pvIndex = pvInt; - pvChoices = static_cast(pvScalarArray); + pvChoices = static_pointer_cast(pvScalarArray); return true; } void PVEnumerated::detach() { - pvIndex = 0; - pvChoices = 0; + pvIndex.reset(); + pvChoices.reset(); } bool PVEnumerated::isAttached() { - if(pvIndex==0 || pvChoices==0) return false; + if(pvIndex.get()==NULL) return false; return true; } bool PVEnumerated::setIndex(int32 index) { - if(pvIndex==0 || pvChoices==0) { + if(pvIndex.get()==NULL ) { throw std::logic_error(notAttached); } if(pvIndex->isImmutable()) return false; @@ -63,7 +63,7 @@ bool PVEnumerated::setIndex(int32 index) int32 PVEnumerated::getIndex() { - if(pvIndex==0 || pvChoices==0) { + if(pvIndex.get()==NULL ) { throw std::logic_error(notAttached); } return pvIndex->get(); @@ -71,48 +71,48 @@ int32 PVEnumerated::getIndex() String PVEnumerated::getChoice() { - if(pvIndex==0 || pvChoices==0) { + if(pvIndex.get()==NULL ) { throw std::logic_error(notAttached); } int index = pvIndex->get(); StringArrayData data; - pvChoices->get(0,pvChoices->getLength(),&data); + pvChoices->get(0,pvChoices->getLength(),data); return data.data[index]; } bool PVEnumerated::choicesMutable() { - if(pvIndex==0 || pvChoices==0) { + if(pvIndex.get()==NULL ) { throw std::logic_error(notAttached); } return pvChoices->isImmutable(); } -StringArray PVEnumerated:: getChoices() +StringArray& PVEnumerated:: getChoices() { - if(pvIndex==0 || pvChoices==0) { + if(pvIndex.get()==NULL ) { throw std::logic_error(notAttached); } StringArrayData data; - pvChoices->get(0,pvChoices->getLength(),&data); + pvChoices->get(0,pvChoices->getLength(),data); return data.data; } int32 PVEnumerated::getNumberChoices() { - if(pvIndex==0 || pvChoices==0) { + if(pvIndex.get()==NULL ) { throw std::logic_error(notAttached); } return pvChoices->getLength(); } -bool PVEnumerated:: setChoices(StringArray choices,int32 numberChoices) +bool PVEnumerated:: setChoices(StringArray & choices) { - if(pvIndex==0 || pvChoices==0) { + if(pvIndex.get()==NULL ) { throw std::logic_error(notAttached); } if(pvChoices->isImmutable()) return false; - pvChoices->put(0,numberChoices,choices,0); + pvChoices->put(0,choices.size(),get(choices),0); return true; } diff --git a/pvDataApp/property/pvEnumerated.h b/pvDataApp/property/pvEnumerated.h index acd678b..382e94a 100644 --- a/pvDataApp/property/pvEnumerated.h +++ b/pvDataApp/property/pvEnumerated.h @@ -13,12 +13,12 @@ namespace epics { namespace pvData { class PVEnumerated { public: - PVEnumerated() : pvIndex(0), pvChoices(0) {} + PVEnumerated() {} //default constructors and destructor are OK //This class should not be extended //returns (false,true) if pvField(isNot, is valid enumerated structure //An automatic detach is issued if already attached. - bool attach(PVField *pvField); + bool attach(PVFieldPtr pvField); void detach(); bool isAttached(); // each of the following throws logic_error is not attached to PVField @@ -27,12 +27,12 @@ public: int32 getIndex(); String getChoice(); bool choicesMutable(); - StringArray getChoices(); + StringArray & getChoices(); int32 getNumberChoices(); - bool setChoices(StringArray choices,int32 numberChoices); + bool setChoices(StringArray & choices); private: - PVInt *pvIndex; - PVStringArray *pvChoices; + PVIntPtr pvIndex; + PVStringArrayPtr pvChoices; }; }} diff --git a/pvDataApp/property/pvTimeStamp.cpp b/pvDataApp/property/pvTimeStamp.cpp index 829ef9d..f0a3fab 100644 --- a/pvDataApp/property/pvTimeStamp.cpp +++ b/pvDataApp/property/pvTimeStamp.cpp @@ -12,78 +12,52 @@ #include namespace epics { namespace pvData { +using std::tr1::static_pointer_cast; + static String noTimeStamp("No timeStamp structure found"); static String notAttached("Not attached to a timeStamp structure"); -bool PVTimeStamp::attach(PVField *pvField) +bool PVTimeStamp::attach(PVFieldPtr pvField) { - PVStructure *pvStructure = 0; - if(pvField->getField()->getFieldName().compare("timeStamp")!=0) { - PVStructure *pvParent = pvField->getParent(); - if(pvParent==0) { - pvField->message(noTimeStamp,errorMessage); - return false; - } - if(pvField->getField()->getFieldName().compare("value")!=0) { + if(pvField->getField()->getType()!=structure) { pvField->message(noTimeStamp,errorMessage); return false; + } + PVStructurePtr xxx = static_pointer_cast(pvField); + PVStructure* pvStructure = xxx.get(); + while(true) { + PVLongPtr pvLong = pvStructure->getLongField("secondsPastEpoch"); + if(pvLong.get()!=NULL) { + pvSecs = pvLong; + pvNano = pvStructure->getIntField("nanoSeconds"); + pvUserTag = pvStructure->getIntField("userTag"); } + if(pvSecs.get()!=NULL + && pvNano.get()!=NULL + && pvUserTag.get()!=NULL) return true; + detach(); // look up the tree for a timeSyamp - while(pvParent!=0) { - PVStructure *pvs = pvParent->getStructureField(String("timeStamp")); - if(pvs!=0) { - pvStructure = pvs; - break; - } - pvParent = pvParent->getParent(); - } - if(pvStructure==0) { - pvField->message(noTimeStamp,errorMessage); - return false; - } - } else { - if(pvField->getField()->getType()!=structure) { - pvField->message(noTimeStamp,errorMessage); - return false; - } - pvStructure = static_cast(pvField); + pvStructure = pvStructure->getParent(); + if(pvStructure==NULL) break; } - PVLong *pvLong = pvStructure->getLongField(String("secondsPastEpoch")); - if(pvLong==0) { - pvField->message(noTimeStamp,errorMessage); - return false; - } - pvSecs = pvLong; - PVInt *pvInt = pvStructure->getIntField(String("nanoSeconds")); - if(pvLong==0) { - pvField->message(noTimeStamp,errorMessage); - return false; - } - pvNano = pvInt; - pvInt = pvStructure->getIntField(String("userTag")); - if(pvInt==0) { - pvField->message(noTimeStamp,errorMessage); - return false; - } - pvUserTag = pvInt; - return true; + return false; } void PVTimeStamp::detach() { - pvSecs = 0; - pvUserTag = 0; - pvNano = 0; + pvSecs.reset(); + pvUserTag.reset(); + pvNano.reset(); } bool PVTimeStamp::isAttached() { - if(pvSecs==0 || pvNano==0) return false; + if(pvSecs.get()==NULL) return false; return true; } void PVTimeStamp::get(TimeStamp & timeStamp) const { - if(pvSecs==0 || pvNano==0) { + if(pvSecs.get()==NULL) { throw std::logic_error(notAttached); } timeStamp.put(pvSecs->get(),pvNano->get()); @@ -92,7 +66,7 @@ void PVTimeStamp::get(TimeStamp & timeStamp) const bool PVTimeStamp::set(TimeStamp const & timeStamp) { - if(pvSecs==0 || pvNano==0 || pvUserTag==0) { + if(pvSecs.get()==NULL) { throw std::logic_error(notAttached); } if(pvSecs->isImmutable() || pvNano->isImmutable()) return false; diff --git a/pvDataApp/property/pvTimeStamp.h b/pvDataApp/property/pvTimeStamp.h index cc3f6a1..d606546 100644 --- a/pvDataApp/property/pvTimeStamp.h +++ b/pvDataApp/property/pvTimeStamp.h @@ -15,12 +15,12 @@ namespace epics { namespace pvData { class PVTimeStamp { public: - PVTimeStamp() : pvSecs(0),pvUserTag(0), pvNano(0) {} + PVTimeStamp(){} //default constructors and destructor are OK //This class should not be extended //returns (false,true) if pvField(isNot, is valid timeStamp structure - bool attach(PVField *pvField); + bool attach(PVFieldPtr pvField); void detach(); bool isAttached(); // following throw logic_error is not attached to PVField @@ -28,9 +28,9 @@ public: void get(TimeStamp &) const; bool set(TimeStamp const & timeStamp); private: - PVLong* pvSecs; - PVInt* pvUserTag; - PVInt* pvNano; + PVLongPtr pvSecs; + PVIntPtr pvUserTag; + PVIntPtr pvNano; }; }} diff --git a/pvDataApp/pv/convert.h b/pvDataApp/pv/convert.h index 7bd049a..d67b995 100644 --- a/pvDataApp/pv/convert.h +++ b/pvDataApp/pv/convert.h @@ -61,16 +61,27 @@ static inline bool operator!=(const StructureArray& a, const StructureArray& b) *

All from methods put data into a PVField, e.g. from means where the PVField gets it's data.

*/ -class Convert : NoDefaultMethods { +class Convert; +typedef std::tr1::shared_ptr ConvertPtr; + +class Convert { public: - Convert(); + static ConvertPtr getConvert(); ~Convert(); /** * Get the full fieldName for the pvField. * @param builder The builder that will have the result. * @param pvField The pvField. */ - void getFullName(StringBuilder buf,PVField *pvField); + void getFullName(StringBuilder buf,PVFieldPtr & pvField); + /** + * Do fields have the same definition. + * + * @param First field + * @param Second field + * @return (false, true) if the fields (are not, are) the same. + */ + bool equals(PVFieldPtr &a,PVFieldPtr &b); /** * Do fields have the same definition. * @@ -79,6 +90,21 @@ public: * @return (false, true) if the fields (are not, are) the same. */ bool equals(PVField &a,PVField &b); + /** + * Convert a PVField to a string. + * @param buf buffer for the result + * @param pv a PVField to convert to a string. + * If a PVField is a structure or array be prepared for a very long string. + * @param indentLevel indentation level + */ + void getString(StringBuilder buf,PVFieldPtr & pvField,int indentLevel); + /** + * Convert a PVField to a string. + * param buf buffer for the result + * @param pv The PVField to convert to a string. + * If the PVField is a structure or array be prepared for a very long string. + */ + void getString(StringBuilder buf,PVFieldPtr & pvField); /** * Convert a PVField to a string. * @param buf buffer for the result @@ -93,7 +119,7 @@ public: * @param pv The PVField to convert to a string. * If the PVField is a structure or array be prepared for a very long string. */ - void getString(StringBuilder buf,PVField *pvField); + void getString(StringBuilder buf,PVField * pvField); /** * Convert from an array of String to a PVScalar * @param pv The PV. @@ -101,14 +127,14 @@ public: * @param fromStartIndex The first element if the array of strings. * @throws std::logic_error if the array of String does not have a valid values. */ - int fromString(PVStructure *pv, std::vector& from, int fromStartIndex = 0); + std::size_t fromString(PVStructurePtr &pv, StringArray const & from, std::size_t fromStartIndex = 0); /** * Convert from a String to a PVScalar * @param pv The PV. * @param from The String value to convert and put into a PV. * @throws std::logic_error if the String does not have a valid value. */ - void fromString(PVScalar *pv, String from); + void fromString(PVScalarPtr & pv, String from); /** * Convert from a String to a PVScalarArray. * The String must be a comma separated set of values optionally enclosed in [] @@ -118,7 +144,7 @@ public: * @throws std::invalid_argument if the element Type is not a scalar. * @throws std::logic_error if the String does not have a valid array values. */ - int fromString(PVScalarArray *pv, String from); + std::size_t fromString(PVScalarArrayPtr & pv, String from); /** * Convert a PVScalarArray from a String array. * The array element type must be a scalar. @@ -131,8 +157,8 @@ public: * @throws std::invalid_argument if the element Type is not a scalar. * @throws std::logic_error if the String does not have a valid value. */ - int fromStringArray(PVScalarArray *pv, int offset, int length, - StringArray from, int fromOffset); + std::size_t fromStringArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length, + StringArray const & from, std::size_t fromOffset); /** * Convert a PVScalarArray to a String array. * @param pv The PV. @@ -142,8 +168,8 @@ public: * @param toOffset Starting element in the string array. * @return Number of elements converted. */ - int toStringArray(PVScalarArray *pv, int offset, int length, - StringArray to, int toOffset); + std::size_t toStringArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length, + StringArray const & to, std::size_t toOffset); /** * Are from and to valid arguments to copy. * This first checks of both arguments have the same Type. @@ -153,7 +179,7 @@ public: * @param to The destination. * @return (false,true) is the arguments (are not, are) compatible. */ - bool isCopyCompatible(FieldConstPtr from, FieldConstPtr to); + bool isCopyCompatible(FieldConstPtr & from, FieldConstPtr & to); /** * Copy from a PVField to another PVField. * This calls one on copyScalar, copyArray, copyStructure. @@ -162,7 +188,7 @@ public: * @param to The destination * @throws std::invalid_argument if the arguments are not compatible. */ - void copy(PVField *from,PVField *to); + void copy(PVFieldPtr & from,PVFieldPtr & to); /** * Are from and to valid arguments to copyScalar. * false will be returned if either argument is not a scalar as defined by Type.isScalar(). @@ -177,14 +203,14 @@ public: * @return (false,true) If the arguments (are not, are) compatible. */ bool isCopyScalarCompatible( - ScalarConstPtr from, ScalarConstPtr to); + ScalarConstPtr & from, ScalarConstPtr & to); /** * Copy from a scalar pv to another scalar pv. * @param from the source. * @param to the destination. * @throws std::invalid_argument if the arguments are not compatible. */ - void copyScalar(PVScalar *from, PVScalar *to); + void copyScalar(PVScalarPtr & from, PVScalarPtr & to); /** * Are from and to valid arguments to copyArray. * The results are like isCopyScalarCompatible except that the tests are made on the elementType. @@ -192,8 +218,8 @@ public: * @param to The to array. * @return (false,true) If the arguments (are not, are) compatible. */ - bool isCopyScalarArrayCompatible(ScalarArrayConstPtr from, - ScalarArrayConstPtr to); + bool isCopyScalarArrayCompatible(ScalarArrayConstPtr & from, + ScalarArrayConstPtr & to); /** * Convert from a source PV array to a destination PV array. * @param from The source array. @@ -204,8 +230,8 @@ public: * @return Number of elements converted. * @throws std::invalid_argument if the arguments are not compatible. */ - int copyScalarArray(PVScalarArray *from, int offset, - PVScalarArray *to, int toOffset, int length); + std::size_t copyScalarArray(PVScalarArrayPtr & from, std::size_t offset, + PVScalarArrayPtr & to, std::size_t toOffset, std::size_t length); /** * Are from and to valid arguments for copyStructure. * They are only compatible if they have the same Structure description. @@ -214,7 +240,7 @@ public: * @return (false,true) If the arguments (are not, are) compatible. */ bool isCopyStructureCompatible( - StructureConstPtr from, StructureConstPtr to); + StructureConstPtr & from, StructureConstPtr & to); /** * Copy from a structure pv to another structure pv. * NOTE: Only compatible nodes are copied. This means: @@ -228,7 +254,7 @@ public: * @param to The destination. * @throws std::invalid_argument if the arguments are not compatible. */ - void copyStructure(PVStructure *from, PVStructure *to); + void copyStructure(PVStructurePtr & from, PVStructurePtr & to); /** * Are from and to valid for copyStructureArray. * @param from The from StructureArray. @@ -236,103 +262,158 @@ public: * @return (false,true) If the arguments (are not, are) compatible. */ bool isCopyStructureArrayCompatible( - StructureArrayConstPtr from, StructureArrayConstPtr to); + StructureArrayConstPtr & from, StructureArrayConstPtr & to); /** * Copy from a structure array to another structure array. * @param from The source array. * @param to The destination array. */ void copyStructureArray( - PVStructureArray *from, PVStructureArray *to); + PVStructureArrayPtr & from, PVStructureArrayPtr & to); /** * Convert a PV to a . * @param pv a PV * @return converted value */ - int8 toByte(PVScalar *pv); + int8 toByte(PVScalarPtr & pv); /** * Convert a PV to a short. * @param pv a PV * @return converted value * @throws std::invalid_argument if the Type is not a numeric scalar */ - int16 toShort(PVScalar *pv); + int16 toShort(PVScalarPtr & pv); /** - * Convert a PV to a short. + * Convert a PV to a int. * @param pv a PV * @return converted value * @throws std::invalid_argument if the Type is not a numeric scalar */ - int32 toInt(PVScalar *pv); + int32 toInt(PVScalarPtr & pv); /** - * Convert a PV to an int + * Convert a PV to an long * @param pv a PV * @return converted value * @throws std::invalid_argument if the Type is not a numeric scalar */ - int64 toLong(PVScalar *pv); + int64 toLong(PVScalarPtr & pv); + /** + * Convert a PV to a ubyte. + * @param pv a PV + * @return converted value + */ + uint8 toUByte(PVScalarPtr & pv); + /** + * Convert a PV to a ushort. + * @param pv a PV + * @return converted value + * @throws std::invalid_argument if the Type is not a numeric scalar + */ + uint16 toUShort(PVScalarPtr & pv); + /** + * Convert a PV to a uint. + * @param pv a PV + * @return converted value + * @throws std::invalid_argument if the Type is not a numeric scalar + */ + uint32 toUInt(PVScalarPtr & pv); + /** + * Convert a PV to an ulong + * @param pv a PV + * @return converted value + * @throws std::invalid_argument if the Type is not a numeric scalar + */ + uint64 toULong(PVScalarPtr & pv); /** * Convert a PV to a float * @param pv a PV * @return converted value * @throws std::invalid_argument if the Type is not a numeric scalar */ - float toFloat(PVScalar *pv); + float toFloat(PVScalarPtr & pv); /** * Convert a PV to a double * @param pv a PV * @return converted value * @throws std::invalid_argument if the Type is not a numeric scalar */ - double toDouble(PVScalar *pv); + double toDouble(PVScalarPtr & pv); /** * Convert a PV to a String * @param pv a PV * @return converted value */ - String toString(PVScalar *pv); + String toString(PVScalarPtr & pv); /** * Convert a PV from a byte * @param pv a PV * @param from value to put into PV * @throws std::invalid_argument if the Type is not a numeric scalar */ - void fromByte(PVScalar *pv,int8 from); + void fromByte(PVScalarPtr & pv,int8 from); /** * Convert a PV from a short * @param pv a PV * @param from value to put into PV * @throws std::invalid_argument if the Type is not a numeric scalar */ - void fromShort(PVScalar *pv,int16 from); + void fromShort(PVScalarPtr & pv,int16 from); /** * Convert a PV from an int * @param pv a PV * @param from value to put into PV * @throws std::invalid_argument if the Type is not a numeric scalar */ - void fromInt(PVScalar *pv, int32 from); + void fromInt(PVScalarPtr & pv, int32 from); /** * Convert a PV from a long * @param pv a PV * @param from value to put into PV * @throws std::invalid_argument if the Type is not a numeric scalar */ - void fromLong(PVScalar *pv, int64 from); + void fromLong(PVScalarPtr & pv, int64 from); + /** + * Convert a PV from a ubyte + * @param pv a PV + * @param from value to put into PV + * @throws std::invalid_argument if the Type is not a numeric scalar + */ + void fromUByte(PVScalarPtr & pv,uint8 from); + /** + * Convert a PV from a ushort + * @param pv a PV + * @param from value to put into PV + * @throws std::invalid_argument if the Type is not a numeric scalar + */ + void fromUShort(PVScalarPtr & pv,uint16 from); + /** + * Convert a PV from an uint + * @param pv a PV + * @param from value to put into PV + * @throws std::invalid_argument if the Type is not a numeric scalar + */ + void fromUInt(PVScalarPtr & pv, uint32 from); + /** + * Convert a PV from a ulong + * @param pv a PV + * @param from value to put into PV + * @throws std::invalid_argument if the Type is not a numeric scalar + */ + void fromULong(PVScalarPtr & pv, uint64 from); /** * Convert a PV from a float * @param pv a PV * @param from value to put into PV * @throws std::invalid_argument if the Type is not a numeric scalar */ - void fromFloat(PVScalar* pv, float from); + void fromFloat(PVScalarPtr & pv, float from); /** * Convert a PV from a double * @param pv a PV * @param from value to put into PV * @throws std::invalid_argument if the Type is not a numeric scalar */ - void fromDouble(PVScalar *pv, double from); + void fromDouble(PVScalarPtr & pv, double from); /** * Convert a PV array to a byte array. * @param pv a PV @@ -343,8 +424,8 @@ public: * @return number of elements converted * @throws std::invalid_argument if the element type is not numeric */ - int toByteArray(PVScalarArray *pv, int offset, int length, - ByteArray to, int toOffset); + std::size_t toByteArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length, + int8* to, std::size_t toOffset); /** * Convert a PV array to a short array. * @param pv a PV @@ -355,8 +436,8 @@ public: * @return number of elements converted * @throws std::invalid_argument if the element type is not numeric */ - int toShortArray(PVScalarArray *pv, int offset, int length, - ShortArray to, int toOffset); + std::size_t toShortArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length, + int16* to, std::size_t toOffset); /** * Convert a PV array to an int array. * @param pv a PV @@ -367,8 +448,8 @@ public: * @return number of elements converted * @throws std::invalid_argument if the element type is not numeric */ - int toIntArray(PVScalarArray *pv, int offset, int length, - IntArray to, int toOffset); + std::size_t toIntArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length, + int32* to, std::size_t toOffset); /** * Convert a PV array to a long array. * @param pv a PV @@ -379,8 +460,56 @@ public: * @return number of elements converted * @throws std::invalid_argument if the element type is not numeric */ - int toLongArray(PVScalarArray *pv, int offset, int length, - LongArray to, int toOffset); + std::size_t toLongArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length, + int64* to, std::size_t toOffset); + /** + * Convert a PV array to a ubyte array. + * @param pv a PV + * @param offset starting element in a PV + * @param length number of elements to transfer + * @param to where to put the PV data + * @param toOffset starting element in the array + * @return number of elements converted + * @throws std::invalid_argument if the element type is not numeric + */ + std::size_t toUByteArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length, + uint8* to, std::size_t toOffset); + /** + * Convert a PV array to a ushort array. + * @param pv a PV + * @param offset starting element in a PV + * @param length number of elements to transfer + * @param to where to put the PV data + * @param toOffset starting element in the array + * @return number of elements converted + * @throws std::invalid_argument if the element type is not numeric + */ + std::size_t toUShortArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length, + uint16* to, std::size_t toOffset); + /** + * Convert a PV array to an uint array. + * @param pv a PV + * @param offset starting element in a PV + * @param length number of elements to transfer + * @param to where to put the PV data + * @param toOffset starting element in the array + * @return number of elements converted + * @throws std::invalid_argument if the element type is not numeric + */ + std::size_t toUIntArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length, + uint32* to, std::size_t toOffset); + /** + * Convert a PV array to a ulong array. + * @param pv a PV + * @param offset starting element in a PV + * @param length number of elements to transfer + * @param to where to put the PV data + * @param toOffset starting element in the array + * @return number of elements converted + * @throws std::invalid_argument if the element type is not numeric + */ + std::size_t toULongArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length, + uint64* to, std::size_t toOffset); /** * Convert a PV array to a float array. * @param pv a PV @@ -391,8 +520,8 @@ public: * @return number of elements converted * @throws std::invalid_argument if the element type is not numeric */ - int toFloatArray(PVScalarArray *pv, int offset, int length, - FloatArray to, int toOffset); + std::size_t toFloatArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length, + float* to, std::size_t toOffset); /** * Convert a PV array to a double array. * @param pv a PV @@ -403,8 +532,8 @@ public: * @return number of elements converted * @throws std::invalid_argument if the element type is not numeric */ - int toDoubleArray(PVScalarArray *pv, int offset, int length, - DoubleArray to, int toOffset); + std::size_t toDoubleArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length, + double* to, std::size_t toOffset); /** * Convert a PV array from a byte array. * @param pv a PV @@ -415,8 +544,8 @@ public: * @return number of elements converted * @throws std::invalid_argument if the element type is not numeric */ - int fromByteArray(PVScalarArray *pv, int offset, int length, - ByteArray from, int fromOffset); + std::size_t fromByteArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length, + int8* frim, std::size_t fromOffset); /** * Convert a PV array from a short array. * @param pv a PV @@ -427,8 +556,8 @@ public: * @return number of elements converted * @throws std::invalid_argument if the element type is not numeric */ - int fromShortArray(PVScalarArray *pv, int offset, int length, - ShortArray from, int fromOffset); + std::size_t fromShortArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length, + int16* frim, std::size_t fromOffset); /** * Convert a PV array from an int array. * @param pv a PV @@ -439,8 +568,8 @@ public: * @return number of elements converted * @throws std::invalid_argument if the element type is not numeric */ - int fromIntArray(PVScalarArray *pv, int offset, int length, - IntArray from, int fromOffset); + std::size_t fromIntArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length, + int32* frim, std::size_t fromOffset); /** * Convert a PV array from a long array. * @param pv a PV @@ -451,8 +580,56 @@ public: * @return number of elements converted * @throws std::invalid_argument if the element type is not numeric */ - int fromLongArray(PVScalarArray *pv, int offset, int length, - LongArray from, int fromOffset); + std::size_t fromLongArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length, + int64* frim, std::size_t fromOffset); + /** + * Convert a PV array from a ubyte array. + * @param pv a PV + * @param offset starting element in a PV + * @param length number of elements to transfer + * @param from value to put into PV + * @param fromOffset + * @return number of elements converted + * @throws std::invalid_argument if the element type is not numeric + */ + std::size_t fromUByteArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length, + uint8* frim, std::size_t fromOffset); + /** + * Convert a PV array from a ushort array. + * @param pv a PV + * @param offset starting element in a PV + * @param length number of elements to transfer + * @param from value to put into PV + * @param fromOffset starting element in the source array + * @return number of elements converted + * @throws std::invalid_argument if the element type is not numeric + */ + std::size_t fromUShortArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length, + uint16* frim, std::size_t fromOffset); + /** + * Convert a PV array from an uint array. + * @param pv a PV + * @param offset starting element in a PV + * @param length number of elements to transfer + * @param from value to put into PV + * @param fromOffset starting element in the source array + * @return number of elements converted + * @throws std::invalid_argument if the element type is not numeric + */ + std::size_t fromUIntArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length, + uint32* frim, std::size_t fromOffset); + /** + * Convert a PV array from a ulong array. + * @param pv a PV + * @param offset starting element in a PV + * @param length number of elements to transfer + * @param from value to put into PV + * @param fromOffset starting element in the source array + * @return number of elements converted + * @throws std::invalid_argument if the element type is not numeric + */ + std::size_t fromULongArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length, + uint64* frim, std::size_t fromOffset); /** * Convert a PV array from a float array. * @param pv a PV @@ -463,8 +640,8 @@ public: * @return number of elements converted * @throws std::invalid_argument if the element type is not numeric */ - int fromFloatArray(PVScalarArray *pv, int offset, int length, - FloatArray from, int fromOffset); + std::size_t fromFloatArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length, + float* frim, std::size_t fromOffset); /** * Convert a PV array from a double array. * @param pv a PV @@ -475,8 +652,8 @@ public: * @return number of elements converted * @throws std::invalid_argument if the element type is not numeric */ - int fromDoubleArray(PVScalarArray *pv, int offset, int length, - DoubleArray from, int fromOffset); + std::size_t fromDoubleArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length, + double* frim, std::size_t fromOffset); /** * Convenience method for implementing toString. * It generates a newline and inserts blanks at the beginning of the newline. @@ -484,9 +661,11 @@ public: * @param indentLevel Indent level, Each level is four spaces. */ void newLine(StringBuilder buf, int indentLevel); +private: + Convert(); }; -extern Convert * getConvert(); +extern ConvertPtr getConvert(); }} #endif /* CONVERT_H */ diff --git a/pvDataApp/pv/pvData.h b/pvDataApp/pv/pvData.h index a2aa597..9014735 100644 --- a/pvDataApp/pv/pvData.h +++ b/pvDataApp/pv/pvData.h @@ -8,13 +8,10 @@ #ifndef PVDATA_H #define PVDATA_H #include +#include #include -#include #include -#include #include -#include -#include namespace epics { namespace pvData { class PVAuxInfo; @@ -31,19 +28,39 @@ class PVStructureArray; /** * typedef for a pointer to a PVStructure. */ -typedef PVStructure * PVStructurePtr; +typedef std::tr1::shared_ptr PVStructurePtr; /** * typedef for a pointer to a array of pointer to PVStructure. */ -typedef PVStructurePtr* PVStructurePtrArray; +typedef std::vector PVStructurePtrArray; +typedef std::vector::iterator PVStructurePtrArray_iterator; +typedef std::vector::const_iterator PVStructurePtrArray_const__iterator; /** * typedef for a pointer to a PVField. */ -typedef PVField* PVFieldPtr; +typedef std::tr1::shared_ptr PVFieldPtr; +/** + * typedef for a pointer to a PVScalar. + */ +typedef std::tr1::shared_ptr PVScalarPtr; +/** + * typedef for a pointer to a PVScalarArray. + */ +typedef std::tr1::shared_ptr PVScalarArrayPtr; +/** + * typedef for a pointer to a PVStructureArray. + */ +typedef std::tr1::shared_ptr PVStructureArrayPtr; /** * typedef for a pointer to a array of pointer to PVField. */ -typedef PVFieldPtr * PVFieldPtrArray; +typedef std::vector PVFieldPtrArray; +typedef std::vector::iterator PVFieldPtrArray_iterator; +typedef std::vector::const_iterator PVFieldPtrArray_const__iterator; +/** + * typedef for a pointer to a PVAuxInfo. + */ +typedef std::tr1::shared_ptr PVAuxInfoPtr; /** * This class provides auxillary information about a PVField. @@ -52,6 +69,10 @@ typedef PVFieldPtr * PVFieldPtrArray; */ class PVAuxInfo : private NoDefaultMethods { public: + typedef std::map PVInfoMap; + typedef std::map::iterator PVInfoIter; + typedef std::pair PVInfoPair; + /** * Constructor * @param The fields to which the Auxinfo is attached. @@ -70,25 +91,20 @@ public: * Add a new auxiliary item or retrieve the interface to an existing item. * * @param key The key. - * @param scalarType The scalrType for the new item being added/ + * @param scalarType The scalarType for the new item being added/ * @return The new PVScalar that has been added to the Auxinfo. */ - PVScalar * createInfo(String key,ScalarType scalarType); - /** - * Get the number of PVScalars in the Auxinfo. - * @return The number. - */ - int getNumberInfo(); + PVScalarPtr createInfo(String key,ScalarType scalarType); /** * Get the Auxinfo with the specified key. * @return The PVScalar or null if it does not exist. */ - PVScalar * getInfo(String key); + PVScalarPtr & getInfo(String key); /** - * Get the Auxinfo with the specified index. - * @return The PVScalar or null if it does not exist. + * Get the map for the info. + * @return The map; */ - PVScalar * getInfo(int index); + PVInfoMap & getInfoMap(); /** * Convert the Auxinfo to a string and add it to builder. * @param builder The string builder. @@ -101,10 +117,8 @@ public: */ void toString(StringBuilder buf,int indentLevel); private: - PVField *pvField; - int lengthInfo; - int numberInfo; - PVScalar **pvInfos; // ptr to array of PVscalar * + PVField * pvField; + PVInfoMap pvInfos; friend class PVDataCreate; }; @@ -129,7 +143,7 @@ public: */ class PVField : virtual public Serializable, - private NoDefaultMethods + public std::tr1::enable_shared_from_this { public: POINTER_DEFINITIONS(PVField); @@ -143,6 +157,11 @@ public: * @param messageType The message type. */ virtual void message(String message,MessageType messageType) ; + /** + * Get the fieldName for this field. + * @return The name or empty string if top level field. + */ + String getFieldName(); /** * Register the message requester. * At most one requester can be registered. @@ -157,24 +176,24 @@ public: * The other offsets are determined by recursively traversing each structure of the tree. * @return The offset. */ - int getFieldOffset() ; + std::size_t getFieldOffset() ; /** * Get the next offset. If the field is a scalar or array field then this is just offset + 1. * If the field is a structure it is the offset of the next field after this structure. * Thus (nextOffset - offset) is always equal to the number of fields within the field. * @return The offset. */ - int getNextFieldOffset() ; + std::size_t getNextFieldOffset() ; /** * Get the total number of fields in this field. * This is equal to nextFieldOffset - fieldOffset. */ - int getNumberFields() ; + std::size_t getNumberFields() ; /** * Get the PVAuxInfo interface for the PVField. * @return The PVAuxInfo interface. */ - PVAuxInfo * getPVAuxInfo(); + PVAuxInfoPtr & getPVAuxInfo(); /** * Is the field immutable, i.e. does it not allow changes. * @return (false,true) if it (is not, is) immutable. @@ -189,17 +208,22 @@ public: * Get the Field that describes the field. * @return Field, which is the reflection interface. */ - FieldConstPtr getField() ; + FieldConstPtr & getField() ; /** * Get the parent of this field. * @return The parent interface or null if this is PVRecord */ PVStructure * getParent() ; + /** + * Replace the data implementation for the field. + * @param newPVField The new implementation + */ + void replacePVField(PVFieldPtr& newPVField); /** * Rename the field name. * @param newName The new name. */ - bool renameField(String newName); + void renameField(String newName); /** * postPut. Called when the field is updated by the implementation. */ @@ -229,13 +253,23 @@ public: */ virtual void toString(StringBuilder buf,int indentLevel) ; protected: - PVField(PVStructure *parent,FieldConstPtr field); - void setParent(PVStructure * parent); + PVField(FieldConstPtr field); + void setParent(PVStructure *parent); + void replaceField(FieldConstPtr &field); private: void message(String fieldName,String message,MessageType messageType); - class PVFieldPvt *pImpl; static void computeOffset(PVField *pvField); - static void computeOffset(PVField *pvField,int offset); + static void computeOffset(PVField *pvField,std::size_t offset); + PVAuxInfoPtr pvAuxInfo; + String fieldName; + PVStructure *parent; + FieldConstPtr field; + size_t fieldOffset; + size_t nextFieldOffset; + bool immutable; + Requester *requester; + PostHandler *postHandler; + std::tr1::shared_ptr convert; friend class PVDataCreate; friend class PVStructure; }; @@ -250,13 +284,15 @@ public: * Destructor */ virtual ~PVScalar(); + typedef PVScalar &reference; + typedef const PVScalar& const_reference; /** * Get the Scalar introspection interface for the PVScalar. * @return the interface. */ ScalarConstPtr getScalar() ; protected: - PVScalar(PVStructure *parent,ScalarConstPtr scalar); + PVScalar(ScalarConstPtr scalar); }; /** @@ -284,21 +320,37 @@ public: */ virtual void put(T value) = 0; protected: - PVScalarValue(PVStructure *parent,ScalarConstPtr scalar) - : PVScalar(parent,scalar) {} + PVScalarValue(ScalarConstPtr scalar) + : PVScalar(scalar) {} private: + friend class PVDataCreate; }; /** * typedefs for the various possible scalar types. */ -typedef PVScalarValue PVBoolean; +typedef PVScalarValue PVBoolean; typedef PVScalarValue PVByte; typedef PVScalarValue PVShort; typedef PVScalarValue PVInt; typedef PVScalarValue PVLong; +typedef PVScalarValue PVUByte; +typedef PVScalarValue PVUShort; +typedef PVScalarValue PVUInt; +typedef PVScalarValue PVULong; typedef PVScalarValue PVFloat; typedef PVScalarValue PVDouble; +typedef std::tr1::shared_ptr PVBooleanPtr; +typedef std::tr1::shared_ptr PVBytePtr; +typedef std::tr1::shared_ptr PVShortPtr; +typedef std::tr1::shared_ptr PVIntPtr; +typedef std::tr1::shared_ptr PVLongPtr; +typedef std::tr1::shared_ptr PVUBytePtr; +typedef std::tr1::shared_ptr PVUShortPtr; +typedef std::tr1::shared_ptr PVUIntPtr; +typedef std::tr1::shared_ptr PVULongPtr; +typedef std::tr1::shared_ptr PVFloatPtr; +typedef std::tr1::shared_ptr PVDoublePtr; /** * PVString is special case, since it implements SerializableArray @@ -310,9 +362,10 @@ public: */ virtual ~PVString() {} protected: - PVString(PVStructure *parent,ScalarConstPtr scalar) - : PVScalarValue(parent,scalar) {} + PVString(ScalarConstPtr & scalar) + : PVScalarValue(scalar) {} }; +typedef std::tr1::shared_ptr PVStringPtr; /** @@ -329,17 +382,17 @@ public: * Get the array length. * @return The length. */ - int getLength() const; + std::size_t getLength() const; /** * Set the array length. * @param The length. */ - void setLength(int length); + void setLength(std::size_t length); /** * Get the array capacity. * @return The capacity. */ - int getCapacity() const; + std::size_t getCapacity() const; /** * Can the capacity be changed. * @return (false,true) if (can not, can) be changed. @@ -354,12 +407,13 @@ public: * Set the array capacity. * @param The capacity. */ - virtual void setCapacity(int capacity) = 0; + virtual void setCapacity(std::size_t capacity) = 0; protected: - PVArray(PVStructure *parent,FieldConstPtr field); - void setCapacityLength(int capacity,int length); + PVArray(FieldConstPtr field); + void setCapacityLength(std::size_t capacity,std::size_t length); private: class PVArrayPvt * pImpl; + friend class PVDataCreate; }; /** @@ -367,6 +421,8 @@ private: */ template class PVArrayData { +private: + std::vector init; public: POINTER_DEFINITIONS(PVArrayData); typedef T value_type; @@ -375,11 +431,14 @@ public: /** * The data array. */ - pointer data; + std::vector & data; /** * The offset. This is the offset into the actual array of the first element in data, */ - int offset; + std::size_t offset; + PVArrayData() + : data(init) + {} }; @@ -393,6 +452,8 @@ public: * Destructor */ virtual ~PVScalarArray(); + typedef PVScalarArray &reference; + typedef const PVScalarArray& const_reference; /** * Get the introspection interface * @return The interface. @@ -400,8 +461,9 @@ public: ScalarArrayConstPtr getScalarArray() ; protected: - PVScalarArray(PVStructure *parent,ScalarArrayConstPtr scalarArray); + PVScalarArray(ScalarArrayConstPtr scalarArray); private: + friend class PVDataCreate; }; /** @@ -412,43 +474,53 @@ typedef PVArrayData StructureArrayData; /** * Data class for a structureArray */ -class PVStructureArray : public PVArray { +class PVStructureArray : public PVArray +{ public: POINTER_DEFINITIONS(PVStructureArray); + typedef PVStructurePtr value_type; + typedef PVStructurePtr* pointer; + typedef const PVStructurePtr* const_pointer; + typedef PVArrayData ArrayDataType; + typedef std::vector vector; + typedef std::tr1::shared_ptr shared_vector; + typedef PVStructureArray &reference; + typedef const PVStructureArray& const_reference; /** * Destructor */ virtual ~PVStructureArray() {} + virtual void setCapacity(size_t capacity); /** * Get the introspection interface * @return The interface. */ - virtual StructureArrayConstPtr getStructureArray() = 0; + virtual StructureArrayConstPtr getStructureArray(); /** * Append new elements to the end of the array. * @param number The number of elements to add. * @return the new length of the array. */ - virtual int append(int number) = 0; + virtual std::size_t append(std::size_t number); /** * Remove elements from the array. * @param offset The offset of the first element to remove. * @param number The number of elements to remove. * @return (false,true) if the elements were removed. */ - virtual bool remove(int offset,int number) = 0; + virtual bool remove(std::size_t offset,std::size_t number); /** * Compress. This removes all null elements from the array. */ - virtual void compress() = 0; + virtual void compress(); /** * Get array elements * @param offset The offset of the first element, * @param length The number of elements to get. * @param data The place where the data is placed. */ - virtual int get(int offset, int length, - StructureArrayData *data) = 0; + virtual std::size_t get(std::size_t offset, std::size_t length, + StructureArrayData &data); /** * Put data into the array. * @param offset The offset of the first element, @@ -457,64 +529,82 @@ public: * @param fromOffset The offset in from. * @return The number of elements put into the array. */ - virtual int put(int offset,int length, - PVStructurePtrArray from, int fromOffset) = 0; + virtual std::size_t put(std::size_t offset,std::size_t length, + pointer const from, std::size_t fromOffset); /** * Share data from another source. * @param value The data to share. * @param capacity The capacity of the array. * @param length The length of the array. */ - virtual void shareData( PVStructurePtrArray value,int capacity,int length) = 0; - + virtual void shareData( + shared_vector const & value, + std::size_t capacity, + std::size_t length); + virtual void serialize(ByteBuffer *pbuffer, + SerializableControl *pflusher) const; + virtual void deserialize(ByteBuffer *buffer, + DeserializableControl *pflusher); + virtual void serialize(ByteBuffer *pbuffer, + SerializableControl *pflusher, std::size_t offset, std::size_t count) const ; + virtual pointer get() { return &((*value.get())[0]); } + virtual pointer get() const { return &((*value.get())[0]); } + virtual vector const & getVector() {return *value;} + virtual shared_vector const & getSharedVector() {return value;} protected: - PVStructureArray(PVStructure *parent, StructureArrayConstPtr structureArray) - : PVArray(parent,structureArray) {} + PVStructureArray( StructureArrayConstPtr structureArray); private: + StructureArrayConstPtr structureArray; + shared_vector value; + friend class PVDataCreate; }; -class PVStructure : public PVField,public BitSetSerializable { +class PVStructure : public PVField, public BitSetSerializable +{ public: POINTER_DEFINITIONS(PVStructure); /** * Destructor */ virtual ~PVStructure(); + typedef PVStructure & reference; + typedef const PVStructure & const_reference; /** * Get the introspection interface * @return The interface. */ - StructureConstPtr getStructure(); + StructureConstPtr & getStructure(); /** * Get the array of pointers to the subfields in the structure. * @return The array. */ - PVFieldPtrArray getPVFields(); + PVFieldPtrArray & getPVFields(); /** * Get the subfield with the specified name. * @param fieldName The name of the field. * @return Pointer to the field or null if field does not exist. */ - PVField *getSubField(String fieldName); + PVFieldPtr & getSubField(String fieldName); /** * Get the subfield with the specified offset. * @param fieldOffset The offset. * @return Pointer to the field or null if field does not exist. */ - PVField *getSubField(int fieldOffset); + PVFieldPtr & getSubField(std::size_t fieldOffset); /** * Append a field to the structure. + * @param fieldName The name of the field to append. * @param pvField The field to append. */ - void appendPVField(PVField *pvField); + void appendPVField(String fieldName,PVFieldPtr & pvField); /** * Append fields to the structure. - * @param numberFields The number of fields. + * @param fieldNames The names of the fields to add. * @param pvFields The fields to append. * @return Pointer to the field or null if field does not exist. */ - void appendPVFields(int numberFields,PVFieldPtrArray pvFields); + void appendPVFields(StringArray & fieldNames,PVFieldPtrArray & pvFields); /** * Remove a field from the structure. * @param fieldName The name of the field to remove. @@ -525,69 +615,93 @@ public: * @param fieldName The name of the field to get. * @return Pointer to the field of null if a field with that name and type does not exist. */ - PVBoolean *getBooleanField(String fieldName); + PVBooleanPtr getBooleanField(String fieldName); /** * Get a byte field with the specified name. * @param fieldName The name of the field to get. * @return Pointer to the field of null if a field with that name and type does not exist. */ - PVByte *getByteField(String fieldName); + PVBytePtr getByteField(String fieldName); /** * Get a short field with the specified name. * @param fieldName The name of the field to get. * @return Pointer to the field of null if a field with that name and type does not exist. */ - PVShort *getShortField(String fieldName); + PVShortPtr getShortField(String fieldName); /** * Get a int field with the specified name. * @param fieldName The name of the field to get. * @return Pointer to the field of null if a field with that name and type does not exist. */ - PVInt *getIntField(String fieldName); + PVIntPtr getIntField(String fieldName); /** * Get a long field with the specified name. * @param fieldName The name of the field to get. * @return Pointer to the field of null if a field with that name and type does not exist. */ - PVLong *getLongField(String fieldName); + PVLongPtr getLongField(String fieldName); + /** + * Get an unsigned byte field with the specified name. + * @param fieldName The name of the field to get. + * @return Pointer to the field of null if a field with that name and type does not exist. + */ + PVUBytePtr getUByteField(String fieldName); + /** + * Get an unsigned short field with the specified name. + * @param fieldName The name of the field to get. + * @return Pointer to the field of null if a field with that name and type does not exist. + */ + PVUShortPtr getUShortField(String fieldName); + /** + * Get an unsigned int field with the specified name. + * @param fieldName The name of the field to get. + * @return Pointer to the field of null if a field with that name and type does not exist. + */ + PVUIntPtr getUIntField(String fieldName); + /** + * Get an unsigned long field with the specified name. + * @param fieldName The name of the field to get. + * @return Pointer to the field of null if a field with that name and type does not exist. + */ + PVULongPtr getULongField(String fieldName); /** * Get a float field with the specified name. * @param fieldName The name of the field to get. * @return Pointer to the field of null if a field with that name and type does not exist. */ - PVFloat *getFloatField(String fieldName); + PVFloatPtr getFloatField(String fieldName); /** * Get a double field with the specified name. * @param fieldName The name of the field to get. * @return Pointer to the field of null if a field with that name and type does not exist. */ - PVDouble *getDoubleField(String fieldName); + PVDoublePtr getDoubleField(String fieldName); /** * Get a string field with the specified name. * @param fieldName The name of the field to get. * @return Pointer to the field of null if a field with that name and type does not exist. */ - PVString *getStringField(String fieldName); + PVStringPtr getStringField(String fieldName); /** * Get a structure field with the specified name. * @param fieldName The name of the field to get. * @return Pointer to the field of null if a field with that name and type does not exist. */ - PVStructure *getStructureField(String fieldName); + PVStructurePtr getStructureField(String fieldName); /** * Get a scalarArray field with the specified name. * @param fieldName The name of the field to get. * @param elementType The element type. * @return Pointer to the field of null if a field with that name and type does not exist. */ - PVScalarArray *getScalarArrayField( + PVScalarArrayPtr getScalarArrayField( String fieldName,ScalarType elementType); /** * Get a structureArray field with the specified name. * @param fieldName The name of the field to get. * @return Pointer to the field of null if a field with that name and type does not exist. */ - PVStructureArray *getStructureArrayField(String fieldName); + PVStructureArrayPtr getStructureArrayField(String fieldName); /** * Get the name if this structure extends another structure. * @return The string which may be null. @@ -605,7 +719,7 @@ public: * @param pflusher Interface to call when buffer is full. */ virtual void serialize( - ByteBuffer *pbuffer,SerializableControl *pflusher) const; + ByteBuffer *pbuffer,SerializableControl *pflusher) const ; /** * Deserialize * @param pbuffer The byte buffer. @@ -631,23 +745,20 @@ public: DeserializableControl*pflusher,BitSet *pbitSet); /** * Constructor - * @param parent The parent structure. * @param structure The introspection interface. */ - PVStructure(PVStructure *parent,StructureConstPtr structure); + PVStructure(StructureConstPtr & structure); /** * Constructor - * @param parent The parent structure. * @param structure The introspection interface. * @param pvFields The array of fields for the structure. */ - PVStructure( - PVStructure *parent, - StructureConstPtr structure, - PVFieldPtrArray pvFields); + PVStructure(StructureConstPtr structure,PVFieldPtrArray & pvFields); private: - void setParentPvt(PVField *pvField,PVStructure *parent); - class PVStructurePvt * pImpl; + PVFieldPtrArray pvFields; + StructureConstPtr structurePtr; + String extendsStructureName; + friend class PVDataCreate; }; template @@ -658,6 +769,10 @@ public: typedef T* pointer; typedef const T* const_pointer; typedef PVArrayData ArrayDataType; + typedef std::vector vector; + typedef std::tr1::shared_ptr shared_vector; + typedef PVValueArray & reference; + typedef const PVValueArray & const_reference; /** * Destructor @@ -669,7 +784,8 @@ public: * @param length The number of elements to get. * @param data The place where the data is placed. */ - virtual int get(int offset, int length, ArrayDataType *data) = 0; + virtual std::size_t get( + std::size_t offset, std::size_t length, ArrayDataType &data) = 0; /** * Put data into the array. * @param offset The offset of the first element, @@ -678,170 +794,169 @@ public: * @param fromOffset The offset in from. * @return The number of elements put into the array. */ - virtual int put(int offset,int length, pointer from, int fromOffset) = 0; + virtual std::size_t put(std::size_t offset, + std::size_t length, pointer const from, std::size_t fromOffset) = 0; /** * Share data from another source. * @param value The data to share. * @param capacity The capacity of the array. * @param length The length of the array. */ - virtual void shareData(pointer value,int capacity,int length) = 0; + virtual void shareData( + shared_vector const & value, + std::size_t capacity, + std::size_t length) = 0; + virtual pointer get() = 0; + virtual pointer get() const = 0; + virtual vector const & getVector() = 0; + virtual shared_vector const & getSharedVector() = 0; protected: - PVValueArray(PVStructure *parent,ScalarArrayConstPtr scalar) - : PVScalarArray(parent,scalar) {} -private: + PVValueArray(ScalarArrayConstPtr scalar) + : PVScalarArray(scalar) {} + friend class PVDataCreate; }; /** * Definitions for the various scalarArray types. */ -typedef PVArrayData BooleanArrayData; -typedef PVValueArray PVBooleanArray; +typedef PVArrayData BooleanArrayData; +typedef PVValueArray PVBooleanArray; +typedef std::tr1::shared_ptr PVBooleanArrayPtr; typedef PVArrayData ByteArrayData; typedef PVValueArray PVByteArray; +typedef std::tr1::shared_ptr PVByteArrayPtr; typedef PVArrayData ShortArrayData; typedef PVValueArray PVShortArray; +typedef std::tr1::shared_ptr PVShortArrayPtr; typedef PVArrayData IntArrayData; typedef PVValueArray PVIntArray; +typedef std::tr1::shared_ptr PVIntArrayPtr; typedef PVArrayData LongArrayData; typedef PVValueArray PVLongArray; +typedef std::tr1::shared_ptr PVLongArrayPtr; +typedef PVArrayData UByteArrayData; +typedef PVValueArray PVUByteArray; +typedef std::tr1::shared_ptr PVUByteArrayPtr; + +typedef PVArrayData UShortArrayData; +typedef PVValueArray PVUShortArray; +typedef std::tr1::shared_ptr PVUShortArrayPtr; + +typedef PVArrayData UIntArrayData; +typedef PVValueArray PVUIntArray; +typedef std::tr1::shared_ptr PVUIntArrayPtr; + +typedef PVArrayData ULongArrayData; +typedef PVValueArray PVULongArray; +typedef std::tr1::shared_ptr PVULongArrayPtr; typedef PVArrayData FloatArrayData; typedef PVValueArray PVFloatArray; +typedef std::tr1::shared_ptr PVFloatArrayPtr; typedef PVArrayData DoubleArrayData; typedef PVValueArray PVDoubleArray; +typedef std::tr1::shared_ptr PVDoubleArrayPtr; typedef PVArrayData StringArrayData; typedef PVValueArray PVStringArray; +typedef std::tr1::shared_ptr PVStringArrayPtr; +class PVDataCreate; +typedef std::tr1::shared_ptr PVDataCreatePtr; /** * This is a singlton class for creating data instances. */ class PVDataCreate { public: + static PVDataCreatePtr getPVDataCreate(); /** * Create a PVField using given Field introspection data. - * @param parent The parent interface. * @param field The introspection data to be used to create PVField. * @return The PVField implementation. */ - PVField *createPVField(PVStructure *parent, - FieldConstPtr field); + PVFieldPtr createPVField(FieldConstPtr & field); /** * Create a PVField using given a PVField to clone. * This method calls the appropriate createPVScalar, createPVArray, or createPVStructure. - * @param parent The parent interface. * @param fieldToClone The field to clone. * @return The PVField implementation */ - PVField *createPVField(PVStructure *parent, - String fieldName,PVField * fieldToClone); + PVFieldPtr createPVField(PVFieldPtr & fieldToClone); /** * Create an implementation of a scalar field reusing the Scalar introspection interface. - * @param parent The parent. * @param scalar The introspection interface. * @return The PVScalar implementation. */ - PVScalar *createPVScalar(PVStructure *parent,ScalarConstPtr scalar); + PVScalarPtr createPVScalar(ScalarConstPtr & scalar); /** * Create an implementation of a scalar field. A Scalar introspection interface is created. - * @param parent The parent interface. - * @param fieldName The field name. * @param fieldType The field type. * @return The PVScalar implementation. */ - PVScalar *createPVScalar(PVStructure *parent, - String fieldName,ScalarType scalarType); + PVScalarPtr createPVScalar(ScalarType scalarType); /** * Create an implementation of a scalar field by cloning an existing PVScalar. * The new PVScalar will have the same value and auxInfo as the original. - * @param parent The parent interface. - * @param fieldName The field name. * @param scalarToClone The PVScalar to clone. * @return The PVScalar implementation. */ - PVScalar *createPVScalar(PVStructure *parent, - String fieldName,PVScalar * scalarToClone); + PVScalarPtr createPVScalar(PVScalarPtr & scalarToClone); /** * Create an implementation of an array field reusing the Array introspection interface. - * @param parent The parent interface. * @param array The introspection interface. * @return The PVScalarArray implementation. */ - PVScalarArray *createPVScalarArray(PVStructure *parent, - ScalarArrayConstPtr scalarArray); + PVScalarArrayPtr createPVScalarArray(ScalarArrayConstPtr & scalarArray); /** * Create an implementation for an array field. An Array introspection interface is created. * @param parent The parent interface. - * @param fieldName The field name. * @param elementType The element type. * @return The PVScalarArray implementation. */ - PVScalarArray *createPVScalarArray(PVStructure *parent, - String fieldName,ScalarType elementType); + PVScalarArrayPtr createPVScalarArray( + ScalarType elementType); /** * Create an implementation of an array field by cloning an existing PVArray. * The new PVArray will have the same value and auxInfo as the original. - * @param parent The parent interface. - * @param fieldName The field name. * @param arrayToClone The PVScalarArray to clone. * @return The PVScalarArray implementation. */ - PVScalarArray *createPVScalarArray(PVStructure *parent, - String fieldName,PVScalarArray * scalarArrayToClone); + PVScalarArrayPtr createPVScalarArray(PVScalarArrayPtr & scalarArrayToClone); /** * Create an implementation of an array with structure elements. - * @param parent The parent interface. * @param structureArray The introspection interface. * All elements share the same introspection interface. * @return The PVStructureArray implementation. */ - PVStructureArray *createPVStructureArray(PVStructure *parent, - StructureArrayConstPtr structureArray); + PVStructureArrayPtr createPVStructureArray(StructureArrayConstPtr & structureArray); /** * Create implementation for PVStructure. - * @param parent The parent interface. * @param structure The introspection interface. * @return The PVStructure implementation */ - PVStructure *createPVStructure(PVStructure *parent, - StructureConstPtr structure); + PVStructurePtr createPVStructure(StructureConstPtr & structure); /** * Create implementation for PVStructure. - * @param parent The parent interface. - * @param fieldName The field name. - * @param fields Array of reflection interfaces for the subFields. - * @return The PVStructure implementation - */ - PVStructure *createPVStructure(PVStructure *parent, - String fieldName,int numberFields,FieldConstPtrArray fields); - /** - * Create implementation for PVStructure. - * @param parent The parent interface. - * @param fieldName The field name. + * @param fieldNames The field names. * @param pvFields Array of PVFields * @return The PVStructure implementation */ - PVStructure *createPVStructure(PVStructure *parent, - String fieldName,int numberFields,PVFieldPtrArray pvFields); + PVStructurePtr createPVStructure( + StringArray & fieldNames,PVFieldPtrArray & pvFields); /** * Create implementation for PVStructure. - * @param parent The parent interface. - * @param fieldName The field name. * @param structToClone A structure. Each subfield and any auxInfo is cloned and added to the newly created structure. * @return The PVStructure implementation. */ - PVStructure *createPVStructure(PVStructure *parent, - String fieldName,PVStructure *structToClone); -protected: + PVStructurePtr createPVStructure(PVStructurePtr & structToClone); +private: PVDataCreate(); - friend PVDataCreate * getPVDataCreate(); }; /** @@ -849,7 +964,7 @@ protected: * @param The PVDataCreate factory. */ -extern PVDataCreate * getPVDataCreate(); +extern PVDataCreatePtr getPVDataCreate(); }} #endif /* PVDATA_H */ diff --git a/pvDataApp/pv/pvIntrospect.h b/pvDataApp/pv/pvIntrospect.h index 1667a60..0f9cced 100644 --- a/pvDataApp/pv/pvIntrospect.h +++ b/pvDataApp/pv/pvIntrospect.h @@ -31,7 +31,7 @@ typedef std::tr1::shared_ptr FieldConstPtr; /** * typedef for an array of shared pointer to an immutable Field. */ -typedef FieldConstPtr * FieldConstPtrArray; +typedef std::vector FieldConstPtrArray; /** * typedef for a shared pointer to an immutable Scalar. */ @@ -113,6 +113,22 @@ enum ScalarType { * The type is long, i. e. a 64 bit signed integer. */ pvLong, + /** + * The type is unsigned byte, i. e. a 8 bit unsigned integer. + */ + pvUByte, + /** + * The type is unsigned short, i. e. a 16 bit unsigned integer. + */ + pvUShort, + /** + * The type is unsigned int, i. e. a 32 bit unsigned integer. + */ + pvUInt, + /** + * The type is unsigned long, i. e. a 64 bit unsigned integer. + */ + pvULong, /** * The type is float, i. e. 32 bit IEEE floating point, */ @@ -132,11 +148,17 @@ enum ScalarType { */ namespace ScalarTypeFunc { /** - * Is the type an integer, i. e. is it one of byte,...long + * Is the type an integer, i. e. is it one of byte,...ulong * @param scalarType The type. * @return (false,true) if the scalarType is an integer. */ bool isInteger(ScalarType scalarType); + /** + * Is the type an unsigned integer, i. e. is it one of ubyte,...ulong + * @param scalarType The type. + * @return (false,true) if the scalarType is an integer. + */ + bool isUInteger(ScalarType scalarType); /** * Is the type numeric, i. e. is it one of byte,...,double * @param scalarType The type. @@ -182,11 +204,6 @@ public: * Destructor. */ virtual ~Field(); - /** - * Get the name of the field. - * @return The field name. - */ - String getFieldName() const{return m_fieldName;} /** * Get the field type. * @return The type. @@ -203,21 +220,13 @@ public: * @param indentLevel The number of blanks at the beginning of new lines. */ virtual void toString(StringBuilder builder,int indentLevel) const; - /** - * Rename the field. - * @param newName The new name. - * This MUST not be called after the field is put into use!!! - */ - void renameField(String newName); protected: /** * Constructor - * @param fieldName The field name. * @param fieldName The field type. */ - Field(String fieldName,Type type); + Field(Type type); private: - String m_fieldName; Type m_fieldType; friend class StructureArray; @@ -264,7 +273,7 @@ public: virtual void deserialize(ByteBuffer *buffer, DeserializableControl *flusher); protected: - Scalar(String fieldName,ScalarType scalarType); + Scalar(ScalarType scalarType); private: ScalarType scalarType; friend class FieldCreate; @@ -276,10 +285,14 @@ private: class ScalarArray : public Field{ public: POINTER_DEFINITIONS(ScalarArray); - ScalarArray(String fieldName,ScalarType scalarType); typedef ScalarArray& reference; typedef const ScalarArray& const_reference; + /** + * Constructor + * @param scalarType The scalarType for the field. + */ + ScalarArray(ScalarType scalarType); /** * Get the scalarType for the elements. * @return the scalarType @@ -339,10 +352,9 @@ public: protected: /** * Constructor. - * @param fieldName The name for the field. * @param structure The introspection interface for the elements. */ - StructureArray(String fieldName,StructureConstPtr structure); + StructureArray(StructureConstPtr structure); /** * Destructor. */ @@ -369,41 +381,45 @@ public: * Get the number of immediate subfields in the structure/ * @return The number of fields. */ - int getNumberFields() const {return numberFields;} + std::size_t getNumberFields() const {return fieldNames.size();} /** * Get the field for the specified fieldName. + * @param fieldName The name of the field to get; * @return The introspection interface. * This will hold a null pointer if the field is not in the structure. */ FieldConstPtr getField(String fieldName) const; + /** + * Get the field for the specified fieldName. + * @param fieldName The index of the field to get; + * @return The introspection interface. + * This will hold a null pointer if the field is not in the structure. + */ + FieldConstPtr getField(std::size_t index) {return fields[index];} /** * Get the field index for the specified fieldName. * @return The introspection interface. * This will be -1 if the field is not in the structure. */ - int getFieldIndex(String fieldName) const; + std::size_t getFieldIndex(String fieldName) const; /** * Get the fields in the structure. * @return The array of fields. */ - FieldConstPtrArray getFields() const {return fields;} + FieldConstPtrArray const & getFields() const {return fields;} /** - * Append a field to the structure. - * @param field The field to append. + * Get the names of the fields in the structure. + * @return The array of fieldNames. */ - void appendField(FieldConstPtr field); + StringArray const & getFieldNames() const {return fieldNames;} + void renameField(std::size_t fieldIndex,String newName) + {fieldNames[fieldIndex] = newName;} /** - * Append an array of fields to the structure. - * @param field The fields to append. - * The array MUST be allocated on the heap. - * The structure takes ownership of the field array. + * Get the name of the field with the specified index; + * @param fieldIndex The index of the desired field. + * @return The fieldName. */ - void appendFields(int numberFields,FieldConstPtrArray fields); - /** - * Remove a field from the structure. - * @param field The field to remove. - */ - void removeField(int index); + String getFieldName(std::size_t fieldIndex){return fieldNames[fieldIndex];} /** * Convert the structure to a string and add it to builder. * @param builder The string builder. @@ -420,76 +436,90 @@ public: virtual void deserialize(ByteBuffer *buffer, DeserializableControl *flusher); protected: - Structure(String fieldName, int numberFields,FieldConstPtrArray fields); + Structure(StringArray fieldNames,FieldConstPtrArray fields); private: - int numberFields; - FieldConstPtrArray fields; + void toStringCommon(StringBuilder buf,int indentLevel) const; + StringArray fieldNames; + FieldConstPtrArray fields; friend class FieldCreate; }; /** * This is a singlton class for creating introspection interfaces. */ -class FieldCreate : NoDefaultMethods { +class FieldCreate; +typedef std::tr1::shared_ptr FieldCreatePtr; + +class FieldCreate { public: - /** - * Create a new Field like an existing field but with a different name. - * @param fieldName The field name. - * @param field An existing field - * @return a {@code Field} interface for the newly created object. - */ - FieldConstPtr create(String fieldName,FieldConstPtr field) const; + static FieldCreatePtr getFieldCreate(); /** * Create a {@code ScalarField}. - * @param fieldName The field name. * @param scalarType The scalar type. * @return a {@code Scalar} interface for the newly created object. * @throws An {@code IllegalArgumentException} if an illegal type is specified. */ - ScalarConstPtr createScalar(String fieldName,ScalarType scalarType) const; + ScalarConstPtr createScalar(ScalarType scalarType) const; /** * Create an {@code Array} field. - * @param fieldName The field name * @param elementType The {@code scalarType} for array elements * @return An {@code Array} Interface for the newly created object. */ - ScalarArrayConstPtr createScalarArray(String fieldName, - ScalarType elementType) const; + ScalarArrayConstPtr createScalarArray(ScalarType elementType) const; /** * Create an {@code Array} field that is has element type Structure * @param fieldName The field name * @param elementStructure The {@code Structure} for each array element. * @return An {@code Array} Interface for the newly created object. */ - StructureConstPtr createStructure (String fieldName, - int numberFields,FieldConstPtrArray fields) const; + StructureArrayConstPtr createStructureArray(StructureConstPtr structure) const; /** * Create a {@code Structure} field. - * @param fieldName The field name - * @param fields The array of {@code Field}s for the structure. + * @param fieldNames The array of {@code fieldNames} for the structure + * @param fields The array of {@code fields} for the structure. * @return a {@code Structure} interface for the newly created object. */ - StructureArrayConstPtr createStructureArray(String fieldName, - StructureConstPtr structure) const; - - /** - * Deserialize {@code Field} instance from given byte buffer. - * @param buffer Buffer containing serialized {@code Field} instance. - * @param control Deserialization control instance. - * @return a deserialized {@code Field} instance. - */ - FieldConstPtr deserialize(ByteBuffer* buffer, DeserializableControl* control) const; + StructureConstPtr createStructure ( + StringArray const & fieldNames, + FieldConstPtrArray const & fields) const; + /** + * Append a field to a structure. + * @param structure The structure to which the field is appended. + * @param fieldName The name of the field. + * @param field The field. + * @return a {@code Structure} interface for the newly created object. + */ + StructureConstPtr appendField( + StructureConstPtr structure, + String fieldName, FieldConstPtr field) const; + /** + * Append fields to a structure. + * @param structure The structure to which the fields appended. + * @param fieldName The names of the fields. + * @param field The fields. + * @return a {@code Structure} interface for the newly created object. + */ + StructureConstPtr appendFields( + StructureConstPtr structure, + StringArray const & fieldNames, + FieldConstPtrArray const & fields) const; + /** + * Deserialize {@code Field} instance from given byte buffer. + * @param buffer Buffer containing serialized {@code Field} instance. + * @param control Deserialization control instance. + * @return a deserialized {@code Field} instance. + */ + FieldConstPtr deserialize(ByteBuffer* buffer, DeserializableControl* control) const; private: FieldCreate(); - friend FieldCreate * getFieldCreate(); }; /** * Get the single class that implemnents FieldCreate, * @param The fieldCreate factory. */ -extern FieldCreate * getFieldCreate(); +extern FieldCreatePtr getFieldCreate(); }} #endif /* PVINTROSPECT_H */ diff --git a/pvDataApp/pv/pvType.h b/pvDataApp/pv/pvType.h index bb4c4fb..e9f2a00 100644 --- a/pvDataApp/pv/pvType.h +++ b/pvDataApp/pv/pvType.h @@ -13,6 +13,7 @@ #ifndef PVTYPE_H #define PVTYPE_H #include +#include #include namespace epics { namespace pvData { @@ -24,7 +25,7 @@ namespace epics { namespace pvData { /** * boolean, i.e. can only have the values {@code false} or {@code true} */ -typedef bool boolean; +typedef uint8_t boolean; /** * A 8 bit signed integer */ @@ -41,6 +42,14 @@ typedef int32_t int32; * A 64 bit signed integer */ typedef int64_t int64; +/** + * A 8 bit unsigned integer + */ +typedef uint8_t uint8; +/** + * A 16 bit unsigned integer + */ +typedef uint16_t uint16; /** * A 32 bit unsigned integer */ @@ -60,40 +69,131 @@ typedef std::string String; /** * A boolean array. */ -typedef bool * BooleanArray; +typedef std::vector BooleanArray; +// get will be the same as for UByte +/* +inline boolean * get(BooleanArray value) +{ + return const_cast(&value[0]); +} +*/ +typedef std::vector::iterator BooleanArray_iterator; +typedef std::vector::const_iterator BooleanArray_const_iterator; /** * A byte array. */ -typedef int8 * ByteArray; +typedef std::vector ByteArray; +inline int8 * get(ByteArray value) +{ + return const_cast(&value[0]); +} +typedef std::vector::iterator ByteArray_iterator; +typedef std::vector::const_iterator ByteArray_const_iterator; /** * A short array. */ -typedef int16 * ShortArray; +typedef std::vector ShortArray; +inline int16 * get(ShortArray value) +{ + return const_cast(&value[0]); +} +typedef std::vector::iterator ShortArray_iterator; +typedef std::vector::const_iterator ShortArray_const_iterator; /** * A int array. */ -typedef int32 * IntArray; +typedef std::vector IntArray; +inline int32 * get(IntArray value) +{ + return const_cast(&value[0]); +} +typedef std::vector::iterator IntArray_iterator; +typedef std::vector::const_iterator IntArray_const_iterator; /** * A long array. */ -typedef int64 * LongArray; +typedef std::vector LongArray; +inline int64 * get(LongArray value) +{ + return const_cast(&value[0]); +} +typedef std::vector::iterator LongArray_iterator; +typedef std::vector::const_iterator LongArray_const_iterator; +/** + * An unsigned byte array. + */ +typedef std::vector UByteArray; +inline uint8 * get(UByteArray value) +{ + return const_cast(&value[0]); +} +typedef std::vector::iterator UByteArray_iterator; +typedef std::vector::const_iterator UByteArray_const_iterator; +/** + * An unsigned short array. + */ +typedef std::vector UShortArray; +inline uint16 * get(UShortArray value) +{ + return const_cast(&value[0]); +} +typedef std::vector::iterator UShortArray_iterator; +typedef std::vector::const_iterator UShortArray_const_iterator; +/** + * An unsigned int array. + */ +typedef std::vector UIntArray; +inline uint32 * get(UIntArray value) +{ + return const_cast(&value[0]); +} +typedef std::vector::iterator UIntArray_iterator; +typedef std::vector::const_iterator UIntArray_const_iterator; +/** + * An unsigned long array. + */ +typedef std::vector ULongArray; +inline uint64 * get(ULongArray value) +{ + return const_cast(&value[0]); +} +typedef std::vector::iterator ULongArray_iterator; +typedef std::vector::const_iterator ULongArray_const_iterator; /** * A float array. */ -typedef float * FloatArray; +typedef std::vector FloatArray; +inline float * get(FloatArray value) +{ + return const_cast(&value[0]); +} +typedef std::vector::iterator FloatArray_iterator; +typedef std::vector::const_iterator FloatArray_const_iterator; /** * A double array. */ -typedef double * DoubleArray; +typedef std::vector DoubleArray; +inline double * get(DoubleArray value) +{ + return const_cast(&value[0]); +} +typedef std::vector::iterator DoubleArray_iterator; +typedef std::vector::const_iterator DoubleArray_const_iterator; /** * A string array. */ -typedef String* StringArray; +typedef std::vector StringArray; +inline String * get(StringArray value) +{ + return const_cast(&value[0]); +} +typedef std::vector::iterator StringArray_iterator; +typedef std::vector::const_iterator StringArray_const_iterator; /** * A convenience definition for toString methods */ -typedef std::string * StringBuilder; +typedef String * StringBuilder; }} #endif /* PVTYPE_H */ diff --git a/pvDataApp/pv/standardField.h b/pvDataApp/pv/standardField.h index 22adf60..477c163 100644 --- a/pvDataApp/pv/standardField.h +++ b/pvDataApp/pv/standardField.h @@ -48,37 +48,18 @@ namespace epics { namespace pvData { * } */ -class StandardField : private NoDefaultMethods { +class StandardField; +typedef std::tr1::shared_ptr StandardFieldPtr; + +class StandardField { public: - StandardField(); + static StandardFieldPtr getStandardField(); ~StandardField(); - ScalarConstPtr scalar(String fieldName,ScalarType type); - StructureConstPtr scalar(String fieldName, - ScalarType type,String properties); - ScalarArrayConstPtr scalarArray(String fieldName, - ScalarType elementType); - StructureConstPtr scalarArray(String fieldName, - ScalarType elementType, String properties); - StructureArrayConstPtr structureArray(String fieldName, - StructureConstPtr structure); - StructureConstPtr structureArray(String fieldName, - StructureConstPtr structure,String properties); - StructureConstPtr structure(String fieldName, - int numFields,FieldConstPtrArray fields); - StructureConstPtr enumerated(String fieldName); - StructureConstPtr enumerated(String fieldName, String properties); - ScalarConstPtr scalarValue(ScalarType type); - StructureConstPtr scalarValue(ScalarType type,String properties); - ScalarArrayConstPtr scalarArrayValue(ScalarType elementType); - StructureConstPtr scalarArrayValue(ScalarType elementType, - String properties); - StructureArrayConstPtr structureArrayValue(StructureConstPtr structure); - StructureConstPtr structureArrayValue(StructureConstPtr structure, - String properties); - StructureConstPtr structureValue( - int numFields,FieldConstPtrArray fields); - StructureConstPtr enumeratedValue(); - StructureConstPtr enumeratedValue(String properties); + StructureConstPtr scalar(ScalarType type,String properties); + StructureConstPtr scalarArray(ScalarType elementType, String properties); + StructureConstPtr structureArray(StructureConstPtr & structure,String properties); + StructureConstPtr enumerated(); + StructureConstPtr enumerated(String properties); StructureConstPtr alarm(); StructureConstPtr timeStamp(); StructureConstPtr display(); @@ -92,10 +73,10 @@ public: StructureConstPtr doubleAlarm(); StructureConstPtr enumeratedAlarm(); private: - static void init(); + StandardField(); }; -extern StandardField * getStandardField(); +extern StandardFieldPtr getStandardField(); }} #endif /* STANDARDFIELD_H */ diff --git a/pvDataApp/pv/standardPVField.h b/pvDataApp/pv/standardPVField.h index 273e5bb..13083e1 100644 --- a/pvDataApp/pv/standardPVField.h +++ b/pvDataApp/pv/standardPVField.h @@ -25,56 +25,23 @@ namespace epics { namespace pvData { * } */ +class StandardPVField; +typedef std::tr1::shared_ptr StandardPVFieldPtr; + class StandardPVField : private NoDefaultMethods { public: - StandardPVField(); + static StandardPVFieldPtr getStandardPVField(); ~StandardPVField(); - PVScalar * scalar(PVStructure *parent,String fieldName,ScalarType type); - PVStructure * scalar(PVStructure *parent, - String fieldName,ScalarType type,String properties); - PVScalarArray * scalarArray(PVStructure *parent, - String fieldName,ScalarType elementType); - PVStructure * scalarArray(PVStructure *parent, - String fieldName,ScalarType elementType, String properties); - PVStructureArray * structureArray(PVStructure *parent, - String fieldName,StructureConstPtr structure); - PVStructure* structureArray(PVStructure *parent, - String fieldName,StructureConstPtr structure,String properties); - PVStructure * enumerated(PVStructure *parent, - String fieldName,StringArray choices, int number); - PVStructure * enumerated(PVStructure *parent, - String fieldName,StringArray choices, int number, String properties); - PVScalar * scalarValue(PVStructure *parent,ScalarType type); - PVStructure * scalarValue(PVStructure *parent, - ScalarType type,String properties); - PVScalarArray * scalarArrayValue( - PVStructure *parent,ScalarType elementType); - PVStructure * scalarArrayValue(PVStructure *parent, - ScalarType elementType, String properties); - PVStructureArray * structureArrayValue(PVStructure *parent, - StructureConstPtr structure); - PVStructure * structureArrayValue(PVStructure *parent, - StructureConstPtr structure,String properties); - PVStructure * enumeratedValue( - PVStructure *parent,StringArray choices,int number); - PVStructure * enumeratedValue(PVStructure *parent, - StringArray choices,int number, String properties); - PVStructure * alarm(PVStructure *parent); - PVStructure * timeStamp(PVStructure *parent); - PVStructure * display(PVStructure *parent); - PVStructure * control(PVStructure *parent); - PVStructure * booleanAlarm(PVStructure *parent); - PVStructure * byteAlarm(PVStructure *parent); - PVStructure * shortAlarm(PVStructure *parent); - PVStructure * intAlarm(PVStructure *parent); - PVStructure * longAlarm(PVStructure *parent); - PVStructure * floatAlarm(PVStructure *parent); - PVStructure * doubleAlarm(PVStructure *parent); - PVStructure * enumeratedAlarm(PVStructure *parent); - PVStructure * powerSupply(PVStructure *parent); + PVStructurePtr scalar(ScalarType type,String properties); + PVStructurePtr scalarArray(ScalarType elementType, String properties); + PVStructurePtr structureArray(StructureConstPtr structure,String properties); + PVStructurePtr enumerated(StringArray choices); + PVStructurePtr enumerated(StringArray choices, String properties); +private: + StandardPVField(); }; -extern StandardPVField * getStandardPVField(); +extern StandardPVFieldPtr getStandardPVField(); }} #endif /* STANDARDPVFIELD_H */ diff --git a/pvDataApp/pvMisc/bitSetUtil.cpp b/pvDataApp/pvMisc/bitSetUtil.cpp index 00d3804..9c9392c 100644 --- a/pvDataApp/pvMisc/bitSetUtil.cpp +++ b/pvDataApp/pvMisc/bitSetUtil.cpp @@ -28,7 +28,7 @@ static bool checkBitSetPVField( } PVStructure *pvStructure = static_cast(pvField); while(offsetgetSubField(offset); + PVField *pvSubField = pvStructure->getSubField(offset).get(); int nbitsNow = pvSubField->getNumberFields(); if(nbitsNow==1) { if(bitSet->get(offset)) { @@ -44,7 +44,7 @@ static bool checkBitSetPVField( pvSubStructure->getPVFields(); int num = pvSubStructure->getStructure()->getNumberFields(); for(int i=0; i DataElement; typedef Queue DataQueue; class Sink : public Runnable { public: - Sink(DataQueue *queue,FILE *auxfd); + Sink(DataQueue &queue,FILE *auxfd); ~Sink(); void stop(); void look(); virtual void run(); private: - DataQueue *queue; + DataQueue queue; FILE *auxfd; bool isStopped; Event *wait; @@ -58,7 +57,7 @@ private: Thread *thread; }; -Sink::Sink(DataQueue *queue,FILE *auxfd) +Sink::Sink(DataQueue &queue,FILE *auxfd) : queue(queue), auxfd(auxfd), isStopped(false), @@ -97,49 +96,51 @@ void Sink::run() wait->wait(); if(isStopped) break; while(true) { - DataElement *element = queue->getUsed(); - if(element==0) { + Data *data = queue.getUsed(); + if(data==NULL) { waitEmpty->signal(); break; } - Data *data = element->getObject(); fprintf(auxfd," sink a %d b %d\n",data->a,data->b); - queue->releaseUsed(element); + queue.releaseUsed(data); } } stopped->signal(); } static void testBasic(FILE * fd,FILE *auxfd ) { - Data *dataArray[numElements]; - for(int i=0; ia = i; - dataArray[i]->b = i*10; + std::vector >dataArray; + dataArray.reserve(numElements); + for(int i=0; i(new Data())); } - DataQueue *queue = new DataQueue(dataArray,numElements); - Sink *sink = new Sink(queue,auxfd); + DataQueue queue(dataArray); + Data *pdata = queue.getFree(); + int value = 0; + while(pdata!=NULL) { + pdata->a = value; + pdata->b = value*10; + value++; + queue.setUsed(pdata); + pdata = queue.getFree(); + } + std::tr1::shared_ptr sink = std::tr1::shared_ptr(new Sink(queue,auxfd)); while(true) { - DataElement *element = queue->getFree(); - if(element==0) break; - Data *data = element->getObject(); + Data * data = queue.getFree(); + if(data==NULL) break; fprintf(auxfd,"source a %d b %d\n",data->a,data->b); - queue->setUsed(element); + queue.setUsed(data); } sink->look(); // now alternate for(int i=0; igetFree(); - assert(element!=0); - Data *data = element->getObject(); + Data *data = queue.getFree(); + assert(data!=NULL); fprintf(auxfd,"source a %d b %d\n",data->a,data->b); - queue->setUsed(element); + queue.setUsed(data); sink->look(); } sink->stop(); - delete sink; - delete queue; - for(int i=0; i #include #include -#include using namespace epics::pvData; -static FieldCreate * fieldCreate = 0; -static PVDataCreate * pvDataCreate = 0; -static StandardField *standardField = 0; -static StandardPVField *standardPVField = 0; -static Convert *convert = 0; -static String builder(""); +static FieldCreatePtr fieldCreate; +static PVDataCreatePtr pvDataCreate; +static StandardFieldPtr standardField; +static StandardPVFieldPtr standardPVField; +static ConvertPtr convert; +static String builder; static String alarmTimeStamp("alarm,timeStamp"); static String allProperties("alarm,timeStamp,display,control"); -static PVStructure *doubleRecord = 0; -static PVStructure *enumeratedRecord = 0; +static PVStructurePtr doubleRecord; +static PVStructurePtr enumeratedRecord; static void createRecords(FILE * fd,FILE *auxfd) { - doubleRecord = standardPVField->scalarValue(0,pvDouble,allProperties); + doubleRecord = standardPVField->scalar(pvDouble,allProperties); builder.clear(); doubleRecord->toString(&builder); fprintf(fd,"%s\n",builder.c_str()); - String choices[4] = { - String("0"),String("1"),String("2"),String("3") - }; - enumeratedRecord = standardPVField->enumeratedValue(0,choices,4,alarmTimeStamp); + StringArray choices; + choices.reserve(4); + choices.push_back("1"); + choices.push_back("2"); + choices.push_back("3"); + choices.push_back("4"); + enumeratedRecord = standardPVField->enumerated(choices,alarmTimeStamp); builder.clear(); enumeratedRecord->toString(&builder); fprintf(fd,"%s\n",builder.c_str()); } -static void deleteRecords(FILE * fd,FILE *auxfd) +static void printRecords(FILE * fd,FILE *auxfd) { fprintf(fd,"doubleRecord\n"); builder.clear(); @@ -72,8 +74,6 @@ static void deleteRecords(FILE * fd,FILE *auxfd) builder.clear(); enumeratedRecord->toString(&builder); fprintf(fd,"%s\n",builder.c_str()); - delete doubleRecord; - delete enumeratedRecord; } static void testAlarm(FILE * fd,FILE *auxfd) @@ -82,8 +82,8 @@ static void testAlarm(FILE * fd,FILE *auxfd) Alarm alarm; PVAlarm pvAlarm; bool result; - PVField *pvField = doubleRecord->getSubField(String("alarm")); - if(pvField==0) { + PVFieldPtr pvField = doubleRecord->getSubField(String("alarm")); + if(pvField.get()==0) { printf("testAlarm ERROR did not find field alarm\n"); return; } @@ -250,9 +250,7 @@ int main(int argc,char *argv[]) testControl(fd,auxfd); testDisplay(fd,auxfd); testEnumerated(fd,auxfd); - deleteRecords(fd,auxfd); - epicsExitCallAtExits(); - CDRMonitor::get().show(fd); + printRecords(fd,auxfd); return(0); } diff --git a/testApp/pv/Makefile b/testApp/pv/Makefile index 3d5489c..497bf96 100644 --- a/testApp/pv/Makefile +++ b/testApp/pv/Makefile @@ -2,9 +2,9 @@ TOP=../.. include $(TOP)/configure/CONFIG -PROD_HOST += temp -temp_SRCS += temp.cpp -temp_LIBS += pvData Com +PROD_HOST += testIntrospect +testIntrospect_SRCS += testIntrospect.cpp +testIntrospect_LIBS += pvData Com PROD_HOST += testPVAppend testPVAppend_SRCS += testPVAppend.cpp @@ -18,10 +18,6 @@ PROD_HOST += testPVAuxInfo testPVAuxInfo_SRCS += testPVAuxInfo.cpp testPVAuxInfo_LIBS += pvData Com -PROD_HOST += testIntrospect -testIntrospect_SRCS += testIntrospect.cpp -testIntrospect_LIBS += pvData Com - PROD_HOST += testPVData testPVData_SRCS += testPVData.cpp testPVData_LIBS += pvData Com diff --git a/testApp/pv/temp.cpp b/testApp/pv/temp.cpp deleted file mode 100644 index 1420d0a..0000000 --- a/testApp/pv/temp.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/* testPVAppend.cpp */ -/** - * Copyright - See the COPYRIGHT that is included with this distribution. - * EPICS pvDataCPP is distributed subject to a Software License Agreement found - * in file LICENSE that is included with this distribution. - */ -/* Author: Marty Kraimer Date: 2010.11 */ - -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -using namespace epics::pvData; - -static FieldCreate * fieldCreate = 0; -static PVDataCreate * pvDataCreate = 0; -static StandardField *standardField = 0; -static StandardPVField *standardPVField = 0; -static Convert *convert = 0; -static String builder(""); -static String alarmTimeStamp("alarm,timeStamp"); -static String alarmTimeStampValueAlarm("alarm,timeStamp,valueAlarm"); -static String allProperties("alarm,timeStamp,display,control,valueAlarm"); - -static void testAppendSimple(FILE * fd) -{ - FieldConstPtrArray fields = new FieldConstPtr[0]; - PVStructure *pvParent = pvDataCreate->createPVStructure( - 0,String("request"),0,fields); - PVString* pvStringField = static_cast( - pvDataCreate->createPVScalar(pvParent, "fieldList", pvString)); - pvStringField->put(String("value,timeStamp")); - pvParent->appendPVField(pvStringField); - builder.clear(); - pvParent->toString(&builder); - fprintf(fd,"%s\n",builder.c_str()); - pvStringField = static_cast( - pvDataCreate->createPVScalar(pvParent, "extra", pvString)); - pvStringField->put(String("junk")); - pvParent->appendPVField(pvStringField); - builder.clear(); - pvParent->toString(&builder); - fprintf(fd,"%s\n",builder.c_str()); - delete pvParent; -} - -static void testAppendMore(FILE * fd) -{ - PVStructure* pvStructure = pvDataCreate->createPVStructure( - 0,"parent", 0); - PVStructure* pvChild1 = pvDataCreate->createPVStructure( - pvStructure, "child1", 0); - PVString *pvStringField = static_cast( - pvDataCreate->createPVScalar(pvChild1,"value", pvString)); - pvStringField->put("bla"); - pvChild1->appendPVField(pvStringField); - pvStructure->appendPVField(pvChild1); - PVStructure* pvChild2 = pvDataCreate->createPVStructure( - pvStructure, "child2", 0); - pvStringField = static_cast( - pvDataCreate->createPVScalar(pvChild2,"value", pvString)); - pvStringField->put("bla"); - pvChild2->appendPVField(pvStringField); - pvStructure->appendPVField(pvChild2); - builder.clear(); - pvStructure->toString(&builder); - fprintf(fd,"%s\n",builder.c_str()); - delete pvStructure; -} - -static void append2(PVStructure* pvStructure, - const char *oneName,const char *twoName, - const char *oneValue,const char *twoValue) -{ - PVField* array[2]; - PVString *pvStringField = static_cast( - pvDataCreate->createPVScalar(0,oneName, pvString)); - pvStringField->put(oneValue); - array[0] = pvStringField; - pvStringField = static_cast( - pvDataCreate->createPVScalar(0,twoName, pvString)); - pvStringField->put(twoValue); - array[1] = pvStringField; - pvStructure->appendPVFields(2,array); -} -static void testAppends(FILE * fd) -{ - PVField** array = new PVField*[2]; - PVStructure* pvChild = pvDataCreate->createPVStructure( - 0, "child1", 0); - append2(pvChild,"Joe","Mary","Good Guy","Good Girl"); - array[0] = pvChild; - pvChild = pvDataCreate->createPVStructure( - 0, "child2", 0); - append2(pvChild,"Bill","Jane","Bad Guy","Bad Girl"); - array[1] = pvChild; - PVStructure* pvStructure = pvDataCreate->createPVStructure( - 0,"parent", 2,array); - builder.clear(); - pvStructure->toString(&builder); - fprintf(fd,"%s\n",builder.c_str()); - PVField *pvField = pvStructure->getSubField("child2.Bill"); - assert(pvField!=0); - bool ok = pvField->renameField("Joe"); - assert(ok); - builder.clear(); - pvStructure->toString(&builder); - fprintf(fd,"%s\n",builder.c_str()); - pvField->getParent()->removePVField("Joe"); - builder.clear(); - pvStructure->toString(&builder); - fprintf(fd,"%s\n",builder.c_str()); - delete pvStructure; -} - -int main(int argc,char *argv[]) -{ - char *fileName = 0; - if(argc>1) fileName = argv[1]; - FILE * fd = stdout; - if(fileName!=0 && fileName[0]!=0) { - fd = fopen(fileName,"w+"); - } - fieldCreate = getFieldCreate(); - pvDataCreate = getPVDataCreate(); - standardField = getStandardField(); - standardPVField = getStandardPVField(); - convert = getConvert(); - //testAppendSimple(fd); - //testAppendMore(fd); - testAppends(fd); - epicsExitCallAtExits(); - CDRMonitor::get().show(fd); - return(0); -} - diff --git a/testApp/pv/testIntrospect.cpp b/testApp/pv/testIntrospect.cpp index 6da6d49..19924da 100644 --- a/testApp/pv/testIntrospect.cpp +++ b/testApp/pv/testIntrospect.cpp @@ -24,15 +24,15 @@ using namespace epics::pvData; -static FieldCreate * fieldCreate = 0; -static PVDataCreate * pvDataCreate = 0; -static StandardField *standardField = 0; +static FieldCreatePtr fieldCreate; +static PVDataCreatePtr pvDataCreate; +static StandardFieldPtr standardField; static String builder(""); -static void testScalarCommon(FILE * fd,String fieldName,ScalarType stype, +static void testScalarCommon(FILE * fd,ScalarType stype, bool isInteger,bool isNumeric,bool isPrimitive) { - ScalarConstPtr pscalar = standardField->scalar(fieldName,stype); + ScalarConstPtr pscalar = fieldCreate->createScalar(stype); Type type = pscalar->getType(); assert(type==scalar); builder.clear(); @@ -47,26 +47,25 @@ static void testScalarCommon(FILE * fd,String fieldName,ScalarType stype, pscalar->toString(&builder); fprintf(fd,"%s\n",builder.c_str()); // create tempory PVField so that memory can be released - PVField *pvField = pvDataCreate->createPVField(0,pscalar); - delete pvField; + PVFieldPtr pvField = pvDataCreate->createPVScalar(pscalar); } static void testScalar(FILE * fd) { fprintf(fd,"\ntestScalar\n"); - testScalarCommon(fd,String("boolean"),pvBoolean,false,false,true); - testScalarCommon(fd,String("byte"),pvByte,true,true,true); - testScalarCommon(fd,String("short"),pvShort,true,true,true); - testScalarCommon(fd,String("int"),pvInt,true,true,true); - testScalarCommon(fd,String("long"),pvLong,true,true,true); - testScalarCommon(fd,String("float"),pvFloat,false,true,true); - testScalarCommon(fd,String("double"),pvDouble,false,true,true); - testScalarCommon(fd,String("string"),pvString,false,false,false); + testScalarCommon(fd,pvBoolean,false,false,true); + testScalarCommon(fd,pvByte,true,true,true); + testScalarCommon(fd,pvShort,true,true,true); + testScalarCommon(fd,pvInt,true,true,true); + testScalarCommon(fd,pvLong,true,true,true); + testScalarCommon(fd,pvFloat,false,true,true); + testScalarCommon(fd,pvDouble,false,true,true); + testScalarCommon(fd,pvString,false,false,false); } -static void testScalarArrayCommon(FILE * fd,String fieldName,ScalarType stype, +static void testScalarArrayCommon(FILE * fd,ScalarType stype, bool isInteger,bool isNumeric,bool isPrimitive) { - ScalarArrayConstPtr pscalar = standardField->scalarArray(fieldName,stype); + ScalarArrayConstPtr pscalar = fieldCreate->createScalarArray(stype); Type type = pscalar->getType(); assert(type==scalarArray); builder.clear(); @@ -81,51 +80,53 @@ static void testScalarArrayCommon(FILE * fd,String fieldName,ScalarType stype, pscalar->toString(&builder); fprintf(fd,"%s\n",builder.c_str()); // create tempory PVField so that memory can be released - PVField *pvField = pvDataCreate->createPVField(0,pscalar); - delete pvField; + PVFieldPtr pvField = pvDataCreate->createPVScalarArray(pscalar); } static void testScalarArray(FILE * fd) { fprintf(fd,"\ntestScalarArray\n"); - testScalarArrayCommon(fd,String("boolean"),pvBoolean,false,false,true); - testScalarArrayCommon(fd,String("byte"),pvByte,true,true,true); - testScalarArrayCommon(fd,String("short"),pvShort,true,true,true); - testScalarArrayCommon(fd,String("int"),pvInt,true,true,true); - testScalarArrayCommon(fd,String("long"),pvLong,true,true,true); - testScalarArrayCommon(fd,String("float"),pvFloat,false,true,true); - testScalarArrayCommon(fd,String("double"),pvDouble,false,true,true); - testScalarArrayCommon(fd,String("string"),pvString,false,false,false); + testScalarArrayCommon(fd,pvBoolean,false,false,true); + testScalarArrayCommon(fd,pvByte,true,true,true); + testScalarArrayCommon(fd,pvShort,true,true,true); + testScalarArrayCommon(fd,pvInt,true,true,true); + testScalarArrayCommon(fd,pvLong,true,true,true); + testScalarArrayCommon(fd,pvFloat,false,true,true); + testScalarArrayCommon(fd,pvDouble,false,true,true); + testScalarArrayCommon(fd,pvString,false,false,false); } static void testSimpleStructure(FILE * fd) { fprintf(fd,"\ntestSimpleStructure\n"); String properties("alarm,timeStamp,display,control,valueAlarm"); - StructureConstPtr ptop = standardField->scalarValue(pvDouble,properties); + StructureConstPtr ptop = standardField->scalar(pvDouble,properties); builder.clear(); ptop->toString(&builder); fprintf(fd,"%s\n",builder.c_str()); // create tempory PVField so that memory can be released - PVField *pvField = pvDataCreate->createPVField(0,ptop); - delete pvField; + PVStructurePtr pvStructure = pvDataCreate->createPVStructure(ptop); } static StructureConstPtr createPowerSupply() { + size_t nfields = 3; String properties("alarm"); - FieldConstPtrArray powerSupply = new FieldConstPtr[3]; - powerSupply[0] = standardField->scalar( - String("voltage"),pvDouble,properties); - powerSupply[1] = standardField->scalar( - String("power"),pvDouble,properties); - powerSupply[2] = standardField->scalar( - String("current"),pvDouble,properties); - return standardField->structure( String("powerSupply"),3,powerSupply); + StringArray names; + names.reserve(nfields); + FieldConstPtrArray powerSupply; + powerSupply.reserve(nfields); + names.push_back("voltage"); + powerSupply.push_back(standardField->scalar(pvDouble,properties)); + names.push_back("power"); + powerSupply.push_back(standardField->scalar(pvDouble,properties)); + names.push_back("current"); + powerSupply.push_back(standardField->scalar(pvDouble,properties)); + return fieldCreate->createStructure(names,powerSupply); } static void testStructureArray(FILE * fd) { fprintf(fd,"\ntestStructureArray\n"); String properties("alarm,timeStamp"); StructureConstPtr powerSupply = createPowerSupply(); - StructureConstPtr top = standardField->structureArrayValue( + StructureConstPtr top = standardField->structureArray( powerSupply,properties); builder.clear(); top->toString(&builder); @@ -147,8 +148,6 @@ int main(int argc,char *argv[]) testScalarArray(fd); testSimpleStructure(fd); testStructureArray(fd); - epicsExitCallAtExits(); - CDRMonitor::get().show(fd,true); return(0); } diff --git a/testApp/pv/testPVAppend.cpp b/testApp/pv/testPVAppend.cpp index 33140df..8240939 100644 --- a/testApp/pv/testPVAppend.cpp +++ b/testApp/pv/testPVAppend.cpp @@ -21,15 +21,15 @@ #include #include #include -#include using namespace epics::pvData; +using std::tr1::static_pointer_cast; -static FieldCreate * fieldCreate = 0; -static PVDataCreate * pvDataCreate = 0; -static StandardField *standardField = 0; -static StandardPVField *standardPVField = 0; -static Convert *convert = 0; +static FieldCreatePtr fieldCreate; +static PVDataCreatePtr pvDataCreate; +static StandardFieldPtr standardField; +static StandardPVFieldPtr standardPVField; +static ConvertPtr convert; static String builder(""); static String alarmTimeStamp("alarm,timeStamp"); static String alarmTimeStampValueAlarm("alarm,timeStamp,valueAlarm"); @@ -37,87 +37,96 @@ static String allProperties("alarm,timeStamp,display,control,valueAlarm"); static void testAppendSimple(FILE * fd) { - FieldConstPtrArray fields = new FieldConstPtr[0]; - PVStructure *pvParent = pvDataCreate->createPVStructure( - 0,String("request"),0,fields); - PVString* pvStringField = static_cast( - pvDataCreate->createPVScalar(pvParent, "fieldList", pvString)); + PVFieldPtrArray fields; + StringArray names; + PVStructurePtr pvParent = pvDataCreate->createPVStructure(names,fields); + PVStringPtr pvStringField = static_pointer_cast( + pvDataCreate->createPVScalar(pvString)); pvStringField->put(String("value,timeStamp")); - pvParent->appendPVField(pvStringField); - builder.clear(); - pvParent->toString(&builder); - fprintf(fd,"%s\n",builder.c_str()); - pvStringField = static_cast( - pvDataCreate->createPVScalar(pvParent, "extra", pvString)); + PVFieldPtr pvField = pvStringField; + pvParent->appendPVField("fieldlist",pvField); + pvStringField = static_pointer_cast( + pvDataCreate->createPVScalar(pvString)); pvStringField->put(String("junk")); - pvParent->appendPVField(pvStringField); + pvField = pvStringField; + pvParent->appendPVField("extra",pvField); builder.clear(); pvParent->toString(&builder); fprintf(fd,"%s\n",builder.c_str()); - delete pvParent; } static void testAppendMore(FILE * fd) { - PVStructure* pvStructure = pvDataCreate->createPVStructure( - 0,"parent", 0); - PVStructure* pvChild1 = pvDataCreate->createPVStructure( - pvStructure, "child1", 0); - PVString *pvStringField = static_cast( - pvDataCreate->createPVScalar(pvChild1,"value", pvString)); + PVFieldPtrArray fields; + StringArray names; + PVStructurePtr pvStructure = pvDataCreate->createPVStructure(names,fields); + PVStructurePtr pvChild1 = pvDataCreate->createPVStructure(names,fields); + PVStringPtr pvStringField = static_pointer_cast( + pvDataCreate->createPVScalar(pvString)); pvStringField->put("bla"); - pvChild1->appendPVField(pvStringField); - pvStructure->appendPVField(pvChild1); - PVStructure* pvChild2 = pvDataCreate->createPVStructure( - pvStructure, "child2", 0); - pvStringField = static_cast( - pvDataCreate->createPVScalar(pvChild2,"value", pvString)); - pvStringField->put("bla"); - pvChild2->appendPVField(pvStringField); - pvStructure->appendPVField(pvChild2); + PVFieldPtr pvField = pvStringField; + pvChild1->appendPVField("value",pvField); + pvField = pvChild1; + pvStructure->appendPVField("child1",pvField); + PVStructurePtr pvChild2 = pvDataCreate->createPVStructure(names,fields); + pvStringField = static_pointer_cast( + pvDataCreate->createPVScalar(pvString)); + pvStringField->put("blabla"); + pvField = pvStringField; + pvChild2->appendPVField("value",pvField); + pvField = pvChild2; + pvStructure->appendPVField("child2",pvField); builder.clear(); pvStructure->toString(&builder); fprintf(fd,"%s\n",builder.c_str()); - delete pvStructure; } -static void append2(PVStructure* pvStructure, +static void append2(PVStructurePtr pvStructure, const char *oneName,const char *twoName, const char *oneValue,const char *twoValue) { - PVField* array[2]; - // make parent null to test setParent - PVString *pvStringField = static_cast( - pvDataCreate->createPVScalar(0,oneName, pvString)); - pvStringField->put(oneValue); - array[0] = pvStringField; - pvStringField = static_cast( - pvDataCreate->createPVScalar(0,twoName, pvString)); - pvStringField->put(twoValue); - array[1] = pvStringField; - pvStructure->appendPVFields(2,array); + PVFieldPtrArray pvFields; + pvFields.reserve(2); + StringArray names; + names.reserve(2); + PVStringPtr pvStringField = static_pointer_cast( + pvDataCreate->createPVScalar(pvString)); + pvStringField->put(oneValue); + names.push_back(oneName); + pvFields.push_back(pvStringField); + pvStringField = static_pointer_cast( + pvDataCreate->createPVScalar(pvString)); + pvStringField->put(twoValue); + names.push_back(twoName); + pvFields.push_back(pvStringField); + pvStructure->appendPVFields(names,pvFields); } static void testAppends(FILE * fd) { - PVField** array = new PVField*[2]; - // make parent null to test setParent - PVStructure* pvChild = pvDataCreate->createPVStructure( - 0, "child1", 0); + PVFieldPtrArray emptyPVFields; + StringArray emptyNames; + PVFieldPtrArray pvFields; + pvFields.reserve(2); + StringArray names; + names.reserve(2); + names.push_back("child1"); + PVStructurePtr pvChild = pvDataCreate->createPVStructure( + emptyNames,emptyPVFields); append2(pvChild,"Joe","Mary","Good Guy","Good Girl"); - array[0] = pvChild; + pvFields.push_back(pvChild); + names.push_back("child2"); pvChild = pvDataCreate->createPVStructure( - 0, "child2", 0); + emptyNames,emptyPVFields); append2(pvChild,"Bill","Jane","Bad Guy","Bad Girl"); - array[1] = pvChild; - PVStructure* pvStructure = pvDataCreate->createPVStructure( - 0,"parent", 2,array); + pvFields.push_back(pvChild); + PVStructurePtr pvStructure = pvDataCreate->createPVStructure( + names,pvFields); builder.clear(); pvStructure->toString(&builder); fprintf(fd,"%s\n",builder.c_str()); - PVField *pvField = pvStructure->getSubField("child2.Bill"); - assert(pvField!=0); - bool ok = pvField->renameField("Joe"); - assert(ok); + PVFieldPtr pvField = pvStructure->getSubField("child2.Bill"); + assert(pvField.get()!=0); + pvField->renameField("Joe"); builder.clear(); pvStructure->toString(&builder); fprintf(fd,"%s\n",builder.c_str()); @@ -125,7 +134,6 @@ static void testAppends(FILE * fd) builder.clear(); pvStructure->toString(&builder); fprintf(fd,"%s\n",builder.c_str()); - delete pvStructure; } int main(int argc,char *argv[]) @@ -144,8 +152,6 @@ int main(int argc,char *argv[]) testAppendSimple(fd); testAppendMore(fd); testAppends(fd); - epicsExitCallAtExits(); - CDRMonitor::get().show(fd,true); return(0); } diff --git a/testApp/pv/testPVAuxInfo.cpp b/testApp/pv/testPVAuxInfo.cpp index 750f178..2c4fda5 100644 --- a/testApp/pv/testPVAuxInfo.cpp +++ b/testApp/pv/testPVAuxInfo.cpp @@ -21,34 +21,35 @@ #include #include #include -#include using namespace epics::pvData; +using std::tr1::static_pointer_cast; -static FieldCreate * fieldCreate = 0; -static PVDataCreate * pvDataCreate = 0; -static StandardField *standardField = 0; -static StandardPVField *standardPVField = 0; -static Convert *convert = 0; -static String buffer(""); +static FieldCreatePtr fieldCreate; +static PVDataCreatePtr pvDataCreate; +static StandardFieldPtr standardField; +static StandardPVFieldPtr standardPVField; +static ConvertPtr convert; +static String buffer; -static void printOffsets(PVStructure *pvStructure,FILE *fd) +static void printOffsets(PVStructurePtr pvStructure,FILE *fd) { - fprintf(fd,"%s offset %d next %d number %d\n", - pvStructure->getField()->getFieldName().c_str(), - pvStructure->getFieldOffset(), - pvStructure->getNextFieldOffset(), - pvStructure->getNumberFields()); + fprintf(fd,"%s offset %lu next %lu number %lu\n", + pvStructure->getFieldName().c_str(), + (long unsigned)pvStructure->getFieldOffset(), + (long unsigned)pvStructure->getNextFieldOffset(), + (long unsigned)pvStructure->getNumberFields()); PVFieldPtrArray fields = pvStructure->getPVFields(); int number = pvStructure->getStructure()->getNumberFields(); for(int i=0; igetField()->getType()==structure) { - printOffsets((PVStructure *)pvField,fd); + PVStructurePtr xxx = static_pointer_cast(pvField); + printOffsets(xxx,fd); continue; } fprintf(fd,"%s offset %d next %d number %d\n", - pvField->getField()->getFieldName().c_str(), + pvField->getFieldName().c_str(), pvField->getFieldOffset(), pvField->getNextFieldOffset(), pvField->getNumberFields()); @@ -57,26 +58,25 @@ 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,control")); - PVStructure *displayLimit = pvStructure->getStructureField( - String("display.limit")); - assert(displayLimit!=0); - PVAuxInfo *auxInfo = displayLimit->getPVAuxInfo(); - auxInfo->createInfo(String("factory"),pvString); - auxInfo->createInfo(String("junk"),pvDouble); - PVScalar *pscalar = auxInfo->getInfo(String("factory")); - assert(pscalar!=0); - convert->fromString(pscalar,String("factoryName")); - pscalar = auxInfo->getInfo(String("junk")); - assert(pscalar!=0); - convert->fromString(pscalar,String("3.0")); + PVStructurePtr pvStructure = standardPVField->scalar( + pvDouble,"alarm,timeStamp,display,control"); + PVStructurePtr display + = pvStructure->getStructureField("display"); + assert(display.get()!=NULL); + PVAuxInfoPtr auxInfo = display->getPVAuxInfo(); + auxInfo->createInfo("factory",pvString); + auxInfo->createInfo("junk",pvDouble); + PVScalarPtr pscalar = auxInfo->getInfo(String("factory")); + assert(pscalar.get()!=0); + convert->fromString(pscalar,"factoryName"); + pscalar = auxInfo->getInfo("junk"); + assert(pscalar.get()!=0); + convert->fromString(pscalar,"3.0"); buffer.clear(); pvStructure->toString(&buffer); fprintf(fd,"%s\n",buffer.c_str()); // now show field offsets printOffsets(pvStructure,fd); - delete pvStructure; } int main(int argc,char *argv[]) @@ -93,8 +93,6 @@ int main(int argc,char *argv[]) standardPVField = getStandardPVField(); convert = getConvert(); testPVAuxInfo(fd); - epicsExitCallAtExits(); - CDRMonitor::get().show(fd,true); return(0); } diff --git a/testApp/pv/testPVData.cpp b/testApp/pv/testPVData.cpp index 2fa6102..7be9181 100644 --- a/testApp/pv/testPVData.cpp +++ b/testApp/pv/testPVData.cpp @@ -21,15 +21,15 @@ #include #include #include -#include using namespace epics::pvData; +using std::tr1::static_pointer_cast; -static FieldCreate * fieldCreate = 0; -static PVDataCreate * pvDataCreate = 0; -static StandardField *standardField = 0; -static StandardPVField *standardPVField = 0; -static Convert *convert = 0; +static FieldCreatePtr fieldCreate; +static PVDataCreatePtr pvDataCreate; +static StandardFieldPtr standardField; +static StandardPVFieldPtr standardPVField; +static ConvertPtr convert; static String builder(""); static String alarmTimeStamp("alarm,timeStamp"); static String alarmTimeStampValueAlarm("alarm,timeStamp,valueAlarm"); @@ -37,38 +37,43 @@ static String allProperties("alarm,timeStamp,display,control,valueAlarm"); static void testAppend(FILE * fd) { - FieldConstPtrArray fields = new FieldConstPtr[0]; - PVStructure *pvParent = pvDataCreate->createPVStructure( - 0,String("request"),0,fields); - PVString* pvStringField = static_cast( - pvDataCreate->createPVScalar(pvParent, "fieldList", pvString)); + PVFieldPtrArray pvFields; + StringArray fieldNames; + PVStructurePtr pvParent = pvDataCreate->createPVStructure( + fieldNames,pvFields); + PVStringPtr pvStringField = static_pointer_cast( + pvDataCreate->createPVScalar(pvString)); pvStringField->put(String("value,timeStamp")); - pvParent->appendPVField(pvStringField); + PVFieldPtr pvField = pvStringField; + pvParent->appendPVField("request",pvField); builder.clear(); pvParent->toString(&builder); fprintf(fd,"%s\n",builder.c_str()); - delete pvParent; } static void testCreatePVStructure(FILE * fd) { - PVStructure * pv0 = standardPVField->scalarValue( - 0,pvDouble,alarmTimeStampValueAlarm); - PVScalar *pv1 = standardPVField->scalar(0,String("extra"),pvString); - PVFieldPtr *pvFields = new PVFieldPtr[2]; - pvFields[0] = pv0; - pvFields[1] = pv1; - PVStructure *pvParent = pvDataCreate->createPVStructure( - 0,String("top"),2,pvFields); + PVStructurePtr pv0 = standardPVField->scalar( + pvDouble,alarmTimeStampValueAlarm); + PVScalarPtr pv1 = pvDataCreate->createPVScalar(pvString); + PVFieldPtrArray pvFields; + StringArray fieldNames; + pvFields.reserve(2); + fieldNames.reserve(2); + fieldNames.push_back("value"); + fieldNames.push_back("extra"); + pvFields.push_back(pv0); + pvFields.push_back(pv1); + PVStructurePtr pvParent = pvDataCreate->createPVStructure( + fieldNames,pvFields); builder.clear(); pvParent->toString(&builder); fprintf(fd,"%s\n",builder.c_str()); - delete pvParent; } static void testPVScalarCommon(FILE * fd,String fieldName,ScalarType stype) { - PVScalar *pvScalar = standardPVField->scalar(0,fieldName,stype); + PVScalarPtr pvScalar = pvDataCreate->createPVScalar(stype); if(stype==pvBoolean) { convert->fromString(pvScalar,String("true")); } else { @@ -77,57 +82,56 @@ static void testPVScalarCommon(FILE * fd,String fieldName,ScalarType stype) builder.clear(); pvScalar->toString(&builder); fprintf(fd,"%s\n",builder.c_str()); - delete pvScalar; } static void testPVScalarWithProperties( FILE * fd,String fieldName,ScalarType stype) { - PVStructure *pvStructure = 0; + PVStructurePtr pvStructure; bool hasValueAlarm = false; bool hasDisplayControl = false; switch(stype) { case pvBoolean: { pvStructure = standardPVField->scalar( - 0,fieldName,stype,alarmTimeStampValueAlarm); + stype,alarmTimeStampValueAlarm); hasValueAlarm = true; - PVBoolean *pvField = pvStructure->getBooleanField(String("value")); + PVBooleanPtr pvField = pvStructure->getBooleanField("value"); pvField->put(true); break; } case pvByte: { pvStructure = standardPVField->scalar( - 0,fieldName,stype,allProperties); + stype,allProperties); hasValueAlarm = true; hasDisplayControl = true; - PVByte *pvField = pvStructure->getByteField(String("value")); + PVBytePtr pvField = pvStructure->getByteField("value"); pvField->put(127); break; } case pvShort: { pvStructure = standardPVField->scalar( - 0,fieldName,stype,allProperties); + stype,allProperties); hasValueAlarm = true; hasDisplayControl = true; - PVShort *pvField = pvStructure->getShortField(String("value")); + PVShortPtr pvField = pvStructure->getShortField("value"); pvField->put(32767); break; } case pvInt: { pvStructure = standardPVField->scalar( - 0,fieldName,stype,allProperties); + stype,allProperties); hasValueAlarm = true; hasDisplayControl = true; - PVInt *pvField = pvStructure->getIntField(String("value")); + PVIntPtr pvField = pvStructure->getIntField("value"); pvField->put((int)0x80000000); break; } case pvLong: { pvStructure = standardPVField->scalar( - 0,fieldName,stype,allProperties); + stype,allProperties); hasValueAlarm = true; hasDisplayControl = true; - PVLong *pvField = pvStructure->getLongField(String("value")); + PVLongPtr pvField = pvStructure->getLongField("value"); int64 value = 0x80000000; value <<= 32; value |= 0xffffffff; @@ -136,79 +140,81 @@ static void testPVScalarWithProperties( } case pvFloat: { pvStructure = standardPVField->scalar( - 0,fieldName,stype,allProperties); + stype,allProperties); hasValueAlarm = true; hasDisplayControl = true; - PVFloat *pvField = pvStructure->getFloatField(String("value")); + PVFloatPtr pvField = pvStructure->getFloatField("value"); pvField->put(1.123e8); break; } case pvDouble: { pvStructure = standardPVField->scalar( - 0,fieldName,stype,allProperties); + stype,allProperties); hasValueAlarm = true; hasDisplayControl = true; - PVDouble *pvField = pvStructure->getDoubleField(String("value")); + PVDoublePtr pvField = pvStructure->getDoubleField("value"); pvField->put(1.123e35); break; } case pvString: { pvStructure = standardPVField->scalar( - 0,fieldName,stype,alarmTimeStamp); - PVString *pvField = pvStructure->getStringField(String("value")); + stype,allProperties); + PVStringPtr pvField = pvStructure->getStringField("value"); pvField->put(String("this is a string")); break; } } - PVLong *seconds = pvStructure->getLongField( + PVLongPtr seconds = pvStructure->getLongField( String("timeStamp.secondsPastEpoch")); assert(seconds!=0); seconds->put(123456789); - PVInt *nano = pvStructure->getIntField(String("timeStamp.nanoSeconds")); + PVIntPtr nano = pvStructure->getIntField(String("timeStamp.nanoSeconds")); assert(nano!=0); nano->put(1000000); - PVInt *severity = pvStructure->getIntField(String("alarm.severity")); + PVIntPtr severity = pvStructure->getIntField(String("alarm.severity")); assert(severity!=0); severity->put(2); - PVString *message = pvStructure->getStringField(String("alarm.message")); + PVStringPtr message = pvStructure->getStringField(String("alarm.message")); assert(message!=0); message->put(String("messageForAlarm")); if(hasDisplayControl) { - PVString *desc = pvStructure->getStringField( + PVStringPtr desc = pvStructure->getStringField( String("display.description")); assert(desc!=0); desc->put(String("this is a description")); - PVString *format = pvStructure->getStringField( + PVStringPtr format = pvStructure->getStringField( String("display.format")); assert(format!=0); format->put(String("f10.2")); - PVString *units = pvStructure->getStringField( + PVStringPtr units = pvStructure->getStringField( String("display.units")); assert(units!=0); units->put(String("SomeUnits")); - PVDouble *limit = pvStructure->getDoubleField( - String("display.limit.low")); + PVDoublePtr limit = pvStructure->getDoubleField( + String("display.limitLow")); assert(limit!=0); limit->put(0.0); limit = pvStructure->getDoubleField( - String("display.limit.high")); + String("display.limitHigh")); assert(limit!=0); limit->put(10.0); limit = pvStructure->getDoubleField( - String("control.limit.low")); + String("control.limitLow")); assert(limit!=0); limit->put(1.0); limit = pvStructure->getDoubleField( - String("control.limit.high")); + String("control.limitHigh")); assert(limit!=0); limit->put(9.0); - PVScalar *pvtemp = (PVScalar *)pvStructure->getSubField( + PVFieldPtr pvField = pvStructure->getSubField( String("valueAlarm.lowAlarmLimit")); - assert(pvtemp!=0); + PVScalarPtr pvtemp = static_pointer_cast(pvField); + assert(pvtemp.get()!=0); convert->fromDouble(pvtemp,1.0); - pvtemp = (PVScalar *)pvStructure->getSubField( + pvField = pvStructure->getSubField( String("valueAlarm.highAlarmLimit")); - assert(pvtemp!=0); + pvtemp = static_pointer_cast(pvField); + assert(pvtemp.get()!=0); convert->fromDouble(pvtemp,9.0); severity = pvStructure->getIntField( String("valueAlarm.lowAlarmSeverity")); @@ -218,7 +224,7 @@ static void testPVScalarWithProperties( String("valueAlarm.highAlarmSeverity")); assert(severity!=0); severity->put(2); - PVBoolean *active = pvStructure->getBooleanField( + PVBooleanPtr active = pvStructure->getBooleanField( String("valueAlarm.active")); assert(active!=0); active->put(true); @@ -226,7 +232,6 @@ static void testPVScalarWithProperties( builder.clear(); pvStructure->toString(&builder); fprintf(fd,"%s\n",builder.c_str()); - delete pvStructure; } static void testPVScalar(FILE * fd) { @@ -250,24 +255,30 @@ static void testPVScalar(FILE * fd) { testPVScalarWithProperties(fd,String("string"),pvString); } + static void testScalarArrayCommon(FILE * fd,String fieldName,ScalarType stype) { - PVStructure *pvStructure = standardPVField->scalarArray( - 0,fieldName,stype,alarmTimeStamp); - PVScalarArray *scalarArray = pvStructure->getScalarArrayField( - String("value"),stype); - assert(scalarArray!=0); + PVStructurePtr pvStructure = standardPVField->scalarArray( + stype,alarmTimeStamp); + PVScalarArrayPtr scalarArray = pvStructure->getScalarArrayField( + "value",stype); + assert(scalarArray.get()!=0); if(stype==pvBoolean) { - String values[] = {String("true"),String("false"),String("true")}; + StringArray values(3); + values[0] = "true"; + values[1] = "false"; + values[2] = "true"; convert->fromStringArray(scalarArray, 0,3,values,0); } else { - String values[] = {String("0"),String("1"),String("2")}; + StringArray values(3); + values[0] = "0"; + values[1] = "1"; + values[2] = "2"; convert->fromStringArray(scalarArray, 0,3,values,0); } builder.clear(); pvStructure->toString(&builder); fprintf(fd,"%s\n",builder.c_str()); - delete pvStructure; } static void testScalarArray(FILE * fd) { @@ -282,7 +293,6 @@ static void testScalarArray(FILE * fd) { testScalarArrayCommon(fd,String("string"),pvString); } - int main(int argc,char *argv[]) { char *fileName = 0; @@ -300,8 +310,6 @@ int main(int argc,char *argv[]) testCreatePVStructure(fd); testPVScalar(fd); testScalarArray(fd); - epicsExitCallAtExits(); - CDRMonitor::get().show(fd,true); return(0); } diff --git a/testApp/pv/testPVStructureArray.cpp b/testApp/pv/testPVStructureArray.cpp index af4c042..cb38421 100644 --- a/testApp/pv/testPVStructureArray.cpp +++ b/testApp/pv/testPVStructureArray.cpp @@ -20,36 +20,38 @@ #include #include #include -#include using namespace epics::pvData; -static FieldCreate * fieldCreate = 0; -static PVDataCreate * pvDataCreate = 0; -static StandardField *standardField = 0; -static StandardPVField *standardPVField = 0; -static String buffer(""); +static FieldCreatePtr fieldCreate; +static PVDataCreatePtr pvDataCreate; +static StandardFieldPtr standardField; +static StandardPVFieldPtr standardPVField; +static String buffer; StructureConstPtr getPowerSupplyStructure() { String properties("alarm"); - FieldConstPtrArray powerSupply = new FieldConstPtr[3]; - powerSupply[0] = standardField->scalar( - String("voltage"),pvDouble,properties); - powerSupply[1] = standardField->scalar( - String("power"),pvDouble,properties); - powerSupply[2] = standardField->scalar( - String("current"),pvDouble,properties); - StructureConstPtr structure = standardField->structure( - String("powerSupply"),3,powerSupply); + FieldConstPtrArray fields; + StringArray fieldNames; + fields.reserve(3); + fieldNames.reserve(3); + fieldNames.push_back("voltage"); + fieldNames.push_back("power"); + fieldNames.push_back("current"); + fields.push_back(standardField->scalar(pvDouble,properties)); + fields.push_back(standardField->scalar(pvDouble,properties)); + fields.push_back(standardField->scalar(pvDouble,properties)); + StructureConstPtr structure = fieldCreate->createStructure( + fieldNames,fields); return structure; } void testPowerSupplyArray(FILE * fd) { - PVStructure* powerSupplyArrayStruct = standardPVField->structureArray( - 0,"powerSupply",getPowerSupplyStructure(),String("alarm,timeStamp")); - PVStructureArray * powerSupplyArray = + PVStructurePtr powerSupplyArrayStruct = standardPVField->structureArray( + getPowerSupplyStructure(),String("alarm,timeStamp")); + PVStructureArrayPtr powerSupplyArray = powerSupplyArrayStruct->getStructureArrayField(String("value")); - assert(powerSupplyArray!=0); + assert(powerSupplyArray.get()!=NULL); int offset = powerSupplyArray->append(5); powerSupplyArray->setLength(offset); buffer.clear(); @@ -64,7 +66,6 @@ void testPowerSupplyArray(FILE * fd) { buffer.clear(); powerSupplyArrayStruct->toString(&buffer); fprintf(fd,"after compress%s\n",buffer.c_str()); - delete powerSupplyArrayStruct; } int main(int argc,char *argv[]) @@ -80,8 +81,6 @@ int main(int argc,char *argv[]) standardField = getStandardField(); standardPVField = getStandardPVField(); testPowerSupplyArray(fd); - epicsExitCallAtExits(); - CDRMonitor::get().show(fd,true); return(0); }