string PvaClientData::getString() { if(PvaClient::getDebug()) cout << "PvaClientData::getString\n"; PVScalarPtr pvScalar; PVStructurePtr pvStructure = getPVStructure(); PVFieldPtr pvValue = pvStructure->getSubField("value"); if(pvValue) { Type type = pvValue->getField()->getType(); if(type==scalar) pvScalar = static_pointer_cast<PVScalar>(pvValue); } if(!pvScalar) { while(true) { const PVFieldPtrArray fieldPtrArray(pvStructure->getPVFields()); if(fieldPtrArray.size()!=1) { throw std::logic_error( "PvaClientData::getString() pvRequest for multiple fields"); } PVFieldPtr pvField(fieldPtrArray[0]); Type type = pvField->getField()->getType(); if(type==scalar) { pvScalar = static_pointer_cast<PVScalar>(pvField); break; } if(pvField->getField()->getType()!=epics::pvData::structure) break; pvStructure = static_pointer_cast<PVStructure>(pvField); } } if(!pvScalar) { throw std::logic_error( "PvaClientData::getString() did not find a scalar field"); } return convert->toString(pvScalar); }
void PVStructure::appendPVFields( StringArray const & fieldNames, PVFieldPtrArray const & pvFields) { size_t origLength = this->pvFields.size(); size_t extra = fieldNames.size(); if(extra==0) return; size_t newLength = origLength + extra; PVFieldPtrArray * xxx = const_cast<PVFieldPtrArray *>(&this->pvFields); xxx->reserve(newLength); for(size_t i=0; i<extra; i++) { xxx->push_back(pvFields[i]); } FieldConstPtrArray fields; fields.reserve(extra); for(size_t i=0; i<extra; i++) fields.push_back(pvFields[i]->getField()); FieldConstPtr field = getFieldCreate()->appendFields( structurePtr,fieldNames,fields); replaceField(field); structurePtr = static_pointer_cast<const Structure>(field); StringArray names = structurePtr->getFieldNames(); for(size_t i=0; i<newLength; i++) { (*xxx)[i]->setParentAndName(this,names[i]); } fixParentStructure(); }
static void testCreatePVStructureWithInvalidName() { testDiag("testCreatePVStructureWithInvalidName"); StringArray fieldNames; fieldNames.push_back("ok"); fieldNames.push_back("this.is-wrong"); PVFieldPtrArray pvFields; pvFields.push_back(pvDataCreate->createPVScalar(pvString)); pvFields.push_back(pvDataCreate->createPVScalar(pvInt)); try{ PVStructurePtr pvParent = pvDataCreate->createPVStructure( fieldNames,pvFields); testFail("Creation of invalid field name '%s' was allowed", fieldNames[1].c_str()); } catch(std::invalid_argument& e) { testDiag("Exception: \"%s\"", e.what()); testPass("Creation of invalid field name '%s' fails as expected", fieldNames[1].c_str()); } }
static void testCreatePVStructure() { PVStructurePtr pv0 = standardPVField->scalar( pvDouble,alarmTimeStampValueAlarm); PVScalarPtr pv1 = pvDataCreate->createPVScalar(pvString); PVFieldPtrArray pvFields; StringArray fieldNames; pvFields.reserve(2); fieldNames.reserve(2); fieldNames.push_back("value"); fieldNames.push_back("extra"); pvFields.push_back(pv0); pvFields.push_back(pv1); PVStructurePtr pvParent = pvDataCreate->createPVStructure( fieldNames,pvFields); std::cout << "testCreatePVStructure PASSED" << std::endl; }
void PVStructure::appendPVField( String const &fieldName, PVFieldPtr const & pvField) { size_t origLength = pvFields.size(); size_t newLength = origLength+1; PVFieldPtrArray * xxx = const_cast<PVFieldPtrArray *>(&pvFields); xxx->push_back(pvField); FieldConstPtr field = getFieldCreate()->appendField( structurePtr,fieldName,pvField->getField()); replaceField(field); structurePtr = static_pointer_cast<const Structure>(field); StringArray fieldNames = structurePtr->getFieldNames(); for(size_t i=0; i<newLength; i++) { pvFields[i]->setParentAndName(this,fieldNames[i]); } fixParentStructure(); }
shared_vector<const double> PvaClientData::getDoubleArray() { if(PvaClient::getDebug()) cout << "PvaClientData::getDoubleArray\n"; PVScalarArrayPtr pvScalarArray; PVStructurePtr pvStructure = getPVStructure(); PVFieldPtr pvValue = pvStructure->getSubField("value"); if(pvValue) { Type type = pvValue->getField()->getType(); if(type==scalarArray) { pvScalarArray = static_pointer_cast<PVScalarArray>(pvValue); } } if(!pvScalarArray) { while(true) { const PVFieldPtrArray fieldPtrArray(pvStructure->getPVFields()); if(fieldPtrArray.size()!=1) { throw std::logic_error( "PvaClientData::getDoubleArray() pvRequest for multiple fields"); } PVFieldPtr pvField(fieldPtrArray[0]); Type type = pvField->getField()->getType(); if(type==scalarArray) { pvScalarArray = static_pointer_cast<PVScalarArray>(pvField); break; } if(pvField->getField()->getType()!=epics::pvData::structure) break; pvStructure = static_pointer_cast<PVStructure>(pvField); } } if(!pvScalarArray) { throw std::logic_error( "PvaClientData::getDoubleArray() did not find a scalarArray field"); } ScalarType scalarType = pvScalarArray->getScalarArray()->getElementType(); if(!ScalarTypeFunc::isNumeric(scalarType)) { throw std::logic_error( "PvaClientData::getDoubleArray() did not find a numeric scalarArray field"); } shared_vector<const double> retValue; pvScalarArray->getAs<const double>(retValue); return retValue; }
void PVStructure::removePVField(String const &fieldName) { PVFieldPtr pvField = getSubField(fieldName); if(pvField.get()==NULL) { String message("removePVField "); message += fieldName + " does not exist"; this->message(message, errorMessage); return; } size_t origLength = pvFields.size(); size_t newLength = origLength - 1; PVFieldPtrArray const & origPVFields = pvFields; FieldConstPtrArray origFields = structurePtr->getFields(); PVFieldPtrArray newPVFields; newPVFields.reserve(newLength); StringArray newFieldNames; newFieldNames.reserve(newLength); FieldConstPtrArray fields; fields.reserve(newLength); for(size_t i=0; i<origLength; i++) { if(origPVFields[i]!=pvField) { newFieldNames.push_back(origPVFields[i]->getFieldName()); newPVFields.push_back(origPVFields[i]); fields.push_back(origFields[i]); } } PVFieldPtrArray * xxx = const_cast<PVFieldPtrArray *>(&pvFields); xxx->swap(newPVFields); FieldConstPtr field = getFieldCreate()->createStructure( structurePtr->getID(),newFieldNames,fields); replaceField(field); structurePtr = static_pointer_cast<const Structure>(field); StringArray fieldNames = structurePtr->getFieldNames(); for(size_t i=0; i<newLength; i++) { pvFields[i]->setParentAndName(this,fieldNames[i]); } }
static void test() { std::ostringstream oss; testDiag("\ntestBitSetUtil\n"); StringArray fieldNames; PVFieldPtrArray pvFields; fieldNames.reserve(5); pvFields.reserve(5); fieldNames.push_back("timeStamp"); fieldNames.push_back("alarm"); fieldNames.push_back("voltage"); fieldNames.push_back("power"); fieldNames.push_back("current"); pvFields.push_back( pvDataCreate->createPVStructure(standardField->timeStamp())); pvFields.push_back( pvDataCreate->createPVStructure(standardField->alarm())); pvFields.push_back( pvDataCreate->createPVStructure( standardField->scalar(pvDouble,"alarm"))); pvFields.push_back( pvDataCreate->createPVStructure( standardField->scalar(pvDouble,"alarm"))); pvFields.push_back( pvDataCreate->createPVStructure( standardField->scalar(pvDouble,"alarm"))); PVStructurePtr pvs = pvDataCreate->createPVStructure( fieldNames,pvFields); int32 nfields = (int32)pvs->getNumberFields(); BitSetPtr bitSet = BitSet::create(nfields); for(int32 i=0; i<nfields; i++) bitSet->set(i); BitSetUtil::compress(bitSet,pvs); bitSet->clear(); PVFieldPtr pvField = pvs->getSubField<PVStructure>("timeStamp"); int32 offsetTimeStamp = (int32)pvField->getFieldOffset(); pvField = pvs->getSubField<PVLong>("timeStamp.secondsPastEpoch"); int32 offsetSeconds = (int32)pvField->getFieldOffset(); pvField = pvs->getSubField<PVInt>("timeStamp.nanoseconds"); int32 offsetNano = (int32)pvField->getFieldOffset(); pvField = pvs->getSubField<PVInt>("timeStamp.userTag"); int32 offsetUserTag = (int32)pvField->getFieldOffset(); bitSet->set(offsetSeconds); BitSetUtil::compress(bitSet,pvs); testOk1(bitSet->get(offsetSeconds)==true); bitSet->set(offsetNano); bitSet->set(offsetUserTag); BitSetUtil::compress(bitSet,pvs); testOk1(bitSet->get(offsetSeconds)==false); testOk1(bitSet->get(offsetTimeStamp)==true); bitSet->clear(); pvField = pvs->getSubField<PVStructure>("current"); int32 offsetCurrent = (int32)pvField->getFieldOffset(); pvField = pvs->getSubField<PVDouble>("current.value"); int32 offsetValue = (int32)pvField->getFieldOffset(); pvField = pvs->getSubField<PVStructure>("current.alarm"); int32 offsetAlarm = (int32)pvField->getFieldOffset(); pvField = pvs->getSubField<PVInt>("current.alarm.severity"); int32 offsetSeverity = (int32)pvField->getFieldOffset(); pvField = pvs->getSubField<PVInt>("current.alarm.status"); int32 offsetStatus = (int32)pvField->getFieldOffset(); pvField = pvs->getSubField<PVString>("current.alarm.message"); int32 offsetMessage = (int32)pvField->getFieldOffset(); bitSet->set(offsetValue); bitSet->set(offsetSeverity); bitSet->set(offsetStatus); bitSet->set(offsetMessage); BitSetUtil::compress(bitSet,pvs); testOk1(bitSet->get(offsetCurrent)==true); bitSet->clear(); bitSet->set(offsetSeverity); bitSet->set(offsetStatus); bitSet->set(offsetMessage); BitSetUtil::compress(bitSet,pvs); testOk1(bitSet->get(offsetAlarm)==true); bitSet->clear(); printf("testBitSetUtil PASSED\n"); }