21 #if EPICS_VERSION_INT>=VERSION_INT(3,15,0,1) 26 #define epicsExportSharedSymbols 35 namespace epics {
namespace pvaClient {
40 static string noStructure(
"no pvStructure ");
41 static string noValue(
"no value field");
42 static string noScalar(
"value is not a scalar");
43 static string noArray(
"value is not an array");
44 static string noScalarArray(
"value is not a scalarArray");
45 static string noAlarm(
"no alarm");
46 static string noTimeStamp(
"no timeStamp");
50 if(PvaClient::getDebug()) cout <<
"PvaClientData::create\n";
56 : structure(structure)
66 if(fieldPtrArray.size()==0) {
67 throw std::logic_error(
"PvaClientData::getSinglePVField() pvRequest for empty structure");
69 if(fieldPtrArray.size()!=1) {
70 PVFieldPtr pvValue = pvStructure->getSubField(
"value");
72 Type type = pvValue->getField()->getType();
75 throw std::logic_error(
"PvaClientData::getSinglePVField() pvRequest for multiple fields");
78 Type type = pvField->getField()->getType();
103 if(pvStructure)
return pvStructure;
109 if(bitSet)
return bitSet;
115 if(!bitSet)
throw std::runtime_error(
messagePrefix + noStructure);
116 size_t nextSet = bitSet->nextSetBit(0);
118 while(nextSet!=string::npos) {
120 pvField = pvStructure;
122 pvField = pvStructure->getSubField(nextSet);
124 string name = pvField->getFullName();
125 out << name <<
" = " << pvField << endl;
126 nextSet = bitSet->nextSetBit(nextSet+1);
136 pvStructure = pvStructureFrom;
138 pvValue = pvStructure->getSubField(
"value");
145 if(!pvValue)
return false;
152 if(!pvValue)
return false;
153 if(pvValue->getField()->getType()==
scalar)
return true;
160 if(!pvValue)
return false;
161 if(pvValue->getField()->getType()==
scalarArray)
return true;
176 if(pvValue->getField()->getType()!=
scalar) {
179 return pvStructure->getSubField<
PVScalar>(
"value");
186 Type type = pvValue->getField()->getType();
190 return pvStructure->getSubField<
PVArray>(
"value");
197 Type type = pvValue->getField()->getType();
208 Type type = pvField->getField()->getType();
210 throw std::logic_error(
"PvaClientData::getDouble() did not find a scalar field");
216 return pvDouble->
get();
219 throw std::logic_error(
220 "PvaClientData::getDouble() did not find a numeric scalar field");
222 return convert->toDouble(pvScalar);
229 Type type = pvField->getField()->getType();
231 throw std::logic_error(
"PvaClientData::getString() did not find a scalar field");
234 return convert->toString(pvScalar);
241 Type type = pvField->getField()->getType();
243 throw std::logic_error(
"PvaClientData::getDoubleArray() did not find a scalarArray field");
248 throw std::logic_error(
249 "PvaClientData::getDoubleArray() did not find a numeric scalarArray field");
252 pvScalarArray->getAs<
const double>(retValue);
260 Type type = pvField->getField()->getType();
262 throw std::logic_error(
"PvaClientData::getStringArray() did not find a scalarArray field");
266 pvScalarArray->getAs<
const string>(retValue);
273 if(!pvStructure)
throw new std::runtime_error(
messagePrefix + noStructure);
289 if(!pvStructure)
throw new std::runtime_error(
messagePrefix + noStructure);
291 if(!pvs)
throw std::runtime_error(
messagePrefix + noTimeStamp);
295 pvTimeStamp.
get(timeStamp);
304 if(!pvStructure)
throw new std::runtime_error(
messagePrefix + noStructure);
311 std::istringstream strm(arg);
314 throw std::runtime_error(
"JSON support not built");
319 const std::string &arg,
const PVUnionPtr &pvUnion)
321 if(pvUnion->getUnion()->isVariant()) {
322 throw std::runtime_error(
messagePrefix +
"varient union not implemented");
324 size_t iequals = arg.find_first_of(
'=');
327 if(iequals==std::string::npos) {
329 mess +=
" was expected to start with field=";
332 field = arg.substr(0,iequals);
333 rest = arg.substr(iequals+1);
341 parse(rest,pvField,bs);
347 if(!pvStructure)
throw std::runtime_error(
messagePrefix + noStructure);
348 if(!bitSet)
throw std::runtime_error(
messagePrefix + noStructure);
349 size_t num = args.size();
350 if(num<1)
throw std::runtime_error(
messagePrefix +
" no arguments");
351 for(
size_t i=0;
i<num; ++
i)
353 string val = args[
i];
354 size_t iequals = val.find_first_of(
'=');
357 if(iequals==std::string::npos) {
358 parse(rest,pvStructure,bitSet);
361 field = val.substr(0,iequals);
362 rest = val.substr(iequals+1);
363 if(field.size()==std::string::npos) {
364 parse(rest,pvStructure,bitSet);
367 PVFieldPtr pvField(pvStructure->getSubField(field));
368 if(!pvField)
throw std::runtime_error(
messagePrefix + field +
" does not exist");
374 for(
size_t i=0;
i<choices.size(); ++
i) {
375 if(choices[
i]==rest) {
385 bitSet->set(pvUnion->getFieldOffset());
388 parse(rest,pvField,bitSet);
394 bool ignoreUnprintable,
401 printJSON(strm,*pvStructure,*bitSet,opts);
403 throw std::runtime_error(
"JSON support not built");
411 for(
size_t i=0;
i<pvFields.size(); ++
i) {
413 Type type(pvField->getField()->getType());
epics::pvData::Alarm getAlarm()
Get the alarm. If the pvStructure has an alarm field it's values are returned. Otherwise an exception...
double getDouble()
Get the value as a double.
PVScalar is the base class for each scalar field.
void parse(const std::vector< std::string > &args)
parse from args
Methods for manipulating alarm.
bool ignoreUnprintable
ignore union/union array when encountered
A holder for a contiguous piece of memory.
shared_ptr< T > static_pointer_cast(shared_ptr< U > const &r) BOOST_NOEXCEPT
Methods for accessing an enumerated structure.
bool attach(PVFieldPtr const &pvField)
bool attach(PVFieldPtr const &pvField)
pvd::StructureConstPtr type
std::tr1::shared_ptr< epics::pvData::PVArray > getArrayValue()
Get the interface to an array value field.
TODO only here because of the Lockable.
std::tr1::shared_ptr< const Structure > StructureConstPtr
bool isValueScalar()
Is the value field a scalar?
Options used during printing.
void get(TimeStamp &timeStamp) const
std::tr1::shared_ptr< PVArray > PVArrayPtr
storage_t::arg_type get() const
epics::pvData::PVScalarPtr getScalarValue()
Return the interface to a scalar value field.
void get(Alarm &alarm) const
epics::pvData::BitSetPtr getChangedBitSet()
Get the changed BitSet for the pvStructure.
epics::pvData::shared_vector< const std::string > getStringArray()
Get the value as a string array.
const ScalarConstPtr getScalar() const
std::tr1::shared_ptr< PVUnion > PVUnionPtr
epics::pvData::PVFieldPtr getSinglePVField()
std::tr1::shared_ptr< PVStructureArray > PVStructureArrayPtr
A base class for PvaClientGetData, PvaClientPutData, and PvaClientMonitorData.
void streamJSON(std::ostream &strm, bool ignoreUnprintable=true, bool multiLine=false)
generate JSON output from the current PVStructure
bool setIndex(int32 index)
void zeroArrayLength()
set length of all array fields to 0
bool isNumeric(ScalarType type)
Base class for a scalarArray.
std::tr1::shared_ptr< PVScalar > PVScalarPtr
epics::pvData::PVStructure::shared_pointer parseJSON(std::istream &strm)
PVUnion has a single subfield.
void printJSON(std::ostream &strm, const PVStructure &val, const BitSet &mask, const JSONPrintOptions &opts)
const ScalarArrayConstPtr getScalarArray() const
std::vector< PVFieldPtr > PVFieldPtrArray
Data interface for a structure,.
bool hasValue()
Is there a top level field named value.
std::tr1::shared_ptr< PVStructure > PVStructurePtr
virtual void setLength(std::size_t length)=0
Data class for a structureArray.
std::ostream & showChanged(std::ostream &out)
Show the fields that have changed value since the last get.
epics::pvData::PVFieldPtr getValue()
Get the interface to the value field.
epics::pvData::shared_vector< const double > getDoubleArray()
Get the value as a double array.
std::tr1::shared_ptr< epics::pvData::PVScalarArray > getScalarArrayValue()
Get the interface to a scalar array value field.
Class that holds the data for each possible scalar type.
std::tr1::shared_ptr< PVField > PVFieldPtr
std::string messagePrefix
std::tr1::shared_ptr< Convert > ConvertPtr
void setMessagePrefix(std::string const &value)
Set a prefix for throw messages.
std::tr1::shared_ptr< BitSet > BitSetPtr
epics::pvData::PVStructurePtr getPVStructure()
Get the pvStructure.
virtual void setLength(std::size_t length) OVERRIDE FINAL
PVStringArray::const_svector getChoices()
epics::pvData::TimeStamp getTimeStamp()
Get the timeStamp. If the pvStructure has a timeStamp field, it's values are returned. Otherwise an exception is thrown.
PVArray is the base class for all array types.
std::tr1::shared_ptr< PVScalarArray > PVScalarArrayPtr
static bool getDebug()
Is debug set?
bool multiLine
include new lines
epics::pvData::StructureConstPtr getStructure()
Get the structure.
std::tr1::shared_ptr< PVDouble > PVDoublePtr
void setData(epics::pvData::PVStructurePtr const &pvStructureFrom, epics::pvData::BitSetPtr const &bitSetFrom)
New data is present.
bool isValueScalarArray()
Is the value field a scalar array?
bool attach(PVFieldPtr const &pvField)
Methods for manipulating timeStamp.
std::tr1::shared_ptr< PvaClientData > PvaClientDataPtr