diff --git a/documentation/COPYRIGHT b/documentation/COPYRIGHT new file mode 100644 index 0000000..7dcbbf7 --- /dev/null +++ b/documentation/COPYRIGHT @@ -0,0 +1,7 @@ +/**************************************************** +Copyright (c) 2008 All rights reserved +Copyright (c) 2008 Martin R. Kraimer +COSYLAB (Control System Laboratory) + (Cosylab) Ljubljana Slovenia +Copyright 2010 Brookhaven National Laboratory +*************************************************** */ diff --git a/documentation/LICENSE b/documentation/LICENSE new file mode 100644 index 0000000..5683195 --- /dev/null +++ b/documentation/LICENSE @@ -0,0 +1,72 @@ +Copyright (c) 2008 Martin R. Kraimer +Copyright (c) 2007 Control System Laboratory, + (COSYLAB) Ljubljana Slovenia +Copyright 2010 Brookhaven National Laboratory + +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +________________________________________________________________________ + +This software is in part copyrighted by the University of Chicago (UofC) + +In no event shall UofC be liable to any party for direct, indirect, +special, incidental, or consequential damages arising out of the use of +this software, its documentation, or any derivatives thereof, even if +UofC has been advised of the possibility of such damage. + +UofC specifically disclaims any warranties, including, but not limited +to, the implied warranties of merchantability, fitness for a particular +purpose, and non-infringement. This software is provided on an "as is" +basis, and UofC has no obligation to provide maintenance, support, +updates, enhancements, or modifications. + +________________________________________________________________________ + +This software is in part copyrighted by the BERLINER SPEICHERRING +GESELLSCHAFT FUER SYNCHROTRONSTRAHLUNG M.B.H. (BESSY), BERLIN, GERMANY. + +In no event shall BESSY be liable to any party for direct, indirect, +special, incidental, or consequential damages arising out of the use of +this software, its documentation, or any derivatives thereof, even if +BESSY has been advised of the possibility of such damage. + +BESSY specifically disclaims any warranties, including, but not limited +to, the implied warranties of merchantability, fitness for a particular +purpose, and non-infringement. This software is provided on an "as is" +basis, and BESSY has no obligation to provide maintenance, support, +updates, enhancements, or modifications. + +________________________________________________________________________ + +This software is in part copyrighted by the Deutsches Elektronen-Synchroton, + Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY. + +In no event shall DESY be liable to any party for direct, indirect, +special, incidental, or consequential damages arising out of the use of +this software, its documentation, or any derivatives thereof, even if +DESY has been advised of the possibility of such damage. + +DESY specifically disclaims any warranties, including, but not limited +to, the implied warranties of merchantability, fitness for a particular +purpose, and non-infringement. This software is provided on an "as is" +basis, and DESY has no obligation to provide maintenance, support, +updates, enhancements, or modifications. +________________________________________________________________________ diff --git a/pvDataApp/factory/3058 b/pvDataApp/factory/3058 deleted file mode 100644 index 6c26c74..0000000 --- a/pvDataApp/factory/3058 +++ /dev/null @@ -1,3584 +0,0 @@ -/* Convert.cpp */ -#include -#include -#include -#include -#include "lock.h" -#include "pvIntrospect.h" -#include "pvData.h" -#include "convert.h" - -namespace epics { namespace pvData { - -static Convert* convert = 0; -static PVDataCreate* pvDataCreate = 0; - -static String trueString("true"); -static String falseString("false"); -static String logicError("Logic error. Should never get here."); -static String illegalScalarType("Illegal ScalarType"); - -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 void convertToString(StringBuilder buffer, - 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 std::vector split(String commaSeparatedList); - -static std::vector split(String commaSeparatedList) { - String::size_type numValues = 1; - String::size_type index=0; - while(true) { - String::size_type pos = commaSeparatedList.find(',',index); - if(pos==String::npos) break; - numValues++; - index = pos +1; - } - std::vector valueList(numValues,""); - index=0; - for(size_t i=0; iempty(); - *buf += pvField->getField()->getFieldName(); - PVStructure *parent; - while((parent=pvField->getParent())!=0) { - pvField = pvField->getParent(); - String name = pvField->getField()->getFieldName(); - if(name.length()>0) { - buf->insert(0,"."); - buf->insert(0,name); - } - } -} - -bool Convert::equals(PVField *a,PVField *b) -{ - return convertEquals(a,b); -} - -void Convert::getString(StringBuilder buf,PVField * pvField,int indentLevel) -{ - convertToString(buf,pvField,indentLevel); -} - -void Convert::getString(StringBuilder buf,PVField * pvField) -{ - convertToString(buf,pvField,0); -} - -void Convert::fromString(PVScalar *pvScalar, String from) -{ - ScalarConstPtr scalar = pvScalar->getScalar(); - ScalarType scalarType = scalar->getScalarType(); - switch(scalarType) { - case pvBoolean: { - PVBoolean *pv = (PVBoolean *)pvScalar; - bool value = - ((from.compare("true")==0) ? true : false); - pv->put(value); - return; - } - case pvByte : { - PVByte *pv = (PVByte*)pvScalar; - int ival; - sscanf(from.c_str(),"%d",&ival); - int8 value = ival; - pv->put(value); - return; - } - case pvShort : { - PVShort *pv = (PVShort*)pvScalar; - int ival; - sscanf(from.c_str(),"%d",&ival); - int16 value = ival; - pv->put(value); - return; - } - case pvInt : { - PVInt *pv = (PVInt*)pvScalar; - int ival; - sscanf(from.c_str(),"%d",&ival); - int32 value = ival; - pv->put(value); - return; - } - case pvLong : { - PVLong *pv = (PVLong*)pvScalar; - int64 ival; - sscanf(from.c_str(),"%lld",&ival); - int64 value = ival; - pv->put(value); - return; - } - case pvFloat : { - PVFloat *pv = (PVFloat*)pvScalar; - float value; - sscanf(from.c_str(),"%f",&value); - pv->put(value); - return; - } - case pvDouble : { - PVDouble*pv = (PVDouble*)pvScalar; - double value; - sscanf(from.c_str(),"%lf",&value); - pv->put(value); - return; - } - case pvString: { - PVString *value = (PVString*)pvScalar; - value->put(from); - return; - } - } - String message("Convert::fromString unknown scalarType "); - ScalarTypeFunc::toString(&message,scalarType); - throw std::logic_error(message); -} - -int Convert::fromString(PVScalarArray *pv, String from) -{ - if(from[0]=='[' && from[from.length()]==']') { - int 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) -{ - return convertFromStringArray(pv,offset,length,from,fromOffset); -} - -int Convert::toStringArray(PVScalarArray * pv, int offset, int length, - String to[], int toOffset) -{ - return convertToStringArray(pv,offset,length,to,toOffset); -} - -bool Convert::isCopyCompatible(FieldConstPtr from, FieldConstPtr to) -{ - if(from->getType()!=to->getType()) return false; - switch(from->getType()) { - case scalar: - return isCopyScalarCompatible((ScalarConstPtr)from,(ScalarConstPtr)to); - case scalarArray: - return isCopyScalarArrayCompatible((ScalarArrayConstPtr)from,(ScalarArrayConstPtr)to); - case structure: - return isCopyStructureCompatible((StructureConstPtr)from,(StructureConstPtr)to); - case structureArray: - return isCopyStructureArrayCompatible((StructureArrayConstPtr)from,(StructureArrayConstPtr)to); - } - String message("Convert::isCopyCompatible should never get here"); - throw std::logic_error(message); -} - -void Convert::copy(PVField *from,PVField *to) -{ - switch(from->getField()->getType()) { - case scalar: - copyScalar((PVScalar *)from,(PVScalar *)to); - return; - case scalarArray: { - PVScalarArray *fromArray = (PVScalarArray *)from; - PVScalarArray *toArray = (PVScalarArray *)to; - int length = copyScalarArray(fromArray,0,toArray,0,fromArray->getLength()); - if(toArray->getLength()!=length) toArray->setLength(length); - return; - } - case structure: - copyStructure((PVStructure *)from,(PVStructure *)to); - return; - case structureArray: { - PVStructureArray *fromArray = (PVStructureArray *)from; - PVStructureArray *toArray = (PVStructureArray *)to; - copyStructureArray(fromArray,toArray); - return; - } - } -} - -bool Convert::isCopyScalarCompatible( - ScalarConstPtr fromField, ScalarConstPtr toField) -{ - ScalarType fromScalarType = fromField->getScalarType(); - ScalarType toScalarType = toField->getScalarType(); - if(fromScalarType==toScalarType) return true; - if(ScalarTypeFunc::isNumeric(fromScalarType) - && ScalarTypeFunc::isNumeric(toScalarType)) return true; - if(fromScalarType==pvString) return true; - if(toScalarType==pvString) return true; - return false; -} - -void Convert::copyScalar(PVScalar *from, PVScalar *to) -{ - if(to->isImmutable()) { - if(from==to) return; - String message("Convert.copyScalar destination is immutable"); - throw std::invalid_argument(message); - } - ScalarType fromType = from->getScalar()->getScalarType(); - ScalarType toType = to->getScalar()->getScalarType(); - switch(fromType) { - case pvBoolean: { - if(toType!=pvBoolean) { - if(toType!=pvString) { - String message("Convert.copyScalar arguments are not compatible"); - throw std::invalid_argument(message); - } - } - PVBoolean *data = (PVBoolean*)from; - if(toType==pvString) { - PVString *dataTo = (PVString*)to; - String buf(""); - data->toString(&buf); - dataTo->put(buf); - } else { - bool value = data->get(); - PVBoolean *dataTo = (PVBoolean*)to; - dataTo->put(value); - } - break; - } - case pvByte : { - PVByte *data = (PVByte*)from; - int8 value = data->get(); - convert->fromByte(to,value); - break; - } - case pvShort : { - PVShort *data = (PVShort*)from; - short value = data->get(); - convert->fromShort(to,value); - break; - } - case pvInt :{ - PVInt *data = (PVInt*)from; - int value = data->get(); - convert->fromInt(to,value); - break; - } - case pvLong : { - PVLong *data = (PVLong*)from; - long value = data->get(); - convert->fromLong(to,value); - break; - } - case pvFloat : { - PVFloat *data = (PVFloat*)from; - float value = data->get(); - convert->fromFloat(to,value); - break; - } - case pvDouble : { - PVDouble *data = (PVDouble*)from; - double value = data->get(); - convert->fromDouble(to,value); - break; - } - case pvString: { - PVString *data = (PVString*)from; - String value = data->get(); - convert->fromString(to,value); - break; - } - } - String message("Convert::copyScalar should never get here"); - throw std::logic_error(message); -} - -bool Convert::isCopyScalarArrayCompatible(ScalarArrayConstPtr fromArray, - ScalarArrayConstPtr toArray) -{ - ScalarType fromType = fromArray->getElementType(); - ScalarType toType = toArray->getElementType(); - if(fromType==toType) return true; - if(ScalarTypeFunc::isNumeric(fromType) - && ScalarTypeFunc::isNumeric(toType)) return true; - if(toType==pvString) return true; - if(fromType==pvString) return true; - return false; -} - -int Convert::copyScalarArray(PVScalarArray *from, int offset, - PVScalarArray *to, int toOffset, int length) -{ - if(to->isImmutable()) { - if(from==to) return from->getLength(); - String message("Convert.copyArray destination is immutable"); - throw std::invalid_argument(message); - } - ScalarType fromElementType = from->getScalarArray()->getElementType(); - ScalarType toElementType = to->getScalarArray()->getElementType(); - - if(from->isImmutable() && (fromElementType==toElementType)) { - if(offset==0 && toOffset==0 && length==from->getLength()) { - return copyArrayDataReference(from,to); - } - } - - int ncopy = 0; - if(ScalarTypeFunc::isNumeric(fromElementType) - && ScalarTypeFunc::isNumeric(toElementType)) { - return copyNumericArray(from,offset,to,toOffset,length); - } else if(toElementType==pvBoolean && fromElementType==pvBoolean) { - PVBooleanArray *pvfrom = (PVBooleanArray*)from; - PVBooleanArray *pvto = (PVBooleanArray*)to; - while(length>0) { - int num = 0; - BooleanArray data = 0; - int fromOffset = 0; - BooleanArrayData booleanArrayData = BooleanArrayData(); - num = pvfrom->get(offset,length,&booleanArrayData); - data = booleanArrayData.data; - fromOffset = booleanArrayData.offset; - if(num<=0) return ncopy; - while(num>0) { - int n = pvto->put(toOffset,num,data,fromOffset); - if(n<=0) return ncopy; - length -= n; num -= n; ncopy+=n; offset += n; toOffset += n; - } - } - } else if(toElementType==pvString && fromElementType==pvString) { - PVStringArray *pvfrom = (PVStringArray*)from; - PVStringArray *pvto = (PVStringArray*)to; - while(length>0) { - int num = 0; - String *data; - int fromOffset = 0; - StringArrayData stringArrayData = StringArrayData(); - num = pvfrom->get(offset,length,&stringArrayData); - data = stringArrayData.data; - fromOffset = stringArrayData.offset; - if(num<=0) return ncopy; - while(num>0) { - int n = pvto->put(toOffset,num,data,fromOffset); - if(n<=0) return ncopy; - length -= n; num -= n; ncopy+=n; offset += n; toOffset += n; - } - } - } else if(toElementType==pvString) { - PVStringArray *pvto = (PVStringArray*)to; - ncopy = from->getLength(); - if(ncopy>length) ncopy = length; - int num = ncopy; - String toData[1]; - while(num>0) { - convert->toStringArray(from,offset,1,toData,0); - if(pvto->put(toOffset,1,toData,0)<=0) break; - num--; offset++; toOffset++; - } - return ncopy; - } else if(fromElementType==pvString) { - PVStringArray *pvfrom = (PVStringArray*)from; - while(length>0) { - int num = 0; - String *data = 0; - int fromOffset = 0; - StringArrayData stringArrayData = StringArrayData(); - num = pvfrom->get(offset,length,&stringArrayData); - data = stringArrayData.data; - fromOffset = stringArrayData.offset; - if(num<=0) return ncopy; - while(num>0) { - int n = fromStringArray(to,toOffset,num,data,fromOffset); - if(n<=0) return ncopy; - length -= n; num -= n; ncopy+=n; offset += n; toOffset += n; - } - } - } - String message("Convert::copyScalarArray should not get here"); - throw std::logic_error(message); -} - -bool Convert::isCopyStructureCompatible( - StructureConstPtr fromStruct, StructureConstPtr toStruct) -{ - FieldConstPtrArray fromFields = fromStruct->getFields(); - FieldConstPtrArray toFields = toStruct->getFields(); - int length = fromStruct->getNumberFields(); - if(length!=toStruct->getNumberFields()) return false; - for(int i=0; igetType(); - Type toType = to->getType(); - if(fromType!=toType) return false; - switch(fromType) { - case scalar: - if(!convert->isCopyScalarCompatible((ScalarConstPtr)from,(ScalarConstPtr)to)) return false; - break; - case scalarArray: - if(!isCopyScalarArrayCompatible((ScalarArrayConstPtr)from,(ScalarArrayConstPtr)to)) - return false; - break; - case structure: - if(!isCopyStructureCompatible((StructureConstPtr)from,(StructureConstPtr)to)) - return false; - break; - case structureArray: - if(!isCopyStructureArrayCompatible((StructureArrayConstPtr)from, - (StructureArrayConstPtr)to)) return false; - } - } - return true; -} - -void Convert::copyStructure(PVStructure *from, PVStructure *to) -{ - if(to->isImmutable()) { - if(from==to) return; - String message("Convert.copyStructure destination is immutable"); - throw std::invalid_argument(message); - } - if(from==to) return; - PVFieldPtrArray fromDatas = from->getPVFields(); - PVFieldPtrArray 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) { - // look for enumerated structure and copy choices first - String fieldName = fromDatas[0]->getField()->getFieldName(); - if(fieldName.compare("index")==0) { - FieldConstPtr fieldIndex = fromDatas[0]->getField(); - FieldConstPtr fieldChoices = fromDatas[1]->getField(); - if(fieldIndex->getType()==scalar - && fieldChoices->getFieldName().compare("choices") - && fieldChoices->getType()==scalarArray) { - PVScalar *pvScalar = (PVScalar*)fromDatas[0]; - PVScalarArray *pvArray = (PVScalarArray*)fromDatas[1]; - if((pvScalar->getScalar()->getScalarType()==pvInt) - && (pvArray->getScalarArray()->getElementType()==pvString)) { - PVScalarArray* toArray = (PVScalarArray*)toDatas[1]; - copyScalarArray(pvArray,0,toArray,0,pvArray->getLength()); - PVScalar *toScalar = (PVScalar*)toDatas[0]; - copyScalar(pvScalar,toScalar); - return; - } - } - } - } - for(int i=0; i < numberFields; i++) { - PVField *fromData = fromDatas[i]; - PVField *toData = toDatas[i]; - Type fromType = fromData->getField()->getType(); - Type toType = toData->getField()->getType(); - if(fromType!=toType) { - String message("Convert.copyStructure Illegal copyStructure"); - throw std::invalid_argument(message); - } - switch(fromType) { - case scalar: - copyScalar((PVScalar*)fromData,(PVScalar*)toData); - break; - case scalarArray: { - PVScalarArray *fromArray = (PVScalarArray*)fromData; - PVScalarArray *toArray = (PVScalarArray*)toData; - int length = copyScalarArray(fromArray,0,toArray,0,fromArray->getLength()); - if(toArray->getLength()!=length) toArray->setLength(length); - break; - } - case structure: - copyStructure((PVStructure*)fromData,(PVStructure*)toData); - break; - case structureArray: { - PVStructureArray *fromArray = (PVStructureArray*)fromData; - PVStructureArray *toArray = (PVStructureArray*)toData; - copyStructureArray(fromArray,toArray); - break; - } - } - } -} - -bool Convert::isCopyStructureArrayCompatible( - StructureArrayConstPtr from, StructureArrayConstPtr to) -{ - return isCopyStructureCompatible(from->getStructure(),to->getStructure()); -} - -void Convert::copyStructureArray( - PVStructureArray *from, PVStructureArray *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())) { - 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; - if(to->getCapacity()setCapacity(length); - to->get(0, length,&structureArrayData); - toArray = structureArrayData.data; - for(int i=0; igetStructureArray()->getStructure(); - toArray[i] = pvDataCreate->createPVStructure(0,structure); - } - copyStructure(fromArray[i],toArray[i]); - } - } - to->setLength(length); - 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 = (PVByte *)pv; - return value->get(); - } - case pvShort: { - PVShort *value = (PVShort *)pv; - return value->get(); - } - case pvInt: { - PVInt *value = (PVInt *)pv; - return value->get(); - } - case pvLong: { - PVLong *value = (PVLong *)pv; - return value->get(); - } - case pvFloat: { - PVFloat *value = (PVFloat *)pv; - return value->get(); - } - case pvDouble: { - PVDouble *value = (PVDouble *)pv; - return 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 = (PVByte *)pv; - return value->get(); - } - case pvShort: { - PVShort *value = (PVShort *)pv; - return value->get(); - } - case pvInt: { - PVInt *value = (PVInt *)pv; - return value->get(); - } - case pvLong: { - PVLong *value = (PVLong *)pv; - return value->get(); - } - case pvFloat: { - PVFloat *value = (PVFloat *)pv; - return value->get(); - } - case pvDouble: { - PVDouble *value = (PVDouble *)pv; - return 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 = (PVByte *)pv; - return value->get(); - } - case pvShort: { - PVShort *value = (PVShort *)pv; - return value->get(); - } - case pvInt: { - PVInt *value = (PVInt *)pv; - return value->get(); - } - case pvLong: { - PVLong *value = (PVLong *)pv; - return value->get(); - } - case pvFloat: { - PVFloat *value = (PVFloat *)pv; - return value->get(); - } - case pvDouble: { - PVDouble *value = (PVDouble *)pv; - return 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 = (PVByte *)pv; - return value->get(); - } - case pvShort: { - PVShort *value = (PVShort *)pv; - return value->get(); - } - case pvInt: { - PVInt *value = (PVInt *)pv; - return value->get(); - } - case pvLong: { - PVLong *value = (PVLong *)pv; - return value->get(); - } - case pvFloat: { - PVFloat *value = (PVFloat *)pv; - return value->get(); - } - case pvDouble: { - PVDouble *value = (PVDouble *)pv; - return 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 = (PVByte *)pv; - return value->get(); - } - case pvShort: { - PVShort *value = (PVShort *)pv; - return value->get(); - } - case pvInt: { - PVInt *value = (PVInt *)pv; - return value->get(); - } - case pvLong: { - PVLong *value = (PVLong *)pv; - return value->get(); - } - case pvFloat: { - PVFloat *value = (PVFloat *)pv; - return value->get(); - } - case pvDouble: { - PVDouble *value = (PVDouble *)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 = (PVByte *)pv; - return value->get(); - } - case pvShort: { - PVShort *value = (PVShort *)pv; - return value->get(); - } - case pvInt: { - PVInt *value = (PVInt *)pv; - return value->get(); - } - case pvLong: { - PVLong *value = (PVLong *)pv; - return value->get(); - } - case pvFloat: { - PVFloat *value = (PVFloat *)pv; - return value->get(); - } - case pvDouble: { - PVDouble *value = (PVDouble *)pv; - return value->get(); - } - case pvString: - throw std::logic_error(String("string can not be converted to double")); - } - throw std::logic_error(logicError); -} - -void Convert::fromByte(PVScalar *pv,int8 from) -{ - 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 = (PVByte *)pv; - value->put(from); return; - } - case pvShort: { - PVShort *value = (PVShort *)pv; - value->put(from); return; - } - case pvInt: { - PVInt *value = (PVInt *)pv; - value->put(from); return; - } - case pvLong: { - PVLong *value = (PVLong *)pv; - value->put(from); return; - } - case pvFloat: { - PVFloat *value = (PVFloat *)pv; - value->put(from); return; - } - case pvDouble: { - PVDouble *value = (PVDouble *)pv; - value->put(from); return; - } - case pvString: { - PVString *value = (PVString *)pv; - char buffer[20]; - int ival = from; - sprintf(buffer,"%d",ival); - String xxx(buffer); - value->put(xxx); - return; - } - } - throw std::logic_error(logicError); -} - -void Convert::fromShort(PVScalar *pv,int16 from) -{ - 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 = (PVByte *)pv; - value->put(from); return; - } - case pvShort: { - PVShort *value = (PVShort *)pv; - value->put(from); return; - } - case pvInt: { - PVInt *value = (PVInt *)pv; - value->put(from); return; - } - case pvLong: { - PVLong *value = (PVLong *)pv; - value->put(from); return; - } - case pvFloat: { - PVFloat *value = (PVFloat *)pv; - value->put(from); return; - } - case pvDouble: { - PVDouble *value = (PVDouble *)pv; - value->put(from); return; - } - case pvString: { - PVString *value = (PVString *)pv; - char buffer[20]; - int ival = from; - sprintf(buffer,"%d",ival); - String xxx(buffer); - value->put(xxx); - return; - } - } - throw std::logic_error(logicError); -} - -void Convert::fromInt(PVScalar *pv, int32 from) -{ - 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 = (PVByte *)pv; - value->put(from); return; - } - case pvShort: { - PVShort *value = (PVShort *)pv; - value->put(from); return; - } - case pvInt: { - PVInt *value = (PVInt *)pv; - value->put(from); return; - } - case pvLong: { - PVLong *value = (PVLong *)pv; - value->put(from); return; - } - case pvFloat: { - PVFloat *value = (PVFloat *)pv; - value->put(from); return; - } - case pvDouble: { - PVDouble *value = (PVDouble *)pv; - value->put(from); return; - } - case pvString: { - PVString *value = (PVString *)pv; - char buffer[20]; - int ival = from; - sprintf(buffer,"%d",ival); - String xxx(buffer); - value->put(xxx); - return; - } - } - throw std::logic_error(logicError); -} - -void Convert::fromLong(PVScalar *pv, int64 from) -{ - 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 = (PVByte *)pv; - value->put(from); return; - } - case pvShort: { - PVShort *value = (PVShort *)pv; - value->put(from); return; - } - case pvInt: { - PVInt *value = (PVInt *)pv; - value->put(from); return; - } - case pvLong: { - PVLong *value = (PVLong *)pv; - value->put(from); return; - } - case pvFloat: { - PVFloat *value = (PVFloat *)pv; - value->put(from); return; - } - case pvDouble: { - PVDouble *value = (PVDouble *)pv; - value->put(from); return; - } - case pvString: { - PVString *value = (PVString *)pv; - char buffer[20]; - int64 ival = from; - sprintf(buffer,"%lld",ival); - String xxx(buffer); - value->put(xxx); - return; - } - } - throw std::logic_error(logicError); -} - -void Convert::fromFloat(PVScalar* pv, float from) -{ - 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 = (PVByte *)pv; - value->put(from); return; - } - case pvShort: { - PVShort *value = (PVShort *)pv; - value->put(from); return; - } - case pvInt: { - PVInt *value = (PVInt *)pv; - value->put(from); return; - } - case pvLong: { - PVLong *value = (PVLong *)pv; - value->put(from); return; - } - case pvFloat: { - PVFloat *value = (PVFloat *)pv; - value->put(from); return; - } - case pvDouble: { - PVDouble *value = (PVDouble *)pv; - value->put(from); return; - } - case pvString: { - PVString *value = (PVString *)pv; - char buffer[20]; - double dval = from; - sprintf(buffer,"%g",dval); - String xxx(buffer); - value->put(xxx); - return; - } - } - throw std::logic_error(logicError); -} - -void Convert::fromDouble(PVScalar *pv, double from) -{ - 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 = (PVByte *)pv; - value->put(from); return; - } - case pvShort: { - PVShort *value = (PVShort *)pv; - value->put(from); return; - } - case pvInt: { - PVInt *value = (PVInt *)pv; - value->put(from); return; - } - case pvLong: { - PVLong *value = (PVLong *)pv; - value->put(from); return; - } - case pvFloat: { - PVFloat *value = (PVFloat *)pv; - value->put(from); return; - } - case pvDouble: { - PVDouble *value = (PVDouble *)pv; - value->put(from); return; - } - case pvString: { - PVString *value = (PVString *)pv; - char buffer[20]; - double dval = from; - sprintf(buffer,"%g",dval); - String xxx(buffer); - value->put(xxx); - return; - } - } - throw std::logic_error(logicError); -} - -int Convert::toByteArray(PVScalarArray * pv, int offset, int length, - int8 to[], int toOffset) -{ - return convertToByteArray(pv, offset, length, to, toOffset); -} - -int Convert::toShortArray(PVScalarArray * pv, int offset, int length, - int16 to[], int toOffset) -{ - return convertToShortArray(pv, offset, length, to, toOffset); -} - -int Convert::toIntArray(PVScalarArray * pv, int offset, int length, - int32 to[], int toOffset) -{ - return convertToIntArray(pv, offset, length, to, toOffset); -} - -int Convert::toLongArray(PVScalarArray * pv, int offset, int length, - int64 to[], int toOffset) -{ - return convertToLongArray(pv, offset, length, to, toOffset); -} - -int Convert::toFloatArray(PVScalarArray * pv, int offset, int length, - float to[], int toOffset) -{ - return convertToFloatArray(pv, offset, length, to, toOffset); -} - -int Convert::toDoubleArray(PVScalarArray * pv, int offset, int length, - double to[], int toOffset) -{ - return convertToDoubleArray(pv, offset, length, to, toOffset); -} - -int Convert::fromByteArray(PVScalarArray *pv, int offset, int length, - int8 from[], int fromOffset) -{ - return convertFromByteArray(pv, offset, length, from, fromOffset); -} - -int Convert::fromShortArray(PVScalarArray *pv, int offset, int length, - int16 from[], int fromOffset) -{ - return convertFromShortArray(pv, offset, length, from, fromOffset); -} - -int Convert::fromIntArray(PVScalarArray *pv, int offset, int length, - int32 from[], int fromOffset) -{ - return convertFromIntArray(pv, offset, length, from, fromOffset); -} - -int Convert::fromLongArray(PVScalarArray *pv, int offset, int length, - int64 from[], int fromOffset) -{ - return convertFromLongArray(pv, offset, length, from, fromOffset); -} - -int Convert::fromFloatArray(PVScalarArray *pv, int offset, int length, - float from[], int fromOffset) -{ - return convertFromFloatArray(pv, offset, length, from, fromOffset); -} - -int Convert::fromDoubleArray(PVScalarArray *pv, int offset, int length, - double from[], int fromOffset) -{ - return convertFromDoubleArray(pv, offset, length, from, fromOffset); -} - -void Convert::newLine(StringBuilder buffer, int indentLevel) -{ - *buffer += "\n"; - for(int i=0; igetScalar()->getScalarType(); - ScalarType bscalarType = b->getScalar()->getScalarType(); - if(ascalarType!=bscalarType) return false; - switch(ascalarType) { - case pvBoolean: { - PVBoolean *pa = (PVBoolean *)a; - PVBoolean *pb = (PVBoolean *)b; - bool avalue = pa->get(); - bool bvalue = pb->get(); - return ((avalue==bvalue) ? true : false); - } - case pvByte: { - PVByte *pa = (PVByte *)a; - PVByte *pb = (PVByte *)b; - int8 avalue = pa->get(); - int8 bvalue = pb->get(); - return ((avalue==bvalue) ? true : false); - } - case pvShort: { - PVShort *pa = (PVShort *)a; - PVShort *pb = (PVShort *)b; - int16 avalue = pa->get(); - int16 bvalue = pb->get(); - return ((avalue==bvalue) ? true : false); - } - case pvInt: { - PVInt *pa = (PVInt *)a; - PVInt *pb = (PVInt *)b; - int32 avalue = pa->get(); - int32 bvalue = pb->get(); - return ((avalue==bvalue) ? true : false); - } - case pvLong: { - PVLong *pa = (PVLong *)a; - PVLong *pb = (PVLong *)b; - int64 avalue = pa->get(); - int64 bvalue = pb->get(); - return ((avalue==bvalue) ? true : false); - } - case pvFloat: { - PVFloat *pa = (PVFloat *)a; - PVFloat *pb = (PVFloat *)b; - float avalue = pa->get(); - float bvalue = pb->get(); - return ((avalue==bvalue) ? true : false); - } - case pvDouble: { - PVDouble *pa = (PVDouble *)a; - PVDouble *pb = (PVDouble *)b; - double avalue = pa->get(); - double bvalue = pb->get(); - return ((avalue==bvalue) ? true : false); - } - case pvString: { - PVString *pa = (PVString *)a; - PVString *pb = (PVString *)b; - String avalue = pa->get(); - String bvalue = pb->get(); - return ((avalue==bvalue) ? true : false); - } - } - String message("should not get here"); - throw std::logic_error(message); -} - -static bool arrayEquals(PVScalarArray *a,PVScalarArray *b) -{ - if(a==b) return true; - ScalarType aType = a->getScalarArray()->getElementType(); - ScalarType bType = b->getScalarArray()->getElementType(); - if(aType!=bType) return false; - if(a->getLength()!=b->getLength()) return false; - int length = a->getLength(); - switch(aType) { - case pvBoolean: { - PVBooleanArray *aarray = (PVBooleanArray *)a; - PVBooleanArray *barray = (PVBooleanArray *)b; - BooleanArrayData adata = BooleanArrayData(); - BooleanArrayData bdata = BooleanArrayData(); - aarray->get(0,length,&adata); - barray->get(0,length,&bdata); - BooleanArray avalue = adata.data; - BooleanArray bvalue = bdata.data; - for(int i=0; iget(0,length,&adata); - barray->get(0,length,&bdata); - ByteArray avalue = adata.data; - ByteArray bvalue = bdata.data; - for(int i=0; iget(0,length,&adata); - barray->get(0,length,&bdata); - ShortArray avalue = adata.data; - ShortArray bvalue = bdata.data; - for(int i=0; iget(0,length,&adata); - barray->get(0,length,&bdata); - IntArray avalue = adata.data; - IntArray bvalue = bdata.data; - for(int i=0; iget(0,length,&adata); - barray->get(0,length,&bdata); - LongArray avalue = adata.data; - LongArray bvalue = bdata.data; - for(int i=0; iget(0,length,&adata); - barray->get(0,length,&bdata); - FloatArray avalue = adata.data; - FloatArray bvalue = bdata.data; - for(int i=0; iget(0,length,&adata); - barray->get(0,length,&bdata); - DoubleArray avalue = adata.data; - DoubleArray bvalue = bdata.data; - for(int i=0; iget(0,length,&adata); - barray->get(0,length,&bdata); - String *avalue = adata.data; - String *bvalue = bdata.data; - for(int i=0; igetStructureArray()->getStructure(); - StructureConstPtr bStructure = b->getStructureArray()->getStructure(); - if(aStructure!=bStructure) return false; - if(a->getLength()!=b->getLength()) return false; - StructureArrayData aData = StructureArrayData(); - StructureArrayData bData = StructureArrayData(); - int 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(); - if(length!=bStructure->getNumberFields()) return false; - PVFieldPtrArray aFields = a->getPVFields(); - PVFieldPtrArray bFields = b->getPVFields(); - for(int i=0; igetField()->getType(); - Type btype = b->getField()->getType(); - if(atype!=btype) return false; - if(atype==scalar) return scalarEquals((PVScalar *)a,(PVScalar *)b); - if(atype==scalarArray) { - return arrayEquals((PVScalarArray *)a,(PVScalarArray *)b); - } - if(atype==structureArray) { - return structureArrayEquals( - (PVStructureArray *)a,(PVStructureArray *)b); - } - if(atype==structure) { - return structureEquals((PVStructure *)a,(PVStructure *)b); - } - String message("should not get here"); - throw std::logic_error(message); -} - -int convertFromByteArray(PVScalarArray *pv, int offset, int len,int8 from[], int 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 = (PVByteArray*) 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 pvShort: { - PVShortArray *pvdata = (PVShortArray*) pv; - int16 data[1]; - while (len > 0) { - data[0] = (int16) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = (PVIntArray*) pv; - int32 data[1]; - while (len > 0) { - data[0] = (int32) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = (PVLongArray*) pv; - int64 data[1]; - while (len > 0) { - data[0] = (int64) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = (PVFloatArray*) pv; - float data[1]; - while (len > 0) { - data[0] = (float) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = (PVDoubleArray*) pv; - double data[1]; - while (len > 0) { - data[0] = (double) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvString: { - String message("convert from byte[] to StringArray not legal"); - throw std::invalid_argument(message); - } - } - String message("Convert::convertFromByteArray should never get here"); - throw std::logic_error(message); -} - -int convertToByteArray(PVScalarArray * pv, int offset, int len,int8 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 = (PVByteArray*) 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 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = (PVIntArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = (PVLongArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = (PVFloatArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = (PVDoubleArray*) 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] = (int8) 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 = (PVByteArray*) pv; - int8 data[1]; - while (len > 0) { - data[0] = (int8) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvShort: { - PVShortArray *pvdata = (PVShortArray*) 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 = (PVIntArray*) pv; - int32 data[1]; - while (len > 0) { - data[0] = (int32) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = (PVLongArray*) pv; - int64 data[1]; - while (len > 0) { - data[0] = (int64) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = (PVFloatArray*) pv; - float data[1]; - while (len > 0) { - data[0] = (float) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = (PVDoubleArray*) pv; - double data[1]; - while (len > 0) { - data[0] = (double) 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 = (PVByteArray*) 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 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = (PVIntArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = (PVLongArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = (PVFloatArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = (PVDoubleArray*) 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] = (int8) 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 = (PVByteArray*) pv; - int8 data[1]; - while (len > 0) { - data[0] = (int8) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvShort: { - PVShortArray *pvdata = (PVShortArray*) pv; - int16 data[1]; - while (len > 0) { - data[0] = (int16) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = (PVIntArray*) 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 = (PVLongArray*) pv; - int64 data[1]; - while (len > 0) { - data[0] = (int64) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = (PVFloatArray*) pv; - float data[1]; - while (len > 0) { - data[0] = (float) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = (PVDoubleArray*) pv; - double data[1]; - while (len > 0) { - data[0] = (double) 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 = (PVByteArray*) 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 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = (PVIntArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = (PVLongArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = (PVFloatArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = (PVDoubleArray*) 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] = (int8) 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 = (PVByteArray*) pv; - int8 data[1]; - while (len > 0) { - data[0] = (int8) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvShort: { - PVShortArray *pvdata = (PVShortArray*) pv; - int16 data[1]; - while (len > 0) { - data[0] = (int16) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = (PVIntArray*) pv; - int32 data[1]; - while (len > 0) { - data[0] = (int32) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = (PVLongArray*) 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 = (PVFloatArray*) pv; - float data[1]; - while (len > 0) { - data[0] = (float) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = (PVDoubleArray*) pv; - double data[1]; - while (len > 0) { - data[0] = (double) 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 = (PVByteArray*) 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 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = (PVIntArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = (PVLongArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = (PVFloatArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = (PVDoubleArray*) 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] = (int8) 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 = (PVByteArray*) pv; - int8 data[1]; - while (len > 0) { - data[0] = (int8) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvShort: { - PVShortArray *pvdata = (PVShortArray*) pv; - int16 data[1]; - while (len > 0) { - data[0] = (int16) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = (PVIntArray*) pv; - int32 data[1]; - while (len > 0) { - data[0] = (int32) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = (PVLongArray*) pv; - int64 data[1]; - while (len > 0) { - data[0] = (int64) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = (PVFloatArray*) 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 = (PVDoubleArray*) pv; - double data[1]; - while (len > 0) { - data[0] = (double) 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 = (PVByteArray*) 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 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = (PVIntArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = (PVLongArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = (PVFloatArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = (PVDoubleArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvString: { - String message("convert StringArray to float[]] not legal"); - throw std::invalid_argument(message); - } - } - String message("Convert::convertToFloatArray should never get here"); - throw std::logic_error(message); -} - -int convertFromDoubleArray(PVScalarArray *pv, int offset, int len,double from[], int 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 = (PVByteArray*) pv; - int8 data[1]; - while (len > 0) { - data[0] = (int8) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvShort: { - PVShortArray *pvdata = (PVShortArray*) pv; - int16 data[1]; - while (len > 0) { - data[0] = (int16) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = (PVIntArray*) pv; - int32 data[1]; - while (len > 0) { - data[0] = (int32) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = (PVLongArray*) pv; - int64 data[1]; - while (len > 0) { - data[0] = (int64) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = (PVFloatArray*) pv; - float data[1]; - while (len > 0) { - data[0] = (float) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = (PVDoubleArray*) 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); -} - -int convertToDoubleArray(PVScalarArray * pv, int offset, int len,double 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 = (PVByteArray*) 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 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = (PVIntArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = (PVLongArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = (PVFloatArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = (PVDoubleArray*) 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] = (int8) 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); -} - -int convertFromStringArray(PVScalarArray *pv, int offset, int len,String from[], int fromOffset) -{ - ScalarType elemType = pv->getScalarArray()->getElementType(); - int ntransfered = 0; - switch (elemType) { - case pvBoolean: { - PVBooleanArray *pvdata = (PVBooleanArray*) pv; - bool data[1]; - while (len > 0) { - String fromString = from[fromOffset]; - data[0] = (fromString.compare("true")==0) ? true : false; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvByte: { - PVByteArray *pvdata = (PVByteArray*) pv; - int8 data[1]; - while (len > 0) { - String fromString = from[fromOffset]; - int ival; - sscanf(fromString.c_str(),"%d",&ival); - data[0] = ival; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvShort: { - PVShortArray *pvdata = (PVShortArray*) pv; - int16 data[1]; - while (len > 0) { - String fromString = from[fromOffset]; - int ival; - sscanf(fromString.c_str(),"%d",&ival); - data[0] = ival; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = (PVIntArray*) pv; - int32 data[1]; - while (len > 0) { - String fromString = from[fromOffset]; - int ival; - sscanf(fromString.c_str(),"%d",&ival); - data[0] = ival; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = (PVLongArray*) pv; - int64 data[1]; - while (len > 0) { - String fromString = from[fromOffset]; - int64 ival; - sscanf(fromString.c_str(),"%lld",&ival); - data[0] = ival; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = (PVFloatArray*) pv; - float data[1]; - while (len > 0) { - String fromString = from[fromOffset]; - float fval; - sscanf(fromString.c_str(),"%f",&fval); - data[0] = fval; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = (PVDoubleArray*) pv; - double data[1]; - while (len > 0) { - String fromString = from[fromOffset]; - double fval; - sscanf(fromString.c_str(),"%lf",&fval); - data[0] = fval; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvString: - PVStringArray *pvdata = (PVStringArray*) 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; - } - String message("Convert::convertFromStringArray should never get here"); - throw std::logic_error(message); -} - -int convertToStringArray(PVScalarArray * pv, int offset, int len,String to[], int toOffset) -{ - ScalarType elementType = pv->getScalarArray()->getElementType(); - int ncopy = pv->getLength(); - if (ncopy > len) ncopy = len; - int num = ncopy; - switch (elementType) { - case pvBoolean: { - PVBooleanArray *pvdata = (PVBooleanArray*) pv; - BooleanArrayData data = BooleanArrayData(); - for (int 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; - } else { - to[toOffset + i] = "bad pv"; - } - } - } - break; - case pvByte: { - PVByteArray *pvdata = (PVByteArray*) pv; - ByteArrayData data = ByteArrayData(); - char cr[30]; - for (int 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); - to[toOffset + i] = String(cr); - } else { - to[toOffset + i] = "bad pv"; - } - } - } - break; - case pvShort: { - PVShortArray *pvdata = (PVShortArray*) pv; - ShortArrayData data = ShortArrayData(); - char cr[30]; - for (int 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); - to[toOffset + i] = String(cr); - } else { - to[toOffset + i] = "bad pv"; - } - } - } - break; - case pvInt: { - PVIntArray *pvdata = (PVIntArray*) pv; - IntArrayData data = IntArrayData(); - char cr[30]; - for (int 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); - to[toOffset + i] = String(cr); - } else { - to[toOffset + i] = "bad pv"; - } - } - } - break; - case pvLong: { - PVLongArray *pvdata = (PVLongArray*) pv; - LongArrayData data = LongArrayData(); - char cr[30]; - for (int 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); - to[toOffset + i] = String(cr); - } else { - to[toOffset + i] = "bad pv"; - } - } - } - break; - case pvFloat: { - PVFloatArray *pvdata = (PVFloatArray*) pv; - FloatArrayData data = FloatArrayData(); - char cr[30]; - for (int 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); - to[toOffset + i] = String(cr); - } else { - to[toOffset + i] = "bad pv"; - } - } - } - break; - case pvDouble: { - PVDoubleArray *pvdata = (PVDoubleArray*) pv; - DoubleArrayData data = DoubleArrayData(); - char cr[30]; - for (int 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); - to[toOffset + i] = String(cr); - } else { - to[toOffset + i] = "bad pv"; - } - } - } - break; - case pvString: { - PVStringArray *pvdata = (PVStringArray*) 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; - dataOffset = stringArrayData.offset; - if (numnow <= 0) { - for (int i = 0; i < num; i++) - to[toOffset + i] = "bad pv"; - break; - } - for(int i=0; igetField()->getType(); - if(type==scalarArray) { - return convertArray(buffer,(PVScalarArray *)pv,indentLevel); - } - if(type==structure) { - return convertStructure(buffer,(PVStructure*)pv,indentLevel); - } - if(type==structureArray) { - return convertStructureArray(buffer,(PVStructureArray*)pv,indentLevel); - } - ScalarConstPtr pscalar = pvScalar->getScalar(); - ScalarType scalarType = pscalar->getScalarType(); - ScalarTypeFunction::toString(buffer,scalarType); - *buffer += " "; - *buffer += scalar->getFieldName(); - PVScalar *pvScalar = (PVScalar*)pv; - *buffer += " "; - switch(scalarType) { - case pvBoolean: { - PVBoolean *data = (PVBoolean*)pv; - bool value = data->get(); - if(value) { - *buffer += "true"; - } else { - *buffer += "false"; - } - } - return; - case pvByte: { - PVByte *data = (PVByte*)pv; - char xxx[30]; - sprintf(xxx,"%d",(int)data->get()); - *buffer += xxx; - } - return; - case pvShort: { - PVShort *data = (PVShort*)pv; - char xxx[30]; - sprintf(xxx,"%d",(int)data->get()); - *buffer += xxx; - } - return; - case pvInt: { - PVInt *data = (PVInt*)pv; - char xxx[30]; - sprintf(xxx,"%d",(int)data->get()); - *buffer += xxx; - } - return; - case pvLong: { - PVLong *data = (PVLong*)pv; - char xxx[30]; - sprintf(xxx,"%lld",(int64)data->get()); - *buffer += xxx; - } - return; - case pvFloat: { - PVFloat *data = (PVFloat*)pv; - char xxx[30]; - sprintf(xxx,"%g",data->get()); - *buffer += xxx; - } - return; - case pvDouble: { - PVDouble *data = (PVDouble*)pv; - char xxx[30]; - sprintf(xxx,"%lg",data->get()); - *buffer += xxx; - } - return; - case pvString: { - PVString *data = (PVString*)pv; - *buffer += data->get(); - } - return; - default: - *buffer += "unknown ScalarType"; - } -} - -void convertStructure(StringBuilder buffer,PVStructure *data,int indentLevel) -{ - convert->newLine(buffer, indentLevel); - *buffer += "structure {"; - PVFieldPtrArray fieldsData = data->getPVFields(); - if (fieldsData != 0) { - int length = data->getStructure()->getNumberFields(); - for(int i=0; igetField(); - convert->newLine(buffer, indentLevel + 1); - int size = fieldnow->getFieldName().length(); - char buff[size+2]; - sprintf(buff,"%s = ",fieldnow->getFieldName().c_str()); - *buffer += buff; - convert->getString(buffer,fieldField,indentLevel + 1); - } - } - convert->newLine(buffer, indentLevel); - *buffer += "}"; -} - -void convertArray(StringBuilder buffer,PVScalarArray * pv,int indentLevel) -{ - ScalarArrayConstPtr array = pv->getScalarArray(); - ScalarType type = array->getElementType(); - switch(type) { - case pvBoolean: { - PVBooleanArray *pvdata = (PVBooleanArray*)pv; - BooleanArrayData data = BooleanArrayData(); - *buffer += "["; - for(int i=0; i < pvdata->getLength(); i++) { - if(i!=0) *buffer += ","; - int num = pvdata->get(i,1,&data); - if(num==1) { - BooleanArray value = data.data; - if(value[data.offset]) { - *buffer += "true"; - } else { - *buffer += "false"; - } - } else { - *buffer += "???? "; - } - } - *buffer += "]"; - break; - } - case pvByte: { - PVByteArray *pvdata = (PVByteArray*)pv; - ByteArrayData data = ByteArrayData(); - *buffer += "["; - for(int i=0; i < pvdata->getLength(); i++) { - if(i!=0) *buffer += ","; - int num = pvdata->get(i,1,&data); - if(num==1) { - int val = data.data[data.offset]; - char buf[16]; - sprintf(buf,"%d",val); - *buffer += buf; - } else { - *buffer += "???? "; - } - } - *buffer += "]"; - break; - } - case pvShort: { - PVShortArray *pvdata = (PVShortArray*)pv; - ShortArrayData data = ShortArrayData(); - *buffer += "["; - for(int i=0; i < pvdata->getLength(); i++) { - if(i!=0) *buffer += ','; - int num = pvdata->get(i,1,&data); - if(num==1) { - int val = data.data[data.offset]; - char buf[16]; - sprintf(buf,"%d",val); - *buffer += buf; - } else { - *buffer += "???? "; - } - } - *buffer += "]"; - break; - } - case pvInt: { - PVIntArray *pvdata = (PVIntArray*)pv; - IntArrayData data = IntArrayData(); - *buffer += "["; - for(int i=0; i < pvdata->getLength(); i++) { - if(i!=0) *buffer += ','; - int num = pvdata->get(i,1,&data); - if(num==1) { - int val = data.data[data.offset]; - char buf[16]; - sprintf(buf,"%d",val); - *buffer += buf; - } else { - *buffer += "???? "; - } - } - *buffer += "]"; - break; - } - case pvLong: { - PVLongArray *pvdata = (PVLongArray*)pv; - LongArrayData data = LongArrayData(); - *buffer += "["; - for(int i=0; i < pvdata->getLength(); i++) { - if(i!=0) *buffer += ','; - int num = pvdata->get(i,1,&data); - if(num==1) { - int64 val = data.data[data.offset]; - char buf[16]; - sprintf(buf,"%lld",val); - *buffer += buf; - } else { - *buffer += "???? "; - } - } - *buffer += "]"; - break; - } - case pvFloat: { - PVFloatArray *pvdata = (PVFloatArray*)pv; - FloatArrayData data = FloatArrayData(); - *buffer += "["; - for(int i=0; i < pvdata->getLength(); i++) { - if(i!=0) *buffer += ','; - int num = pvdata->get(i,1,&data); - if(num==1) { - float val = data.data[data.offset]; - char buf[16]; - sprintf(buf,"%g",val); - *buffer += buf; - } else { - *buffer += "???? "; - } - } - *buffer += "]"; - break; - } - case pvDouble: { - PVDoubleArray *pvdata = (PVDoubleArray*)pv; - DoubleArrayData data = DoubleArrayData(); - *buffer += "["; - for(int i=0; i < pvdata->getLength(); i++) { - if(i!=0) *buffer += ','; - int num = pvdata->get(i,1,&data); - if(num==1) { - double val = data.data[data.offset]; - char buf[16]; - sprintf(buf,"%lg",val); - *buffer += buf; - } else { - *buffer += "???? "; - } - } - *buffer += ("]"); - break; - } - case pvString: { - PVStringArray *pvdata = (PVStringArray*)pv; - StringArrayData data = StringArrayData(); - *buffer += "["; - for(int i=0; i < pvdata->getLength(); i++) { - if(i!=0) *buffer += ","; - int num = pvdata->get(i,1,&data); - StringPtrArray value = data.data; - if(num==1) { - if(value[data.offset].length()>0) { - *buffer += value[data.offset].c_str(); - } else { - *buffer += "null"; - } - } else { - *buffer += "null"; - } - } - *buffer += "]"; - break; - } - default: - *buffer += " array element is unknown ScalarType"; - } - if(pv->isImmutable()) { - *buffer += " immutable "; - } -} - -void convertStructureArray(StringBuilder buffer, - PVStructureArray * pvdata,int indentLevel) -{ - StructureArrayData data = StructureArrayData(); - int length = pvdata->getLength(); - pvdata->get(0, length, &data); - *buffer += "["; - for (int i = 0; i < length; i++) { - if (i != 0) { - *buffer += ","; - } - convert->newLine(buffer, indentLevel + 1); - PVStructure *pvStructure = data.data[i]; - if (pvStructure == 0) { - *buffer += "null"; - } else { - pvStructure->toString(buffer,indentLevel+1); - } - } - convert->newLine(buffer, indentLevel); - *buffer += "]"; -} - -int 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()); - 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()); - 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()); - 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()); - 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()); - 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()); - 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()); - 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()); - break; - } - } - to->setImmutable(); - return from->getLength(); -} - -int copyNumericArray(PVScalarArray *from, int offset, PVScalarArray *to, int toOffset, int len) -{ - ScalarType fromElementType = from->getScalarArray()->getElementType(); - int 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; - if (num <= 0) break; - while (num > 0) { - int n = convert->fromByteArray( - to, toOffset, num, data, dataOffset); - if (n <= 0) break; - len -= n; - num -= n; - ncopy += n; - offset += n; - toOffset += n; - } - } - break; - } - 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; - if (num <= 0) break; - while (num > 0) { - int n = convert->fromShortArray( - to, toOffset, num, data, dataOffset); - if (n <= 0) break; - len -= n; - num -= n; - ncopy += n; - offset += n; - toOffset += n; - } - } - break; - } - 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; - if (num <= 0) break; - while (num > 0) { - int n = convert->fromIntArray( - to, toOffset, num, data, dataOffset); - if (n <= 0) break; - len -= n; - num -= n; - ncopy += n; - offset += n; - toOffset += n; - } - } - break; - } - 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; - if (num <= 0) break; - while (num > 0) { - int n = convert->fromLongArray( - to, toOffset, num, data, dataOffset); - if (n <= 0) break; - len -= n; - num -= n; - ncopy += n; - offset += n; - toOffset += n; - } - } - break; - } - case pvFloat: { - PVFloatArray *pvfrom = (PVFloatArray*) from; - while (len > 0) { - int num = 0; - FloatArrayData floatArrayData = FloatArrayData(); - num = pvfrom->get(offset, len, &floatArrayData); - FloatArray data = floatArrayData.data; - int dataOffset = floatArrayData.offset; - if (num <= 0) break; - while (num > 0) { - int n = convert->fromFloatArray( - to, toOffset, num, data, dataOffset); - if (n <= 0) break; - len -= n; - num -= n; - ncopy += n; - offset += n; - toOffset += n; - } - } - break; - } - case pvDouble: { - PVDoubleArray *pvfrom = (PVDoubleArray*) from; - while (len > 0) { - int num = 0; - DoubleArrayData doubleArrayData = DoubleArrayData(); - num = pvfrom->get(offset, len, &doubleArrayData); - DoubleArray data = doubleArrayData.data; - int dataOffset = doubleArrayData.offset; - if (num <= 0) break; - while (num > 0) { - int n = convert->fromDoubleArray( - to, toOffset, num, data, dataOffset); - if (n <= 0) break; - len -= n; - num -= n; - ncopy += n; - offset += n; - toOffset += n; - } - } - break; - } - case pvString: - throw std::logic_error(String("PVStringArray is not a numeric array")); - } - return ncopy; -} - -class ConvertExt : public Convert { -public: - ConvertExt(): Convert(){}; -}; - -Convert * getConvert() { - static Mutex mutex = Mutex(); - Lock xx(&mutex); - - if(convert==0){ - convert = new ConvertExt(); - pvDataCreate = getPVDataCreate(); - } - return convert; -} - -}} diff --git a/pvDataApp/factory/3139 b/pvDataApp/factory/3139 deleted file mode 100644 index ea6403c..0000000 --- a/pvDataApp/factory/3139 +++ /dev/null @@ -1,3578 +0,0 @@ -/* Convert.cpp */ -#include -#include -#include -#include -#include "lock.h" -#include "pvIntrospect.h" -#include "pvData.h" -#include "convert.h" - -namespace epics { namespace pvData { - -static Convert* convert = 0; -static PVDataCreate* pvDataCreate = 0; - -static String trueString("true"); -static String falseString("false"); -static String logicError("Logic error. Should never get here."); -static String illegalScalarType("Illegal ScalarType"); - -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 void convertToString(StringBuilder buffer, - 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 std::vector split(String commaSeparatedList); - -static std::vector split(String commaSeparatedList) { - String::size_type numValues = 1; - String::size_type index=0; - while(true) { - String::size_type pos = commaSeparatedList.find(',',index); - if(pos==String::npos) break; - numValues++; - index = pos +1; - } - std::vector valueList(numValues,""); - index=0; - for(size_t i=0; iempty(); - *buf += pvField->getField()->getFieldName(); - PVStructure *parent; - while((parent=pvField->getParent())!=0) { - pvField = pvField->getParent(); - String name = pvField->getField()->getFieldName(); - if(name.length()>0) { - buf->insert(0,"."); - buf->insert(0,name); - } - } -} - -bool Convert::equals(PVField *a,PVField *b) -{ - return convertEquals(a,b); -} - -void Convert::getString(StringBuilder buf,PVField * pvField,int indentLevel) -{ - convertToString(buf,pvField,indentLevel); -} - -void Convert::getString(StringBuilder buf,PVField * pvField) -{ - convertToString(buf,pvField,0); -} - -void Convert::fromString(PVScalar *pvScalar, String from) -{ - ScalarConstPtr scalar = pvScalar->getScalar(); - ScalarType scalarType = scalar->getScalarType(); - switch(scalarType) { - case pvBoolean: { - PVBoolean *pv = (PVBoolean *)pvScalar; - bool value = - ((from.compare("true")==0) ? true : false); - pv->put(value); - return; - } - case pvByte : { - PVByte *pv = (PVByte*)pvScalar; - int ival; - sscanf(from.c_str(),"%d",&ival); - int8 value = ival; - pv->put(value); - return; - } - case pvShort : { - PVShort *pv = (PVShort*)pvScalar; - int ival; - sscanf(from.c_str(),"%d",&ival); - int16 value = ival; - pv->put(value); - return; - } - case pvInt : { - PVInt *pv = (PVInt*)pvScalar; - int ival; - sscanf(from.c_str(),"%d",&ival); - int32 value = ival; - pv->put(value); - return; - } - case pvLong : { - PVLong *pv = (PVLong*)pvScalar; - int64 ival; - sscanf(from.c_str(),"%lld",&ival); - int64 value = ival; - pv->put(value); - return; - } - case pvFloat : { - PVFloat *pv = (PVFloat*)pvScalar; - float value; - sscanf(from.c_str(),"%f",&value); - pv->put(value); - return; - } - case pvDouble : { - PVDouble*pv = (PVDouble*)pvScalar; - double value; - sscanf(from.c_str(),"%lf",&value); - pv->put(value); - return; - } - case pvString: { - PVString *value = (PVString*)pvScalar; - value->put(from); - return; - } - } - String message("Convert::fromString unknown scalarType "); - ScalarTypeFunc::toString(&message,scalarType); - throw std::logic_error(message); -} - -int Convert::fromString(PVScalarArray *pv, String from) -{ - if(from[0]=='[' && from[from.length()]==']') { - int 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) -{ - return convertFromStringArray(pv,offset,length,from,fromOffset); -} - -int Convert::toStringArray(PVScalarArray * pv, int offset, int length, - String to[], int toOffset) -{ - return convertToStringArray(pv,offset,length,to,toOffset); -} - -bool Convert::isCopyCompatible(FieldConstPtr from, FieldConstPtr to) -{ - if(from->getType()!=to->getType()) return false; - switch(from->getType()) { - case scalar: - return isCopyScalarCompatible((ScalarConstPtr)from,(ScalarConstPtr)to); - case scalarArray: - return isCopyScalarArrayCompatible((ScalarArrayConstPtr)from,(ScalarArrayConstPtr)to); - case structure: - return isCopyStructureCompatible((StructureConstPtr)from,(StructureConstPtr)to); - case structureArray: - return isCopyStructureArrayCompatible((StructureArrayConstPtr)from,(StructureArrayConstPtr)to); - } - String message("Convert::isCopyCompatible should never get here"); - throw std::logic_error(message); -} - -void Convert::copy(PVField *from,PVField *to) -{ - switch(from->getField()->getType()) { - case scalar: - copyScalar((PVScalar *)from,(PVScalar *)to); - return; - case scalarArray: { - PVScalarArray *fromArray = (PVScalarArray *)from; - PVScalarArray *toArray = (PVScalarArray *)to; - int length = copyScalarArray(fromArray,0,toArray,0,fromArray->getLength()); - if(toArray->getLength()!=length) toArray->setLength(length); - return; - } - case structure: - copyStructure((PVStructure *)from,(PVStructure *)to); - return; - case structureArray: { - PVStructureArray *fromArray = (PVStructureArray *)from; - PVStructureArray *toArray = (PVStructureArray *)to; - copyStructureArray(fromArray,toArray); - return; - } - } -} - -bool Convert::isCopyScalarCompatible( - ScalarConstPtr fromField, ScalarConstPtr toField) -{ - ScalarType fromScalarType = fromField->getScalarType(); - ScalarType toScalarType = toField->getScalarType(); - if(fromScalarType==toScalarType) return true; - if(ScalarTypeFunc::isNumeric(fromScalarType) - && ScalarTypeFunc::isNumeric(toScalarType)) return true; - if(fromScalarType==pvString) return true; - if(toScalarType==pvString) return true; - return false; -} - -void Convert::copyScalar(PVScalar *from, PVScalar *to) -{ - if(to->isImmutable()) { - if(from==to) return; - String message("Convert.copyScalar destination is immutable"); - throw std::invalid_argument(message); - } - ScalarType fromType = from->getScalar()->getScalarType(); - ScalarType toType = to->getScalar()->getScalarType(); - switch(fromType) { - case pvBoolean: { - if(toType!=pvBoolean) { - if(toType!=pvString) { - String message("Convert.copyScalar arguments are not compatible"); - throw std::invalid_argument(message); - } - } - PVBoolean *data = (PVBoolean*)from; - if(toType==pvString) { - PVString *dataTo = (PVString*)to; - String buf(""); - data->toString(&buf); - dataTo->put(buf); - } else { - bool value = data->get(); - PVBoolean *dataTo = (PVBoolean*)to; - dataTo->put(value); - } - break; - } - case pvByte : { - PVByte *data = (PVByte*)from; - int8 value = data->get(); - convert->fromByte(to,value); - break; - } - case pvShort : { - PVShort *data = (PVShort*)from; - short value = data->get(); - convert->fromShort(to,value); - break; - } - case pvInt :{ - PVInt *data = (PVInt*)from; - int value = data->get(); - convert->fromInt(to,value); - break; - } - case pvLong : { - PVLong *data = (PVLong*)from; - long value = data->get(); - convert->fromLong(to,value); - break; - } - case pvFloat : { - PVFloat *data = (PVFloat*)from; - float value = data->get(); - convert->fromFloat(to,value); - break; - } - case pvDouble : { - PVDouble *data = (PVDouble*)from; - double value = data->get(); - convert->fromDouble(to,value); - break; - } - case pvString: { - PVString *data = (PVString*)from; - String value = data->get(); - convert->fromString(to,value); - break; - } - } - String message("Convert::copyScalar should never get here"); - throw std::logic_error(message); -} - -bool Convert::isCopyScalarArrayCompatible(ScalarArrayConstPtr fromArray, - ScalarArrayConstPtr toArray) -{ - ScalarType fromType = fromArray->getElementType(); - ScalarType toType = toArray->getElementType(); - if(fromType==toType) return true; - if(ScalarTypeFunc::isNumeric(fromType) - && ScalarTypeFunc::isNumeric(toType)) return true; - if(toType==pvString) return true; - if(fromType==pvString) return true; - return false; -} - -int Convert::copyScalarArray(PVScalarArray *from, int offset, - PVScalarArray *to, int toOffset, int length) -{ - if(to->isImmutable()) { - if(from==to) return from->getLength(); - String message("Convert.copyArray destination is immutable"); - throw std::invalid_argument(message); - } - ScalarType fromElementType = from->getScalarArray()->getElementType(); - ScalarType toElementType = to->getScalarArray()->getElementType(); - - if(from->isImmutable() && (fromElementType==toElementType)) { - if(offset==0 && toOffset==0 && length==from->getLength()) { - return copyArrayDataReference(from,to); - } - } - - int ncopy = 0; - if(ScalarTypeFunc::isNumeric(fromElementType) - && ScalarTypeFunc::isNumeric(toElementType)) { - return copyNumericArray(from,offset,to,toOffset,length); - } else if(toElementType==pvBoolean && fromElementType==pvBoolean) { - PVBooleanArray *pvfrom = (PVBooleanArray*)from; - PVBooleanArray *pvto = (PVBooleanArray*)to; - while(length>0) { - int num = 0; - BooleanArray data = 0; - int fromOffset = 0; - BooleanArrayData booleanArrayData = BooleanArrayData(); - num = pvfrom->get(offset,length,&booleanArrayData); - data = booleanArrayData.data; - fromOffset = booleanArrayData.offset; - if(num<=0) return ncopy; - while(num>0) { - int n = pvto->put(toOffset,num,data,fromOffset); - if(n<=0) return ncopy; - length -= n; num -= n; ncopy+=n; offset += n; toOffset += n; - } - } - } else if(toElementType==pvString && fromElementType==pvString) { - PVStringArray *pvfrom = (PVStringArray*)from; - PVStringArray *pvto = (PVStringArray*)to; - while(length>0) { - int num = 0; - String *data; - int fromOffset = 0; - StringArrayData stringArrayData = StringArrayData(); - num = pvfrom->get(offset,length,&stringArrayData); - data = stringArrayData.data; - fromOffset = stringArrayData.offset; - if(num<=0) return ncopy; - while(num>0) { - int n = pvto->put(toOffset,num,data,fromOffset); - if(n<=0) return ncopy; - length -= n; num -= n; ncopy+=n; offset += n; toOffset += n; - } - } - } else if(toElementType==pvString) { - PVStringArray *pvto = (PVStringArray*)to; - ncopy = from->getLength(); - if(ncopy>length) ncopy = length; - int num = ncopy; - String toData[1]; - while(num>0) { - convert->toStringArray(from,offset,1,toData,0); - if(pvto->put(toOffset,1,toData,0)<=0) break; - num--; offset++; toOffset++; - } - return ncopy; - } else if(fromElementType==pvString) { - PVStringArray *pvfrom = (PVStringArray*)from; - while(length>0) { - int num = 0; - String *data = 0; - int fromOffset = 0; - StringArrayData stringArrayData = StringArrayData(); - num = pvfrom->get(offset,length,&stringArrayData); - data = stringArrayData.data; - fromOffset = stringArrayData.offset; - if(num<=0) return ncopy; - while(num>0) { - int n = fromStringArray(to,toOffset,num,data,fromOffset); - if(n<=0) return ncopy; - length -= n; num -= n; ncopy+=n; offset += n; toOffset += n; - } - } - } - String message("Convert::copyScalarArray should not get here"); - throw std::logic_error(message); -} - -bool Convert::isCopyStructureCompatible( - StructureConstPtr fromStruct, StructureConstPtr toStruct) -{ - FieldConstPtrArray fromFields = fromStruct->getFields(); - FieldConstPtrArray toFields = toStruct->getFields(); - int length = fromStruct->getNumberFields(); - if(length!=toStruct->getNumberFields()) return false; - for(int i=0; igetType(); - Type toType = to->getType(); - if(fromType!=toType) return false; - switch(fromType) { - case scalar: - if(!convert->isCopyScalarCompatible((ScalarConstPtr)from,(ScalarConstPtr)to)) return false; - break; - case scalarArray: - if(!isCopyScalarArrayCompatible((ScalarArrayConstPtr)from,(ScalarArrayConstPtr)to)) - return false; - break; - case structure: - if(!isCopyStructureCompatible((StructureConstPtr)from,(StructureConstPtr)to)) - return false; - break; - case structureArray: - if(!isCopyStructureArrayCompatible((StructureArrayConstPtr)from, - (StructureArrayConstPtr)to)) return false; - } - } - return true; -} - -void Convert::copyStructure(PVStructure *from, PVStructure *to) -{ - if(to->isImmutable()) { - if(from==to) return; - String message("Convert.copyStructure destination is immutable"); - throw std::invalid_argument(message); - } - if(from==to) return; - PVFieldPtrArray fromDatas = from->getPVFields(); - PVFieldPtrArray 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) { - // look for enumerated structure and copy choices first - String fieldName = fromDatas[0]->getField()->getFieldName(); - if(fieldName.compare("index")==0) { - FieldConstPtr fieldIndex = fromDatas[0]->getField(); - FieldConstPtr fieldChoices = fromDatas[1]->getField(); - if(fieldIndex->getType()==scalar - && fieldChoices->getFieldName().compare("choices") - && fieldChoices->getType()==scalarArray) { - PVScalar *pvScalar = (PVScalar*)fromDatas[0]; - PVScalarArray *pvArray = (PVScalarArray*)fromDatas[1]; - if((pvScalar->getScalar()->getScalarType()==pvInt) - && (pvArray->getScalarArray()->getElementType()==pvString)) { - PVScalarArray* toArray = (PVScalarArray*)toDatas[1]; - copyScalarArray(pvArray,0,toArray,0,pvArray->getLength()); - PVScalar *toScalar = (PVScalar*)toDatas[0]; - copyScalar(pvScalar,toScalar); - return; - } - } - } - } - for(int i=0; i < numberFields; i++) { - PVField *fromData = fromDatas[i]; - PVField *toData = toDatas[i]; - Type fromType = fromData->getField()->getType(); - Type toType = toData->getField()->getType(); - if(fromType!=toType) { - String message("Convert.copyStructure Illegal copyStructure"); - throw std::invalid_argument(message); - } - switch(fromType) { - case scalar: - copyScalar((PVScalar*)fromData,(PVScalar*)toData); - break; - case scalarArray: { - PVScalarArray *fromArray = (PVScalarArray*)fromData; - PVScalarArray *toArray = (PVScalarArray*)toData; - int length = copyScalarArray(fromArray,0,toArray,0,fromArray->getLength()); - if(toArray->getLength()!=length) toArray->setLength(length); - break; - } - case structure: - copyStructure((PVStructure*)fromData,(PVStructure*)toData); - break; - case structureArray: { - PVStructureArray *fromArray = (PVStructureArray*)fromData; - PVStructureArray *toArray = (PVStructureArray*)toData; - copyStructureArray(fromArray,toArray); - break; - } - } - } -} - -bool Convert::isCopyStructureArrayCompatible( - StructureArrayConstPtr from, StructureArrayConstPtr to) -{ - return isCopyStructureCompatible(from->getStructure(),to->getStructure()); -} - -void Convert::copyStructureArray( - PVStructureArray *from, PVStructureArray *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())) { - 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; - if(to->getCapacity()setCapacity(length); - to->get(0, length,&structureArrayData); - toArray = structureArrayData.data; - for(int i=0; igetStructureArray()->getStructure(); - toArray[i] = pvDataCreate->createPVStructure(0,structure); - } - copyStructure(fromArray[i],toArray[i]); - } - } - to->setLength(length); - 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 = (PVByte *)pv; - return value->get(); - } - case pvShort: { - PVShort *value = (PVShort *)pv; - return value->get(); - } - case pvInt: { - PVInt *value = (PVInt *)pv; - return value->get(); - } - case pvLong: { - PVLong *value = (PVLong *)pv; - return value->get(); - } - case pvFloat: { - PVFloat *value = (PVFloat *)pv; - return value->get(); - } - case pvDouble: { - PVDouble *value = (PVDouble *)pv; - return 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 = (PVByte *)pv; - return value->get(); - } - case pvShort: { - PVShort *value = (PVShort *)pv; - return value->get(); - } - case pvInt: { - PVInt *value = (PVInt *)pv; - return value->get(); - } - case pvLong: { - PVLong *value = (PVLong *)pv; - return value->get(); - } - case pvFloat: { - PVFloat *value = (PVFloat *)pv; - return value->get(); - } - case pvDouble: { - PVDouble *value = (PVDouble *)pv; - return 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 = (PVByte *)pv; - return value->get(); - } - case pvShort: { - PVShort *value = (PVShort *)pv; - return value->get(); - } - case pvInt: { - PVInt *value = (PVInt *)pv; - return value->get(); - } - case pvLong: { - PVLong *value = (PVLong *)pv; - return value->get(); - } - case pvFloat: { - PVFloat *value = (PVFloat *)pv; - return value->get(); - } - case pvDouble: { - PVDouble *value = (PVDouble *)pv; - return 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 = (PVByte *)pv; - return value->get(); - } - case pvShort: { - PVShort *value = (PVShort *)pv; - return value->get(); - } - case pvInt: { - PVInt *value = (PVInt *)pv; - return value->get(); - } - case pvLong: { - PVLong *value = (PVLong *)pv; - return value->get(); - } - case pvFloat: { - PVFloat *value = (PVFloat *)pv; - return value->get(); - } - case pvDouble: { - PVDouble *value = (PVDouble *)pv; - return 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 = (PVByte *)pv; - return value->get(); - } - case pvShort: { - PVShort *value = (PVShort *)pv; - return value->get(); - } - case pvInt: { - PVInt *value = (PVInt *)pv; - return value->get(); - } - case pvLong: { - PVLong *value = (PVLong *)pv; - return value->get(); - } - case pvFloat: { - PVFloat *value = (PVFloat *)pv; - return value->get(); - } - case pvDouble: { - PVDouble *value = (PVDouble *)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 = (PVByte *)pv; - return value->get(); - } - case pvShort: { - PVShort *value = (PVShort *)pv; - return value->get(); - } - case pvInt: { - PVInt *value = (PVInt *)pv; - return value->get(); - } - case pvLong: { - PVLong *value = (PVLong *)pv; - return value->get(); - } - case pvFloat: { - PVFloat *value = (PVFloat *)pv; - return value->get(); - } - case pvDouble: { - PVDouble *value = (PVDouble *)pv; - return value->get(); - } - case pvString: - throw std::logic_error(String("string can not be converted to double")); - } - throw std::logic_error(logicError); -} - -void Convert::fromByte(PVScalar *pv,int8 from) -{ - 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 = (PVByte *)pv; - value->put(from); return; - } - case pvShort: { - PVShort *value = (PVShort *)pv; - value->put(from); return; - } - case pvInt: { - PVInt *value = (PVInt *)pv; - value->put(from); return; - } - case pvLong: { - PVLong *value = (PVLong *)pv; - value->put(from); return; - } - case pvFloat: { - PVFloat *value = (PVFloat *)pv; - value->put(from); return; - } - case pvDouble: { - PVDouble *value = (PVDouble *)pv; - value->put(from); return; - } - case pvString: { - PVString *value = (PVString *)pv; - char buffer[20]; - int ival = from; - sprintf(buffer,"%d",ival); - String xxx(buffer); - value->put(xxx); - return; - } - } - throw std::logic_error(logicError); -} - -void Convert::fromShort(PVScalar *pv,int16 from) -{ - 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 = (PVByte *)pv; - value->put(from); return; - } - case pvShort: { - PVShort *value = (PVShort *)pv; - value->put(from); return; - } - case pvInt: { - PVInt *value = (PVInt *)pv; - value->put(from); return; - } - case pvLong: { - PVLong *value = (PVLong *)pv; - value->put(from); return; - } - case pvFloat: { - PVFloat *value = (PVFloat *)pv; - value->put(from); return; - } - case pvDouble: { - PVDouble *value = (PVDouble *)pv; - value->put(from); return; - } - case pvString: { - PVString *value = (PVString *)pv; - char buffer[20]; - int ival = from; - sprintf(buffer,"%d",ival); - String xxx(buffer); - value->put(xxx); - return; - } - } - throw std::logic_error(logicError); -} - -void Convert::fromInt(PVScalar *pv, int32 from) -{ - 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 = (PVByte *)pv; - value->put(from); return; - } - case pvShort: { - PVShort *value = (PVShort *)pv; - value->put(from); return; - } - case pvInt: { - PVInt *value = (PVInt *)pv; - value->put(from); return; - } - case pvLong: { - PVLong *value = (PVLong *)pv; - value->put(from); return; - } - case pvFloat: { - PVFloat *value = (PVFloat *)pv; - value->put(from); return; - } - case pvDouble: { - PVDouble *value = (PVDouble *)pv; - value->put(from); return; - } - case pvString: { - PVString *value = (PVString *)pv; - char buffer[20]; - int ival = from; - sprintf(buffer,"%d",ival); - String xxx(buffer); - value->put(xxx); - return; - } - } - throw std::logic_error(logicError); -} - -void Convert::fromLong(PVScalar *pv, int64 from) -{ - 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 = (PVByte *)pv; - value->put(from); return; - } - case pvShort: { - PVShort *value = (PVShort *)pv; - value->put(from); return; - } - case pvInt: { - PVInt *value = (PVInt *)pv; - value->put(from); return; - } - case pvLong: { - PVLong *value = (PVLong *)pv; - value->put(from); return; - } - case pvFloat: { - PVFloat *value = (PVFloat *)pv; - value->put(from); return; - } - case pvDouble: { - PVDouble *value = (PVDouble *)pv; - value->put(from); return; - } - case pvString: { - PVString *value = (PVString *)pv; - char buffer[20]; - int64 ival = from; - sprintf(buffer,"%lld",ival); - String xxx(buffer); - value->put(xxx); - return; - } - } - throw std::logic_error(logicError); -} - -void Convert::fromFloat(PVScalar* pv, float from) -{ - 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 = (PVByte *)pv; - value->put(from); return; - } - case pvShort: { - PVShort *value = (PVShort *)pv; - value->put(from); return; - } - case pvInt: { - PVInt *value = (PVInt *)pv; - value->put(from); return; - } - case pvLong: { - PVLong *value = (PVLong *)pv; - value->put(from); return; - } - case pvFloat: { - PVFloat *value = (PVFloat *)pv; - value->put(from); return; - } - case pvDouble: { - PVDouble *value = (PVDouble *)pv; - value->put(from); return; - } - case pvString: { - PVString *value = (PVString *)pv; - char buffer[20]; - double dval = from; - sprintf(buffer,"%g",dval); - String xxx(buffer); - value->put(xxx); - return; - } - } - throw std::logic_error(logicError); -} - -void Convert::fromDouble(PVScalar *pv, double from) -{ - 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 = (PVByte *)pv; - value->put(from); return; - } - case pvShort: { - PVShort *value = (PVShort *)pv; - value->put(from); return; - } - case pvInt: { - PVInt *value = (PVInt *)pv; - value->put(from); return; - } - case pvLong: { - PVLong *value = (PVLong *)pv; - value->put(from); return; - } - case pvFloat: { - PVFloat *value = (PVFloat *)pv; - value->put(from); return; - } - case pvDouble: { - PVDouble *value = (PVDouble *)pv; - value->put(from); return; - } - case pvString: { - PVString *value = (PVString *)pv; - char buffer[20]; - double dval = from; - sprintf(buffer,"%g",dval); - String xxx(buffer); - value->put(xxx); - return; - } - } - throw std::logic_error(logicError); -} - -int Convert::toByteArray(PVScalarArray * pv, int offset, int length, - int8 to[], int toOffset) -{ - return convertToByteArray(pv, offset, length, to, toOffset); -} - -int Convert::toShortArray(PVScalarArray * pv, int offset, int length, - int16 to[], int toOffset) -{ - return convertToShortArray(pv, offset, length, to, toOffset); -} - -int Convert::toIntArray(PVScalarArray * pv, int offset, int length, - int32 to[], int toOffset) -{ - return convertToIntArray(pv, offset, length, to, toOffset); -} - -int Convert::toLongArray(PVScalarArray * pv, int offset, int length, - int64 to[], int toOffset) -{ - return convertToLongArray(pv, offset, length, to, toOffset); -} - -int Convert::toFloatArray(PVScalarArray * pv, int offset, int length, - float to[], int toOffset) -{ - return convertToFloatArray(pv, offset, length, to, toOffset); -} - -int Convert::toDoubleArray(PVScalarArray * pv, int offset, int length, - double to[], int toOffset) -{ - return convertToDoubleArray(pv, offset, length, to, toOffset); -} - -int Convert::fromByteArray(PVScalarArray *pv, int offset, int length, - int8 from[], int fromOffset) -{ - return convertFromByteArray(pv, offset, length, from, fromOffset); -} - -int Convert::fromShortArray(PVScalarArray *pv, int offset, int length, - int16 from[], int fromOffset) -{ - return convertFromShortArray(pv, offset, length, from, fromOffset); -} - -int Convert::fromIntArray(PVScalarArray *pv, int offset, int length, - int32 from[], int fromOffset) -{ - return convertFromIntArray(pv, offset, length, from, fromOffset); -} - -int Convert::fromLongArray(PVScalarArray *pv, int offset, int length, - int64 from[], int fromOffset) -{ - return convertFromLongArray(pv, offset, length, from, fromOffset); -} - -int Convert::fromFloatArray(PVScalarArray *pv, int offset, int length, - float from[], int fromOffset) -{ - return convertFromFloatArray(pv, offset, length, from, fromOffset); -} - -int Convert::fromDoubleArray(PVScalarArray *pv, int offset, int length, - double from[], int fromOffset) -{ - return convertFromDoubleArray(pv, offset, length, from, fromOffset); -} - -void Convert::newLine(StringBuilder buffer, int indentLevel) -{ - *buffer += "\n"; - for(int i=0; igetScalar()->getScalarType(); - ScalarType bscalarType = b->getScalar()->getScalarType(); - if(ascalarType!=bscalarType) return false; - switch(ascalarType) { - case pvBoolean: { - PVBoolean *pa = (PVBoolean *)a; - PVBoolean *pb = (PVBoolean *)b; - bool avalue = pa->get(); - bool bvalue = pb->get(); - return ((avalue==bvalue) ? true : false); - } - case pvByte: { - PVByte *pa = (PVByte *)a; - PVByte *pb = (PVByte *)b; - int8 avalue = pa->get(); - int8 bvalue = pb->get(); - return ((avalue==bvalue) ? true : false); - } - case pvShort: { - PVShort *pa = (PVShort *)a; - PVShort *pb = (PVShort *)b; - int16 avalue = pa->get(); - int16 bvalue = pb->get(); - return ((avalue==bvalue) ? true : false); - } - case pvInt: { - PVInt *pa = (PVInt *)a; - PVInt *pb = (PVInt *)b; - int32 avalue = pa->get(); - int32 bvalue = pb->get(); - return ((avalue==bvalue) ? true : false); - } - case pvLong: { - PVLong *pa = (PVLong *)a; - PVLong *pb = (PVLong *)b; - int64 avalue = pa->get(); - int64 bvalue = pb->get(); - return ((avalue==bvalue) ? true : false); - } - case pvFloat: { - PVFloat *pa = (PVFloat *)a; - PVFloat *pb = (PVFloat *)b; - float avalue = pa->get(); - float bvalue = pb->get(); - return ((avalue==bvalue) ? true : false); - } - case pvDouble: { - PVDouble *pa = (PVDouble *)a; - PVDouble *pb = (PVDouble *)b; - double avalue = pa->get(); - double bvalue = pb->get(); - return ((avalue==bvalue) ? true : false); - } - case pvString: { - PVString *pa = (PVString *)a; - PVString *pb = (PVString *)b; - String avalue = pa->get(); - String bvalue = pb->get(); - return ((avalue==bvalue) ? true : false); - } - } - String message("should not get here"); - throw std::logic_error(message); -} - -static bool arrayEquals(PVScalarArray *a,PVScalarArray *b) -{ - if(a==b) return true; - ScalarType aType = a->getScalarArray()->getElementType(); - ScalarType bType = b->getScalarArray()->getElementType(); - if(aType!=bType) return false; - if(a->getLength()!=b->getLength()) return false; - int length = a->getLength(); - switch(aType) { - case pvBoolean: { - PVBooleanArray *aarray = (PVBooleanArray *)a; - PVBooleanArray *barray = (PVBooleanArray *)b; - BooleanArrayData adata = BooleanArrayData(); - BooleanArrayData bdata = BooleanArrayData(); - aarray->get(0,length,&adata); - barray->get(0,length,&bdata); - BooleanArray avalue = adata.data; - BooleanArray bvalue = bdata.data; - for(int i=0; iget(0,length,&adata); - barray->get(0,length,&bdata); - ByteArray avalue = adata.data; - ByteArray bvalue = bdata.data; - for(int i=0; iget(0,length,&adata); - barray->get(0,length,&bdata); - ShortArray avalue = adata.data; - ShortArray bvalue = bdata.data; - for(int i=0; iget(0,length,&adata); - barray->get(0,length,&bdata); - IntArray avalue = adata.data; - IntArray bvalue = bdata.data; - for(int i=0; iget(0,length,&adata); - barray->get(0,length,&bdata); - LongArray avalue = adata.data; - LongArray bvalue = bdata.data; - for(int i=0; iget(0,length,&adata); - barray->get(0,length,&bdata); - FloatArray avalue = adata.data; - FloatArray bvalue = bdata.data; - for(int i=0; iget(0,length,&adata); - barray->get(0,length,&bdata); - DoubleArray avalue = adata.data; - DoubleArray bvalue = bdata.data; - for(int i=0; iget(0,length,&adata); - barray->get(0,length,&bdata); - String *avalue = adata.data; - String *bvalue = bdata.data; - for(int i=0; igetStructureArray()->getStructure(); - StructureConstPtr bStructure = b->getStructureArray()->getStructure(); - if(aStructure!=bStructure) return false; - if(a->getLength()!=b->getLength()) return false; - StructureArrayData aData = StructureArrayData(); - StructureArrayData bData = StructureArrayData(); - int 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(); - if(length!=bStructure->getNumberFields()) return false; - PVFieldPtrArray aFields = a->getPVFields(); - PVFieldPtrArray bFields = b->getPVFields(); - for(int i=0; igetField()->getType(); - Type btype = b->getField()->getType(); - if(atype!=btype) return false; - if(atype==scalar) return scalarEquals((PVScalar *)a,(PVScalar *)b); - if(atype==scalarArray) { - return arrayEquals((PVScalarArray *)a,(PVScalarArray *)b); - } - if(atype==structureArray) { - return structureArrayEquals( - (PVStructureArray *)a,(PVStructureArray *)b); - } - if(atype==structure) { - return structureEquals((PVStructure *)a,(PVStructure *)b); - } - String message("should not get here"); - throw std::logic_error(message); -} - -int convertFromByteArray(PVScalarArray *pv, int offset, int len,int8 from[], int 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 = (PVByteArray*) 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 pvShort: { - PVShortArray *pvdata = (PVShortArray*) pv; - int16 data[1]; - while (len > 0) { - data[0] = (int16) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = (PVIntArray*) pv; - int32 data[1]; - while (len > 0) { - data[0] = (int32) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = (PVLongArray*) pv; - int64 data[1]; - while (len > 0) { - data[0] = (int64) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = (PVFloatArray*) pv; - float data[1]; - while (len > 0) { - data[0] = (float) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = (PVDoubleArray*) pv; - double data[1]; - while (len > 0) { - data[0] = (double) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvString: { - String message("convert from byte[] to StringArray not legal"); - throw std::invalid_argument(message); - } - } - String message("Convert::convertFromByteArray should never get here"); - throw std::logic_error(message); -} - -int convertToByteArray(PVScalarArray * pv, int offset, int len,int8 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 = (PVByteArray*) 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 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = (PVIntArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = (PVLongArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = (PVFloatArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = (PVDoubleArray*) 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] = (int8) 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 = (PVByteArray*) pv; - int8 data[1]; - while (len > 0) { - data[0] = (int8) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvShort: { - PVShortArray *pvdata = (PVShortArray*) 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 = (PVIntArray*) pv; - int32 data[1]; - while (len > 0) { - data[0] = (int32) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = (PVLongArray*) pv; - int64 data[1]; - while (len > 0) { - data[0] = (int64) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = (PVFloatArray*) pv; - float data[1]; - while (len > 0) { - data[0] = (float) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = (PVDoubleArray*) pv; - double data[1]; - while (len > 0) { - data[0] = (double) 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 = (PVByteArray*) 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 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = (PVIntArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = (PVLongArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = (PVFloatArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = (PVDoubleArray*) 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] = (int8) 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 = (PVByteArray*) pv; - int8 data[1]; - while (len > 0) { - data[0] = (int8) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvShort: { - PVShortArray *pvdata = (PVShortArray*) pv; - int16 data[1]; - while (len > 0) { - data[0] = (int16) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = (PVIntArray*) 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 = (PVLongArray*) pv; - int64 data[1]; - while (len > 0) { - data[0] = (int64) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = (PVFloatArray*) pv; - float data[1]; - while (len > 0) { - data[0] = (float) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = (PVDoubleArray*) pv; - double data[1]; - while (len > 0) { - data[0] = (double) 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 = (PVByteArray*) 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 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = (PVIntArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = (PVLongArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = (PVFloatArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = (PVDoubleArray*) 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] = (int8) 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 = (PVByteArray*) pv; - int8 data[1]; - while (len > 0) { - data[0] = (int8) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvShort: { - PVShortArray *pvdata = (PVShortArray*) pv; - int16 data[1]; - while (len > 0) { - data[0] = (int16) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = (PVIntArray*) pv; - int32 data[1]; - while (len > 0) { - data[0] = (int32) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = (PVLongArray*) 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 = (PVFloatArray*) pv; - float data[1]; - while (len > 0) { - data[0] = (float) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = (PVDoubleArray*) pv; - double data[1]; - while (len > 0) { - data[0] = (double) 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 = (PVByteArray*) 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 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = (PVIntArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = (PVLongArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = (PVFloatArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = (PVDoubleArray*) 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] = (int8) 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 = (PVByteArray*) pv; - int8 data[1]; - while (len > 0) { - data[0] = (int8) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvShort: { - PVShortArray *pvdata = (PVShortArray*) pv; - int16 data[1]; - while (len > 0) { - data[0] = (int16) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = (PVIntArray*) pv; - int32 data[1]; - while (len > 0) { - data[0] = (int32) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = (PVLongArray*) pv; - int64 data[1]; - while (len > 0) { - data[0] = (int64) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = (PVFloatArray*) 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 = (PVDoubleArray*) pv; - double data[1]; - while (len > 0) { - data[0] = (double) 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 = (PVByteArray*) 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 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = (PVIntArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = (PVLongArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = (PVFloatArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = (PVDoubleArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvString: { - String message("convert StringArray to float[]] not legal"); - throw std::invalid_argument(message); - } - } - String message("Convert::convertToFloatArray should never get here"); - throw std::logic_error(message); -} - -int convertFromDoubleArray(PVScalarArray *pv, int offset, int len,double from[], int 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 = (PVByteArray*) pv; - int8 data[1]; - while (len > 0) { - data[0] = (int8) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvShort: { - PVShortArray *pvdata = (PVShortArray*) pv; - int16 data[1]; - while (len > 0) { - data[0] = (int16) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = (PVIntArray*) pv; - int32 data[1]; - while (len > 0) { - data[0] = (int32) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = (PVLongArray*) pv; - int64 data[1]; - while (len > 0) { - data[0] = (int64) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = (PVFloatArray*) pv; - float data[1]; - while (len > 0) { - data[0] = (float) from[fromOffset]; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = (PVDoubleArray*) 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); -} - -int convertToDoubleArray(PVScalarArray * pv, int offset, int len,double 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 = (PVByteArray*) 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 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = (PVIntArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = (PVLongArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = (PVFloatArray*) 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] = (int8) dataArray[i + dataOffset]; - len -= num; - offset += num; - toOffset += num; - ntransfered += num; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = (PVDoubleArray*) 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] = (int8) 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); -} - -int convertFromStringArray(PVScalarArray *pv, int offset, int len,String from[], int fromOffset) -{ - ScalarType elemType = pv->getScalarArray()->getElementType(); - int ntransfered = 0; - switch (elemType) { - case pvBoolean: { - PVBooleanArray *pvdata = (PVBooleanArray*) pv; - bool data[1]; - while (len > 0) { - String fromString = from[fromOffset]; - data[0] = (fromString.compare("true")==0) ? true : false; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvByte: { - PVByteArray *pvdata = (PVByteArray*) pv; - int8 data[1]; - while (len > 0) { - String fromString = from[fromOffset]; - int ival; - sscanf(fromString.c_str(),"%d",&ival); - data[0] = ival; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvShort: { - PVShortArray *pvdata = (PVShortArray*) pv; - int16 data[1]; - while (len > 0) { - String fromString = from[fromOffset]; - int ival; - sscanf(fromString.c_str(),"%d",&ival); - data[0] = ival; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvInt: { - PVIntArray *pvdata = (PVIntArray*) pv; - int32 data[1]; - while (len > 0) { - String fromString = from[fromOffset]; - int ival; - sscanf(fromString.c_str(),"%d",&ival); - data[0] = ival; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvLong: { - PVLongArray *pvdata = (PVLongArray*) pv; - int64 data[1]; - while (len > 0) { - String fromString = from[fromOffset]; - int64 ival; - sscanf(fromString.c_str(),"%lld",&ival); - data[0] = ival; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvFloat: { - PVFloatArray *pvdata = (PVFloatArray*) pv; - float data[1]; - while (len > 0) { - String fromString = from[fromOffset]; - float fval; - sscanf(fromString.c_str(),"%f",&fval); - data[0] = fval; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvDouble: { - PVDoubleArray *pvdata = (PVDoubleArray*) pv; - double data[1]; - while (len > 0) { - String fromString = from[fromOffset]; - double fval; - sscanf(fromString.c_str(),"%lf",&fval); - data[0] = fval; - if (pvdata->put(offset, 1, data, 0) == 0) - return ntransfered; - --len; - ++ntransfered; - ++offset; - ++fromOffset; - } - return ntransfered; - } - case pvString: - PVStringArray *pvdata = (PVStringArray*) 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; - } - String message("Convert::convertFromStringArray should never get here"); - throw std::logic_error(message); -} - -int convertToStringArray(PVScalarArray * pv, int offset, int len,String to[], int toOffset) -{ - ScalarType elementType = pv->getScalarArray()->getElementType(); - int ncopy = pv->getLength(); - if (ncopy > len) ncopy = len; - int num = ncopy; - switch (elementType) { - case pvBoolean: { - PVBooleanArray *pvdata = (PVBooleanArray*) pv; - BooleanArrayData data = BooleanArrayData(); - for (int 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; - } else { - to[toOffset + i] = "bad pv"; - } - } - } - break; - case pvByte: { - PVByteArray *pvdata = (PVByteArray*) pv; - ByteArrayData data = ByteArrayData(); - char cr[30]; - for (int 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); - to[toOffset + i] = String(cr); - } else { - to[toOffset + i] = "bad pv"; - } - } - } - break; - case pvShort: { - PVShortArray *pvdata = (PVShortArray*) pv; - ShortArrayData data = ShortArrayData(); - char cr[30]; - for (int 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); - to[toOffset + i] = String(cr); - } else { - to[toOffset + i] = "bad pv"; - } - } - } - break; - case pvInt: { - PVIntArray *pvdata = (PVIntArray*) pv; - IntArrayData data = IntArrayData(); - char cr[30]; - for (int 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); - to[toOffset + i] = String(cr); - } else { - to[toOffset + i] = "bad pv"; - } - } - } - break; - case pvLong: { - PVLongArray *pvdata = (PVLongArray*) pv; - LongArrayData data = LongArrayData(); - char cr[30]; - for (int 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); - to[toOffset + i] = String(cr); - } else { - to[toOffset + i] = "bad pv"; - } - } - } - break; - case pvFloat: { - PVFloatArray *pvdata = (PVFloatArray*) pv; - FloatArrayData data = FloatArrayData(); - char cr[30]; - for (int 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); - to[toOffset + i] = String(cr); - } else { - to[toOffset + i] = "bad pv"; - } - } - } - break; - case pvDouble: { - PVDoubleArray *pvdata = (PVDoubleArray*) pv; - DoubleArrayData data = DoubleArrayData(); - char cr[30]; - for (int 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); - to[toOffset + i] = String(cr); - } else { - to[toOffset + i] = "bad pv"; - } - } - } - break; - case pvString: { - PVStringArray *pvdata = (PVStringArray*) 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; - dataOffset = stringArrayData.offset; - if (numnow <= 0) { - for (int i = 0; i < num; i++) - to[toOffset + i] = "bad pv"; - break; - } - for(int i=0; igetField()->getType(); - if(type==scalarArray) { - return convertArray(buffer,(PVScalarArray *)pv,indentLevel); - } - if(type==structure) { - return convertStructure(buffer,(PVStructure*)pv,indentLevel); - } - if(type==structureArray) { - return convertStructureArray(buffer,(PVStructureArray*)pv,indentLevel); - } - PVScalar *pvScalar = (PVScalar*)pv; - ScalarConstPtr pscalar = pvScalar->getScalar(); - ScalarType scalarType = pscalar->getScalarType(); - ScalarTypeFunc::toString(buffer,scalarType); - *buffer += " "; - *buffer += pscalar->getFieldName(); - *buffer += " "; - switch(scalarType) { - case pvBoolean: { - PVBoolean *data = (PVBoolean*)pv; - bool value = data->get(); - if(value) { - *buffer += "true"; - } else { - *buffer += "false"; - } - } - return; - case pvByte: { - PVByte *data = (PVByte*)pv; - char xxx[30]; - sprintf(xxx,"%d",(int)data->get()); - *buffer += xxx; - } - return; - case pvShort: { - PVShort *data = (PVShort*)pv; - char xxx[30]; - sprintf(xxx,"%d",(int)data->get()); - *buffer += xxx; - } - return; - case pvInt: { - PVInt *data = (PVInt*)pv; - char xxx[30]; - sprintf(xxx,"%d",(int)data->get()); - *buffer += xxx; - } - return; - case pvLong: { - PVLong *data = (PVLong*)pv; - char xxx[30]; - sprintf(xxx,"%lld",(int64)data->get()); - *buffer += xxx; - } - return; - case pvFloat: { - PVFloat *data = (PVFloat*)pv; - char xxx[30]; - sprintf(xxx,"%g",data->get()); - *buffer += xxx; - } - return; - case pvDouble: { - PVDouble *data = (PVDouble*)pv; - char xxx[30]; - sprintf(xxx,"%lg",data->get()); - *buffer += xxx; - } - return; - case pvString: { - PVString *data = (PVString*)pv; - *buffer += data->get(); - } - return; - default: - *buffer += "unknown ScalarType"; - } -} - -void convertStructure(StringBuilder buffer,PVStructure *data,int indentLevel) -{ - *buffer += "structure "; - *buffer += data->getField()->getFieldName(); - convert->newLine(buffer, indentLevel+1); - PVFieldPtrArray fieldsData = data->getPVFields(); - if (fieldsData != 0) { - int length = data->getStructure()->getNumberFields(); - for(int i=0; itoString(buffer,indentLevel + 1); - if(inewLine(buffer, indentLevel+1); - } - } -} - -void convertArray(StringBuilder buffer,PVScalarArray * pv,int indentLevel) -{ - ScalarArrayConstPtr array = pv->getScalarArray(); - ScalarType type = array->getElementType(); - switch(type) { - case pvBoolean: { - PVBooleanArray *pvdata = (PVBooleanArray*)pv; - BooleanArrayData data = BooleanArrayData(); - *buffer += "["; - for(int i=0; i < pvdata->getLength(); i++) { - if(i!=0) *buffer += ","; - int num = pvdata->get(i,1,&data); - if(num==1) { - BooleanArray value = data.data; - if(value[data.offset]) { - *buffer += "true"; - } else { - *buffer += "false"; - } - } else { - *buffer += "???? "; - } - } - *buffer += "]"; - break; - } - case pvByte: { - PVByteArray *pvdata = (PVByteArray*)pv; - ByteArrayData data = ByteArrayData(); - *buffer += "["; - for(int i=0; i < pvdata->getLength(); i++) { - if(i!=0) *buffer += ","; - int num = pvdata->get(i,1,&data); - if(num==1) { - int val = data.data[data.offset]; - char buf[16]; - sprintf(buf,"%d",val); - *buffer += buf; - } else { - *buffer += "???? "; - } - } - *buffer += "]"; - break; - } - case pvShort: { - PVShortArray *pvdata = (PVShortArray*)pv; - ShortArrayData data = ShortArrayData(); - *buffer += "["; - for(int i=0; i < pvdata->getLength(); i++) { - if(i!=0) *buffer += ','; - int num = pvdata->get(i,1,&data); - if(num==1) { - int val = data.data[data.offset]; - char buf[16]; - sprintf(buf,"%d",val); - *buffer += buf; - } else { - *buffer += "???? "; - } - } - *buffer += "]"; - break; - } - case pvInt: { - PVIntArray *pvdata = (PVIntArray*)pv; - IntArrayData data = IntArrayData(); - *buffer += "["; - for(int i=0; i < pvdata->getLength(); i++) { - if(i!=0) *buffer += ','; - int num = pvdata->get(i,1,&data); - if(num==1) { - int val = data.data[data.offset]; - char buf[16]; - sprintf(buf,"%d",val); - *buffer += buf; - } else { - *buffer += "???? "; - } - } - *buffer += "]"; - break; - } - case pvLong: { - PVLongArray *pvdata = (PVLongArray*)pv; - LongArrayData data = LongArrayData(); - *buffer += "["; - for(int i=0; i < pvdata->getLength(); i++) { - if(i!=0) *buffer += ','; - int num = pvdata->get(i,1,&data); - if(num==1) { - int64 val = data.data[data.offset]; - char buf[16]; - sprintf(buf,"%lld",val); - *buffer += buf; - } else { - *buffer += "???? "; - } - } - *buffer += "]"; - break; - } - case pvFloat: { - PVFloatArray *pvdata = (PVFloatArray*)pv; - FloatArrayData data = FloatArrayData(); - *buffer += "["; - for(int i=0; i < pvdata->getLength(); i++) { - if(i!=0) *buffer += ','; - int num = pvdata->get(i,1,&data); - if(num==1) { - float val = data.data[data.offset]; - char buf[16]; - sprintf(buf,"%g",val); - *buffer += buf; - } else { - *buffer += "???? "; - } - } - *buffer += "]"; - break; - } - case pvDouble: { - PVDoubleArray *pvdata = (PVDoubleArray*)pv; - DoubleArrayData data = DoubleArrayData(); - *buffer += "["; - for(int i=0; i < pvdata->getLength(); i++) { - if(i!=0) *buffer += ','; - int num = pvdata->get(i,1,&data); - if(num==1) { - double val = data.data[data.offset]; - char buf[16]; - sprintf(buf,"%lg",val); - *buffer += buf; - } else { - *buffer += "???? "; - } - } - *buffer += ("]"); - break; - } - case pvString: { - PVStringArray *pvdata = (PVStringArray*)pv; - StringArrayData data = StringArrayData(); - *buffer += "["; - for(int i=0; i < pvdata->getLength(); i++) { - if(i!=0) *buffer += ","; - int num = pvdata->get(i,1,&data); - StringPtrArray value = data.data; - if(num==1) { - if(value[data.offset].length()>0) { - *buffer += value[data.offset].c_str(); - } else { - *buffer += "null"; - } - } else { - *buffer += "null"; - } - } - *buffer += "]"; - break; - } - default: - *buffer += " array element is unknown ScalarType"; - } - if(pv->isImmutable()) { - *buffer += " immutable "; - } -} - -void convertStructureArray(StringBuilder buffer, - PVStructureArray * pvdata,int indentLevel) -{ - StructureArrayData data = StructureArrayData(); - int length = pvdata->getLength(); - pvdata->get(0, length, &data); - *buffer += "["; - for (int i = 0; i < length; i++) { - if (i != 0) { - *buffer += ","; - } - convert->newLine(buffer, indentLevel + 1); - PVStructure *pvStructure = data.data[i]; - if (pvStructure == 0) { - *buffer += "null"; - } else { - pvStructure->toString(buffer,indentLevel+1); - } - } - convert->newLine(buffer, indentLevel); - *buffer += "]"; -} - -int 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()); - 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()); - 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()); - 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()); - 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()); - 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()); - 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()); - 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()); - break; - } - } - to->setImmutable(); - return from->getLength(); -} - -int copyNumericArray(PVScalarArray *from, int offset, PVScalarArray *to, int toOffset, int len) -{ - ScalarType fromElementType = from->getScalarArray()->getElementType(); - int 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; - if (num <= 0) break; - while (num > 0) { - int n = convert->fromByteArray( - to, toOffset, num, data, dataOffset); - if (n <= 0) break; - len -= n; - num -= n; - ncopy += n; - offset += n; - toOffset += n; - } - } - break; - } - 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; - if (num <= 0) break; - while (num > 0) { - int n = convert->fromShortArray( - to, toOffset, num, data, dataOffset); - if (n <= 0) break; - len -= n; - num -= n; - ncopy += n; - offset += n; - toOffset += n; - } - } - break; - } - 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; - if (num <= 0) break; - while (num > 0) { - int n = convert->fromIntArray( - to, toOffset, num, data, dataOffset); - if (n <= 0) break; - len -= n; - num -= n; - ncopy += n; - offset += n; - toOffset += n; - } - } - break; - } - 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; - if (num <= 0) break; - while (num > 0) { - int n = convert->fromLongArray( - to, toOffset, num, data, dataOffset); - if (n <= 0) break; - len -= n; - num -= n; - ncopy += n; - offset += n; - toOffset += n; - } - } - break; - } - case pvFloat: { - PVFloatArray *pvfrom = (PVFloatArray*) from; - while (len > 0) { - int num = 0; - FloatArrayData floatArrayData = FloatArrayData(); - num = pvfrom->get(offset, len, &floatArrayData); - FloatArray data = floatArrayData.data; - int dataOffset = floatArrayData.offset; - if (num <= 0) break; - while (num > 0) { - int n = convert->fromFloatArray( - to, toOffset, num, data, dataOffset); - if (n <= 0) break; - len -= n; - num -= n; - ncopy += n; - offset += n; - toOffset += n; - } - } - break; - } - case pvDouble: { - PVDoubleArray *pvfrom = (PVDoubleArray*) from; - while (len > 0) { - int num = 0; - DoubleArrayData doubleArrayData = DoubleArrayData(); - num = pvfrom->get(offset, len, &doubleArrayData); - DoubleArray data = doubleArrayData.data; - int dataOffset = doubleArrayData.offset; - if (num <= 0) break; - while (num > 0) { - int n = convert->fromDoubleArray( - to, toOffset, num, data, dataOffset); - if (n <= 0) break; - len -= n; - num -= n; - ncopy += n; - offset += n; - toOffset += n; - } - } - break; - } - case pvString: - throw std::logic_error(String("PVStringArray is not a numeric array")); - } - return ncopy; -} - -class ConvertExt : public Convert { -public: - ConvertExt(): Convert(){}; -}; - -Convert * getConvert() { - static Mutex mutex = Mutex(); - Lock xx(&mutex); - - if(convert==0){ - convert = new ConvertExt(); - pvDataCreate = getPVDataCreate(); - } - return convert; -} - -}} diff --git a/pvDataApp/factory/AbstractPVArray.h b/pvDataApp/factory/AbstractPVArray.h index 6df873e..8d344fc 100644 --- a/pvDataApp/factory/AbstractPVArray.h +++ b/pvDataApp/factory/AbstractPVArray.h @@ -1,4 +1,10 @@ /*AbstractPVArray.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 ABSTRACTPVARRAY_H #define ABSTRACTPVARRAY_H #include diff --git a/pvDataApp/factory/AbstractPVField.h b/pvDataApp/factory/AbstractPVField.h index 1f74af5..423447b 100644 --- a/pvDataApp/factory/AbstractPVField.h +++ b/pvDataApp/factory/AbstractPVField.h @@ -1,4 +1,9 @@ /*AbstractPVField.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 ABSTRACTPVFIELD_H #define ABSTRACTPVFIELD_H #include diff --git a/pvDataApp/factory/AbstractPVScalar.h b/pvDataApp/factory/AbstractPVScalar.h index 7314e4d..804ebd6 100644 --- a/pvDataApp/factory/AbstractPVScalar.h +++ b/pvDataApp/factory/AbstractPVScalar.h @@ -1,4 +1,9 @@ /*AbstractPVScalar.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 ABSTRACTPVSCALAR_H #define ABSTRACTPVSCALAR_H #include diff --git a/pvDataApp/factory/AbstractPVScalarArray.h b/pvDataApp/factory/AbstractPVScalarArray.h index 64b997a..9726b3d 100644 --- a/pvDataApp/factory/AbstractPVScalarArray.h +++ b/pvDataApp/factory/AbstractPVScalarArray.h @@ -1,4 +1,9 @@ /*AbstractPVScalarArray.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 ABSTRACTPVSCALARARRAY_H #define ABSTRACTPVSCALARARRAY_H #include diff --git a/pvDataApp/factory/BasePVBoolean.h b/pvDataApp/factory/BasePVBoolean.h index ddb3391..f793ac8 100644 --- a/pvDataApp/factory/BasePVBoolean.h +++ b/pvDataApp/factory/BasePVBoolean.h @@ -1,4 +1,9 @@ /*BasePVBoolean.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 BASEPVBOOLEAN_H #define BASEPVBOOLEAN_H #include diff --git a/pvDataApp/factory/BasePVBooleanArray.h b/pvDataApp/factory/BasePVBooleanArray.h index 51c8613..09d7645 100644 --- a/pvDataApp/factory/BasePVBooleanArray.h +++ b/pvDataApp/factory/BasePVBooleanArray.h @@ -1,4 +1,9 @@ /*BasePVBooleanArrray.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 BASEPVBOOLEANARRAY_H #define BASEPVBOOLEANARRAY_H #include diff --git a/pvDataApp/factory/BasePVByte.h b/pvDataApp/factory/BasePVByte.h index 7376ada..6f049a8 100644 --- a/pvDataApp/factory/BasePVByte.h +++ b/pvDataApp/factory/BasePVByte.h @@ -1,4 +1,9 @@ /*BasePVByte.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 BASEPVBYTE_H #define BASEPVBYTE_H #include diff --git a/pvDataApp/factory/BasePVByteArray.h b/pvDataApp/factory/BasePVByteArray.h index 851b991..696a7b9 100644 --- a/pvDataApp/factory/BasePVByteArray.h +++ b/pvDataApp/factory/BasePVByteArray.h @@ -1,4 +1,9 @@ /*BasePVByteArray.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 BASEPVBYTEARRAY_H #define BASEPVBYTEARRAY_H #include diff --git a/pvDataApp/factory/BasePVDouble.h b/pvDataApp/factory/BasePVDouble.h index 3949d5e..8c07af0 100644 --- a/pvDataApp/factory/BasePVDouble.h +++ b/pvDataApp/factory/BasePVDouble.h @@ -1,4 +1,9 @@ /*BasePVDouble.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 BASEPVDOUBLE_H #define BASEPVDOUBLE_H #include diff --git a/pvDataApp/factory/BasePVDoubleArray.h b/pvDataApp/factory/BasePVDoubleArray.h index 54f0d50..e97c412 100644 --- a/pvDataApp/factory/BasePVDoubleArray.h +++ b/pvDataApp/factory/BasePVDoubleArray.h @@ -1,4 +1,9 @@ /*BasePVDoubleArray.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 BASEPVDOUBLEARRAY_H #define BASEPVDOUBLEARRAY_H #include diff --git a/pvDataApp/factory/BasePVFloat.h b/pvDataApp/factory/BasePVFloat.h index 69f673d..5baa37c 100644 --- a/pvDataApp/factory/BasePVFloat.h +++ b/pvDataApp/factory/BasePVFloat.h @@ -1,4 +1,9 @@ /*BasePVFloat.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 BASEPVFLOAT_H #define BASEPVFLOAT_H #include diff --git a/pvDataApp/factory/BasePVFloatArray.h b/pvDataApp/factory/BasePVFloatArray.h index 5c50fd6..1d42ca0 100644 --- a/pvDataApp/factory/BasePVFloatArray.h +++ b/pvDataApp/factory/BasePVFloatArray.h @@ -1,4 +1,9 @@ /*BasePVFloatArray.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 BASEPVFLOATARRAY_H #define BASEPVFLOATARRAY_H #include diff --git a/pvDataApp/factory/BasePVInt.h b/pvDataApp/factory/BasePVInt.h index 28469c3..c613f6b 100644 --- a/pvDataApp/factory/BasePVInt.h +++ b/pvDataApp/factory/BasePVInt.h @@ -1,4 +1,9 @@ /*BasePVInt.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 BASEPVINT_H #define BASEPVINT_H #include diff --git a/pvDataApp/factory/BasePVIntArray.h b/pvDataApp/factory/BasePVIntArray.h index b2935f7..5331c9d 100644 --- a/pvDataApp/factory/BasePVIntArray.h +++ b/pvDataApp/factory/BasePVIntArray.h @@ -1,4 +1,9 @@ /*BasePVIntArray.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 BASEPVINTARRAY_H #define BASEPVINTARRAY_H #include diff --git a/pvDataApp/factory/BasePVLong.h b/pvDataApp/factory/BasePVLong.h index 9be656c..71ad294 100644 --- a/pvDataApp/factory/BasePVLong.h +++ b/pvDataApp/factory/BasePVLong.h @@ -1,4 +1,9 @@ /*BasePVLong.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 BASEPVLONG_H #define BASEPVLONG_H #include diff --git a/pvDataApp/factory/BasePVLongArray.h b/pvDataApp/factory/BasePVLongArray.h index 7cd45ee..bdcbc28 100644 --- a/pvDataApp/factory/BasePVLongArray.h +++ b/pvDataApp/factory/BasePVLongArray.h @@ -1,4 +1,9 @@ /*BasePVLongArray.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 BASEPVLONGARRAY_H #define BASEPVLONGARRAY_H #include diff --git a/pvDataApp/factory/BasePVShort.h b/pvDataApp/factory/BasePVShort.h index 111b2e9..f36ddb4 100644 --- a/pvDataApp/factory/BasePVShort.h +++ b/pvDataApp/factory/BasePVShort.h @@ -1,4 +1,9 @@ /*BasePVShort.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 BASEPVSHORT_H #define BASEPVSHORT_H #include diff --git a/pvDataApp/factory/BasePVShortArray.h b/pvDataApp/factory/BasePVShortArray.h index 18ef9b5..b9ed07d 100644 --- a/pvDataApp/factory/BasePVShortArray.h +++ b/pvDataApp/factory/BasePVShortArray.h @@ -1,4 +1,9 @@ /*BasePVShortArray.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 BASEPVSHORTARRAY_H #define BASEPVSHORTARRAY_H #include diff --git a/pvDataApp/factory/BasePVString.h b/pvDataApp/factory/BasePVString.h index 6319e56..27b9616 100644 --- a/pvDataApp/factory/BasePVString.h +++ b/pvDataApp/factory/BasePVString.h @@ -1,4 +1,9 @@ /*BasePVString.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 BASEPVSTRING_H #define BASEPVSTRING_H #include diff --git a/pvDataApp/factory/BasePVStringArray.h b/pvDataApp/factory/BasePVStringArray.h index cb7564e..45ed3c9 100644 --- a/pvDataApp/factory/BasePVStringArray.h +++ b/pvDataApp/factory/BasePVStringArray.h @@ -1,4 +1,9 @@ /*BasePVStringArray.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 BASEPVSTRINGARRAY_H #define BASEPVSTRINGARRAY_H #include diff --git a/pvDataApp/factory/BasePVStructure.h b/pvDataApp/factory/BasePVStructure.h index e023421..10a8c77 100644 --- a/pvDataApp/factory/BasePVStructure.h +++ b/pvDataApp/factory/BasePVStructure.h @@ -1,4 +1,9 @@ /*BasePVStructure.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 BASEPVSTRUCTURE_H #define BASEPVSTRUCTURE_H #include diff --git a/pvDataApp/factory/BasePVStructureArray.h b/pvDataApp/factory/BasePVStructureArray.h index 03505db..b904525 100644 --- a/pvDataApp/factory/BasePVStructureArray.h +++ b/pvDataApp/factory/BasePVStructureArray.h @@ -1,4 +1,9 @@ /*BasePVStructureArray.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 BASEPVSTRUCTUREARRAY_H #define BASEPVSTRUCTUREARRAY_H #include diff --git a/pvDataApp/factory/Convert.cpp b/pvDataApp/factory/Convert.cpp index 00d2950..1aa17a1 100644 --- a/pvDataApp/factory/Convert.cpp +++ b/pvDataApp/factory/Convert.cpp @@ -1,4 +1,9 @@ /* Convert.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 diff --git a/pvDataApp/factory/FieldCreateFactory.cpp b/pvDataApp/factory/FieldCreateFactory.cpp index 606b2e9..167100c 100644 --- a/pvDataApp/factory/FieldCreateFactory.cpp +++ b/pvDataApp/factory/FieldCreateFactory.cpp @@ -1,4 +1,9 @@ /*FieldCreateFactory.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 diff --git a/pvDataApp/factory/PVAuxInfoImpl.cpp b/pvDataApp/factory/PVAuxInfoImpl.cpp index 52105d1..f08533d 100644 --- a/pvDataApp/factory/PVAuxInfoImpl.cpp +++ b/pvDataApp/factory/PVAuxInfoImpl.cpp @@ -1,4 +1,9 @@ /*PVAuxInfo.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 diff --git a/pvDataApp/factory/PVDataCreateFactory.cpp b/pvDataApp/factory/PVDataCreateFactory.cpp index a9e3378..9b907ee 100644 --- a/pvDataApp/factory/PVDataCreateFactory.cpp +++ b/pvDataApp/factory/PVDataCreateFactory.cpp @@ -1,4 +1,9 @@ /*PVDataCreateFactory.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 diff --git a/pvDataApp/factory/StandardField.cpp b/pvDataApp/factory/StandardField.cpp index 23b6951..76c6844 100644 --- a/pvDataApp/factory/StandardField.cpp +++ b/pvDataApp/factory/StandardField.cpp @@ -1,4 +1,9 @@ /* StandardField.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 diff --git a/pvDataApp/factory/StandardPVField.cpp b/pvDataApp/factory/StandardPVField.cpp index 4681900..8993eb2 100644 --- a/pvDataApp/factory/StandardPVField.cpp +++ b/pvDataApp/factory/StandardPVField.cpp @@ -1,4 +1,9 @@ /* StandardPVField.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 diff --git a/pvDataApp/factory/TypeFunc.cpp b/pvDataApp/factory/TypeFunc.cpp index d778390..8fbc921 100644 --- a/pvDataApp/factory/TypeFunc.cpp +++ b/pvDataApp/factory/TypeFunc.cpp @@ -1,4 +1,9 @@ - +/*TypeFunc.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 diff --git a/pvDataApp/factory/factory.h b/pvDataApp/factory/factory.h index a9e9420..3310d47 100644 --- a/pvDataApp/factory/factory.h +++ b/pvDataApp/factory/factory.h @@ -1,4 +1,9 @@ /*factory.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 FACTORY_H #define FACTORY_H diff --git a/pvDataApp/misc/Makefile b/pvDataApp/misc/Makefile index 510fac3..5f13ed9 100644 --- a/pvDataApp/misc/Makefile +++ b/pvDataApp/misc/Makefile @@ -19,6 +19,7 @@ INC += executor.h INC += showConstructDestruct.h INC += timeStamp.h INC += timeFunction.h +INC += timer.h LIBSRCS += byteBuffer.cpp LIBSRCS += bitSet.cpp @@ -30,6 +31,7 @@ LIBSRCS += thread.cpp LIBSRCS += executor.cpp LIBSRCS += timeStamp.cpp LIBSRCS += timeFunction.cpp +LIBSRCS += timer.cpp LIBRARY=pvMisc diff --git a/pvDataApp/misc/bitSet.cpp b/pvDataApp/misc/bitSet.cpp index 9e07622..0948c55 100644 --- a/pvDataApp/misc/bitSet.cpp +++ b/pvDataApp/misc/bitSet.cpp @@ -1,3 +1,9 @@ +/* bitSet.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 "string.h" #include "stdio.h" #include "bitSet.h" diff --git a/pvDataApp/misc/bitSet.h b/pvDataApp/misc/bitSet.h index 3fad16e..8e957be 100644 --- a/pvDataApp/misc/bitSet.h +++ b/pvDataApp/misc/bitSet.h @@ -1,4 +1,9 @@ /* bitSet.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 BITSET_H #define BITSET_H #include diff --git a/pvDataApp/misc/byteBuffer.cpp b/pvDataApp/misc/byteBuffer.cpp index c5acf31..7ee6730 100644 --- a/pvDataApp/misc/byteBuffer.cpp +++ b/pvDataApp/misc/byteBuffer.cpp @@ -1,3 +1,8 @@ +/** + * 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. + */ /* * byteBuffer.cpp * diff --git a/pvDataApp/misc/byteBuffer.h b/pvDataApp/misc/byteBuffer.h index d3c74f2..61e488c 100644 --- a/pvDataApp/misc/byteBuffer.h +++ b/pvDataApp/misc/byteBuffer.h @@ -1,4 +1,9 @@ /* byteBuffer.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 BYTEBUFFER_H #define BYTEBUFFER_H diff --git a/pvDataApp/misc/epicsException.h b/pvDataApp/misc/epicsException.h index 36ef646..8c6755d 100644 --- a/pvDataApp/misc/epicsException.h +++ b/pvDataApp/misc/epicsException.h @@ -1,3 +1,8 @@ +/** + * 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. + */ /* * epicsException.hpp * diff --git a/pvDataApp/misc/event.cpp b/pvDataApp/misc/event.cpp index 62624ad..31b19e7 100644 --- a/pvDataApp/misc/event.cpp +++ b/pvDataApp/misc/event.cpp @@ -1,4 +1,9 @@ /* event.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 diff --git a/pvDataApp/misc/event.h b/pvDataApp/misc/event.h index 96a3ff5..25e0edf 100644 --- a/pvDataApp/misc/event.h +++ b/pvDataApp/misc/event.h @@ -1,4 +1,9 @@ /* event.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 EVENT_H #define EVENT_H #include diff --git a/pvDataApp/misc/executor.cpp b/pvDataApp/misc/executor.cpp index b3d9b40..dcce275 100644 --- a/pvDataApp/misc/executor.cpp +++ b/pvDataApp/misc/executor.cpp @@ -1,4 +1,9 @@ -/* executor.h */ +/* executor.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 @@ -186,6 +191,10 @@ Executor::~Executor() { totalDestruct++; } +Executor *Executor::create(String threadName,ThreadPriority priority) +{ + return new Executor(threadName,priority); +} ExecutorNode * Executor::createNode(Command*command) {return pImpl->createNode(command);} diff --git a/pvDataApp/misc/executor.h b/pvDataApp/misc/executor.h index bb4be4a..b778cf7 100644 --- a/pvDataApp/misc/executor.h +++ b/pvDataApp/misc/executor.h @@ -1,4 +1,9 @@ /* executor.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 EXECUTOR_H #define EXECUTOR_H #include @@ -19,12 +24,13 @@ public: class Executor : private NoDefaultMethods { public: - Executor(String threadName,ThreadPriority priority); static ConstructDestructCallback *getConstructDestructCallback(); + static Executor *create(String threadName,ThreadPriority priority); ExecutorNode * createNode(Command *command); void execute(ExecutorNode *node); void destroy(); private: + Executor(String threadName,ThreadPriority priority); ~Executor(); class ExecutorPvt *pImpl; }; diff --git a/pvDataApp/misc/linkedList.h b/pvDataApp/misc/linkedList.h index 8dbf33b..757830d 100644 --- a/pvDataApp/misc/linkedList.h +++ b/pvDataApp/misc/linkedList.h @@ -1,4 +1,9 @@ /* linkedList.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 LINKEDLIST_H #define LINKEDLIST_H #include "linkedListVoid.h" diff --git a/pvDataApp/misc/linkedListVoid.cpp b/pvDataApp/misc/linkedListVoid.cpp index 118d6ce..f6fd2c2 100644 --- a/pvDataApp/misc/linkedListVoid.cpp +++ b/pvDataApp/misc/linkedListVoid.cpp @@ -1,4 +1,9 @@ /* linkedListVoid.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 diff --git a/pvDataApp/misc/linkedListVoid.h b/pvDataApp/misc/linkedListVoid.h index 3bedef2..4abacac 100644 --- a/pvDataApp/misc/linkedListVoid.h +++ b/pvDataApp/misc/linkedListVoid.h @@ -1,4 +1,9 @@ /* linkedListVoid.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. + */ #include "pvType.h" #include "showConstructDestruct.h" diff --git a/pvDataApp/misc/lock.h b/pvDataApp/misc/lock.h index 1e44562..6cb928d 100644 --- a/pvDataApp/misc/lock.h +++ b/pvDataApp/misc/lock.h @@ -1,4 +1,9 @@ /* lock.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 LOCK_H #define LOCK_H #include diff --git a/pvDataApp/misc/noDefaultMethods.h b/pvDataApp/misc/noDefaultMethods.h index 6ef3102..89eb52d 100644 --- a/pvDataApp/misc/noDefaultMethods.h +++ b/pvDataApp/misc/noDefaultMethods.h @@ -1,4 +1,9 @@ /* noDefaultMethods.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 NO_DEFAULT_METHODS_H #define NO_DEFAULT_METHODS_H namespace epics { namespace pvData { diff --git a/pvDataApp/misc/pvType.h b/pvDataApp/misc/pvType.h index 7fb3a5d..b0fa1d3 100644 --- a/pvDataApp/misc/pvType.h +++ b/pvDataApp/misc/pvType.h @@ -1,4 +1,9 @@ /* pvType.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. + */ #include #ifndef PVTYPE_H #define PVTYPE_H diff --git a/pvDataApp/misc/requester.h b/pvDataApp/misc/requester.h index 1363e02..ff3d7af 100644 --- a/pvDataApp/misc/requester.h +++ b/pvDataApp/misc/requester.h @@ -1,4 +1,9 @@ /* requester.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. + */ #include #ifndef REQUESTER_H #define REQUESTER_H diff --git a/pvDataApp/misc/serialize.h b/pvDataApp/misc/serialize.h index ad4f14d..45e65f8 100644 --- a/pvDataApp/misc/serialize.h +++ b/pvDataApp/misc/serialize.h @@ -1,4 +1,9 @@ /* serialize.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 SERIALIZE_H #define SERIALIZE_H #include "bitSet.h" diff --git a/pvDataApp/misc/serializeHelper.cpp b/pvDataApp/misc/serializeHelper.cpp index e05512d..549432d 100644 --- a/pvDataApp/misc/serializeHelper.cpp +++ b/pvDataApp/misc/serializeHelper.cpp @@ -1,3 +1,8 @@ +/** + * 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. + */ /* * serializeHelper.cpp * diff --git a/pvDataApp/misc/serializeHelper.h b/pvDataApp/misc/serializeHelper.h index 8b54bc2..8ce9605 100644 --- a/pvDataApp/misc/serializeHelper.h +++ b/pvDataApp/misc/serializeHelper.h @@ -1,3 +1,8 @@ +/** + * 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. + */ /* * serializeHelper.h * diff --git a/pvDataApp/misc/showConstructDestruct.cpp b/pvDataApp/misc/showConstructDestruct.cpp index 035a145..c39fcec 100644 --- a/pvDataApp/misc/showConstructDestruct.cpp +++ b/pvDataApp/misc/showConstructDestruct.cpp @@ -1,4 +1,9 @@ /* showConstructDestruct.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 diff --git a/pvDataApp/misc/showConstructDestruct.h b/pvDataApp/misc/showConstructDestruct.h index f73a229..e7b1c54 100644 --- a/pvDataApp/misc/showConstructDestruct.h +++ b/pvDataApp/misc/showConstructDestruct.h @@ -1,4 +1,9 @@ /* showConstructDestruct.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 SHOWCONSTRUCTDESTRUCT_H #define SHOWCONSTRUCTDESTRUCT_H #include diff --git a/pvDataApp/misc/thread.cpp b/pvDataApp/misc/thread.cpp index cf0a625..4c13f19 100644 --- a/pvDataApp/misc/thread.cpp +++ b/pvDataApp/misc/thread.cpp @@ -1,4 +1,9 @@ /* thread.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 diff --git a/pvDataApp/misc/thread.h b/pvDataApp/misc/thread.h index 7351729..bfb1407 100644 --- a/pvDataApp/misc/thread.h +++ b/pvDataApp/misc/thread.h @@ -1,4 +1,9 @@ /* thread.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 THREAD_H #define THREAD_H #include "noDefaultMethods.h" diff --git a/pvDataApp/misc/timeFunction.cpp b/pvDataApp/misc/timeFunction.cpp index 0dd8846..3435f1d 100644 --- a/pvDataApp/misc/timeFunction.cpp +++ b/pvDataApp/misc/timeFunction.cpp @@ -1,4 +1,9 @@ /* timeFunction.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 "noDefaultMethods.h" #include "pvType.h" #include "timeStamp.h" @@ -27,15 +32,15 @@ TimeFunction::~TimeFunction() {} double TimeFunction::timeCall() { - TimeStamp startTime(0,0); - TimeStamp endTime(0,0); + TimeStamp startTime; + TimeStamp endTime; double perCall = 0.0; long ntimes = 1; while(true) { startTime.getCurrent(); for(long i=0; ifunction(); endTime.getCurrent(); - double diff = TimeStamp::diffInSeconds(&endTime,&startTime); + double diff = TimeStamp::diff(endTime,startTime); if(diff>=1.0) { perCall = diff/(double)ntimes; break; diff --git a/pvDataApp/misc/timeFunction.h b/pvDataApp/misc/timeFunction.h index 29c77b2..2bd6c2b 100644 --- a/pvDataApp/misc/timeFunction.h +++ b/pvDataApp/misc/timeFunction.h @@ -1,4 +1,9 @@ /* timeFunction.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 TIMEFUNCTION_H #define TIMEFUNCTION_H #include "noDefaultMethods.h" diff --git a/pvDataApp/misc/timeStamp.cpp b/pvDataApp/misc/timeStamp.cpp index 7fe8746..d147a2c 100644 --- a/pvDataApp/misc/timeStamp.cpp +++ b/pvDataApp/misc/timeStamp.cpp @@ -1,4 +1,15 @@ /* timeStamp.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 "noDefaultMethods.h" #include "pvType.h" @@ -6,40 +17,126 @@ namespace epics { namespace pvData { -static uint64 TS_EPOCH_SEC_PAST_1970=7305*86400; +int32 milliSecPerSec = 1000; +int32 microSecPerSec = milliSecPerSec*milliSecPerSec; +int32 nanoSecPerSec = milliSecPerSec*microSecPerSec; +int64 posixEpochAtEpicsEpoch = POSIX_TIME_AT_EPICS_EPOCH; -TimeStamp::TimeStamp(uint64 secondsPastEpoch,uint32 nanoSeconds) +TimeStamp::TimeStamp(int64 secondsPastEpoch,int32 nanoSeconds) : secondsPastEpoch(secondsPastEpoch),nanoSeconds(nanoSeconds) {} -TimeStamp::~TimeStamp() {} - -int64 TimeStamp::getEpicsSecondsPastEpoch() -{ - return secondsPastEpoch - TS_EPOCH_SEC_PAST_1970; -} - -void TimeStamp::put(uint64 seconds,uint32 nano) -{ - secondsPastEpoch = seconds; - nanoSeconds = nano; -} void TimeStamp::getCurrent() { epicsTimeStamp epicsTime; epicsTimeGetCurrent(&epicsTime); secondsPastEpoch = epicsTime.secPastEpoch; - secondsPastEpoch += TS_EPOCH_SEC_PAST_1970; + secondsPastEpoch += posixEpochAtEpicsEpoch; nanoSeconds = epicsTime.nsec; } -double TimeStamp::diffInSeconds(TimeStamp *left,TimeStamp *right) +double TimeStamp::toSeconds() const { - double diff = left->secondsPastEpoch - right->secondsPastEpoch; - int64 nano =left->nanoSeconds - right->nanoSeconds; - diff += ((double)nano)/1e9; - return diff; + double value = secondsPastEpoch; + double nano = nanoSeconds; + value += nano/1e9; + return value; +} + +int64 TimeStamp::diffInt(TimeStamp const & left,TimeStamp const&right ) +{ + int64 sl = left.secondsPastEpoch; + int32 nl = left.nanoSeconds; + int64 sr = right.secondsPastEpoch; + int32 nr = right.nanoSeconds; + int64 sdiff = sl - sr; + sdiff *= nanoSecPerSec; + sdiff += nl - nr; + return sdiff; +} + +bool TimeStamp::operator==(TimeStamp const &right) const +{ + int64 sdiff = diffInt(*this,right); + if(sdiff==0) return true; + return false; +} + +bool TimeStamp::operator!=(TimeStamp const &right) const +{ + int64 sdiff = diffInt(*this,right); + if(sdiff!=0) return true; + return false; +} + +bool TimeStamp::operator<=(TimeStamp const &right) const +{ + int64 sdiff = diffInt(*this,right); + if(sdiff<=0) return true; + return false; +} + +bool TimeStamp::operator< (TimeStamp const &right) const +{ + int64 sdiff = diffInt(*this,right); + if(sdiff<0) return true; + return false; +} + +bool TimeStamp::operator>=(TimeStamp const &right) const +{ + int64 sdiff = diffInt(*this,right); + if(sdiff>=0) return true; + return false; +} + +bool TimeStamp::operator>(TimeStamp const &right) const +{ + int64 sdiff = diffInt(*this,right); + if(sdiff>0) return true; + return false; +} + +double TimeStamp::diff(TimeStamp const & a,TimeStamp const & b) +{ + double result = a.secondsPastEpoch - b.secondsPastEpoch; + result += (a.nanoSeconds - b.nanoSeconds)/1e9; + return result; +} + + +TimeStamp & TimeStamp::operator+=(int64 seconds) +{ + secondsPastEpoch += seconds; + return *this; +} + +TimeStamp & TimeStamp::operator-=(int64 seconds) +{ + secondsPastEpoch -= seconds; + return *this; +} + +TimeStamp & TimeStamp::operator+=(double seconds) +{ + int64 secs = seconds; + int64 nano = (seconds - secs)*1e9; + nanoSeconds += nano; + if(nanoSeconds>nanoSecPerSec) { + nanoSeconds -= nanoSecPerSec; + secondsPastEpoch += 1; + } else if(nanoSeconds<-nanoSecPerSec) { + nanoSeconds += -nanoSecPerSec; + secondsPastEpoch -= 1; + } + secondsPastEpoch += secs; + return *this; +} + +TimeStamp & TimeStamp::operator-=(double seconds) +{ + return operator+=(-seconds); } int64 TimeStamp::getMilliseconds() diff --git a/pvDataApp/misc/timeStamp.h b/pvDataApp/misc/timeStamp.h index 0c767da..f95654d 100644 --- a/pvDataApp/misc/timeStamp.h +++ b/pvDataApp/misc/timeStamp.h @@ -1,25 +1,57 @@ /* timeStamp.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 TIMESTAMP_H #define TIMESTAMP_H -#include "noDefaultMethods.h" +#include "epicsTime.h" #include "pvType.h" namespace epics { namespace pvData { -class TimeStamp : private NoDefaultMethods { +extern int32 milliSecPerSec; +extern int32 microSecPerSec; +extern int32 nanoSecPerSec; +extern int64 posixEpochAtEpicsEpoch; + +class TimeStamp { public: - TimeStamp(uint64 secondsPastEpoch,uint32 nanoSeconds); - ~TimeStamp(); - int64 getSecondsPastEpoch(){return secondsPastEpoch;} - int32 getNanoSeconds() {return nanoSeconds;} - int64 getEpicsSecondsPastEpoch(); - void put(uint64 secondsPastEpoch,uint32 nanoSeconds); + TimeStamp() + :secondsPastEpoch(0),nanoSeconds(0) {} + //default constructors and destructor are OK + //This class should not be extended + TimeStamp(int64 secondsPastEpoch,int32 nanoSeconds = 0); + TimeStamp(epicsTimeStamp &epics); + int64 getSecondsPastEpoch() const {return secondsPastEpoch;} + int64 getEpicsSecondsPastEpoch() const { + return secondsPastEpoch - posixEpochAtEpicsEpoch; + } + int32 getNanoSeconds() const {return nanoSeconds;} + void put(int64 secondsPastEpoch,int32 nanoSeconds = 0) { + this->secondsPastEpoch = secondsPastEpoch; + this->nanoSeconds = nanoSeconds; + } void getCurrent(); - static double diffInSeconds(TimeStamp *left,TimeStamp *right); + double toSeconds() const ; + bool operator==(TimeStamp const &) const; + bool operator!=(TimeStamp const &) const; + bool operator<=(TimeStamp const &) const; + bool operator< (TimeStamp const &) const; + bool operator>=(TimeStamp const &) const; + bool operator> (TimeStamp const &) const; + static double diff(TimeStamp const & a,TimeStamp const & b); + TimeStamp & operator+=(int64 seconds); + TimeStamp & operator-=(int64 seconds); + TimeStamp & operator+=(double seconds); + TimeStamp & operator-=(double seconds); // milliseconds since epoch int64 getMilliseconds(); void put(int64 milliseconds); + private: + static int64 diffInt(TimeStamp const &left,TimeStamp const &right ); int64 secondsPastEpoch; int32 nanoSeconds; }; diff --git a/pvDataApp/misc/timer.cpp b/pvDataApp/misc/timer.cpp new file mode 100644 index 0000000..5fbd531 --- /dev/null +++ b/pvDataApp/misc/timer.cpp @@ -0,0 +1,332 @@ +/* timer.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 "pvType.h" +#include "lock.h" +#include "noDefaultMethods.h" +#include "showConstructDestruct.h" +#include "linkedList.h" +#include "thread.h" +#include "timeStamp.h" +#include "timer.h" +#include "event.h" + +namespace epics { namespace pvData { + + +static volatile int64 totalNodeConstruct = 0; +static volatile int64 totalNodeDestruct = 0; +static volatile int64 totalTimerConstruct = 0; +static volatile int64 totalTimerDestruct = 0; +static Mutex *globalMutex = 0; + +static int64 getTotalTimerNodeConstruct() +{ + Lock xx(globalMutex); + return totalNodeConstruct; +} + +static int64 getTotalTimerNodeDestruct() +{ + Lock xx(globalMutex); + return totalNodeDestruct; +} + +static int64 getTotalTimerConstruct() +{ + Lock xx(globalMutex); + return totalTimerConstruct; +} + +static int64 getTotalTimerDestruct() +{ + Lock xx(globalMutex); + return totalTimerDestruct; +} + +static ConstructDestructCallback *pCDCallbackTimerNode; +static ConstructDestructCallback *pCDCallbackTimer; + +static void init() +{ + static Mutex mutex = Mutex(); + Lock xx(&mutex); + if(globalMutex==0) { + globalMutex = new Mutex(); + pCDCallbackTimerNode = new ConstructDestructCallback( + "timerNode", + getTotalTimerNodeConstruct,getTotalTimerNodeDestruct,0); + + pCDCallbackTimer = new ConstructDestructCallback( + "timer", + getTotalTimerConstruct,getTotalTimerDestruct,0); + } +} + +ConstructDestructCallback * TimerNode::getConstructDestructCallback() +{ + init(); + return pCDCallbackTimerNode; +} + +ConstructDestructCallback * Timer::getConstructDestructCallback() +{ + init(); + return pCDCallbackTimer; +} + +class TimerNodePvt; + +typedef LinkedListNode ListNode; +typedef LinkedList List; + +class TimerNodePvt { +public: + TimerNode *timerNode; + TimerCallback *callback; + ListNode *listNode; + TimeStamp timeToRun; + TimerPvt *timerPvt; + double period; + TimerNodePvt(TimerNode *timerNode,TimerCallback *callback); + ~TimerNodePvt(); +}; + +TimerNodePvt::TimerNodePvt(TimerNode *timerNode,TimerCallback *callback) +: timerNode(timerNode),callback(callback), + listNode(new ListNode(this)),timeToRun(TimeStamp()), + timerPvt(0), period(0.0) +{} + +TimerNodePvt::~TimerNodePvt() +{ + delete listNode; +} + +struct TimerPvt : public RunnableReady { +public: + TimerPvt(String threadName,ThreadPriority priority); + ~TimerPvt(); + virtual void run(ThreadReady *threadReady); +public: // only used by this source module + List *list; + Mutex mutex; + Event *waitForWork; + Event *waitForDone; + Thread *thread; + volatile bool alive; +}; + +TimerPvt::TimerPvt(String threadName,ThreadPriority priority) +: list(new List()), + mutex(Mutex()), + waitForWork(new Event(eventEmpty)), + waitForDone(new Event(eventEmpty)), + thread(new Thread(threadName,priority,this)), + alive(true) +{ + thread->start(); +} + +TimerPvt::~TimerPvt() +{ + delete thread; + delete waitForDone; + delete waitForWork; + delete list; +} + +static void addElement(TimerPvt *timer,TimerNodePvt *node) +{ + List *list = timer->list; + ListNode *nextNode = list->getHead(); + if(nextNode==0) { + list->addTail(node->listNode); + return; + } + while(true) { + TimerNodePvt *listNode = nextNode->getObject(); + if((node->timeToRun)<(listNode->timeToRun)) { + list->insertBefore(listNode->listNode,node->listNode); + return; + } + nextNode = list->getNext(listNode->listNode); + if(nextNode==0) { + list->addTail(node->listNode); + return; + } + } +} + + +TimerNode::TimerNode(TimerCallback *callback) +: pImpl(new TimerNodePvt(this,callback)) +{ + init(); + Lock xx(globalMutex); + totalNodeConstruct++; +} + +TimerNode *TimerNode::create(TimerCallback *callback) +{ + return new TimerNode(callback); +} + +TimerNode::~TimerNode() +{ + delete pImpl; + Lock xx(globalMutex); + totalNodeDestruct++; +} + +void TimerNode::destroy() +{ + cancel(); + delete this; +} + +void TimerNode::cancel() +{ + TimerPvt *timerPvt = pImpl->timerPvt; + if(timerPvt==0) return; + Lock xx(&timerPvt->mutex); + if(pImpl->timerPvt==0) return; + pImpl->timerPvt->list->remove(pImpl); + pImpl->timerPvt = 0; +} + +bool TimerNode::isScheduled() +{ + TimerPvt *pvt = pImpl->timerPvt; + if(pvt==0) return false; + Lock xx(&pvt->mutex); + return pImpl->listNode->isOnList(); +} + + +void TimerPvt::run(ThreadReady *threadReady) +{ + threadReady->ready(); + TimeStamp currentTime; + while(alive) { + currentTime.getCurrent(); + TimeStamp *timeToRun = 0; + double period = 0.0; + TimerNodePvt *nodeToCall = 0; + { + Lock xx(&mutex); + ListNode *listNode = list->getHead(); + if(listNode!=0) { + TimerNodePvt *timerNodePvt = listNode->getObject(); + timeToRun = &timerNodePvt->timeToRun; + double diff = TimeStamp::diff( + *timeToRun,currentTime); + if(diff<=0.0) { + nodeToCall = timerNodePvt; + list->removeHead(); + period = timerNodePvt->period; + if(period>0) { + timerNodePvt->timeToRun += period; + addElement(this,timerNodePvt); + } else { + timerNodePvt->timerPvt = 0; + } + listNode = list->getHead(); + if(listNode!=0) { + timerNodePvt = listNode->getObject(); + timeToRun = &timerNodePvt->timeToRun; + } else { + timeToRun = 0; + } + } + } + } + if(nodeToCall!=0) { + nodeToCall->callback->callback(); + } + if(!alive) break; + if(timeToRun==0) { + waitForWork->wait(); + } else { + double delay = TimeStamp::diff(*timeToRun,currentTime); + waitForWork->wait(delay); + } + } + waitForDone->signal(); +} + +Timer::Timer(String threadName, ThreadPriority priority) +: pImpl(new TimerPvt(threadName,priority)) +{ + init(); + Lock xx(globalMutex); + totalTimerConstruct++; +} + +Timer * Timer::create(String threadName, ThreadPriority priority) +{ + return new Timer(threadName,priority); +} + +Timer::~Timer() { + delete pImpl; + Lock xx(globalMutex); + totalTimerDestruct++; +} + +void Timer::destroy() +{ + { + Lock xx(&pImpl->mutex); + pImpl->alive = false; + pImpl->waitForWork->signal(); + pImpl->waitForDone->wait(); + } + List *list = pImpl->list; + ListNode *node = 0; + while((node = list->removeHead())!=0) { + node->getObject()->callback->timerStopped(); + } + delete this; +} + +void Timer::scheduleAfterDelay(TimerNode *timerNode,double delay) +{ + schedulePeriodic(timerNode,delay,0.0); +} +void Timer::schedulePeriodic(TimerNode *timerNode,double delay,double period) +{ + TimerNodePvt *timerNodePvt = timerNode->pImpl; + if(timerNodePvt->listNode->isOnList()) { + throw std::logic_error(String("already queued")); + } + if(!pImpl->alive) { + timerNodePvt->callback->timerStopped(); + return; + } + TimeStamp *timeStamp = &timerNodePvt->timeToRun; + timeStamp->getCurrent(); + *timeStamp += delay; + timerNodePvt->period = period; + bool isFirst = false; + { + Lock xx(&pImpl->mutex); + timerNodePvt->timerPvt = pImpl; + addElement(pImpl,timerNodePvt); + TimerNodePvt *first = pImpl->list->getHead()->getObject(); + if(first==timerNodePvt) isFirst = true; + } + if(isFirst) pImpl->waitForWork->signal(); +} + +}} diff --git a/pvDataApp/misc/timer.h b/pvDataApp/misc/timer.h new file mode 100644 index 0000000..f71d3fa --- /dev/null +++ b/pvDataApp/misc/timer.h @@ -0,0 +1,57 @@ +/* timer.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 TIMER_H +#define TIMER_H +#include +#include +#include +#include +#include + +#include "pvType.h" +#include "thread.h" +#include "noDefaultMethods.h" +#include "showConstructDestruct.h" + +namespace epics { namespace pvData { + +class TimerCallback { +public: + virtual void callback() = 0; + virtual void timerStopped() = 0; +}; + +class TimerNode : private NoDefaultMethods { +public: + static ConstructDestructCallback *getConstructDestructCallback(); + static TimerNode *create(TimerCallback *timerCallback); + void destroy(); + void cancel(); + bool isScheduled(); +private: + TimerNode(TimerCallback *timerCallback); + ~TimerNode(); + class TimerNodePvt *pImpl; + friend class Timer; +}; + +class Timer : private NoDefaultMethods { +public: + static ConstructDestructCallback *getConstructDestructCallback(); + static Timer * create(String threadName, ThreadPriority priority); + void destroy(); + void scheduleAfterDelay(TimerNode *timerNode,double delay); + void schedulePeriodic(TimerNode *timerNode,double delay,double period); +private: + Timer(String threadName, ThreadPriority priority); + ~Timer(); + class TimerPvt *pImpl; + friend class TimerNode; +}; + +}} +#endif /* TIMER_H */ diff --git a/pvDataApp/miscTest/Makefile b/pvDataApp/miscTest/Makefile index 340501a..e41f91c 100644 --- a/pvDataApp/miscTest/Makefile +++ b/pvDataApp/miscTest/Makefile @@ -2,6 +2,10 @@ TOP=../.. include $(TOP)/configure/CONFIG +PROD_HOST += testTimeStamp +testTimeStamp_SRCS += testTimeStamp.cpp +testTimeStamp_LIBS += pvMisc Com + PROD_HOST += testLinkedList testLinkedList_SRCS += testLinkedList.cpp testLinkedList_LIBS += pvMisc Com @@ -10,6 +14,10 @@ PROD_HOST += testThread testThread_SRCS += testThread.cpp testThread_LIBS += pvMisc Com +PROD_HOST += testTimer +testTimer_SRCS += testTimer.cpp +testTimer_LIBS += pvMisc Com + PROD_HOST += testBitSet testBitSet_SRCS += testBitSet.cpp testBitSet_LIBS += pvMisc Com diff --git a/pvDataApp/miscTest/testBaseException.cpp b/pvDataApp/miscTest/testBaseException.cpp index bd16b51..c2cefed 100644 --- a/pvDataApp/miscTest/testBaseException.cpp +++ b/pvDataApp/miscTest/testBaseException.cpp @@ -1,4 +1,9 @@ /* testBaseException.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: Matej Sekoranja Date: 2010.10.18 */ #include diff --git a/pvDataApp/miscTest/testBitSet.cpp b/pvDataApp/miscTest/testBitSet.cpp index 7c05567..15eda03 100644 --- a/pvDataApp/miscTest/testBitSet.cpp +++ b/pvDataApp/miscTest/testBitSet.cpp @@ -1,4 +1,9 @@ /* testBitSet.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: Matej Sekoranja Date: 2010.10.18 */ #include diff --git a/pvDataApp/miscTest/testByteBuffer.cpp b/pvDataApp/miscTest/testByteBuffer.cpp index b9f9424..7de8607 100644 --- a/pvDataApp/miscTest/testByteBuffer.cpp +++ b/pvDataApp/miscTest/testByteBuffer.cpp @@ -1,3 +1,8 @@ +/** + * 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. + */ /* * testByteBuffer.cpp * diff --git a/pvDataApp/miscTest/testLinkedList.cpp b/pvDataApp/miscTest/testLinkedList.cpp index 022044f..8b668d0 100644 --- a/pvDataApp/miscTest/testLinkedList.cpp +++ b/pvDataApp/miscTest/testLinkedList.cpp @@ -1,3 +1,8 @@ +/** + * 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. + */ /* * testLinkedList.cpp * @@ -270,8 +275,8 @@ static void testOrderedQueue(FILE * fd ) { } static void testTime(FILE *auxFd) { - TimeStamp startTime(0,0); - TimeStamp endTime(0,0); + TimeStamp startTime; + TimeStamp endTime; int numNodes = 1000; LinkedList *basicList = new BasicList(); @@ -288,7 +293,7 @@ static void testTime(FILE *auxFd) { while(basicNode!=0) basicNode = basicList->removeHead(); } endTime.getCurrent(); - double diff = TimeStamp::diffInSeconds(&endTime,&startTime); + double diff = TimeStamp::diff(endTime,startTime); diff /= 1000.0; fprintf(auxFd,"diff %f milliSeconds\n",diff); diff = diff/1000.0; // convert from milliseconds to seconds @@ -303,8 +308,8 @@ static void testTime(FILE *auxFd) { } static void testTimeLocked(FILE *auxFd) { - TimeStamp startTime(0,0); - TimeStamp endTime(0,0); + TimeStamp startTime; + TimeStamp endTime; Mutex *mutex = new Mutex(); int numNodes = 1000; @@ -332,7 +337,7 @@ static void testTimeLocked(FILE *auxFd) { } } endTime.getCurrent(); - double diff = TimeStamp::diffInSeconds(&endTime,&startTime); + double diff = TimeStamp::diff(endTime,startTime); diff *= 1000.0; fprintf(auxFd,"diff %f milliSeconds\n",diff); diff = diff/1000.0; // convert from milliseconds to seconds @@ -348,8 +353,8 @@ static void testTimeLocked(FILE *auxFd) { typedef std::list stdList; static void testArrayListTime(FILE *auxFd) { - TimeStamp startTime(0,0); - TimeStamp endTime(0,0); + TimeStamp startTime; + TimeStamp endTime; int numNodes = 1000; stdList basicList; @@ -368,7 +373,7 @@ static void testArrayListTime(FILE *auxFd) { } } endTime.getCurrent(); - double diff = TimeStamp::diffInSeconds(&endTime,&startTime); + double diff = TimeStamp::diff(endTime,startTime); diff *= 1000.0; fprintf(auxFd,"diff %f milliSeconds\n",diff); diff = diff/1000.0; // convert from milliseconds to seconds @@ -381,8 +386,8 @@ static void testArrayListTime(FILE *auxFd) { } static void testArrayListTimeLocked(FILE *auxFd) { - TimeStamp startTime(0,0); - TimeStamp endTime(0,0); + TimeStamp startTime; + TimeStamp endTime; int numNodes = 1000; Mutex *mutex = new Mutex(); @@ -406,7 +411,7 @@ static void testArrayListTimeLocked(FILE *auxFd) { } } endTime.getCurrent(); - double diff = TimeStamp::diffInSeconds(&endTime,&startTime); + double diff = TimeStamp::diff(endTime,startTime); diff *= 1000.0; fprintf(auxFd,"diff %f milliSeconds\n",diff); diff = diff/1000.0; // convert from milliseconds to seconds diff --git a/pvDataApp/miscTest/testSerialization.cpp b/pvDataApp/miscTest/testSerialization.cpp index 8e30303..d8635f8 100644 --- a/pvDataApp/miscTest/testSerialization.cpp +++ b/pvDataApp/miscTest/testSerialization.cpp @@ -1,3 +1,8 @@ +/** + * 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. + */ /* * testSerialization.cpp * diff --git a/pvDataApp/miscTest/testThread.cpp b/pvDataApp/miscTest/testThread.cpp index 49d7836..c54ed55 100644 --- a/pvDataApp/miscTest/testThread.cpp +++ b/pvDataApp/miscTest/testThread.cpp @@ -1,3 +1,8 @@ +/** + * 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. + */ /* * testThread.cpp * @@ -60,7 +65,7 @@ void Basic::command() static void testBasic(FILE *fd) { - Executor *executor = new Executor(String("basic"),middlePriority); + Executor *executor = Executor::create(String("basic"),middlePriority); Basic *basic = new Basic(executor); basic->run(); delete basic; @@ -84,7 +89,7 @@ private: }; static void testThreadContext(FILE *fd,FILE *auxFd) { - Executor *executor = new Executor(String("basic"),middlePriority); + Executor *executor = Executor::create(String("basic"),middlePriority); Basic *basic = new Basic(executor); MyFunc myFunc(basic); TimeFunction timeFunction(&myFunc); diff --git a/pvDataApp/miscTest/testTimeStamp.cpp b/pvDataApp/miscTest/testTimeStamp.cpp new file mode 100644 index 0000000..484174c --- /dev/null +++ b/pvDataApp/miscTest/testTimeStamp.cpp @@ -0,0 +1,114 @@ +/** + * 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. + */ +/* + * testTimeStamp.cpp + * + * Created on: 2010.11 + * Author: Marty Kraimer + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include "timeStamp.h" + +using namespace epics::pvData; + +void testTimeStamp(FILE *fd,FILE *auxfd) +{ + assert(nanoSecPerSec==1000000000); + TimeStamp current; + current.getCurrent(); + fprintf(auxfd,"current %lli %i milliSec %lli\n", + current.getSecondsPastEpoch(), + current.getNanoSeconds(), + current.getMilliseconds()); + TimeStamp right; + TimeStamp left; + right.put(current.getSecondsPastEpoch(),current.getNanoSeconds()); + left.put(current.getSecondsPastEpoch(),current.getNanoSeconds()); + double diff; + diff = TimeStamp::diff(left,right); + fprintf(fd,"diff %e\n",diff); + assert(diff==0.0); + assert((left==right)); + assert(!(left!=right)); + assert((left<=right)); + assert(!(left=right)); + assert(!(left>right)); + left.put(current.getSecondsPastEpoch()+1,current.getNanoSeconds()); + diff = TimeStamp::diff(left,right); + fprintf(fd,"diff %e\n",diff); + assert(!(left==right)); + assert((left!=right)); + assert(!(left<=right)); + assert(!(left=right)); + assert((left>right)); + left.put(current.getSecondsPastEpoch()-1,current.getNanoSeconds()); + diff = TimeStamp::diff(left,right); + fprintf(fd,"diff %e\n",diff); + assert(diff==-1.0); + assert(!(left==right)); + assert((left!=right)); + assert((left<=right)); + assert((left=right)); + assert(!(left>right)); + left.put(current.getSecondsPastEpoch(),current.getNanoSeconds()-nanoSecPerSec); + diff = TimeStamp::diff(left,right); + fprintf(fd,"diff %e\n",diff); + assert(diff==-1.0); + assert(!(left==right)); + assert((left!=right)); + assert((left<=right)); + assert((left=right)); + assert(!(left>right)); + left.put(current.getSecondsPastEpoch(),current.getNanoSeconds()-1); + diff = TimeStamp::diff(left,right); + fprintf(fd,"diff %e\n",diff); + assert(diff<0.0); + assert(!(left==right)); + assert((left!=right)); + assert((left<=right)); + assert((left=right)); + assert(!(left>right)); + left.put(current.getSecondsPastEpoch(),current.getNanoSeconds()); + left += .1; + diff = TimeStamp::diff(left,right); + fprintf(fd,"diff %e\n",diff); + left.put(current.getSecondsPastEpoch(),current.getNanoSeconds()); + int64 inc = -1; + left += inc; + diff = TimeStamp::diff(left,right); + assert(diff==-1.0); +} + +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+"); + } + char *auxFileName = 0; + if(argc>2) auxFileName = argv[2]; + FILE *auxfd = stdout; + if(auxFileName!=0 && auxFileName[0]!=0) { + auxfd = fopen(auxFileName,"w+"); + } + testTimeStamp(fd,auxfd); + return (0); +} diff --git a/pvDataApp/miscTest/testTimer.cpp b/pvDataApp/miscTest/testTimer.cpp new file mode 100644 index 0000000..f5b1bc5 --- /dev/null +++ b/pvDataApp/miscTest/testTimer.cpp @@ -0,0 +1,117 @@ +/** + * 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. + */ +/* + * testTimer.cpp + * + * Created on: 2010.11 + * Author: Marty Kraimer + */ + +#include +#include +#include +#include +#include + +#include +#include "timeStamp.h" +#include "event.h" +#include "timer.h" +#include "thread.h" +#include "showConstructDestruct.h" + +using namespace epics::pvData; + +static TimeStamp currentTimeStamp; +static double oneDelay = 4.0; +static double twoDelay = 2.0; + +class MyCallback : public TimerCallback { +public: + MyCallback(String name,FILE *fd,FILE *auxfd,Event *wait) + : name(name),fd(fd),auxfd(auxfd),wait(wait), + timerNode(TimerNode::create(this)),timeStamp(TimeStamp()) + { + } + ~MyCallback() + { + timerNode->destroy(); + } + virtual void callback() + { + timeStamp.getCurrent(); + wait->signal(); + } + virtual void timerStopped() + { + fprintf(fd,"timerStopped %s\n",name.c_str()); + } + TimerNode *getTimerNode() { return timerNode;} + TimeStamp &getTimeStamp() { return timeStamp;} +private: + String name; + FILE *fd; + FILE *auxfd; + Event *wait; + TimerNode *timerNode; + TimeStamp timeStamp; +}; + +static void testBasic(FILE *fd, FILE *auxfd) +{ + String one("one"); + String two("two"); + Event *eventOne = new Event(eventEmpty); + Event *eventTwo = new Event(eventEmpty); + Timer *timer = Timer::create(String("timer"),middlePriority); + MyCallback *callbackOne = new MyCallback( + one,fd,auxfd,eventOne); + MyCallback *callbackTwo = new MyCallback( + two,fd,auxfd,eventTwo); + currentTimeStamp.getCurrent(); + timer->scheduleAfterDelay(callbackOne->getTimerNode(),oneDelay); + timer->scheduleAfterDelay(callbackTwo->getTimerNode(),twoDelay); + eventOne->wait(); + eventTwo->wait(); + double diff; + diff = TimeStamp::diff( + callbackOne->getTimeStamp(),currentTimeStamp); + fprintf(auxfd,"one requested %f diff %f seconds\n",oneDelay,diff); + diff = TimeStamp::diff( + callbackTwo->getTimeStamp(),currentTimeStamp); + fprintf(auxfd,"two requested %f diff %f seconds\n",twoDelay,diff); + timer->destroy(); + delete callbackOne; + delete callbackTwo; + delete eventOne; + delete eventTwo; +} + +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+"); + } + char *auxFileName = 0; + if(argc>2) auxFileName = argv[2]; + FILE *auxfd = stdout; + if(auxFileName!=0 && auxFileName[0]!=0) { + auxfd = fopen(auxFileName,"w+"); + } + oneDelay = .4; + twoDelay = .2; + testBasic(fd,auxfd); + oneDelay = .2; + twoDelay = .4; + testBasic(fd,auxfd); + oneDelay = .0; + twoDelay = .0; + testBasic(fd,auxfd); + getShowConstructDestruct()->constuctDestructTotals(fd); + return (0); +} diff --git a/pvDataApp/property/Makefile b/pvDataApp/property/Makefile index 9cac164..5ea247b 100644 --- a/pvDataApp/property/Makefile +++ b/pvDataApp/property/Makefile @@ -3,11 +3,13 @@ TOP=../.. include $(TOP)/configure/CONFIG INC += enumerated.h +INC += pvTimeStamp.h -LIBSRCS += enumerated.cpp -enumerated_LIBS += pvFactory pvMisc Com +#LIBSRCS += enumerated.cpp +#LIBSRCS += pvTimeStamp.cpp +#enumerated_LIBS += pvFactory pvMisc Com -LIBRARY=pvProperty +#LIBRARY=pvProperty include $(TOP)/configure/RULES diff --git a/pvDataApp/property/enumerated.cpp b/pvDataApp/property/enumerated.cpp index aeb1d4a..19e75fc 100644 --- a/pvDataApp/property/enumerated.cpp +++ b/pvDataApp/property/enumerated.cpp @@ -1,4 +1,9 @@ /* enumerated.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 "pvType.h" diff --git a/pvDataApp/property/enumerated.h b/pvDataApp/property/enumerated.h index 49c807f..6b9a3dd 100644 --- a/pvDataApp/property/enumerated.h +++ b/pvDataApp/property/enumerated.h @@ -1,28 +1,37 @@ /* enumerated.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. + */ #include -#include +#include "pvTypes.h" +#include "pvData.h" #ifndef ENUMERATED_H #define ENUMERATED_H -#include "pvIntrospect.h" -#include "pvData.h" #include "noDefaultMethods.h" namespace epics { namespace pvData { -class Enumerated : private NoDefaultMethods { +class Enumerated ; public: - static Enumerated* create(PVField *pvField); + //default constructors and destructor are OK + //This class should not be extended + + //returns (false,true) if pvField(isNot, is valid enumerated structure + bool attach(PVField *pvField); ~Enumerated(); - PVInt *getIndex() { return pvIndex;} + // each of the following throws logic_error is not attached to PVField + void putIndex(int32 index); + int32 getIndex(); String getChoice(); - PVStringArray *getChoices() { return pvChoices;} - PVStructure *getPV() { return pvStructure;} + bool choicesMutable(); + StringArray getChoices(); + int32 getNumberChoices(); + // also throws logic_error of immutable + void putChoices(StringArray choices,int32 numberChoices); private: - Enumerated(PVStructure *pvStructure, - PVInt *pvIndex,PVStringArray *pvChoices); - PVStructure *pvStructure; PVInt *pvIndex; PVStringArray *pvChoices; - StringArrayData stringArrayData; }; }} diff --git a/pvDataApp/property/pvTimeStamp.h b/pvDataApp/property/pvTimeStamp.h new file mode 100644 index 0000000..a0547de --- /dev/null +++ b/pvDataApp/property/pvTimeStamp.h @@ -0,0 +1,33 @@ +/* pvTimeStamp.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. + */ +#include +#include +#ifndef PVTIMESTAMP_H +#define PVTIMESTAMP_H +#include "pvTypes.h" +#include "timeStamp.h" +#include "pvData.h" +namespace epics { namespace pvData { + +class PVTimeStamp { +public: + //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); + // throws logic_error is not attached to PVField + TimeStamp &get(); + // throws logic_error is not attached to PVField + void put (TimeStamp &timeStamp); +private: + PVLong* pvSecs; + PVInt* pvNano; +}; + +}} +#endif /* PVTIMESTAMP_H */ diff --git a/pvDataApp/pv/convert.h b/pvDataApp/pv/convert.h index 65f6878..2800b91 100644 --- a/pvDataApp/pv/convert.h +++ b/pvDataApp/pv/convert.h @@ -1,4 +1,9 @@ /* convert.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. + */ #include #include #ifndef CONVERT_H diff --git a/pvDataApp/pv/pvData.h b/pvDataApp/pv/pvData.h index acd54a2..37c2f5b 100644 --- a/pvDataApp/pv/pvData.h +++ b/pvDataApp/pv/pvData.h @@ -1,4 +1,9 @@ /* pvData.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. + */ #include #include #include diff --git a/pvDataApp/pv/pvIntrospect.h b/pvDataApp/pv/pvIntrospect.h index 8cf237c..9bb6ab5 100644 --- a/pvDataApp/pv/pvIntrospect.h +++ b/pvDataApp/pv/pvIntrospect.h @@ -1,4 +1,9 @@ /* pvIntrospect.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. + */ #include #include #ifndef PVINTROSPECT_H diff --git a/pvDataApp/pv/standardField.h b/pvDataApp/pv/standardField.h index fa7f807..fdcc9ce 100644 --- a/pvDataApp/pv/standardField.h +++ b/pvDataApp/pv/standardField.h @@ -1,4 +1,9 @@ /* standardField.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. + */ #include #include #ifndef STANDARDFIELD_H diff --git a/pvDataApp/pv/standardPVField.h b/pvDataApp/pv/standardPVField.h index 70258c2..be1ea74 100644 --- a/pvDataApp/pv/standardPVField.h +++ b/pvDataApp/pv/standardPVField.h @@ -1,4 +1,9 @@ /* standardPVField.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. + */ #include #include #ifndef STANDARDPVFIELD_H diff --git a/pvDataApp/pvTest/testIntrospect.cpp b/pvDataApp/pvTest/testIntrospect.cpp index 302daeb..494e3d2 100644 --- a/pvDataApp/pvTest/testIntrospect.cpp +++ b/pvDataApp/pvTest/testIntrospect.cpp @@ -1,4 +1,9 @@ /* testIntrospect.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.09 */ #include diff --git a/pvDataApp/pvTest/testPVAuxInfo.cpp b/pvDataApp/pvTest/testPVAuxInfo.cpp index 86850d1..0fbb678 100644 --- a/pvDataApp/pvTest/testPVAuxInfo.cpp +++ b/pvDataApp/pvTest/testPVAuxInfo.cpp @@ -1,4 +1,9 @@ /* testPVAuxInfo.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 diff --git a/pvDataApp/pvTest/testPVData.cpp b/pvDataApp/pvTest/testPVData.cpp index 3ed4ea1..f3dd870 100644 --- a/pvDataApp/pvTest/testPVData.cpp +++ b/pvDataApp/pvTest/testPVData.cpp @@ -1,4 +1,9 @@ /* testPVdata.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 diff --git a/pvDataApp/pvTest/testPVStructureArray.cpp b/pvDataApp/pvTest/testPVStructureArray.cpp index 4ffa071..5f64c77 100644 --- a/pvDataApp/pvTest/testPVStructureArray.cpp +++ b/pvDataApp/pvTest/testPVStructureArray.cpp @@ -1,4 +1,9 @@ /* testPVStructureArray.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.10 */ #include diff --git a/pvDataApp/pvTest/testPVType.cpp b/pvDataApp/pvTest/testPVType.cpp index 7e02a7d..9706b77 100644 --- a/pvDataApp/pvTest/testPVType.cpp +++ b/pvDataApp/pvTest/testPVType.cpp @@ -1,4 +1,9 @@ /* testPVType.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.09 */ #include diff --git a/test/testAll.pl b/test/testAll.pl index c6a9776..c2aefb8 100755 --- a/test/testAll.pl +++ b/test/testAll.pl @@ -8,3 +8,5 @@ system ("./testIntrospect.pl"); system ("./testPVData.pl"); system ("./testPVStructureArray.pl"); system ("./testPVAuxInfo.pl"); +system ("./testTimeStamp.pl"); +system ("./testTimer.pl"); diff --git a/test/testLinkedListAux b/test/testLinkedListAux index d43d975..92b2aeb 100644 --- a/test/testLinkedListAux +++ b/test/testLinkedListAux @@ -5,16 +5,16 @@ time per iteration 0.000025 microseconds time per addTail/removeHead 0.000000 microseconds Time test locked -diff 183.634382 milliSeconds -time per iteration 183.634382 microseconds -time per addTail/removeHead 0.091817 microseconds +diff 186.459567 milliSeconds +time per iteration 186.459567 microseconds +time per addTail/removeHead 0.093230 microseconds Time ArrayList test -diff 647.257745 milliSeconds -time per iteration 647.257745 microseconds -time per addTail/removeHead 0.323629 microseconds +diff 652.028489 milliSeconds +time per iteration 652.028489 microseconds +time per addTail/removeHead 0.326014 microseconds Time ArrayList test locked -diff 810.656009 milliSeconds -time per iteration 810.656009 microseconds -time per addTail/removeHead 0.405328 microseconds +diff 799.889631 milliSeconds +time per iteration 799.889631 microseconds +time per addTail/removeHead 0.399945 microseconds diff --git a/test/testThreadAux b/test/testThreadAux index 31075d3..cdcf511 100644 --- a/test/testThreadAux +++ b/test/testThreadAux @@ -1 +1 @@ -time per call 38.976797 microseconds +time per call 36.953844 microseconds diff --git a/test/testTimeStamp b/test/testTimeStamp new file mode 100644 index 0000000..6bde499 --- /dev/null +++ b/test/testTimeStamp @@ -0,0 +1,6 @@ +diff 0.000000e+00 +diff 1.000000e+00 +diff -1.000000e+00 +diff -1.000000e+00 +diff -1.000000e-09 +diff 1.000000e-01 diff --git a/test/testTimeStamp.pl b/test/testTimeStamp.pl new file mode 100755 index 0000000..83283e3 --- /dev/null +++ b/test/testTimeStamp.pl @@ -0,0 +1,12 @@ +eval 'exec perl -S $0 ${1+"$@"}' # -*- Mode: perl -*- + if $running_under_some_shell; # testTimeStamp.pl +use Env; +system ("rm testTimeStamp"); +system ("rm testTimeStampDiff"); +system ("../bin/${EPICS_HOST_ARCH}/testTimeStamp testTimeStamp testTimeStampAux"); +system ("diff testTimeStamp testTimeStampGold >> testTimeStampDiff"); +if(-z "testTimeStampDiff") { + print "testTimeStamp OK\n"; +} else { + print "testTimeStamp Failed\n"; +} diff --git a/test/testTimeStampAux b/test/testTimeStampAux new file mode 100644 index 0000000..2df1bed --- /dev/null +++ b/test/testTimeStampAux @@ -0,0 +1 @@ +current 1290514910 631889964 milliSec 1290514910631 diff --git a/test/testTimeStampDiff b/test/testTimeStampDiff new file mode 100644 index 0000000..e69de29 diff --git a/test/testTimeStampGold b/test/testTimeStampGold new file mode 100644 index 0000000..6bde499 --- /dev/null +++ b/test/testTimeStampGold @@ -0,0 +1,6 @@ +diff 0.000000e+00 +diff 1.000000e+00 +diff -1.000000e+00 +diff -1.000000e+00 +diff -1.000000e-09 +diff 1.000000e-01 diff --git a/test/testTimer b/test/testTimer new file mode 100644 index 0000000..33d35fa --- /dev/null +++ b/test/testTimer @@ -0,0 +1,4 @@ +event: totalConstruct 15 totalDestruct 15 +thread: totalConstruct 3 totalDestruct 3 +timerNode: totalConstruct 6 totalDestruct 6 +timer: totalConstruct 3 totalDestruct 3 diff --git a/test/testTimer.pl b/test/testTimer.pl new file mode 100755 index 0000000..e41e1da --- /dev/null +++ b/test/testTimer.pl @@ -0,0 +1,12 @@ +eval 'exec perl -S $0 ${1+"$@"}' # -*- Mode: perl -*- + if $running_under_some_shell; # testTimer.pl +use Env; +system ("rm testTimer"); +system ("rm testTimerDiff"); +system ("../bin/${EPICS_HOST_ARCH}/testTimer testTimer testTimerAux"); +system ("diff testTimer testTimerGold >> testTimerDiff"); +if(-z "testTimerDiff") { + print "testTimer OK\n"; +} else { + print "testTimer Failed\n"; +} diff --git a/test/testTimerAux b/test/testTimerAux new file mode 100644 index 0000000..8da2b31 --- /dev/null +++ b/test/testTimerAux @@ -0,0 +1,6 @@ +one requested 0.400000 diff 0.400227 seconds +two requested 0.200000 diff 0.200181 seconds +one requested 0.200000 diff 0.200259 seconds +two requested 0.400000 diff 0.400413 seconds +one requested 0.000000 diff 0.000058 seconds +two requested 0.000000 diff 0.000082 seconds diff --git a/test/testTimerDiff b/test/testTimerDiff new file mode 100644 index 0000000..e69de29 diff --git a/test/testTimerGold b/test/testTimerGold new file mode 100644 index 0000000..33d35fa --- /dev/null +++ b/test/testTimerGold @@ -0,0 +1,4 @@ +event: totalConstruct 15 totalDestruct 15 +thread: totalConstruct 3 totalDestruct 3 +timerNode: totalConstruct 6 totalDestruct 6 +timer: totalConstruct 3 totalDestruct 3