support unsigned; move fieldName; pvData use shared_pointer everywhere

This commit is contained in:
Marty Kraimer
2012-05-08 09:29:30 -04:00
parent 2693201cfd
commit 87bff33c30
65 changed files with 5026 additions and 5435 deletions
+6 -9
View File
@@ -6,8 +6,6 @@ PVDATA = $(TOP)/pvDataApp/
SRC_DIRS += $(PVDATA)/misc
INC += noDefaultMethods.h
INC += linkedListVoid.h
INC += linkedList.h
INC += lock.h
INC += requester.h
INC += serialize.h
@@ -18,10 +16,11 @@ INC += serializeHelper.h
INC += event.h
INC += thread.h
INC += executor.h
INC += linkedList.h
INC += linkedListVoid.h
INC += CDRMonitor.h
INC += timeFunction.h
INC += timer.h
INC += queueVoid.h
INC += queue.h
INC += messageQueue.h
INC += destroyable.h
@@ -29,7 +28,7 @@ INC += status.h
INC += sharedPtr.h
LIBSRCS += CDRMonitor.cpp
#LIBSRCS += byteBuffer.cpp
LIBSRCS += byteBuffer.cpp
LIBSRCS += bitSet.cpp
LIBSRCS += epicsException.cpp
LIBSRCS += requester.cpp
@@ -39,8 +38,6 @@ LIBSRCS += event.cpp
LIBSRCS += executor.cpp
LIBSRCS += timeFunction.cpp
LIBSRCS += timer.cpp
LIBSRCS += queueVoid.cpp
LIBSRCS += messageQueue.cpp
LIBSRCS += status.cpp
SRC_DIRS += $(PVDATA)/pv
@@ -56,14 +53,14 @@ SRC_DIRS += $(PVDATA)/factory
INC += factory.h
LIBSRCS += TypeFunc.cpp
LIBSRCS += PVAuxInfoImpl.cpp
LIBSRCS += FieldCreateFactory.cpp
LIBSRCS += PVAuxInfoImpl.cpp
LIBSRCS += PVField.cpp
LIBSRCS += PVScalar.cpp
LIBSRCS += PVArray.cpp
LIBSRCS += PVScalarArray.cpp
LIBSRCS += PVStructure.cpp
LIBSRCS += DefaultPVStructureArray.cpp
LIBSRCS += PVStructureArray.cpp
LIBSRCS += PVDataCreateFactory.cpp
LIBSRCS += Convert.cpp
LIBSRCS += Compare.cpp
@@ -97,7 +94,7 @@ LIBSRCS += bitSetUtil.cpp
SRC_DIRS += $(PVDATA)/monitor
INC += monitor.h
INC += monitorQueue.h
LIBSRCS += monitorQueue.cpp
#LIBSRCS += monitorQueue.cpp
LIBRARY=pvData
+4 -6
View File
@@ -56,30 +56,28 @@ bool operator==(const Scalar& a, const Scalar& b)
{
if(&a==&b)
return true;
return a.getScalarType()==b.getScalarType() && a.getFieldName()==b.getFieldName();
return a.getScalarType()==b.getScalarType();
}
bool operator==(const ScalarArray& a, const ScalarArray& b)
{
if(&a==&b)
return true;
return a.getElementType()==b.getElementType() && a.getFieldName()==b.getFieldName();
return a.getElementType()==b.getElementType();
}
bool operator==(const Structure& a, const Structure& b)
{
if(&a==&b)
return true;
int nflds=a.getNumberFields();
size_t nflds=a.getNumberFields();
if (b.getNumberFields()!=nflds)
return false;
if (a.getFieldName()!=b.getFieldName())
return false;
// std::equals does not work, since FieldConstPtrArray is an array of shared_pointers
FieldConstPtrArray af = a.getFields();
FieldConstPtrArray bf = b.getFields();
for (int i = 0; i < nflds; i++)
for (size_t i = 0; i < nflds; i++)
if (*(af[i].get()) != *(bf[i].get()))
return false;
return true;
+1661 -2085
View File
File diff suppressed because it is too large Load Diff
@@ -1,251 +0,0 @@
/*PVStructureArray.cpp*/
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*/
#include <cstddef>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <pv/pvData.h>
#include <pv/convert.h>
#include <pv/factory.h>
#include <pv/serializeHelper.h>
#include "DefaultPVStructureArray.h"
using std::tr1::static_pointer_cast;
using std::tr1::const_pointer_cast;
namespace epics { namespace pvData {
BasePVStructureArray::BasePVStructureArray(
PVStructure *parent,StructureArrayConstPtr structureArray)
: PVStructureArray(parent,structureArray),
structureArray(structureArray),
structureArrayData(new StructureArrayData()),
value(new PVStructurePtr[0])
{
}
BasePVStructureArray::~BasePVStructureArray()
{
delete structureArrayData;
int number = getCapacity();
for(int i=0; i<number; i++) {
if(value[i]!=0) {
delete value[i];
}
}
delete[] value;
}
int BasePVStructureArray::append(int number)
{
int currentLength = getCapacity();
int newLength = currentLength + number;
setCapacity(newLength);
StructureConstPtr structure = structureArray->getStructure();
for(int i=currentLength; i<newLength; i++) {
value[i] = getPVDataCreate()->createPVStructure(0,structure);
}
return newLength;
}
bool BasePVStructureArray::remove(int offset,int number)
{
int length = getCapacity();
if(offset+number>length) return false;
for(int i=offset;i<offset+number;i++) {
if(value[i]!=0) {
delete value[i];
value[i] = 0;
}
}
return true;
}
void BasePVStructureArray::compress() {
int length = getCapacity();
int newLength = 0;
for(int i=0; i<length; i++) {
if(value[i]!=0) {
newLength++;
continue;
}
// find first non 0
int notNull = 0;
for(int j=i+1;j<length;j++) {
if(value[j]!=0) {
notNull = j;
break;
}
}
if(notNull!=0) {
value[i] = value[notNull];
value[notNull] = 0;
newLength++;
continue;
}
break;
}
setCapacity(newLength);
}
void BasePVStructureArray::setCapacity(int capacity) {
if(getCapacity()==capacity) return;
if(!isCapacityMutable()) {
std::string message("not capacityMutable");
PVField::message(message, errorMessage);
return;
}
int length = getCapacity();
int numRemove = length - capacity;
if(numRemove>0) remove(length,numRemove);
PVStructurePtrArray newValue = new PVStructurePtr[capacity];
int limit = length;
if(length>capacity) limit = capacity;
for(int i=0; i<limit; i++) newValue[i] = value[i];
for(int i=limit; i<capacity; i++) newValue[i] = 0;
if(length>capacity) length = capacity;
delete[] value;
value = newValue;
setCapacityLength(capacity,length);
}
StructureArrayConstPtr BasePVStructureArray::getStructureArray()
{
return structureArray;
}
int BasePVStructureArray::get(
int offset, int len, StructureArrayData *data)
{
int n = len;
int length = getLength();
if(offset+len > length) {
n = length - offset;
if(n<0) n = 0;
}
data->data = value;
data->offset = offset;
return n;
}
int BasePVStructureArray::put(int offset,int len,
PVStructurePtrArray from, int fromOffset)
{
if(isImmutable()) {
message(String("field is immutable"), errorMessage);
return 0;
}
if(from==value) return len;
if(len<1) return 0;
int length = getLength();
int capacity = getCapacity();
if(offset+len > length) {
int newlength = offset + len;
if(newlength>capacity) {
setCapacity(newlength);
capacity = getCapacity();
newlength = capacity;
len = newlength - offset;
if(len<=0) return 0;
}
length = newlength;
setLength(length);
}
StructureConstPtr structure = structureArray->getStructure();
for(int i=0; i<len; i++) {
if(value[i+offset]!=0) delete value[i+offset];
PVStructurePtr frompv = from[i+fromOffset];
if(frompv==0) {
value[i+offset] = 0;
continue;
}
if(frompv->getStructure()!=structure) {
throw std::invalid_argument(String(
"Element is not a compatible structure"));
}
value[i+offset] = frompv;
}
postPut();
return len;
}
void BasePVStructureArray::shareData(
PVStructurePtrArray newValue,int capacity,int length)
{
for(int i=0; i<getLength(); i++) {
if(value[i]!=0) delete value[i];
}
delete[] value;
value = newValue;
setCapacity(capacity);
setLength(length);
}
void BasePVStructureArray::serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher) const {
serialize(pbuffer, pflusher, 0, getLength());
}
void BasePVStructureArray::deserialize(ByteBuffer *pbuffer,
DeserializableControl *pcontrol) {
int size = SerializeHelper::readSize(pbuffer, pcontrol);
if(size>=0) {
// prepare array, if necessary
if(size>getCapacity()) setCapacity(size);
for(int i = 0; i<size; i++) {
pcontrol->ensureData(1);
int8 temp = pbuffer->getByte();
if(temp==0) {
if (value[i]) {
delete value[i];
value[i] = NULL;
}
}
else {
if(value[i]==NULL) {
value[i] = getPVDataCreate()->createPVStructure(
NULL, structureArray->getStructure());
}
value[i]->deserialize(pbuffer, pcontrol);
}
}
setLength(size);
postPut();
}
}
void BasePVStructureArray::serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher, int offset, int count) const {
// cache
int length = getLength();
// check bounds
if(offset<0)
offset = 0;
else if(offset>length) offset = length;
if(count<0) count = length;
int maxCount = length-offset;
if(count>maxCount) count = maxCount;
// write
SerializeHelper::writeSize(count, pbuffer, pflusher);
for(int i = 0; i<count; i++) {
if(pbuffer->getRemaining()<1) pflusher->flushSerializeBuffer();
PVStructure* pvStructure = value[i+offset];
if(pvStructure==NULL) {
pbuffer->putByte(0);
}
else {
pbuffer->putByte(1);
pvStructure->serialize(pbuffer, pflusher);
}
}
}
}}
+38 -26
View File
@@ -17,32 +17,44 @@
namespace epics { namespace pvData {
class BasePVStructureArray : public PVStructureArray {
public:
BasePVStructureArray(PVStructure *parent,
StructureArrayConstPtr structureArray);
virtual ~BasePVStructureArray();
virtual StructureArrayConstPtr getStructureArray();
virtual int append(int number);
virtual bool remove(int offset,int number);
virtual void compress();
virtual void setCapacity(int capacity);
virtual int get(int offset, int length,
StructureArrayData *data);
virtual int put(int offset,int length,
PVStructurePtrArray from, int fromOffset);
virtual void shareData( PVStructurePtrArray value,int capacity,int length);
virtual void serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher) const;
virtual void deserialize(ByteBuffer *buffer,
DeserializableControl *pflusher);
virtual void serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher, int offset, int count) const;
private:
StructureArrayConstPtr structureArray;
StructureArrayData *structureArrayData;
PVStructurePtrArray value;
};
class BasePVStructureArray : public PVStructureArray {
public:
POINTER_DEFINITIONS(PVStructureArray);
typedef PVStructurePtr* pointer;
typedef std::vector<PVStructurePtr> vector;
typedef std::tr1::shared_ptr<vector> shared_vector;
BasePVStructureArray(PVStructure *parent,
StructureArrayConstPtr structureArray);
virtual ~BasePVStructureArray();
virtual StructureArrayConstPtr getStructureArray();
virtual std::size_t append(std::size_t number);
virtual bool remove(std::size_t offset,std::size_t number);
virtual void compress();
virtual void setCapacity(std::size_t capacity);
virtual std::size_t get(std::size_t offset, std::size_t length,
StructureArrayData &data);
virtual std::size_t put(std::size_t offset,std::size_t length,
vector const & from, std::size_t fromOffset);
virtual void shareData(
shared_vector const & value,
std::size_t capacity,
std::size_t length);
virtual pointer getRaw();
virtual pointer getRaw() const;
virtual vector const & getVector(){return *value.get();}
virtual shared_vector const & getSharedVector(){return value;};
virtual void serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher) const;
virtual void deserialize(ByteBuffer *buffer,
DeserializableControl *pflusher);
virtual void serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher, std::size_t offset, std::size_t count) const ;
private:
StructureArrayConstPtr structureArray;
shared_vector value;
};
}}
#endif /*DEFAULTPVSTRUCTUREARRAY_H*/
+136 -136
View File
@@ -12,10 +12,10 @@
#include <pv/pvIntrospect.h>
#include <pv/convert.h>
#include <pv/factory.h>
#include <pv/CDRMonitor.h>
#include <pv/serializeHelper.h>
using std::tr1::static_pointer_cast;
using std::size_t;
namespace epics { namespace pvData {
@@ -27,54 +27,41 @@ static void newLine(StringBuilder buffer, int indentLevel)
for(int i=0; i<indentLevel; i++) *buffer += " ";
}
PVDATA_REFCOUNT_MONITOR_DEFINE(field);
Field::Field(String fieldName,Type type)
:m_fieldName(fieldName)
,m_fieldType(type)
Field::Field(Type type)
: m_fieldType(type)
{
PVDATA_REFCOUNT_MONITOR_CONSTRUCT(field);
}
Field::~Field() {
PVDATA_REFCOUNT_MONITOR_DESTRUCT(field);
// note that compiler automatically calls destructor for fieldName
if(debugLevel==highDebug) printf("~Field %s\n",m_fieldName.c_str());
}
void Field::renameField(String newName)
{
m_fieldName = newName;
}
void Field::toString(StringBuilder buffer,int indentLevel) const{
*buffer += " ";
*buffer += m_fieldName.c_str();
}
Scalar::Scalar(String fieldName,ScalarType scalarType)
: Field(fieldName,scalar),scalarType(scalarType){}
Scalar::Scalar(ScalarType scalarType)
: Field(scalar),scalarType(scalarType){}
Scalar::~Scalar(){}
void Scalar::toString(StringBuilder buffer,int indentLevel) const{
ScalarTypeFunc::toString(buffer,scalarType);
Field::toString(buffer,indentLevel);
}
void Scalar::serialize(ByteBuffer *buffer, SerializableControl *control) const {
/*
control->ensureBuffer(1);
buffer->putByte((int8)(epics::pvData::scalar << 4 | getScalarType()));
SerializeHelper::serializeString(getFieldName(), buffer, control);
*/
}
void Scalar::deserialize(ByteBuffer *buffer, DeserializableControl *control) {
}
static void serializeStructureField(const Structure* structure, ByteBuffer* buffer, SerializableControl* control)
{
/*
SerializeHelper::serializeString(structure->getFieldName(), buffer, control);
FieldConstPtrArray fields = structure->getFields();
SerializeHelper::writeSize(structure->getNumberFields(), buffer, control);
@@ -82,10 +69,13 @@ static void serializeStructureField(const Structure* structure, ByteBuffer* buff
{
control->cachedSerialize(fields[i], buffer);
}
*/
}
static StructureConstPtr deserializeStructureField(const FieldCreate* fieldCreate, ByteBuffer* buffer, DeserializableControl* control)
{
throw std::invalid_argument("for Matej to convert");
/*
const String structureFieldName = SerializeHelper::deserializeString(buffer, control);
const int32 size = SerializeHelper::readSize(buffer, control);
FieldConstPtrArray fields = NULL;
@@ -105,33 +95,32 @@ static StructureConstPtr deserializeStructureField(const FieldCreate* fieldCreat
StructureConstPtr structure = fieldCreate->createStructure(structureFieldName, size, fields);
return structure;
*/
}
ScalarArray::ScalarArray(String fieldName,ScalarType elementType)
: Field(fieldName,scalarArray),elementType(elementType){}
ScalarArray::ScalarArray(ScalarType elementType)
: Field(scalarArray),elementType(elementType){}
ScalarArray::~ScalarArray() {}
void ScalarArray::toString(StringBuilder buffer,int indentLevel) const{
ScalarTypeFunc::toString(buffer,elementType);
*buffer += "[]";
Field::toString(buffer,indentLevel);
}
void ScalarArray::serialize(ByteBuffer *buffer, SerializableControl *control) const {
/*
control->ensureBuffer(1);
buffer->putByte((int8)(epics::pvData::scalarArray << 4 | getElementType()));
SerializeHelper::serializeString(getFieldName(), buffer, control);
*/
}
void ScalarArray::deserialize(ByteBuffer *buffer, DeserializableControl *control) {
}
StructureArray::StructureArray(String fieldName,StructureConstPtr structure)
: Field(fieldName,structureArray),pstructure(structure)
StructureArray::StructureArray(StructureConstPtr structure)
: Field(structureArray),pstructure(structure)
{
}
@@ -140,187 +129,195 @@ StructureArray::~StructureArray() {
}
void StructureArray::toString(StringBuilder buffer,int indentLevel) const {
*buffer += "structure[]";
Field::toString(buffer,indentLevel);
newLine(buffer,indentLevel + 1);
pstructure->toString(buffer,indentLevel + 1);
if(indentLevel==0) {
*buffer += "structure[]";
newLine(buffer,indentLevel + 1);
pstructure->toString(buffer,indentLevel + 1);
return;
}
pstructure->toString(buffer,indentLevel);
}
void StructureArray::serialize(ByteBuffer *buffer, SerializableControl *control) const {
/*
control->ensureBuffer(1);
buffer->putByte((int8)(epics::pvData::structureArray << 4));
SerializeHelper::serializeString(getFieldName(), buffer, control);
// we also need to serialize structure field...
serializeStructureField(getStructure().get(), buffer, control);
*/
}
void StructureArray::deserialize(ByteBuffer *buffer, DeserializableControl *control) {
}
Structure::Structure (String fieldName,
int numberFields, FieldConstPtrArray infields)
: Field(fieldName,structure),
numberFields(numberFields),
Structure::Structure (StringArray fieldNames,FieldConstPtrArray infields)
: Field(structure),
fieldNames(fieldNames),
fields(infields)
{
for(int i=0; i<numberFields; i++) {
String name = fields[i]->getFieldName();
if(fieldNames.size()!=fields.size()) {
throw std::invalid_argument("fieldNames.size()!=fields.size()");
}
size_t number = fields.size();
for(size_t i=0; i<number; i++) {
String name = fieldNames[i];
// look for duplicates
for(int j=i+1; j<numberFields; j++) {
String otherName = fields[j]->getFieldName();
for(size_t j=i+1; j<number; j++) {
String otherName = fieldNames[j];
int result = name.compare(otherName);
if(result==0) {
String message("duplicate fieldName ");
message += name;
delete[] fields;
throw std::invalid_argument(message);
}
}
}
}
Structure::~Structure() {
if(debugLevel==highDebug)
printf("~Structure %s\n",Field::getFieldName().c_str());
Structure::~Structure() { }
delete[] fields;
}
FieldConstPtr Structure::getField(String fieldName) const {
for(int i=0; i<numberFields; i++) {
size_t numberFields = fields.size();
for(size_t i=0; i<numberFields; i++) {
FieldConstPtr pfield = fields[i];
int result = fieldName.compare(pfield->getFieldName());
int result = fieldName.compare(fieldNames[i]);
if(result==0) return pfield;
}
return FieldConstPtr();
}
int Structure::getFieldIndex(String fieldName) const {
for(int i=0; i<numberFields; i++) {
size_t Structure::getFieldIndex(String fieldName) const {
size_t numberFields = fields.size();
for(size_t i=0; i<numberFields; i++) {
FieldConstPtr pfield = fields[i];
int result = fieldName.compare(pfield->getFieldName());
int result = fieldName.compare(fieldNames[i]);
if(result==0) return i;
}
return -1;
}
void Structure::appendField(FieldConstPtr field)
{
FieldConstPtr *newFields = new FieldConstPtr[numberFields+1];
for(int i=0; i<numberFields; i++) newFields[i] = fields[i];
newFields[numberFields] = field;
delete[] fields;
fields = newFields;
numberFields++;
}
void Structure::appendFields(int numberNew,FieldConstPtrArray nfields)
{
FieldConstPtr *newFields = new FieldConstPtr[numberFields+numberNew];
for(int i=0; i<numberFields; i++) newFields[i] = fields[i];
for(int i=0; i<numberNew; i++) newFields[numberFields+i] = nfields[i];
delete[] fields;
fields = newFields;
numberFields += numberNew;
}
void Structure::removeField(int index)
{
if(index<0 || index>=numberFields) {
throw std::invalid_argument(
String("Structure::removeField index out of bounds"));
}
FieldConstPtr *newFields = new FieldConstPtr[numberFields-1];
int ind=0;
for(int i=0; i<numberFields; i++) {
if(i==index) continue;
newFields[ind++] = fields[i];
}
delete[] fields;
fields = newFields;
--numberFields;
}
void Structure::toString(StringBuilder buffer,int indentLevel) const{
*buffer += "structure";
Field::toString(buffer,indentLevel);
newLine(buffer,indentLevel+1);
for(int i=0; i<numberFields; i++) {
toStringCommon(buffer,indentLevel+1);
}
void Structure::toStringCommon(StringBuilder buffer,int indentLevel) const{
newLine(buffer,indentLevel);
size_t numberFields = fields.size();
for(size_t i=0; i<numberFields; i++) {
FieldConstPtr pfield = fields[i];
pfield->toString(buffer,indentLevel+1);
if(i<numberFields-1) newLine(buffer,indentLevel+1);
switch(pfield->getType()) {
case scalar:
case scalarArray:
pfield->toString(buffer, indentLevel);
*buffer += " ";
*buffer += fieldNames[i];
break;
case structure:
{
Field const *xxx = pfield.get();
Structure const *pstruct = static_cast<Structure const*>(xxx);
*buffer += "structure ";
*buffer += fieldNames[i];
pstruct->toStringCommon(buffer,indentLevel + 1);
break;
}
case structureArray:
*buffer += "structure[] " + fieldNames[i];
newLine(buffer,indentLevel +1);
pfield->toString(buffer,indentLevel +1);
break;
}
if(i<numberFields-1) newLine(buffer,indentLevel);
}
}
void Structure::serialize(ByteBuffer *buffer, SerializableControl *control) const {
/*
control->ensureBuffer(1);
buffer->putByte((int8)(epics::pvData::structure << 4));
serializeStructureField(this, buffer, control);
*/
}
void Structure::deserialize(ByteBuffer *buffer, DeserializableControl *control) {
}
ScalarConstPtr FieldCreate::createScalar(String fieldName,
ScalarType scalarType) const
ScalarConstPtr FieldCreate::createScalar(ScalarType scalarType) const
{
ScalarConstPtr scalar(new Scalar(fieldName,scalarType), Field::Deleter());
ScalarConstPtr scalar(new Scalar(scalarType), Field::Deleter());
return scalar;
}
ScalarArrayConstPtr FieldCreate::createScalarArray(
String fieldName,ScalarType elementType) const
ScalarArrayConstPtr FieldCreate::createScalarArray(ScalarType elementType) const
{
ScalarArrayConstPtr scalarArray(new ScalarArray(fieldName,elementType), Field::Deleter());
ScalarArrayConstPtr scalarArray(new ScalarArray(elementType), Field::Deleter());
return scalarArray;
}
StructureConstPtr FieldCreate::createStructure (
String fieldName,int numberFields,
FieldConstPtr fields[]) const
StringArray const & fieldNames,FieldConstPtrArray const & fields) const
{
StructureConstPtr structure(new Structure(
fieldName,numberFields,fields), Field::Deleter());
StructureConstPtr structure(
new Structure(fieldNames,fields), Field::Deleter());
return structure;
}
StructureArrayConstPtr FieldCreate::createStructureArray(
String fieldName,StructureConstPtr structure) const
StructureConstPtr structure) const
{
StructureArrayConstPtr structureArray(new StructureArray(fieldName,structure), Field::Deleter());
StructureArrayConstPtr structureArray(
new StructureArray(structure), Field::Deleter());
return structureArray;
}
FieldConstPtr FieldCreate::create(String fieldName,
FieldConstPtr pfield) const
StructureConstPtr FieldCreate::appendField(
StructureConstPtr structure,String fieldName, FieldConstPtr field) const
{
FieldConstPtr ret;
Type type = pfield->getType();
switch(type) {
case scalar: {
ScalarConstPtr pscalar = static_pointer_cast<const Scalar>(pfield);
return createScalar(fieldName,pscalar->getScalarType());
StringArray oldNames = structure->getFieldNames();
FieldConstPtrArray oldFields = structure->getFields();
size_t oldLen = oldNames.size();
StringArray newNames(oldLen+1);
FieldConstPtrArray newFields(oldLen+1);
for(size_t i = 0; i<oldLen; i++) {
newNames[i] = oldNames[i];
newFields[i] = oldFields[i];
}
case scalarArray: {
ScalarArrayConstPtr pscalarArray = static_pointer_cast<const ScalarArray>(pfield);
return createScalarArray(fieldName,pscalarArray->getElementType());
newNames[oldLen] = fieldName;
newFields[oldLen] = field;
return createStructure(newNames,newFields);
}
StructureConstPtr FieldCreate::appendFields(
StructureConstPtr structure,
StringArray const & fieldNames,
FieldConstPtrArray const & fields) const
{
StringArray oldNames = structure->getFieldNames();
FieldConstPtrArray oldFields = structure->getFields();
size_t oldLen = oldNames.size();
size_t extra = fieldNames.size();
StringArray newNames(oldLen+extra);
FieldConstPtrArray newFields(oldLen+extra);
for(size_t i = 0; i<oldLen; i++) {
newNames[i] = oldNames[i];
newFields[i] = oldFields[i];
}
case structure: {
StructureConstPtr pstructure = static_pointer_cast<const Structure>(pfield);
return createStructure(fieldName,pstructure->getNumberFields(),pstructure->getFields());
for(size_t i = 0; i<extra; i++) {
newNames[oldLen +i] = fieldNames[i];
newFields[oldLen +i] = fields[i];
}
case structureArray: {
StructureArrayConstPtr pstructureArray = static_pointer_cast<const StructureArray>(pfield);
return createStructureArray(fieldName,pstructureArray->getStructure());
}
}
String message("field ");
message += fieldName;
THROW_EXCEPTION2(std::logic_error, message);
return createStructure(newNames,newFields);
}
FieldConstPtr FieldCreate::deserialize(ByteBuffer* buffer, DeserializableControl* control) const
{
throw std::invalid_argument("for Matej to convert");
/*
control->ensureData(1);
const int8 typeCode = buffer->getByte();
@@ -356,20 +353,23 @@ FieldConstPtr FieldCreate::deserialize(ByteBuffer* buffer, DeserializableControl
return FieldConstPtr();
}
}
*/
}
static FieldCreate* fieldCreate = 0;
FieldCreate::FieldCreate()
FieldCreatePtr FieldCreate::getFieldCreate()
{
}
FieldCreate * getFieldCreate() {
static FieldCreatePtr fieldCreate;
static Mutex mutex;
Lock xx(mutex);
if(fieldCreate==0) fieldCreate = new FieldCreate();
if(fieldCreate.get()==0) fieldCreate = FieldCreatePtr(new FieldCreate());
return fieldCreate;
}
FieldCreate::FieldCreate(){}
FieldCreatePtr getFieldCreate() {
return FieldCreate::getFieldCreate();
}
}}
+11 -9
View File
@@ -12,19 +12,21 @@
#include <pv/pvData.h>
#include <pv/factory.h>
using std::size_t;
namespace epics { namespace pvData {
class PVArrayPvt {
public:
PVArrayPvt() : length(0),capacity(0),capacityMutable(true)
{}
int length;
int capacity;
size_t length;
size_t capacity;
bool capacityMutable;
};
PVArray::PVArray(PVStructure *parent,FieldConstPtr field)
: PVField(parent,field),pImpl(new PVArrayPvt())
PVArray::PVArray(FieldConstPtr field)
: PVField(field),pImpl(new PVArrayPvt())
{ }
PVArray::~PVArray()
@@ -32,13 +34,13 @@ namespace epics { namespace pvData {
delete pImpl;
}
int PVArray::getLength() const {return pImpl->length;}
size_t PVArray::getLength() const {return pImpl->length;}
int PVArray::getCapacity() const {return pImpl->capacity;}
size_t PVArray::getCapacity() const {return pImpl->capacity;}
static String fieldImmutable("field is immutable");
void PVArray::setLength(int length) {
void PVArray::setLength(size_t length) {
if(length==pImpl->length) return;
if(PVField::isImmutable()) {
PVField::message(fieldImmutable,errorMessage);
@@ -49,7 +51,7 @@ namespace epics { namespace pvData {
pImpl->length = length;
}
void PVArray::setCapacityLength(int capacity,int length) {
void PVArray::setCapacityLength(size_t capacity,size_t length) {
pImpl->capacity = capacity;
pImpl->length = length;
}
@@ -74,7 +76,7 @@ namespace epics { namespace pvData {
static String capacityImmutable("capacity is immutable");
void PVArray::setCapacity(int capacity) {
void PVArray::setCapacity(size_t capacity) {
if(PVField::isImmutable()) {
PVField::message(fieldImmutable,errorMessage);
return;
+26 -41
View File
@@ -17,11 +17,13 @@
namespace epics { namespace pvData {
static PVScalarPtr nullPVScalar;
PVDATA_REFCOUNT_MONITOR_DEFINE(pvAuxInfo);
PVAuxInfo::PVAuxInfo(PVField *pvField)
: pvField(pvField),lengthInfo(1),numberInfo(0),
pvInfos(new PVScalar *[1])
PVAuxInfo::PVAuxInfo(PVField * pvField)
: pvField(pvField),
pvInfos(std::map<String,std::tr1::shared_ptr<PVScalar> > ())
{
PVDATA_REFCOUNT_MONITOR_CONSTRUCT(pvAuxInfo);
}
@@ -29,8 +31,6 @@ PVAuxInfo::PVAuxInfo(PVField *pvField)
PVAuxInfo::~PVAuxInfo()
{
PVDATA_REFCOUNT_MONITOR_DESTRUCT(pvAuxInfo);
for(int i=0; i<numberInfo; i++) delete pvInfos[i];
delete[] pvInfos;
}
@@ -38,49 +38,34 @@ PVField * PVAuxInfo::getPVField() {
return pvField;
}
PVScalar * PVAuxInfo::createInfo(String key,ScalarType scalarType)
PVScalarPtr PVAuxInfo::createInfo(String key,ScalarType scalarType)
{
for(int i=0; i<numberInfo; i++) {
PVScalar *pvScalar = pvInfos[i];
if(key.compare(pvScalar->getField()->getFieldName())==0) {
String message("AuxoInfo:create key ");
message += key.c_str();
message += " already exists with scalarType ";
ScalarTypeFunc::toString(&message,scalarType);
pvField->message(message,errorMessage);
return 0;
}
PVInfoIter iter = pvInfos.find(key);
if(iter!=pvInfos.end()) {
String message = key.c_str();
message += " already exists ";
pvField->message(message,errorMessage);
return nullPVScalar;
}
if(lengthInfo==numberInfo) {
int newLength = lengthInfo+4;
PVScalar ** newInfos = new PVScalar *[newLength];
lengthInfo = newLength;
for(int i=0; i<numberInfo; i++) newInfos[i] = pvInfos[i];
for(int i= numberInfo; i<lengthInfo; i++) newInfos[i] = 0;
delete[] pvInfos;
pvInfos = newInfos;
}
PVScalar *pvScalar = getPVDataCreate()->createPVScalar(0,key,scalarType);
pvInfos[numberInfo++] = pvScalar;
PVScalarPtr pvScalar = getPVDataCreate()->createPVScalar(scalarType);
pvInfos.insert(PVInfoPair(key,pvScalar));
return pvScalar;
}
PVScalar * PVAuxInfo::getInfo(String key)
PVScalarPtr& PVAuxInfo::getInfo(String key)
{
for(int i=0; i<numberInfo; i++) {
PVScalar *pvScalar = pvInfos[i];
if(key.compare(pvScalar->getField()->getFieldName())==0) return pvScalar;
}
return 0;
PVInfoIter iter;
iter = pvInfos.find(key);
if(iter==pvInfos.end()) return nullPVScalar;
return iter->second;
}
PVScalar * PVAuxInfo::getInfo(int index)
PVAuxInfo::PVInfoMap & PVAuxInfo::getInfoMap()
{
if(index<0 || index>=numberInfo) return 0;
return pvInfos[index];
return pvInfos;
}
int PVAuxInfo::getNumberInfo() { return numberInfo;}
void PVAuxInfo::toString(StringBuilder buf)
{
@@ -89,13 +74,13 @@ void PVAuxInfo::toString(StringBuilder buf)
void PVAuxInfo::toString(StringBuilder buf,int indentLevel)
{
if(numberInfo==0) return;
Convert *convert = getConvert();
if(pvInfos.size()<=0) return;
ConvertPtr convert = getConvert();
convert->newLine(buf,indentLevel);
*buf += "auxInfo";
for(int i=0; i<numberInfo; i++) {
for(PVInfoIter iter = pvInfos.begin(); iter!= pvInfos.end(); ++iter) {
convert->newLine(buf,indentLevel+1);
PVScalar *value = pvInfos[i];
PVFieldPtr value = iter->second;
value->toString(buf,indentLevel + 1);
}
}
+250 -197
View File
@@ -17,16 +17,15 @@
#include <pv/convert.h>
#include <pv/factory.h>
#include <pv/serializeHelper.h>
#include "DefaultPVStructureArray.h"
using std::tr1::static_pointer_cast;
using std::tr1::const_pointer_cast;
using std::size_t;
namespace epics { namespace pvData {
static Convert* convert = 0;
static FieldCreate * fieldCreate = 0;
static PVDataCreate* pvDataCreate = 0;
/** Default storage for scalar values
*/
@@ -37,7 +36,7 @@ public:
typedef T* pointer;
typedef const T* const_pointer;
BasePVScalar(PVStructure *parent,ScalarConstPtr scalar);
BasePVScalar(ScalarConstPtr &scalar);
virtual ~BasePVScalar();
virtual T get();
virtual void put(T val);
@@ -50,8 +49,8 @@ private:
};
template<typename T>
BasePVScalar<T>::BasePVScalar(PVStructure *parent,ScalarConstPtr scalar)
: PVScalarValue<T>(parent,scalar),value(0)
BasePVScalar<T>::BasePVScalar(ScalarConstPtr &scalar)
: PVScalarValue<T>(scalar),value(0)
{}
//Note: '0' is a suitable default for all POD types (not String)
@@ -79,11 +78,15 @@ void BasePVScalar<T>::deserialize(ByteBuffer *pbuffer,
value = pbuffer->get<T>();
}
typedef BasePVScalar<bool> BasePVBoolean;
typedef BasePVScalar<boolean> BasePVBoolean;
typedef BasePVScalar<int8> BasePVByte;
typedef BasePVScalar<int16> BasePVShort;
typedef BasePVScalar<int32> BasePVInt;
typedef BasePVScalar<int64> BasePVLong;
typedef BasePVScalar<uint8> BasePVUByte;
typedef BasePVScalar<uint16> BasePVUShort;
typedef BasePVScalar<uint32> BasePVUInt;
typedef BasePVScalar<uint64> BasePVULong;
typedef BasePVScalar<float> BasePVFloat;
typedef BasePVScalar<double> BasePVDouble;
@@ -94,7 +97,7 @@ public:
typedef String* pointer;
typedef const String* const_pointer;
BasePVString(PVStructure *parent,ScalarConstPtr scalar);
BasePVString(ScalarConstPtr &scalar);
virtual ~BasePVString();
virtual String get();
virtual void put(String val);
@@ -103,13 +106,13 @@ public:
virtual void deserialize(ByteBuffer *pbuffer,
DeserializableControl *pflusher);
virtual void serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher, int offset, int count) const;
SerializableControl *pflusher, size_t offset, size_t count) const;
private:
String value;
};
BasePVString::BasePVString(PVStructure *parent,ScalarConstPtr scalar)
: PVString(parent,scalar),value()
BasePVString::BasePVString(ScalarConstPtr &scalar)
: PVString(scalar),value()
{}
BasePVString::~BasePVString() {}
@@ -131,15 +134,15 @@ void BasePVString::deserialize(ByteBuffer *pbuffer,
}
void BasePVString::serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher, int offset, int count) const
SerializableControl *pflusher, size_t offset, size_t count) const
{
// check bounds
const int length = /*(value == null) ? 0 :*/ value.length();
const size_t length = /*(value == null) ? 0 :*/ value.length();
if (offset < 0) offset = 0;
else if (offset > length) offset = length;
if (count < 0) count = length;
const int maxCount = length - offset;
const size_t maxCount = length - offset;
if (count > maxCount)
count = maxCount;
@@ -152,40 +155,63 @@ void BasePVString::serialize(ByteBuffer *pbuffer,
template<typename T>
class DefaultPVArray : public PVValueArray<T> {
public:
typedef T value_type;
typedef T* pointer;
typedef const T* const_pointer;
typedef std::vector<T> vector;
typedef std::tr1::shared_ptr<vector> shared_vector;
DefaultPVArray(PVStructure *parent,ScalarArrayConstPtr scalarArray);
DefaultPVArray(ScalarArrayConstPtr &scalarArray);
virtual ~DefaultPVArray();
virtual void setCapacity(int capacity);
virtual int get(int offset, int length, PVArrayData<T> *data) ;
virtual int put(int offset,int length, pointer from,
int fromOffset);
virtual void shareData(pointer value,int capacity,int length);
virtual void setCapacity(size_t capacity);
virtual size_t get(size_t offset, size_t length, PVArrayData<T> &data) ;
virtual size_t put(size_t offset,size_t length, pointer const from,
size_t fromOffset);
virtual void shareData(
std::tr1::shared_ptr<std::vector<T> > const & value,
std::size_t capacity,
std::size_t length);
virtual pointer get() ;
virtual pointer get() const ;
virtual vector const & getVector() { return *value.get(); }
virtual shared_vector const & getSharedVector(){return value;};
// from Serializable
virtual void serialize(ByteBuffer *pbuffer,SerializableControl *pflusher) const;
virtual void deserialize(ByteBuffer *pbuffer,DeserializableControl *pflusher);
virtual void serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher, int offset, int count) const;
SerializableControl *pflusher, size_t offset, size_t count) const;
private:
pointer value;
shared_vector value;
};
template<typename T>
DefaultPVArray<T>::DefaultPVArray(PVStructure *parent,
ScalarArrayConstPtr scalarArray)
: PVValueArray<T>(parent,scalarArray),value(new T[0])
T *DefaultPVArray<T>::get()
{
std::vector<T> *vec = value.get();
T *praw = &((*vec)[0]);
return praw;
}
template<typename T>
T *DefaultPVArray<T>::get() const
{
std::vector<T> *vec = value.get();
T *praw = &((*vec)[0]);
return praw;
}
template<typename T>
DefaultPVArray<T>::DefaultPVArray(ScalarArrayConstPtr &scalarArray)
: PVValueArray<T>(scalarArray),
value(std::tr1::shared_ptr<std::vector<T> >(new std::vector<T>()))
{ }
template<typename T>
DefaultPVArray<T>::~DefaultPVArray()
{
delete[] value;
}
{ }
template<typename T>
void DefaultPVArray<T>::setCapacity(int capacity)
void DefaultPVArray<T>::setCapacity(size_t capacity)
{
if(PVArray::getCapacity()==capacity) return;
if(!PVArray::isCapacityMutable()) {
@@ -193,43 +219,45 @@ void DefaultPVArray<T>::setCapacity(int capacity)
PVField::message(message, errorMessage);
return;
}
int length = PVArray::getLength();
if(length>capacity) length = capacity;
T *newValue = new T[capacity];
for(int i=0; i<length; i++) newValue[i] = value[i];
delete[]value;
value = newValue;
size_t length = PVArray::getLength();
std::vector<T> array(capacity);
size_t num = PVArray::getLength();
if(num>capacity) num = capacity;
T * from = get();
for (size_t i=0; i<num; i++) array[i] = from[i];
value->swap(array);
PVArray::setCapacityLength(capacity,length);
}
template<typename T>
int DefaultPVArray<T>::get(int offset, int len, PVArrayData<T> *data)
size_t DefaultPVArray<T>::get(size_t offset, size_t len, PVArrayData<T> &data)
{
int n = len;
int length = this->getLength();
size_t n = len;
size_t length = this->getLength();
if(offset+len > length) {
n = length-offset;
if(n<0) n = 0;
}
data->data = value;
data->offset = offset;
data.data = *value.get();
data.offset = offset;
return n;
}
template<typename T>
int DefaultPVArray<T>::put(int offset,int len,
pointer from,int fromOffset)
size_t DefaultPVArray<T>::put(size_t offset,size_t len,
pointer const from,size_t fromOffset)
{
if(PVField::isImmutable()) {
PVField::message("field is immutable",errorMessage);
return 0;
}
if(from==value) return len;
T * pvalue = get();
if(from==pvalue) return len;
if(len<1) return 0;
int length = this->getLength();
int capacity = this->getCapacity();
size_t length = this->getLength();
size_t capacity = this->getCapacity();
if(offset+len > length) {
int newlength = offset + len;
size_t newlength = offset + len;
if(newlength>capacity) {
setCapacity(newlength);
newlength = this->getCapacity();
@@ -238,8 +266,9 @@ int DefaultPVArray<T>::put(int offset,int len,
}
length = newlength;
}
for(int i=0;i<len;i++) {
value[i+offset] = from[i+fromOffset];
pvalue = get();
for(size_t i=0;i<len;i++) {
pvalue[i+offset] = from[i+fromOffset];
}
this->setLength(length);
this->postPut();
@@ -247,10 +276,12 @@ int DefaultPVArray<T>::put(int offset,int len,
}
template<typename T>
void DefaultPVArray<T>::shareData(pointer shareValue,int capacity,int length)
void DefaultPVArray<T>::shareData(
std::tr1::shared_ptr<std::vector<T> > const & sharedValue,
std::size_t capacity,
std::size_t length)
{
delete[] value;
value = shareValue;
value = sharedValue;
PVArray::setCapacityLength(capacity,length);
}
@@ -263,21 +294,21 @@ void DefaultPVArray<T>::serialize(ByteBuffer *pbuffer,
template<typename T>
void DefaultPVArray<T>::deserialize(ByteBuffer *pbuffer,
DeserializableControl *pcontrol) {
int size = SerializeHelper::readSize(pbuffer, pcontrol);
size_t size = SerializeHelper::readSize(pbuffer, pcontrol);
// if (size>0) { pcontrol->ensureData(sizeof(T)-1); pbuffer->align(sizeof(T)); }
if(size>=0) {
// prepare array, if necessary
if(size>this->getCapacity()) this->setCapacity(size);
// retrieve value from the buffer
int i = 0;
size_t i = 0;
while(true) {
/*
int maxIndex = std::min(size-i, (int)(pbuffer->getRemaining()/sizeof(T)))+i;
size_t maxIndex = std::min(size-i, (int)(pbuffer->getRemaining()/sizeof(T)))+i;
for(; i<maxIndex; i++)
value[i] = pbuffer->get<T>();
*/
int maxCount = std::min(size-i, (int)(pbuffer->getRemaining()/sizeof(T)));
pbuffer->getArray<T>(&value[i], maxCount);
size_t maxCount = std::min(size-i, (pbuffer->getRemaining()/sizeof(T)));
pbuffer->getArray<T>(get(), maxCount);
i += maxCount;
if(i<size)
@@ -294,9 +325,9 @@ void DefaultPVArray<T>::deserialize(ByteBuffer *pbuffer,
template<typename T>
void DefaultPVArray<T>::serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher, int offset, int count) const {
SerializableControl *pflusher, size_t offset, size_t count) const {
// cache
int length = this->getLength();
size_t length = this->getLength();
// check bounds
if(offset<0)
@@ -304,24 +335,25 @@ void DefaultPVArray<T>::serialize(ByteBuffer *pbuffer,
else if(offset>length) offset = length;
if(count<0) count = length;
int maxCount = length-offset;
size_t maxCount = length-offset;
if(count>maxCount) count = maxCount;
// write
SerializeHelper::writeSize(count, pbuffer, pflusher);
//if (count == 0) return; pcontrol->ensureData(sizeof(T)-1); pbuffer->align(sizeof(T));
int end = offset+count;
int i = offset;
size_t end = offset+count;
size_t i = offset;
while(true) {
/*
int maxIndex = std::min<int>(end-i, (int)(pbuffer->getRemaining()/sizeof(T)))+i;
size_t maxIndex = std::min<int>(end-i, (int)(pbuffer->getRemaining()/sizeof(T)))+i;
for(; i<maxIndex; i++)
pbuffer->put<T>(value[i]);
*/
int maxCount = std::min<int>(end-i, (int)(pbuffer->getRemaining()/sizeof(T)));
pbuffer->putArray<T>(&value[i], maxCount);
size_t maxCount = std::min<int>(end-i, (int)(pbuffer->getRemaining()/sizeof(T)));
T * pvalue = const_cast<T *>(get());
pbuffer->putArray<T>(pvalue, maxCount);
i += maxCount;
if(i<end)
@@ -336,14 +368,16 @@ void DefaultPVArray<T>::serialize(ByteBuffer *pbuffer,
template<>
void DefaultPVArray<String>::deserialize(ByteBuffer *pbuffer,
DeserializableControl *pcontrol) {
int size = SerializeHelper::readSize(pbuffer, pcontrol);
size_t size = SerializeHelper::readSize(pbuffer, pcontrol);
if(size>=0) {
// prepare array, if necessary
if(size>getCapacity()) setCapacity(size);
// retrieve value from the buffer
for(int i = 0; i<size; i++)
value[i] = SerializeHelper::deserializeString(pbuffer,
String * pvalue = get();
for(size_t i = 0; i<size; i++) {
pvalue[i] = SerializeHelper::deserializeString(pbuffer,
pcontrol);
}
// set new length
setLength(size);
postPut();
@@ -353,8 +387,8 @@ void DefaultPVArray<String>::deserialize(ByteBuffer *pbuffer,
template<>
void DefaultPVArray<String>::serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher, int offset, int count) const {
int length = getLength();
SerializableControl *pflusher, size_t offset, size_t count) const {
size_t length = getLength();
// check bounds
if(offset<0)
@@ -362,21 +396,27 @@ void DefaultPVArray<String>::serialize(ByteBuffer *pbuffer,
else if(offset>length) offset = length;
if(count<0) count = length;
int maxCount = length-offset;
size_t maxCount = length-offset;
if(count>maxCount) count = maxCount;
// write
SerializeHelper::writeSize(count, pbuffer, pflusher);
int end = offset+count;
for(int i = offset; i<end; i++)
SerializeHelper::serializeString(value[i], pbuffer, pflusher);
size_t end = offset+count;
String * pvalue = get();
for(size_t i = offset; i<end; i++) {
SerializeHelper::serializeString(pvalue[i], pbuffer, pflusher);
}
}
typedef DefaultPVArray<bool> DefaultPVBooleanArray;
typedef DefaultPVArray<boolean> DefaultPVBooleanArray;
typedef DefaultPVArray<int8> BasePVByteArray;
typedef DefaultPVArray<int16> BasePVShortArray;
typedef DefaultPVArray<int32> BasePVIntArray;
typedef DefaultPVArray<int64> BasePVLongArray;
typedef DefaultPVArray<uint8> BasePVUByteArray;
typedef DefaultPVArray<uint16> BasePVUShortArray;
typedef DefaultPVArray<uint32> BasePVUIntArray;
typedef DefaultPVArray<uint64> BasePVULongArray;
typedef DefaultPVArray<float> BasePVFloatArray;
typedef DefaultPVArray<double> BasePVDoubleArray;
typedef DefaultPVArray<String> BasePVStringArray;
@@ -385,217 +425,230 @@ typedef DefaultPVArray<String> BasePVStringArray;
PVDataCreate::PVDataCreate(){ }
PVField *PVDataCreate::createPVField(PVStructure *parent,
FieldConstPtr field)
PVFieldPtr PVDataCreate::createPVField(FieldConstPtr & field)
{
switch(field->getType()) {
case scalar: {
ScalarConstPtr xx = static_pointer_cast<const Scalar>(field);
return createPVScalar(parent,xx);
return createPVScalar(xx);
}
case scalarArray: {
ScalarArrayConstPtr xx = static_pointer_cast<const ScalarArray>(field);
return (PVField *)createPVScalarArray(parent,xx);
return createPVScalarArray(xx);
}
case structure: {
StructureConstPtr xx = static_pointer_cast<const Structure>(field);
return (PVField *)createPVStructure(parent,xx);
return createPVStructure(xx);
}
case structureArray: {
StructureArrayConstPtr xx = static_pointer_cast<const StructureArray>(field);
return createPVStructureArray(parent,xx);
return createPVStructureArray(xx);
}
}
String message("PVDataCreate::createPVField should never get here");
throw std::logic_error(message);
throw std::logic_error("PVDataCreate::createPVField should never get here");
}
PVField *PVDataCreate::createPVField(PVStructure *parent,
String fieldName,PVField * fieldToClone)
PVFieldPtr PVDataCreate::createPVField(PVFieldPtr & fieldToClone)
{
switch(fieldToClone->getField()->getType()) {
case scalar:
return createPVScalar(parent,fieldName,(PVScalar*)fieldToClone);
{
PVScalarPtr pvScalar = static_pointer_cast<PVScalar>(fieldToClone);
return createPVScalar(pvScalar);
}
case scalarArray:
return (PVField *)createPVScalarArray(parent,fieldName,
(PVScalarArray *)fieldToClone);
{
PVScalarArrayPtr pvScalarArray
= static_pointer_cast<PVScalarArray>(fieldToClone);
return createPVScalarArray(pvScalarArray);
}
case structure:
return (PVField *)createPVStructure(parent,fieldName,
(PVStructure *)fieldToClone);
{
PVStructurePtr pvStructure
= static_pointer_cast<PVStructure>(fieldToClone);
StringArray fieldNames = pvStructure->getStructure()->getFieldNames();
PVFieldPtrArray pvFieldPtrArray = pvStructure->getPVFields();
return createPVStructure(fieldNames,pvFieldPtrArray);
}
case structureArray:
String message(
"PVDataCreate::createPVField structureArray not valid fieldToClone");
throw std::invalid_argument(message);
{
PVStructureArrayPtr from
= static_pointer_cast<PVStructureArray>(fieldToClone);
StructureArrayConstPtr structureArray = from->getStructureArray();
PVStructureArrayPtr to = createPVStructureArray(
structureArray);
convert->copyStructureArray(from, to);
return to;
}
}
String message("PVDataCreate::createPVField should never get here");
throw std::logic_error(message);
throw std::logic_error("PVDataCreate::createPVField should never get here");
}
PVScalar *PVDataCreate::createPVScalar(PVStructure *parent,ScalarConstPtr scalar)
PVScalarPtr PVDataCreate::createPVScalar(ScalarConstPtr & scalar)
{
ScalarType scalarType = scalar->getScalarType();
switch(scalarType) {
case pvBoolean:
return new BasePVBoolean(parent,scalar);
return PVScalarPtr(new BasePVBoolean(scalar));
case pvByte:
return new BasePVByte(parent,scalar);
return PVScalarPtr(new BasePVByte(scalar));
case pvShort:
return new BasePVShort(parent,scalar);
return PVScalarPtr(new BasePVShort(scalar));
case pvInt:
return new BasePVInt(parent,scalar);
return PVScalarPtr(new BasePVInt(scalar));
case pvLong:
return new BasePVLong(parent,scalar);
return PVScalarPtr(new BasePVLong(scalar));
case pvUByte:
return PVScalarPtr(new BasePVUByte(scalar));
case pvUShort:
return PVScalarPtr(new BasePVUShort(scalar));
case pvUInt:
return PVScalarPtr(new BasePVUInt(scalar));
case pvULong:
return PVScalarPtr(new BasePVULong(scalar));
case pvFloat:
return new BasePVFloat(parent,scalar);
return PVScalarPtr(new BasePVFloat(scalar));
case pvDouble:
return new BasePVDouble(parent,scalar);
return PVScalarPtr(new BasePVDouble(scalar));
case pvString:
return new BasePVString(parent,scalar);
return PVScalarPtr(new BasePVString(scalar));
}
String message("PVDataCreate::createPVScalar should never get here");
throw std::logic_error(message);
throw std::logic_error("PVDataCreate::createPVScalar should never get here");
}
PVScalar *PVDataCreate::createPVScalar(PVStructure *parent,
String fieldName,ScalarType scalarType)
PVScalarPtr PVDataCreate::createPVScalar(ScalarType scalarType)
{
ScalarConstPtr scalar = fieldCreate->createScalar(fieldName,scalarType);
return createPVScalar(parent,scalar);
ScalarConstPtr scalar = fieldCreate->createScalar(scalarType);
return createPVScalar(scalar);
}
PVScalar *PVDataCreate::createPVScalar(PVStructure *parent,
String fieldName,PVScalar * scalarToClone)
PVScalarPtr PVDataCreate::createPVScalar(PVScalarPtr & scalarToClone)
{
PVScalar *pvScalar = createPVScalar(parent,fieldName,
scalarToClone->getScalar()->getScalarType());
ScalarType scalarType = scalarToClone->getScalar()->getScalarType();
PVScalarPtr pvScalar = createPVScalar(scalarType);
convert->copyScalar(scalarToClone, pvScalar);
PVAuxInfo *from = scalarToClone->getPVAuxInfo();
PVAuxInfo *to = pvScalar->getPVAuxInfo();
int numberInfo = from->getNumberInfo();
for(int i=0; i<numberInfo; i++) {
PVScalar *pvFrom = from->getInfo(i);
ScalarConstPtr scalar = pvFrom->getScalar();
PVScalar *pvTo = to->createInfo(scalar->getFieldName(),scalar->getScalarType());
convert->copyScalar(pvFrom,pvTo);
PVAuxInfoPtr from = scalarToClone->getPVAuxInfo();
PVAuxInfoPtr to = pvScalar->getPVAuxInfo();
PVAuxInfo::PVInfoMap & map = from->getInfoMap();
for(PVAuxInfo::PVInfoIter iter = map.begin(); iter!= map.end(); ++iter) {
String key = iter->first;
PVScalarPtr pvFrom = iter->second;
ScalarConstPtr scalar = pvFrom->getScalar();
PVScalarPtr pvTo = to->createInfo(key,scalar->getScalarType());
convert->copyScalar(pvFrom,pvTo);
}
return pvScalar;
}
PVScalarArray *PVDataCreate::createPVScalarArray(PVStructure *parent,
ScalarArrayConstPtr scalarArray)
PVScalarArrayPtr PVDataCreate::createPVScalarArray(
ScalarArrayConstPtr & scalarArray)
{
switch(scalarArray->getElementType()) {
case pvBoolean:
return new DefaultPVBooleanArray(parent,scalarArray);
return PVScalarArrayPtr(new DefaultPVBooleanArray(scalarArray));
case pvByte:
return new BasePVByteArray(parent,scalarArray);
return PVScalarArrayPtr(new BasePVByteArray(scalarArray));
case pvShort:
return new BasePVShortArray(parent,scalarArray);
return PVScalarArrayPtr(new BasePVShortArray(scalarArray));
case pvInt:
return new BasePVIntArray(parent,scalarArray);
return PVScalarArrayPtr(new BasePVIntArray(scalarArray));
case pvLong:
return new BasePVLongArray(parent,scalarArray);
return PVScalarArrayPtr(new BasePVLongArray(scalarArray));
case pvUByte:
return PVScalarArrayPtr(new BasePVUByteArray(scalarArray));
case pvUShort:
return PVScalarArrayPtr(new BasePVUShortArray(scalarArray));
case pvUInt:
return PVScalarArrayPtr(new BasePVUIntArray(scalarArray));
case pvULong:
return PVScalarArrayPtr(new BasePVULongArray(scalarArray));
case pvFloat:
return new BasePVFloatArray(parent,scalarArray);
return PVScalarArrayPtr(new BasePVFloatArray(scalarArray));
case pvDouble:
return new BasePVDoubleArray(parent,scalarArray);
return PVScalarArrayPtr(new BasePVDoubleArray(scalarArray));
case pvString:
return new BasePVStringArray(parent,scalarArray);
return PVScalarArrayPtr(new BasePVStringArray(scalarArray));
}
String message("PVDataCreate::createPVScalarArray should never get here");
throw std::logic_error(message);
throw std::logic_error("PVDataCreate::createPVScalarArray should never get here");
}
PVScalarArray *PVDataCreate::createPVScalarArray(PVStructure *parent,
String fieldName,ScalarType elementType)
PVScalarArrayPtr PVDataCreate::createPVScalarArray(
ScalarType elementType)
{
return createPVScalarArray(parent,
fieldCreate->createScalarArray(fieldName, elementType));
ScalarArrayConstPtr scalarArray = fieldCreate->createScalarArray(elementType);
return createPVScalarArray(scalarArray);
}
PVScalarArray *PVDataCreate::createPVScalarArray(PVStructure *parent,
String fieldName,PVScalarArray * arrayToClone)
PVScalarArrayPtr PVDataCreate::createPVScalarArray(
PVScalarArrayPtr &arrayToClone)
{
PVScalarArray *pvArray = createPVScalarArray(parent,fieldName,
PVScalarArrayPtr pvArray = createPVScalarArray(
arrayToClone->getScalarArray()->getElementType());
convert->copyScalarArray(arrayToClone,0, pvArray,0,arrayToClone->getLength());
PVAuxInfo *from = arrayToClone->getPVAuxInfo();
PVAuxInfo *to = pvArray->getPVAuxInfo();
int numberInfo = from->getNumberInfo();
for(int i=0; i<numberInfo; i++) {
PVScalar *pvFrom = from->getInfo(i);
ScalarConstPtr scalar = pvFrom->getScalar();
PVScalar *pvTo = to->createInfo(scalar->getFieldName(),scalar->getScalarType());
convert->copyScalar(pvFrom,pvTo);
PVAuxInfoPtr from = arrayToClone->getPVAuxInfo();
PVAuxInfoPtr to = pvArray->getPVAuxInfo();
PVAuxInfo::PVInfoMap & map = from->getInfoMap();
for(PVAuxInfo::PVInfoIter iter = map.begin(); iter!= map.end(); ++iter) {
String key = iter->first;
PVScalarPtr pvFrom = iter->second;
ScalarConstPtr scalar = pvFrom->getScalar();
PVScalarPtr pvTo = to->createInfo(key,scalar->getScalarType());
convert->copyScalar(pvFrom,pvTo);
}
return pvArray;
}
PVStructureArray *PVDataCreate::createPVStructureArray(PVStructure *parent,
StructureArrayConstPtr structureArray)
PVStructureArrayPtr PVDataCreate::createPVStructureArray(
StructureArrayConstPtr & structureArray)
{
return new BasePVStructureArray(parent,structureArray);
return PVStructureArrayPtr(new PVStructureArray(structureArray));
}
PVStructure *PVDataCreate::createPVStructure(PVStructure *parent,
StructureConstPtr structure)
PVStructurePtr PVDataCreate::createPVStructure(
StructureConstPtr &structure)
{
PVStructure *pvStructure = new PVStructure(parent,structure);
return pvStructure;
return PVStructurePtr(new PVStructure(structure));
}
PVStructure *PVDataCreate::createPVStructure(PVStructure *parent,
String fieldName,int numberFields,FieldConstPtrArray fields)
PVStructurePtr PVDataCreate::createPVStructure(
StringArray & fieldNames,PVFieldPtrArray & pvFields)
{
StructureConstPtr structure = fieldCreate->createStructure(
fieldName,numberFields, fields);
return new PVStructure(parent,structure);
size_t num = fieldNames.size();
FieldConstPtrArray fields(num);
for (size_t i=0;i<num;i++) fields[i] = pvFields[i]->getField();
StructureConstPtr structure = fieldCreate->createStructure(fieldNames,fields);
return PVStructurePtr(new PVStructure(structure,pvFields));
}
PVStructure *PVDataCreate::createPVStructure(PVStructure *parent,
String fieldName,int numberFields,PVFieldPtrArray pvFields)
PVStructurePtr PVDataCreate::createPVStructure(PVStructurePtr &structToClone)
{
FieldConstPtrArray fields = new FieldConstPtr[numberFields];
for(int i=0; i<numberFields;i++) {
fields[i] = pvFields[i]->getField();
}
StructureConstPtr structure = fieldCreate->createStructure(
fieldName,numberFields,fields);
PVStructure *pvStructure = new PVStructure(parent,structure,pvFields);
return pvStructure;
}
PVStructure *PVDataCreate::createPVStructure(PVStructure *parent,
String fieldName,PVStructure *structToClone)
{
FieldConstPtrArray fields = 0;
int numberFields = 0;
PVStructure *pvStructure = 0;;
FieldConstPtrArray field;
if(structToClone==0) {
fields = new FieldConstPtr[0];
StructureConstPtr structure = fieldCreate->createStructure(
fieldName,numberFields,fields);
pvStructure = new PVStructure(parent,structure);
} else {
StructureConstPtr structure = structToClone->getStructure();
pvStructure = new PVStructure(parent,structure);
convert->copyStructure(structToClone,pvStructure);
FieldConstPtrArray fields(0);
StringArray fieldNames(0);
StructureConstPtr structure = fieldCreate->createStructure(fieldNames,fields);
return PVStructurePtr(new PVStructure(structure));
}
StructureConstPtr structure = structToClone->getStructure();
PVStructurePtr pvStructure(new PVStructure(structure));
convert->copyStructure(structToClone,pvStructure);
return pvStructure;
}
PVDataCreate * getPVDataCreate() {
static Mutex mutex;
Lock xx(mutex);
PVDataCreatePtr PVDataCreate::getPVDataCreate()
{
static PVDataCreatePtr pvDataCreate;
static Mutex mutex;
Lock xx(mutex);
if(pvDataCreate==0){
pvDataCreate = new PVDataCreate();
convert = getConvert();
fieldCreate = getFieldCreate();
}
return pvDataCreate;
}
if(pvDataCreate.get()==0) pvDataCreate = PVDataCreatePtr(new PVDataCreate());
return pvDataCreate;
}
PVDataCreatePtr getPVDataCreate() {
return PVDataCreate::getPVDataCreate();
}
}}
+143 -131
View File
@@ -12,72 +12,39 @@
#include <pv/pvData.h>
#include <pv/factory.h>
#include <pv/convert.h>
#include <pv/CDRMonitor.h>
using std::tr1::const_pointer_cast;
using std::size_t;
namespace epics { namespace pvData {
static String notImplemented("not implemented");
PVDATA_REFCOUNT_MONITOR_DEFINE(pvField);
class PVFieldPvt {
public:
PVFieldPvt(PVStructure *parent,FieldConstPtr field);
~PVFieldPvt();
PVStructure *parent;
FieldConstPtr field;
int fieldOffset;
int nextFieldOffset;
PVAuxInfo *pvAuxInfo;
bool immutable;
Requester *requester;
PostHandler *postHandler;
Convert *convert;
};
PVFieldPvt::PVFieldPvt(PVStructure *parent,FieldConstPtr field)
: parent(parent),field(field),
fieldOffset(0), nextFieldOffset(0),
pvAuxInfo(0),
immutable(false),requester(0),postHandler(0),
convert(getConvert())
PVField::PVField(FieldConstPtr field)
: parent(NULL),field(field),
fieldOffset(0), nextFieldOffset(0),
immutable(false),requester(0),postHandler(0),
convert(getConvert())
{
}
PVFieldPvt::~PVFieldPvt()
{
if(pvAuxInfo!=0) delete pvAuxInfo;
}
PVField::PVField(PVStructure *parent,FieldConstPtr field)
: pImpl(new PVFieldPvt(parent,field))
{
PVDATA_REFCOUNT_MONITOR_CONSTRUCT(pvField);
}
PVField::~PVField()
{
PVDATA_REFCOUNT_MONITOR_DESTRUCT(pvField);
delete pImpl;
}
{ }
void PVField::message(String fieldName,String message,MessageType messageType)
{
if(pImpl->parent!=0) {
String parentName = pImpl->parent->getField()->getFieldName();
if(parent!=NULL) {
String parentName = parent->getFieldName();
if(parentName.length()>0) {
fieldName = parentName + "." + fieldName;
}
pImpl->parent->message(fieldName,message,messageType);
parent->message(fieldName,message,messageType);
return;
}
if(pImpl->requester) {
if(requester) {
String mess = fieldName + " " + message;
pImpl->requester->message(mess,messageType);
requester->message(mess,messageType);
} else {
printf("%s %s %s\n",
messageTypeName[messageType].c_str(),
@@ -88,129 +55,174 @@ void PVField::message(String fieldName,String message,MessageType messageType)
void PVField::message(String message,MessageType messageType)
{
PVField::message(pImpl->field->getFieldName(),message,messageType);
PVField::message(fieldName,message,messageType);
}
String PVField::getFieldName()
{
if(parent==NULL) return fieldName;
PVFieldPtrArray pvFields = parent->getPVFields();
StringArray const & fieldNames = parent->getStructure()->getFieldNames();
for(size_t i=0; i<pvFields.size(); i++) {
if(pvFields[i].get()==this) {
fieldName = fieldNames[i];
return fieldName;
}
}
throw std::logic_error("PVField::PVField did not find fieldName");
}
void PVField::setRequester(Requester *requester)
{
if(pImpl->parent!=0) {
throw std::logic_error(String(
"PVField::setRequester only legal for top level structure"));
if(parent!=NULL) {
throw std::logic_error(
"PVField::setRequester only legal for top level structure");
}
if(pImpl->requester!=0) {
if(pImpl->requester==requester) return;
throw std::logic_error(String(
"PVField::setRequester requester is already present"));
if(requester!=NULL) {
if(requester==requester) return;
throw std::logic_error(
"PVField::setRequester requester is already present");
}
pImpl->requester = requester;
requester = requester;
}
int PVField::getFieldOffset()
size_t PVField::getFieldOffset()
{
if(pImpl->nextFieldOffset==0) computeOffset(this);
return pImpl->fieldOffset;
if(nextFieldOffset==0) computeOffset(this);
return fieldOffset;
}
int PVField::getNextFieldOffset()
size_t PVField::getNextFieldOffset()
{
if(pImpl->nextFieldOffset==0) computeOffset(this);
return pImpl->nextFieldOffset;
if(nextFieldOffset==0) computeOffset(this);
return nextFieldOffset;
}
int PVField::getNumberFields()
size_t PVField::getNumberFields()
{
if(pImpl->nextFieldOffset==0) computeOffset(this);
return (pImpl->nextFieldOffset - pImpl->fieldOffset);
if(nextFieldOffset==0) computeOffset(this);
return (nextFieldOffset - fieldOffset);
}
PVAuxInfo * PVField::getPVAuxInfo(){
if(pImpl->pvAuxInfo==0) {
pImpl->pvAuxInfo = new PVAuxInfo(this);
PVAuxInfoPtr & PVField::getPVAuxInfo(){
if(pvAuxInfo.get()==NULL) {
pvAuxInfo = PVAuxInfoPtr(new PVAuxInfo(this));
}
return pImpl->pvAuxInfo;
return pvAuxInfo;
}
bool PVField::isImmutable() {return pImpl->immutable;}
bool PVField::isImmutable() {return immutable;}
void PVField::setImmutable() {pImpl->immutable = true;}
void PVField::setImmutable() {immutable = true;}
FieldConstPtr PVField::getField() {return pImpl->field;}
FieldConstPtr & PVField::getField() {return field;}
PVStructure * PVField::getParent() {return pImpl->parent;}
PVStructure *PVField::getParent() {return parent;}
bool PVField::renameField(String newName)
void PVField::replacePVField(PVFieldPtr & newPVField)
{
if(pImpl->parent!=0) {
StructureConstPtr structure = pImpl->parent->getStructure();
int index = structure->getFieldIndex(newName);
if(index>=0) return false;
if(parent==NULL) {
throw std::logic_error("no parent");
}
Field::shared_pointer field(const_pointer_cast<Field>(pImpl->field));
field->renameField(newName);
return true;
PVFieldPtrArray pvFields = parent->getPVFields();
StructureConstPtr structure = parent->getStructure();
StringArray fieldNames = structure->getFieldNames();
for(size_t i=0; i<fieldNames.size(); i++) {
if(newPVField->getFieldName().compare(fieldNames[i]) == 0) {
pvFields[i] = newPVField;
return;
}
}
throw std::logic_error("Did not find field in parent");
}
void PVField::replaceField(FieldConstPtr &xxx)
{
field = xxx;
}
void PVField::renameField(String newName)
{
if(parent==NULL) {
throw std::logic_error("no parent");
}
std::tr1::shared_ptr<Structure> parentStructure = const_pointer_cast<Structure>(
parent->getStructure());
StringArray const &fieldNames = parentStructure->getFieldNames();
FieldConstPtrArray const &fields = parentStructure->getFields();
for(size_t i=0; i<fields.size(); i++) {
if(fields[i].get()==field.get()) {
parentStructure->renameField(i,newName);
return;
}
}
throw std::logic_error("Did not find field in parent");
}
void PVField::postPut()
{
if(pImpl->postHandler!=0) pImpl->postHandler->postPut();
if(postHandler!=NULL) postHandler->postPut();
}
void PVField::setPostHandler(PostHandler *postHandler)
{
if(pImpl->postHandler!=0) {
if(postHandler==pImpl->postHandler) return;
String message(
if(postHandler!=NULL) {
if(postHandler==postHandler) return;
throw std::logic_error(
"PVField::setPostHandler a postHandler is already registered");
throw std::logic_error(message);
}
pImpl->postHandler = postHandler;
postHandler = postHandler;
}
void PVField::setParent(PVStructure * parent)
void PVField::setParent(PVStructure * xxx)
{
pImpl->parent = parent;
parent = xxx;
}
bool PVField::equals(PVField &pv)
{
return pImpl->convert->equals(*this,pv);
return convert->equals(*this,pv);
}
void PVField::toString(StringBuilder buf) {toString(buf,0);}
void PVField::toString(StringBuilder buf)
{
toString(buf,0);
}
void PVField::toString(StringBuilder buf,int indentLevel)
{
pImpl->convert->getString(buf,this,indentLevel);
if(pImpl->pvAuxInfo==0) return;
pImpl->pvAuxInfo->toString(buf,indentLevel);
static ConvertPtr convert = getConvert();
convert->getString(buf,this,indentLevel);
if(pvAuxInfo.get()!=NULL) pvAuxInfo->toString(buf,indentLevel);
}
void PVField::computeOffset(PVField * pvField) {
PVStructure *pvTop = pvField->getParent();
if(pvTop==0) {
PVStructure * pvTop = pvField->getParent();
if(pvTop==NULL) {
if(pvField->getField()->getType()!=structure) {
pvField->pImpl->fieldOffset = 0;
pvField->pImpl->nextFieldOffset = 1;
pvField->fieldOffset = 0;
pvField->nextFieldOffset = 1;
return;
}
pvTop = static_cast<PVStructure *>(pvField);
} else {
while(pvTop->getParent()!=0) pvTop = pvTop->getParent();
while(pvTop->getParent()!=NULL) pvTop = pvTop->getParent();
}
int offset = 0;
int nextOffset = 1;
PVFieldPtrArray pvFields = pvTop->getPVFields();
for(int i=0; i < pvTop->getStructure()->getNumberFields(); i++) {
PVFieldPtrArray pvFields = pvTop->getPVFields();
for(size_t i=0; i < pvTop->getStructure()->getNumberFields(); i++) {
offset = nextOffset;
PVField *pvField = pvFields[i];
PVField *pvField = pvFields[i].get();
FieldConstPtr field = pvField->getField();
switch(field->getType()) {
case scalar:
case scalarArray:
case structureArray:{
nextOffset++;
pvField->pImpl->fieldOffset = offset;
pvField->pImpl->nextFieldOffset = nextOffset;
pvField->fieldOffset = offset;
pvField->nextFieldOffset = nextOffset;
break;
}
case structure: {
@@ -220,36 +232,36 @@ void PVField::computeOffset(PVField * pvField) {
}
}
PVField *top = (PVField *)pvTop;
top->pImpl->fieldOffset = 0;
top->pImpl->nextFieldOffset = nextOffset;
top->fieldOffset = 0;
top->nextFieldOffset = nextOffset;
}
void PVField::computeOffset(PVField * pvField,int offset) {
int beginOffset = offset;
int nextOffset = offset + 1;
PVStructure *pvStructure = static_cast<PVStructure *>(pvField);
PVFieldPtrArray pvFields = pvStructure->getPVFields();
for(int i=0; i < pvStructure->getStructure()->getNumberFields(); i++) {
offset = nextOffset;
PVField *pvSubField = pvFields[i];
FieldConstPtr field = pvSubField->getField();
switch(field->getType()) {
case scalar:
case scalarArray:
case structureArray: {
nextOffset++;
pvSubField->pImpl->fieldOffset = offset;
pvSubField->pImpl->nextFieldOffset = nextOffset;
break;
}
case structure: {
pvSubField->computeOffset(pvSubField,offset);
nextOffset = pvSubField->getNextFieldOffset();
}
}
}
pvField->pImpl->fieldOffset = beginOffset;
pvField->pImpl->nextFieldOffset = nextOffset;
void PVField::computeOffset(PVField * pvField,size_t offset) {
int beginOffset = offset;
int nextOffset = offset + 1;
PVStructure *pvStructure = static_cast<PVStructure *>(pvField);
PVFieldPtrArray pvFields = pvStructure->getPVFields();
for(size_t i=0; i < pvStructure->getStructure()->getNumberFields(); i++) {
offset = nextOffset;
PVField *pvSubField = pvFields[i].get();
FieldConstPtr field = pvSubField->getField();
switch(field->getType()) {
case scalar:
case scalarArray:
case structureArray: {
nextOffset++;
pvSubField->fieldOffset = offset;
pvSubField->nextFieldOffset = nextOffset;
break;
}
case structure: {
pvSubField->computeOffset(pvSubField,offset);
nextOffset = pvSubField->getNextFieldOffset();
}
}
}
pvField->fieldOffset = beginOffset;
pvField->nextFieldOffset = nextOffset;
}
}}
+2 -2
View File
@@ -17,8 +17,8 @@ namespace epics { namespace pvData {
PVScalar::~PVScalar() {}
PVScalar::PVScalar(PVStructure *parent,ScalarConstPtr scalar)
: PVField(parent,scalar) {}
PVScalar::PVScalar(ScalarConstPtr scalar)
: PVField(scalar) {}
ScalarConstPtr PVScalar::getScalar()
{
+2 -3
View File
@@ -17,9 +17,8 @@ namespace epics { namespace pvData {
PVScalarArray::~PVScalarArray() {}
PVScalarArray::PVScalarArray(PVStructure *parent,
ScalarArrayConstPtr scalarArray)
: PVArray(parent,scalarArray) {}
PVScalarArray::PVScalarArray(ScalarArrayConstPtr scalarArray)
: PVArray(scalarArray) {}
ScalarArrayConstPtr PVScalarArray::getScalarArray()
{
File diff suppressed because it is too large Load Diff
+227
View File
@@ -0,0 +1,227 @@
/*PVStructureArray.cpp*/
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*/
#include <cstddef>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <pv/pvData.h>
#include <pv/convert.h>
#include <pv/factory.h>
#include <pv/serializeHelper.h>
using std::tr1::static_pointer_cast;
using std::tr1::const_pointer_cast;
using std::size_t;
namespace epics { namespace pvData {
PVStructureArray::PVStructureArray(StructureArrayConstPtr structureArray)
: PVArray(structureArray),
structureArray(structureArray),
value(std::tr1::shared_ptr<std::vector<PVStructurePtr> >
(new std::vector<PVStructurePtr>()))
{
}
size_t PVStructureArray::append(size_t number)
{
size_t currentLength = getCapacity();
size_t newLength = currentLength + number;
setCapacity(newLength);
StructureConstPtr structure = structureArray->getStructure();
for(size_t i=currentLength; i<newLength; i++) {
PVStructurePtrArray vec = *value.get();
vec[i] = getPVDataCreate()->createPVStructure(structure);
}
return newLength;
}
bool PVStructureArray::remove(size_t offset,size_t number)
{
size_t length = getCapacity();
if(offset+number>length) return false;
value->erase(value->begin()+ offset,value->begin()+number-1);
return true;
}
void PVStructureArray::compress() {
size_t length = getCapacity();
size_t newLength = 0;
PVStructurePtrArray vec = *value.get();
for(size_t i=0; i<length; i++) {
if(vec[i].get()!=NULL) {
newLength++;
continue;
}
// find first non 0
size_t notNull = 0;
for(size_t j=i+1;j<length;j++) {
if(vec[j].get()!=NULL) {
notNull = j;
break;
}
}
if(notNull!=0) {
vec[i] = vec[notNull];
vec[notNull].reset();
newLength++;
continue;
}
break;
}
setCapacity(newLength);
}
void PVStructureArray::setCapacity(size_t capacity) {
if(getCapacity()==capacity) return;
if(!isCapacityMutable()) {
std::string message("not capacityMutable");
PVField::message(message, errorMessage);
return;
}
size_t length = getCapacity();
PVStructurePtrArray array(capacity);
size_t num = PVArray::getLength();
if(num>capacity) num = capacity;
PVStructurePtr * from = get();
for (size_t i=0; i<num; i++) array[i] = from[i];
value->swap(array);
setCapacityLength(capacity,length);
}
StructureArrayConstPtr PVStructureArray::getStructureArray()
{
return structureArray;
}
size_t PVStructureArray::get(
size_t offset, size_t len, StructureArrayData &data)
{
size_t n = len;
size_t length = getLength();
if(offset+len > length) {
n = length - offset;
if(n<0) n = 0;
}
data.data = *value.get();
data.offset = offset;
return n;
}
size_t PVStructureArray::put(size_t offset,size_t len,
PVStructurePtr* const from, size_t fromOffset)
{
if(isImmutable()) {
message(String("field is immutable"), errorMessage);
return 0;
}
std::vector<PVStructurePtr> to = *value.get();
if(from==&to[0]) return len;
if(len<1) return 0;
size_t length = getLength();
size_t capacity = getCapacity();
if(offset+len > length) {
size_t newlength = offset + len;
if(newlength>capacity) {
setCapacity(newlength);
capacity = getCapacity();
newlength = capacity;
len = newlength - offset;
if(len<=0) return 0;
}
length = newlength;
setLength(length);
}
to = *value.get();
StructureConstPtr structure = structureArray->getStructure();
for(size_t i=0; i<len; i++) {
PVStructurePtr frompv = from[i+fromOffset];
if(frompv.get()!=NULL) {
if(frompv->getStructure()!=structure) {
throw std::invalid_argument(String(
"Element is not a compatible structure"));
}
}
to[i+offset] = frompv;
}
postPut();
setLength(length);
return len;
}
void PVStructureArray::shareData(
std::tr1::shared_ptr<std::vector<PVStructurePtr> > const & sharedValue,
std::size_t capacity,
std::size_t length)
{
value = sharedValue;
setCapacityLength(capacity,length);
}
void PVStructureArray::serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher) const {
serialize(pbuffer, pflusher, 0, getLength());
}
void PVStructureArray::deserialize(ByteBuffer *pbuffer,
DeserializableControl *pcontrol) {
size_t size = SerializeHelper::readSize(pbuffer, pcontrol);
if(size>=0) {
// prepare array, if necessary
if(size>getCapacity()) setCapacity(size);
PVStructurePtrArray pvArray = *value.get();
for(size_t i = 0; i<size; i++) {
pcontrol->ensureData(1);
size_t temp = pbuffer->getByte();
if(temp==0) {
pvArray[i].reset();
}
else {
if(pvArray[i].get()==NULL) {
StructureConstPtr structure = structureArray->getStructure();
pvArray[i] = getPVDataCreate()->createPVStructure(structure);
}
pvArray[i]->deserialize(pbuffer, pcontrol);
}
}
setLength(size);
postPut();
}
}
void PVStructureArray::serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher, size_t offset, size_t count) const {
// cache
size_t length = getLength();
// check bounds
if(offset<0)
offset = 0;
else if(offset>length) offset = length;
if(count<0) count = length;
size_t maxCount = length-offset;
if(count>maxCount) count = maxCount;
PVStructurePtrArray pvArray = *value.get();
// write
SerializeHelper::writeSize(count, pbuffer, pflusher);
for(size_t i = 0; i<count; i++) {
if(pbuffer->getRemaining()<1) pflusher->flushSerializeBuffer();
PVStructurePtr pvStructure = pvArray[i+offset];
if(pvStructure.get()==NULL) {
pbuffer->putByte(0);
}
else {
pbuffer->putByte(1);
pvStructure->serialize(pbuffer, pflusher);
}
}
}
}}
+250 -280
View File
@@ -12,16 +12,13 @@
#include <pv/lock.h>
#include <pv/pvIntrospect.h>
#include <pv/standardField.h>
#include <pv/CDRMonitor.h>
using std::tr1::static_pointer_cast;
namespace epics { namespace pvData {
static StandardField* standardField = 0;
static String notImplemented("not implemented");
static FieldCreate* fieldCreate = 0;
static FieldCreatePtr fieldCreate;
static String valueFieldName("value");
// following are preallocated structures
@@ -41,158 +38,213 @@ static StructureConstPtr enumeratedAlarmField;
static void createAlarm() {
FieldConstPtrArray fields = new FieldConstPtr[3];
fields[0] = fieldCreate->createScalar(String("severity"),pvInt);
fields[1] = fieldCreate->createScalar(String("status"),pvInt);
fields[2] = fieldCreate->createScalar(String("message"),pvString);
alarmField = fieldCreate->createStructure(String("alarm"),3,fields);
size_t num = 3;
FieldConstPtrArray fields(num);
StringArray names(num);
names[0] = "severity";
names[1] = "status";
names[2] = "message";
fields[0] = fieldCreate->createScalar(pvInt);
fields[1] = fieldCreate->createScalar(pvInt);
fields[2] = fieldCreate->createScalar(pvString);
alarmField = fieldCreate->createStructure(names,fields);
}
static void createTimeStamp() {
FieldConstPtrArray fields = new FieldConstPtr[3];
fields[0] = fieldCreate->createScalar(String("secondsPastEpoch"),pvLong);
fields[1] = fieldCreate->createScalar(String("nanoSeconds"),pvInt);
fields[2] = fieldCreate->createScalar(String("userTag"),pvInt);
timeStampField = fieldCreate->createStructure(String("timeStamp"),3,fields);
size_t num = 3;
FieldConstPtrArray fields(num);
StringArray names(num);
names[0] = "secondsPastEpoch";
names[1] = "nanoSeconds";
names[2] = "userTag";
fields[0] = fieldCreate->createScalar(pvLong);
fields[1] = fieldCreate->createScalar(pvInt);
fields[2] = fieldCreate->createScalar(pvInt);
timeStampField = fieldCreate->createStructure(names,fields);
}
static void createDisplay() {
FieldConstPtrArray limitFields = new FieldConstPtr[2];
limitFields[0] = fieldCreate->createScalar(String("low"),pvDouble);
limitFields[1] = fieldCreate->createScalar(String("high"),pvDouble);
FieldConstPtrArray fields = new FieldConstPtr[4];
fields[0] = fieldCreate->createScalar(String("description"),pvString);
fields[1] = fieldCreate->createScalar(String("format"),pvString);
fields[2] = fieldCreate->createScalar(String("units"),pvString);
fields[3] = fieldCreate->createStructure(String("limit"),2,limitFields);
displayField = fieldCreate->createStructure(String("display"),4,fields);
size_t num = 5;
FieldConstPtrArray fields(num);
StringArray names(num);
names[0] = "limitLow";
names[1] = "limitHigh";
names[2] = "description";
names[3] = "format";
names[4] = "units";
fields[0] = fieldCreate->createScalar(pvDouble);
fields[1] = fieldCreate->createScalar(pvDouble);
fields[2] = fieldCreate->createScalar(pvString);
fields[3] = fieldCreate->createScalar(pvString);
fields[4] = fieldCreate->createScalar(pvString);
displayField = fieldCreate->createStructure(names,fields);
}
static void createControl() {
FieldConstPtrArray limitFields = new FieldConstPtr[2];
limitFields[0] = fieldCreate->createScalar(String("low"),pvDouble);
limitFields[1] = fieldCreate->createScalar(String("high"),pvDouble);
FieldConstPtrArray fields = new FieldConstPtr[2];
fields[0] = fieldCreate->createStructure(String("limit"),2,limitFields);
fields[1] = fieldCreate->createScalar(String("minStep"),pvDouble);
controlField = fieldCreate->createStructure(String("control"),2,fields);
size_t num = 3;
FieldConstPtrArray fields(num);
StringArray names(num);
names[0] = "limitLow";
names[1] = "limitHigh";
names[2] = "minStep";
fields[0] = fieldCreate->createScalar(pvDouble);
fields[1] = fieldCreate->createScalar(pvDouble);
fields[2] = fieldCreate->createScalar(pvDouble);
controlField = fieldCreate->createStructure(names,fields);
}
static void createBooleanAlarm() {
FieldConstPtrArray fields = new FieldConstPtr[4];
fields[0] = fieldCreate->createScalar(String("active"),pvBoolean);
fields[1] = fieldCreate->createScalar(String("falseSeverity"),pvInt);
fields[2] = fieldCreate->createScalar(String("trueSeverity"),pvInt);
fields[3] = fieldCreate->createScalar(String("changeStateSeverity"),pvInt);
booleanAlarmField = fieldCreate->createStructure(String("valueAlarm"),4,fields);
size_t num = 4;
FieldConstPtrArray fields(num);
StringArray names(num);
names[0] = "active";
names[1] = "falseSeverity";
names[2] = "trueSeverity";
names[3] = "changeStateSeverity";
booleanAlarmField = fieldCreate->createStructure(names,fields);
}
static void createByteAlarm() {
int numFields = 10;
FieldConstPtrArray fields = new FieldConstPtr[numFields];
fields[0] = fieldCreate->createScalar(String("active"),pvBoolean);
fields[1] = fieldCreate->createScalar(String("lowAlarmLimit"),pvByte);
fields[2] = fieldCreate->createScalar(String("lowWarningLimit"),pvByte);
fields[3] = fieldCreate->createScalar(String("highWarningLimit"),pvByte);
fields[4] = fieldCreate->createScalar(String("highAlarmLimit"),pvByte);
fields[5] = fieldCreate->createScalar(String("lowAlarmSeverity"),pvInt);
fields[6] = fieldCreate->createScalar(String("lowWarningSeverity"),pvInt);
fields[7] = fieldCreate->createScalar(String("highWarningSeverity"),pvInt);
fields[8] = fieldCreate->createScalar(String("highAlarmSeverity"),pvInt);
fields[9] = fieldCreate->createScalar(String("hystersis"),pvByte);
byteAlarmField = fieldCreate->createStructure(String("valueAlarm"),numFields,fields);
size_t numFields = 10;
FieldConstPtrArray fields(numFields);
StringArray names(numFields);
names[0] = "active";
names[1] = "lowAlarmLimit";
names[2] = "lowWarningLimit";
names[3] = "highWarningLimit";
names[4] = "highAlarmLimit";
names[5] = "lowAlarmSeverity";
names[6] = "lowWarningSeverity";
names[7] = "highWarningSeverity";
names[8] = "highAlarmSeverity";
names[9] = "hystersis";
fields[0] = fieldCreate->createScalar(pvBoolean);
for(size_t i=0; i<numFields; i++ ) {
fields[i] = fieldCreate->createScalar(pvByte);
}
byteAlarmField = fieldCreate->createStructure(names,fields);
}
static void createShortAlarm() {
int numFields = 10;
FieldConstPtrArray fields = new FieldConstPtr[numFields];
fields[0] = fieldCreate->createScalar(String("active"),pvBoolean);
fields[1] = fieldCreate->createScalar(String("lowAlarmLimit"),pvShort);
fields[2] = fieldCreate->createScalar(String("lowWarningLimit"),pvShort);
fields[3] = fieldCreate->createScalar(String("highWarningLimit"),pvShort);
fields[4] = fieldCreate->createScalar(String("highAlarmLimit"),pvShort);
fields[5] = fieldCreate->createScalar(String("lowAlarmSeverity"),pvInt);
fields[6] = fieldCreate->createScalar(String("lowWarningSeverity"),pvInt);
fields[7] = fieldCreate->createScalar(String("highWarningSeverity"),pvInt);
fields[8] = fieldCreate->createScalar(String("highAlarmSeverity"),pvInt);
fields[9] = fieldCreate->createScalar(String("hystersis"),pvShort);
shortAlarmField = fieldCreate->createStructure(String("valueAlarm"),numFields,fields);
size_t numFields = 10;
FieldConstPtrArray fields(numFields);
StringArray names(numFields);
names[0] = "active";
names[1] = "lowAlarmLimit";
names[2] = "lowWarningLimit";
names[3] = "highWarningLimit";
names[4] = "highAlarmLimit";
names[5] = "lowAlarmSeverity";
names[6] = "lowWarningSeverity";
names[7] = "highWarningSeverity";
names[8] = "highAlarmSeverity";
names[9] = "hystersis";
fields[0] = fieldCreate->createScalar(pvBoolean);
for(size_t i=0; i<numFields; i++ ) {
fields[i] = fieldCreate->createScalar(pvShort);
}
shortAlarmField = fieldCreate->createStructure(names,fields);
}
static void createIntAlarm() {
int numFields = 10;
FieldConstPtrArray fields = new FieldConstPtr[numFields];
fields[0] = fieldCreate->createScalar(String("active"),pvBoolean);
fields[1] = fieldCreate->createScalar(String("lowAlarmLimit"),pvInt);
fields[2] = fieldCreate->createScalar(String("lowWarningLimit"),pvInt);
fields[3] = fieldCreate->createScalar(String("highWarningLimit"),pvInt);
fields[4] = fieldCreate->createScalar(String("highAlarmLimit"),pvInt);
fields[5] = fieldCreate->createScalar(String("lowAlarmSeverity"),pvInt);
fields[6] = fieldCreate->createScalar(String("lowWarningSeverity"),pvInt);
fields[7] = fieldCreate->createScalar(String("highWarningSeverity"),pvInt);
fields[8] = fieldCreate->createScalar(String("highAlarmSeverity"),pvInt);
fields[9] = fieldCreate->createScalar(String("hystersis"),pvInt);
intAlarmField = fieldCreate->createStructure(String("valueAlarm"),numFields,fields);
size_t numFields = 10;
FieldConstPtrArray fields(numFields);
StringArray names(numFields);
names[0] = "active";
names[1] = "lowAlarmLimit";
names[2] = "lowWarningLimit";
names[3] = "highWarningLimit";
names[4] = "highAlarmLimit";
names[5] = "lowAlarmSeverity";
names[6] = "lowWarningSeverity";
names[7] = "highWarningSeverity";
names[8] = "highAlarmSeverity";
names[9] = "hystersis";
fields[0] = fieldCreate->createScalar(pvBoolean);
for(size_t i=0; i<numFields; i++ ) {
fields[i] = fieldCreate->createScalar(pvInt);
}
intAlarmField = fieldCreate->createStructure(names,fields);
}
static void createLongAlarm() {
int numFields = 10;
FieldConstPtrArray fields = new FieldConstPtr[numFields];
fields[0] = fieldCreate->createScalar(String("active"),pvBoolean);
fields[1] = fieldCreate->createScalar(String("lowAlarmLimit"),pvLong);
fields[2] = fieldCreate->createScalar(String("lowWarningLimit"),pvLong);
fields[3] = fieldCreate->createScalar(String("highWarningLimit"),pvLong);
fields[4] = fieldCreate->createScalar(String("highAlarmLimit"),pvLong);
fields[5] = fieldCreate->createScalar(String("lowAlarmSeverity"),pvInt);
fields[6] = fieldCreate->createScalar(String("lowWarningSeverity"),pvInt);
fields[7] = fieldCreate->createScalar(String("highWarningSeverity"),pvInt);
fields[8] = fieldCreate->createScalar(String("highAlarmSeverity"),pvInt);
fields[9] = fieldCreate->createScalar(String("hystersis"),pvLong);
longAlarmField = fieldCreate->createStructure(String("valueAlarm"),numFields,fields);
size_t numFields = 10;
FieldConstPtrArray fields(numFields);
StringArray names(numFields);
names[0] = "active";
names[1] = "lowAlarmLimit";
names[2] = "lowWarningLimit";
names[3] = "highWarningLimit";
names[4] = "highAlarmLimit";
names[5] = "lowAlarmSeverity";
names[6] = "lowWarningSeverity";
names[7] = "highWarningSeverity";
names[8] = "highAlarmSeverity";
names[9] = "hystersis";
fields[0] = fieldCreate->createScalar(pvBoolean);
for(size_t i=0; i<numFields; i++ ) {
fields[i] = fieldCreate->createScalar(pvLong);
}
longAlarmField = fieldCreate->createStructure(names,fields);
}
static void createFloatAlarm() {
int numFields = 10;
FieldConstPtrArray fields = new FieldConstPtr[numFields];
fields[0] = fieldCreate->createScalar(String("active"),pvBoolean);
fields[1] = fieldCreate->createScalar(String("lowAlarmLimit"),pvFloat);
fields[2] = fieldCreate->createScalar(String("lowWarningLimit"),pvFloat);
fields[3] = fieldCreate->createScalar(String("highWarningLimit"),pvFloat);
fields[4] = fieldCreate->createScalar(String("highAlarmLimit"),pvFloat);
fields[5] = fieldCreate->createScalar(String("lowAlarmSeverity"),pvInt);
fields[6] = fieldCreate->createScalar(String("lowWarningSeverity"),pvInt);
fields[7] = fieldCreate->createScalar(String("highWarningSeverity"),pvInt);
fields[8] = fieldCreate->createScalar(String("highAlarmSeverity"),pvInt);
fields[9] = fieldCreate->createScalar(String("hystersis"),pvFloat);
floatAlarmField = fieldCreate->createStructure(String("valueAlarm"),numFields,fields);
size_t numFields = 10;
FieldConstPtrArray fields(numFields);
StringArray names(numFields);
names[0] = "active";
names[1] = "lowAlarmLimit";
names[2] = "lowWarningLimit";
names[3] = "highWarningLimit";
names[4] = "highAlarmLimit";
names[5] = "lowAlarmSeverity";
names[6] = "lowWarningSeverity";
names[7] = "highWarningSeverity";
names[8] = "highAlarmSeverity";
names[9] = "hystersis";
fields[0] = fieldCreate->createScalar(pvBoolean);
for(size_t i=0; i<numFields; i++ ) {
fields[i] = fieldCreate->createScalar(pvFloat);
}
floatAlarmField = fieldCreate->createStructure(names,fields);
}
static void createDoubleAlarm() {
int numFields = 10;
FieldConstPtrArray fields = new FieldConstPtr[numFields];
fields[0] = fieldCreate->createScalar(String("active"),pvBoolean);
fields[1] = fieldCreate->createScalar(String("lowAlarmLimit"),pvDouble);
fields[2] = fieldCreate->createScalar(String("lowWarningLimit"),pvDouble);
fields[3] = fieldCreate->createScalar(String("highWarningLimit"),pvDouble);
fields[4] = fieldCreate->createScalar(String("highAlarmLimit"),pvDouble);
fields[5] = fieldCreate->createScalar(String("lowAlarmSeverity"),pvInt);
fields[6] = fieldCreate->createScalar(String("lowWarningSeverity"),pvInt);
fields[7] = fieldCreate->createScalar(String("highWarningSeverity"),pvInt);
fields[8] = fieldCreate->createScalar(String("highAlarmSeverity"),pvInt);
fields[9] = fieldCreate->createScalar(String("hystersis"),pvDouble);
doubleAlarmField = fieldCreate->createStructure(String("valueAlarm"),numFields,fields);
size_t numFields = 10;
FieldConstPtrArray fields(numFields);
StringArray names(numFields);
names[0] = "active";
names[1] = "lowAlarmLimit";
names[2] = "lowWarningLimit";
names[3] = "highWarningLimit";
names[4] = "highAlarmLimit";
names[5] = "lowAlarmSeverity";
names[6] = "lowWarningSeverity";
names[7] = "highWarningSeverity";
names[8] = "highAlarmSeverity";
names[9] = "hystersis";
fields[0] = fieldCreate->createScalar(pvDouble);
for(size_t i=0; i<numFields; i++ ) {
fields[i] = fieldCreate->createScalar(pvByte);
}
doubleAlarmField = fieldCreate->createStructure(names,fields);
}
static void createEnumeratedAlarm() {
int numFields = 3;
FieldConstPtrArray fields = new FieldConstPtr[numFields];
fields[0] = fieldCreate->createScalar(String("active"),pvBoolean);
fields[1] = fieldCreate->createScalar(String("stateSeverity"),pvInt);
fields[2] = fieldCreate->createScalar(String("changeStateSeverity"),pvInt);
enumeratedAlarmField = fieldCreate->createStructure(String("valueAlarm"),numFields,fields);
size_t numFields = 3;
FieldConstPtrArray fields(numFields);
StringArray names(numFields);
names[0] = "active";
names[1] = "stateSeverity";
names[2] = "changeStateSeverity";
fields[0] = fieldCreate->createScalar(pvBoolean);
fields[1] = fieldCreate->createScalar(pvInt);
fields[2] = fieldCreate->createScalar(pvInt);
enumeratedAlarmField = fieldCreate->createStructure(names,fields);
}
static StructureConstPtr createProperties(String fieldName,FieldConstPtr field,String properties) {
static StructureConstPtr createProperties(FieldConstPtr field,String properties)
{
bool gotAlarm = false;
bool gotTimeStamp = false;
bool gotDisplay = false;
@@ -225,12 +277,13 @@ static StructureConstPtr createProperties(String fieldName,FieldConstPtr field,S
}
if(type==structure) {
StructureConstPtr structurePtr = static_pointer_cast<const Structure>(field);
if(structurePtr->getNumberFields()==2) {
StringArray names = structurePtr->getFieldNames();
if(names.size()==2) {
FieldConstPtrArray fields = structurePtr->getFields();
FieldConstPtr first = fields[0];
FieldConstPtr second = fields[1];
String nameFirst = first->getFieldName();
String nameSecond = second->getFieldName();
String nameFirst = names[0];
String nameSecond = names[1];
int compareFirst = nameFirst.compare("index");
int compareSecond = nameSecond.compare("choices");
if(compareFirst==0 && compareSecond==0) {
@@ -250,138 +303,75 @@ static StructureConstPtr createProperties(String fieldName,FieldConstPtr field,S
}
throw std::logic_error(String("valueAlarm property for illegal type"));
}
int numFields = numProp+1;
FieldConstPtrArray fields = new FieldConstPtr[numFields];
size_t numFields = numProp+1;
FieldConstPtrArray fields(numFields);
StringArray names(numFields);
int next = 0;
names[0] = "value";
fields[next++] = field;
if(gotAlarm) {fields[next++] = alarmField;}
if(gotTimeStamp) {fields[next++] = timeStampField;}
if(gotDisplay) {fields[next++] = displayField;}
if(gotControl) {fields[next++] = controlField;}
if(gotValueAlarm) {fields[next++] = valueAlarm;}
return fieldCreate->createStructure(fieldName,numFields,fields);
if(gotAlarm) {
names[next] = "alarm";
fields[next++] = alarmField;
}
if(gotTimeStamp) {
names[next] = "timeStamp";
fields[next++] = timeStampField;
}
if(gotDisplay) {
names[next] = "display";
fields[next++] = displayField;
}
if(gotControl) {
names[next] = "control";
fields[next++] = controlField;
}
if(gotValueAlarm) {
names[next] = "valueAlarm";
fields[next++] = valueAlarm;
}
return fieldCreate->createStructure(names,fields);
}
ScalarConstPtr StandardField::scalar(String fieldName,ScalarType type)
{
return fieldCreate->createScalar(fieldName,type);
}
StructureConstPtr StandardField::scalar(
String fieldName,ScalarType type,String properties)
ScalarType type,String properties)
{
ScalarConstPtr field = fieldCreate->createScalar(valueFieldName,type);
return createProperties(fieldName,field,properties);
}
ScalarArrayConstPtr StandardField::scalarArray(
String fieldName,ScalarType elementType)
{
return fieldCreate->createScalarArray(fieldName,elementType);
ScalarConstPtr field = fieldCreate->createScalar(type);
return createProperties(field,properties);
}
StructureConstPtr StandardField::scalarArray(
String fieldName,ScalarType elementType, String properties)
{
ScalarArrayConstPtr field = fieldCreate->createScalarArray(
valueFieldName,elementType);
return createProperties(fieldName,field,properties);
}
StructureArrayConstPtr StandardField::structureArray(
String fieldName,StructureConstPtr structure)
{
return fieldCreate->createStructureArray(fieldName,structure);
}
StructureConstPtr StandardField::structureArray(
String fieldName,StructureConstPtr structure,String properties)
{
StructureArrayConstPtr field = fieldCreate->createStructureArray(
valueFieldName,structure);
return createProperties(fieldName,field,properties);
}
StructureConstPtr StandardField::structure(
String fieldName,int numFields,FieldConstPtrArray fields)
{
return fieldCreate->createStructure(fieldName,numFields,fields);
}
StructureConstPtr StandardField::enumerated(String fieldName)
{
FieldConstPtrArray fields = new FieldConstPtr[2];
fields[0] = fieldCreate->createScalar(String("index"),pvInt);
fields[1] = fieldCreate->createScalarArray(String("choices"),pvString);
return fieldCreate->createStructure(fieldName,2,fields);
}
StructureConstPtr StandardField::enumerated(
String fieldName,String properties)
{
StructureConstPtr field = standardField->enumerated(valueFieldName);
return createProperties(fieldName,field,properties);
}
ScalarConstPtr StandardField::scalarValue(ScalarType type)
{
return fieldCreate->createScalar(valueFieldName,type);
}
StructureConstPtr StandardField::scalarValue(ScalarType type,String properties)
{
ScalarConstPtr field = fieldCreate->createScalar(valueFieldName,type);
return createProperties(valueFieldName,field,properties);
}
ScalarArrayConstPtr StandardField::scalarArrayValue(ScalarType elementType)
{
return fieldCreate->createScalarArray(valueFieldName,elementType);
}
StructureConstPtr StandardField::scalarArrayValue(
ScalarType elementType, String properties)
{
ScalarArrayConstPtr field = fieldCreate->createScalarArray(
valueFieldName,elementType);
return createProperties(valueFieldName,field,properties);
ScalarArrayConstPtr field = fieldCreate->createScalarArray(elementType);
return createProperties(field,properties);
}
StructureArrayConstPtr StandardField::structureArrayValue(
StructureConstPtr structure)
{
return fieldCreate->createStructureArray(valueFieldName,structure);
}
StructureConstPtr StandardField::structureArrayValue(
StructureConstPtr structure,String properties)
StructureConstPtr StandardField::structureArray(
StructureConstPtr &structure,String properties)
{
StructureArrayConstPtr field = fieldCreate->createStructureArray(
valueFieldName,structure);
return createProperties(valueFieldName,field,properties);
structure);
return createProperties(field,properties);
}
StructureConstPtr StandardField::structureValue(
int numFields,FieldConstPtrArray fields)
StructureConstPtr StandardField::enumerated()
{
return fieldCreate->createStructure(valueFieldName,numFields,fields);
size_t num = 2;
FieldConstPtrArray fields(num);
StringArray names(num);
names[0] = "index";
names[1] = "choices";
fields[0] = fieldCreate->createScalar(pvInt);
fields[1] = fieldCreate->createScalarArray(pvString);
return fieldCreate->createStructure(names,fields);
}
StructureConstPtr StandardField::enumeratedValue()
StructureConstPtr StandardField::enumerated(String properties)
{
FieldConstPtrArray fields = new FieldConstPtr[2];
fields[0] = fieldCreate->createScalar(String("index"),pvInt);
fields[1] = fieldCreate->createScalarArray(String("choices"),pvString);
return fieldCreate->createStructure(valueFieldName,2,fields);
}
StructureConstPtr StandardField::enumeratedValue( String properties)
{
StructureConstPtr field = standardField->enumerated(valueFieldName);
return createProperties(valueFieldName,field,properties);
StructureConstPtr field = enumerated(valueFieldName);
return createProperties(field,properties);
}
StructureConstPtr StandardField::alarm()
@@ -444,58 +434,38 @@ StructureConstPtr StandardField::enumeratedAlarm()
return enumeratedAlarmField;
}
void StandardField::init()
StandardFieldPtr StandardField::getStandardField()
{
createAlarm();
createTimeStamp();
createDisplay();
createControl();
createBooleanAlarm();
createByteAlarm();
createShortAlarm();
createIntAlarm();
createLongAlarm();
createFloatAlarm();
createDoubleAlarm();
createEnumeratedAlarm();
static StandardFieldPtr standardFieldCreate;
static Mutex mutex;
Lock xx(mutex);
if(standardFieldCreate.get()==0)
{
fieldCreate = getFieldCreate();
createAlarm();
createTimeStamp();
createDisplay();
createControl();
createBooleanAlarm();
createByteAlarm();
createShortAlarm();
createIntAlarm();
createLongAlarm();
createFloatAlarm();
createDoubleAlarm();
createEnumeratedAlarm();
standardFieldCreate = StandardFieldPtr(new StandardField());
}
return standardFieldCreate;
}
StandardField::StandardField(){}
StandardField::~StandardField(){}
StandardField::StandardField(){init();}
StandardField::~StandardField(){
}
static void myDeleteStatic(void*)
{
alarmField.reset();
timeStampField.reset();
displayField.reset();
controlField.reset();
booleanAlarmField.reset();
byteAlarmField.reset();
shortAlarmField.reset();
intAlarmField.reset();
longAlarmField.reset();
floatAlarmField.reset();
doubleAlarmField.reset();
enumeratedAlarmField.reset();
}
static void myInitStatic(void*)
{
standardField = new StandardField();
fieldCreate = getFieldCreate();
epicsAtExit(&myDeleteStatic,0);
}
static
epicsThreadOnceId myInitOnce = EPICS_THREAD_ONCE_INIT;
StandardField * getStandardField() {
epicsThreadOnce(&myInitOnce,&myInitStatic,0);
return standardField;
StandardFieldPtr getStandardField() {
return StandardField::getStandardField();
}
}}
+52 -275
View File
@@ -14,16 +14,15 @@
#include <pv/convert.h>
#include <pv/standardField.h>
#include <pv/standardPVField.h>
#include <pv/CDRMonitor.h>
namespace epics { namespace pvData {
static StandardField *standardField = 0;
static StandardFieldPtr standardField;
static FieldCreatePtr fieldCreate;
static PVDataCreatePtr pvDataCreate;
static String notImplemented("not implemented");
static FieldCreate* fieldCreate = 0;
static PVDataCreate* pvDataCreate = 0;
static StandardPVField *standardPVField = 0;
static void addExtendsStructureName(PVStructure *pvStructure,String properties)
{
@@ -36,20 +35,20 @@ static void addExtendsStructureName(PVStructure *pvStructure,String properties)
if(properties.find("display")!=String::npos) gotDisplay = true;
if(properties.find("control")!=String::npos) gotControl = true;
if(gotAlarm) {
PVStructure *pv = pvStructure->getStructureField(String("alarm"));
if(pv!=0) pv->putExtendsStructureName(String("alarm"));
PVStructure *pv = pvStructure->getStructureField("alarm").get();
if(pv!=NULL) pv->putExtendsStructureName("alarm");
}
if(gotTimeStamp) {
PVStructure *pv = pvStructure->getStructureField(String("timeStamp"));
if(pv!=0) pv->putExtendsStructureName(String("timeStamp"));
PVStructure *pv = pvStructure->getStructureField("timeStamp").get();
if(pv!=NULL) pv->putExtendsStructureName("timeStamp");
}
if(gotDisplay) {
PVStructure *pv = pvStructure->getStructureField(String("display"));
if(pv!=0) pv->putExtendsStructureName(String("display"));
PVStructure *pv = pvStructure->getStructureField("display").get();
if(pv!=NULL) pv->putExtendsStructureName("display");
}
if(gotControl) {
PVStructure *pv = pvStructure->getStructureField(String("control"));
if(pv!=0) pv->putExtendsStructureName(String("control"));
PVStructure *pv = pvStructure->getStructureField("control").get();
if(pv!=NULL) pv->putExtendsStructureName(String("control"));
}
}
@@ -57,297 +56,75 @@ StandardPVField::StandardPVField(){}
StandardPVField::~StandardPVField(){}
PVScalar * StandardPVField::scalar(PVStructure *parent,
String fieldName,ScalarType type)
PVStructurePtr StandardPVField::scalar(ScalarType type,String properties)
{
ScalarConstPtr field = standardField->scalar(fieldName,type);
return pvDataCreate->createPVScalar(parent,field);
}
PVStructure * StandardPVField::scalar(PVStructure *parent,
String fieldName,ScalarType type,String properties)
{
StructureConstPtr field = standardField->scalar(fieldName,type,properties);
PVStructure * pvStructure = pvDataCreate->createPVStructure(parent,field);
addExtendsStructureName(pvStructure,properties);
StructureConstPtr field = standardField->scalar(type,properties);
PVStructurePtr pvStructure = pvDataCreate->createPVStructure(field);
addExtendsStructureName(pvStructure.get(),properties);
return pvStructure;
}
PVScalarArray * StandardPVField::scalarArray(PVStructure *parent,
String fieldName,ScalarType elementType)
PVStructurePtr StandardPVField::scalarArray(ScalarType elementType, String properties)
{
ScalarArrayConstPtr field = standardField->scalarArray(
fieldName,elementType);
return pvDataCreate->createPVScalarArray(parent,field);
}
PVStructure * StandardPVField::scalarArray(PVStructure *parent,
String fieldName,ScalarType elementType, String properties)
{
StructureConstPtr field = standardField->scalarArray(
fieldName,elementType,properties);
PVStructure * pvStructure = pvDataCreate->createPVStructure(parent,field);
addExtendsStructureName(pvStructure,properties);
StructureConstPtr field = standardField->scalarArray(elementType,properties);
PVStructurePtr pvStructure = pvDataCreate->createPVStructure(field);
addExtendsStructureName(pvStructure.get(),properties);
return pvStructure;
}
PVStructureArray * StandardPVField::structureArray(PVStructure *parent,
String fieldName,StructureConstPtr structure)
PVStructurePtr StandardPVField::structureArray(StructureConstPtr structure,String properties)
{
StructureArrayConstPtr field = standardField->structureArray(
fieldName,structure);
return pvDataCreate->createPVStructureArray(parent,field);
}
PVStructure* StandardPVField::structureArray(PVStructure *parent,
String fieldName,StructureConstPtr structure,String properties)
{
StructureConstPtr field = standardField->structureArray(
fieldName,structure,properties);
PVStructure * pvStructure = pvDataCreate->createPVStructure(parent,field);
addExtendsStructureName(pvStructure,properties);
StructureConstPtr field = standardField->structureArray(structure,properties);
PVStructurePtr pvStructure = pvDataCreate->createPVStructure(field);
addExtendsStructureName(pvStructure.get(),properties);
return pvStructure;
}
PVStructure * StandardPVField::enumerated(PVStructure *parent,
String fieldName,StringArray choices,int number)
PVStructurePtr StandardPVField::enumerated(StringArray choices)
{
StructureConstPtr field = standardField->enumerated(fieldName);
PVStructure *pvStructure = pvDataCreate->createPVStructure(parent,field);
PVScalarArray *pvScalarArray = pvStructure->getScalarArrayField(
StructureConstPtr field = standardField->enumerated();
PVStructurePtr pvStructure = pvDataCreate->createPVStructure(field);
PVScalarArrayPtr pvScalarArray = pvStructure->getScalarArrayField(
"choices",pvString);
if(pvScalarArray==0) {
if(pvScalarArray.get()==NULL) {
throw std::logic_error(String("StandardPVField::enumerated"));
}
PVStringArray *pvChoices = static_cast<PVStringArray *>(pvScalarArray);
pvChoices->put(0,number,choices,0);
PVStringArray * pvChoices = static_cast<PVStringArray *>(pvScalarArray.get());
pvChoices->put(0,choices.size(),get(choices),0);
return pvStructure;
}
PVStructure * StandardPVField::enumerated(PVStructure *parent,
String fieldName,StringArray choices,int number, String properties)
PVStructurePtr StandardPVField::enumerated(StringArray choices,String properties)
{
StructureConstPtr field = standardField->enumerated(
fieldName,properties);
PVStructure *pvStructure = pvDataCreate->createPVStructure(parent,field);
addExtendsStructureName(pvStructure,properties);
PVScalarArray *pvScalarArray = pvStructure->getScalarArrayField(
fieldName += ".choices",pvString);
if(pvScalarArray==0) {
StructureConstPtr field = standardField->enumerated(properties);
PVStructurePtr pvStructure = pvDataCreate->createPVStructure(field);
addExtendsStructureName(pvStructure.get(),properties);
PVScalarArrayPtr pvScalarArray = pvStructure->getScalarArrayField("value.choices",pvString);
if(pvScalarArray.get()==NULL) {
throw std::logic_error(String("StandardPVField::enumerated"));
}
PVStringArray *pvChoices = static_cast<PVStringArray *>(pvScalarArray);
pvChoices->put(0,number,choices,0);
PVStringArray * pvChoices = static_cast<PVStringArray *>(pvScalarArray.get());
pvChoices->put(0,choices.size(),get(choices),0);
return pvStructure;
}
PVScalar * StandardPVField::scalarValue(PVStructure *parent,
ScalarType scalarType)
StandardPVFieldPtr StandardPVField::getStandardPVField()
{
ScalarConstPtr field = standardField->scalarValue(scalarType);
return pvDataCreate->createPVScalar(parent,field);
}
static StandardPVFieldPtr standardPVField;
static Mutex mutex;
Lock xx(mutex);
PVStructure * StandardPVField::scalarValue(PVStructure *parent,
ScalarType type,String properties)
{
StructureConstPtr field = standardField->scalarValue(type,properties);
PVStructure * pvStructure = pvDataCreate->createPVStructure(parent,field);
addExtendsStructureName(pvStructure,properties);
return pvStructure;
}
PVScalarArray * StandardPVField::scalarArrayValue(PVStructure *parent,
ScalarType elementType)
{
ScalarArrayConstPtr scalarArray =
standardField->scalarArrayValue(elementType);
return pvDataCreate->createPVScalarArray(0,scalarArray);
}
PVStructure * StandardPVField::scalarArrayValue(PVStructure *parent,
ScalarType elementType, String properties)
{
StructureConstPtr field = standardField->scalarArrayValue(
elementType,properties);
PVStructure * pvStructure = pvDataCreate->createPVStructure(parent,field);
addExtendsStructureName(pvStructure,properties);
return pvStructure;
}
PVStructureArray * StandardPVField::structureArrayValue(PVStructure *parent,
StructureConstPtr structure)
{
StructureArrayConstPtr field = standardField->structureArrayValue(
structure);
return pvDataCreate->createPVStructureArray(parent,field);
}
PVStructure * StandardPVField::structureArrayValue(PVStructure *parent,
StructureConstPtr structure,String properties)
{
StructureConstPtr field = standardField->structureArrayValue(
structure,properties);
PVStructure * pvStructure = pvDataCreate->createPVStructure(parent,field);
addExtendsStructureName(pvStructure,properties);
return pvStructure;
}
PVStructure * StandardPVField::enumeratedValue(PVStructure *parent,
StringArray choices,int number)
{
StructureConstPtr field = standardField->enumeratedValue();
PVStructure *pvStructure = pvDataCreate->createPVStructure(parent,field);
PVScalarArray *pvScalarArray = pvStructure->getScalarArrayField(
"choices",pvString);
if(pvScalarArray==0) {
throw std::logic_error(String("StandardPVField::enumerated"));
if(standardPVField.get()==NULL) {
standardField = getStandardField();
fieldCreate = getFieldCreate();
pvDataCreate = getPVDataCreate();
standardPVField= StandardPVFieldPtr(new StandardPVField());
}
PVStringArray *pvChoices = static_cast<PVStringArray *>(pvScalarArray);
pvChoices->put(0,number,choices,0);
return pvStructure;
}
PVStructure * StandardPVField::enumeratedValue(PVStructure *parent,
StringArray choices, int number,String properties)
{
StructureConstPtr field = standardField->enumeratedValue( properties);
PVStructure *pvStructure = pvDataCreate->createPVStructure(parent,field);
addExtendsStructureName(pvStructure,properties);
PVScalarArray *pvScalarArray = pvStructure->getScalarArrayField(
String("value.choices"),pvString);
if(pvScalarArray==0) {
throw std::logic_error(String("StandardPVField::enumerated"));
}
PVStringArray *pvChoices = static_cast<PVStringArray *>(pvScalarArray);
pvChoices->put(0,number,choices,0);
return pvStructure;
}
PVStructure * StandardPVField::alarm(PVStructure *parent)
{
StructureConstPtr field = standardField->alarm();
return pvDataCreate->createPVStructure(parent,field);
}
PVStructure * StandardPVField::timeStamp(PVStructure *parent)
{
StructureConstPtr field = standardField->timeStamp();
return pvDataCreate->createPVStructure(parent,field);
}
PVStructure * StandardPVField::display(PVStructure *parent)
{
StructureConstPtr field = standardField->display();
return pvDataCreate->createPVStructure(parent,field);
}
PVStructure * StandardPVField::control(PVStructure *parent)
{
StructureConstPtr field = standardField->control();
return pvDataCreate->createPVStructure(parent,field);
}
PVStructure * StandardPVField::booleanAlarm(PVStructure *parent)
{
StructureConstPtr field = standardField->booleanAlarm();
return pvDataCreate->createPVStructure(parent,field);
}
PVStructure * StandardPVField::byteAlarm(PVStructure *parent)
{
StructureConstPtr field = standardField->byteAlarm();
return pvDataCreate->createPVStructure(parent,field);
}
PVStructure * StandardPVField::shortAlarm(PVStructure *parent)
{
StructureConstPtr field = standardField->shortAlarm();
return pvDataCreate->createPVStructure(parent,field);
}
PVStructure * StandardPVField::intAlarm(PVStructure *parent)
{
StructureConstPtr field = standardField->intAlarm();
return pvDataCreate->createPVStructure(parent,field);
}
PVStructure * StandardPVField::longAlarm(PVStructure *parent)
{
StructureConstPtr field = standardField->longAlarm();
return pvDataCreate->createPVStructure(parent,field);
}
PVStructure * StandardPVField::floatAlarm(PVStructure *parent)
{
StructureConstPtr field = standardField->floatAlarm();
return pvDataCreate->createPVStructure(parent,field);
}
PVStructure * StandardPVField::doubleAlarm(PVStructure *parent)
{
StructureConstPtr field = standardField->doubleAlarm();
return pvDataCreate->createPVStructure(parent,field);
}
PVStructure * StandardPVField::enumeratedAlarm(PVStructure *parent)
{
StructureConstPtr field = standardField->enumeratedAlarm();
return pvDataCreate->createPVStructure(parent,field);
}
PVStructure * StandardPVField::powerSupply(PVStructure *parent)
{
StructureConstPtr alarmField = standardField->alarm();
StructureConstPtr timeStampField = standardField->timeStamp();
StructureConstPtr voltageField = standardField->scalar(
String("voltage"),pvDouble,String("alarm"));
StructureConstPtr powerField = standardField->scalar(
String("power"),pvDouble,String("alarm"));
StructureConstPtr currentField = standardField->scalar(
String("current"),pvDouble,String("alarm"));
FieldConstPtr fields[3];
fields[0] = voltageField;
fields[1] = powerField;
fields[2] = currentField;
StructureConstPtr valueField = standardField->structureValue( 3,fields);
fields[0] = alarmField;
fields[1] = timeStampField;
fields[2] = valueField;
StructureConstPtr structureField = standardField->structureValue(3,fields);
return pvDataCreate->createPVStructure(parent,structureField);
}
class StandardPVFieldExt : public StandardPVField {
public:
StandardPVFieldExt(): StandardPVField(){};
};
static void myDeleteStatic(void*)
{
delete standardPVField;
}
static void myInitStatic(void*)
{
fieldCreate = getFieldCreate();
pvDataCreate = getPVDataCreate();
standardField = getStandardField();
standardPVField = new StandardPVFieldExt();
epicsAtExit(&myDeleteStatic, 0);
}
static
epicsThreadOnceId myInitOnce = EPICS_THREAD_ONCE_INIT;
StandardPVField * getStandardPVField() {
epicsThreadOnce(&myInitOnce, &myInitStatic, 0);
return standardPVField;
}
StandardPVFieldPtr getStandardPVField() {
return StandardPVField::getStandardPVField();
}
}}
+9 -2
View File
@@ -33,7 +33,12 @@ namespace TypeFunc {
namespace ScalarTypeFunc {
bool isInteger(ScalarType type) {
if(type>=pvByte && type<=pvLong) return true;
if(type>=pvByte && type<=pvULong) return true;
return false;
}
bool isUInteger(ScalarType type) {
if(type>=pvUByte && type<=pvULong) return true;
return false;
}
@@ -48,7 +53,9 @@ namespace ScalarTypeFunc {
}
static const char* names[] = {
"boolean", "byte", "short", "int", "long",
"boolean",
"byte", "short", "int", "long",
"ubyte", "ushort", "uint", "ulong",
"float", "double", "string",
};
ScalarType getScalarType(String pvalue) {
+36 -36
View File
@@ -153,7 +153,7 @@ inline double swap(double val)
}
#define is_aligned(POINTER, BYTE_COUNT) \
(((uintptr_t)(const void *)(POINTER)) % (BYTE_COUNT) == 0)
(((std::ptrdiff_t)(const void *)(POINTER)) % (BYTE_COUNT) == 0)
/*template <bool ENDIANESS_SUPPORT = false,
bool UNALIGNED_ACCESS = false,
@@ -182,7 +182,7 @@ public:
* @param byteOrder The byte order.
* Must be one of EPICS_BYTE_ORDER,EPICS_ENDIAN_LITTLE,EPICS_ENDIAN_BIG,
*/
ByteBuffer(uintptr_t size, int byteOrder = EPICS_BYTE_ORDER) :
ByteBuffer(std::size_t size, int byteOrder = EPICS_BYTE_ORDER) :
_buffer(0), _size(size),
_reverseEndianess(byteOrder != EPICS_BYTE_ORDER),
_reverseFloatEndianess(byteOrder != EPICS_FLOAT_WORD_ORDER)
@@ -244,9 +244,9 @@ public:
* Returns the current position.
* @return The current position in the raw data.
*/
inline uintptr_t getPosition()
inline std::ptrdiff_t getPosition()
{
return (((uintptr_t)(const void *)_position) - ((uintptr_t)(const void *)_buffer));
return (((std::ptrdiff_t)(const void *)_position) - ((std::ptrdiff_t)(const void *)_buffer));
}
/**
* Sets the buffer position.
@@ -255,7 +255,7 @@ public:
* @param pos The offset into the raw buffer.
* The new position value; must be no larger than the current limit
*/
inline void setPosition(uintptr_t pos)
inline void setPosition(std::ptrdiff_t pos)
{
_position = _buffer + pos;
}
@@ -264,9 +264,9 @@ public:
*
* @return The offset into the raw buffer.
*/
inline uintptr_t getLimit()
inline std::ptrdiff_t getLimit()
{
return (((uintptr_t)(const void *)_limit) - ((uintptr_t)(const void *)_buffer));
return (((std::ptrdiff_t)(const void *)_limit) - ((std::ptrdiff_t)(const void *)_buffer));
}
/**
* Sets this buffer's limit.
@@ -276,7 +276,7 @@ public:
* @param limit The new position value;
* must be no larger than the current limit
*/
inline void setLimit(uintptr_t limit)
inline void setLimit(std::ptrdiff_t limit)
{
_limit = _buffer + limit;
}
@@ -285,16 +285,16 @@ public:
*
* @return The number of elements remaining in this buffer.
*/
inline uintptr_t getRemaining()
inline std::size_t getRemaining()
{
return (((uintptr_t)(const void *)_limit) - ((uintptr_t)(const void *)_position));
return (((std::ptrdiff_t)(const void *)_limit) - ((std::ptrdiff_t)(const void *)_position));
}
/**
* Returns The size, i.e. capacity of the raw data buffer in bytes.
*
* @return The size of the raw data buffer.
*/
inline uintptr_t getSize()
inline std::size_t getSize()
{
return _size;
}
@@ -359,7 +359,7 @@ public:
* @param value The value to be put into the byte buffer.
*/
template<typename T>
inline void put(uintptr_t index, T value)
inline void put(std::size_t index, T value)
{
// this avoids int8 specialization, compiler will take care if optimization, -O2 or more
if (sizeof(T) == 1)
@@ -470,7 +470,7 @@ public:
* @return The object.
*/
template<typename T>
inline T get(uintptr_t index)
inline T get(std::size_t index)
{
// this avoids int8 specialization, compiler will take care if optimization, -O2 or more
if (sizeof(T) == 1)
@@ -525,7 +525,7 @@ public:
* @param offset The starting position within src.
* @param count The number of bytes to put into the byte buffer,
*/
inline void put(const char* src, uintptr_t src_offset, uintptr_t count) {
inline void put(const char* src, std::size_t src_offset, std::size_t count) {
//if(count>getRemaining()) THROW_BASE_EXCEPTION("buffer overflow");
memcpy(_position, src + src_offset, count);
_position += count;
@@ -538,7 +538,7 @@ public:
* @param offset The starting position within src.
* @param count The number of bytes to put into the byte buffer,
*/
inline void get(char* dest, uintptr_t dest_offset, uintptr_t count) {
inline void get(char* dest, std::size_t dest_offset, std::size_t count) {
//if(count>getRemaining()) THROW_BASE_EXCEPTION("buffer overflow");
memcpy(dest + dest_offset, _position, count);
_position += count;
@@ -551,7 +551,7 @@ public:
* @param count The number of elements.
*/
template<typename T>
inline void putArray(T* values, uintptr_t count)
inline void putArray(T* values, std::size_t count)
{
// this avoids int8 specialization, compiler will take care if optimization, -O2 or more
if (sizeof(T) == 1)
@@ -570,7 +570,7 @@ public:
// ... so that we can be fast changing endianess
if (ENDIANESS_SUPPORT && reverse<T>())
{
for (uintptr_t i = 0; i < count; i++)
for (std::size_t i = 0; i < count; i++)
{
*start = swap<T>(*start);
start++;
@@ -585,7 +585,7 @@ public:
* @param count The number of elements.
*/
template<typename T>
inline void getArray(T* values, uintptr_t count)
inline void getArray(T* values, std::size_t count)
{
// this avoids int8 specialization, compiler will take care if optimization, -O2 or more
if (sizeof(T) == 1)
@@ -604,7 +604,7 @@ public:
// ... so that we can be fast changing endianess
if (ENDIANESS_SUPPORT && reverse<T>())
{
for (uintptr_t i = 0; i < count; i++)
for (std::size_t i = 0; i < count; i++)
{
*start = swap<T>(*start);
start++;
@@ -627,8 +627,8 @@ public:
*/
inline void align(int size)
{
const uintptr_t k = size - 1;
_position = (char*)((((uintptr_t)(const void *)_position) + k) & ~(k));
const std::size_t k = size - 1;
_position = (char*)((((std::ptrdiff_t)(const void *)_position) + k) & ~(k));
}
/**
* Put a boolean value into the byte buffer.
@@ -679,49 +679,49 @@ public:
* @param index The offset in the byte buffer,
* @param value The value.
*/
inline void putBoolean(uintptr_t index, bool value) { put< int8>(index, value); }
inline void putBoolean(std::size_t index, bool value) { put< int8>(index, value); }
/**
* Put a byte value into the byte buffer at the specified index.
*
* @param index The offset in the byte buffer,
* @param value The value.
*/
inline void putByte (uintptr_t index, int8 value) { put< int8>(index, value); }
inline void putByte (std::size_t index, int8 value) { put< int8>(index, value); }
/**
* Put a short value into the byte buffer at the specified index.
*
* @param index The offset in the byte buffer,
* @param value The value.
*/
inline void putShort (uintptr_t index, int16 value) { put< int16>(index, value); }
inline void putShort (std::size_t index, int16 value) { put< int16>(index, value); }
/**
* Put an int value into the byte buffer at the specified index.
*
* @param index The offset in the byte buffer,
* @param value The value.
*/
inline void putInt (uintptr_t index, int32 value) { put< int32>(index, value); }
inline void putInt (std::size_t index, int32 value) { put< int32>(index, value); }
/**
* Put a long value into the byte buffer at the specified index.
*
* @param index The offset in the byte buffer,
* @param value The value.
*/
inline void putLong (uintptr_t index, int64 value) { put< int64>(index, value); }
inline void putLong (std::size_t index, int64 value) { put< int64>(index, value); }
/**
* Put a float value into the byte buffer at the specified index.
*
* @param index The offset in the byte buffer,
* @param value The value.
*/
inline void putFloat (uintptr_t index, float value) { put< float>(index, value); }
inline void putFloat (std::size_t index, float value) { put< float>(index, value); }
/**
* Put a double value into the byte buffer at the specified index.
*
* @param index The offset in the byte buffer,
* @param value The value.
*/
inline void putDouble (uintptr_t index,double value) { put<double>(index, value); }
inline void putDouble (std::size_t index,double value) { put<double>(index, value); }
/**
* Get a boolean value from the byte buffer.
@@ -772,49 +772,49 @@ public:
* @param index The offset in the byte buffer.
* @return The value.
*/
inline bool getBoolean(uintptr_t index) { return get< int8>(index) != 0; }
inline bool getBoolean(std::size_t index) { return get< int8>(index) != 0; }
/**
* Get a byte value from the byte buffer at the specified index.
*
* @param index The offset in the byte buffer.
* @return The value.
*/
inline int8 getByte (uintptr_t index) { return get< int8>(index); }
inline int8 getByte (std::size_t index) { return get< int8>(index); }
/**
* Get a short value from the byte buffer at the specified index.
*
* @param index The offset in the byte buffer.
* @return The value.
*/
inline int16 getShort (uintptr_t index) { return get< int16>(index); }
inline int16 getShort (std::size_t index) { return get< int16>(index); }
/**
* Get an int value from the byte buffer at the specified index.
*
* @param index The offset in the byte buffer.
* @return The value.
*/
inline int32 getInt (uintptr_t index) { return get< int32>(index); }
inline int32 getInt (std::size_t index) { return get< int32>(index); }
/**
* Get a long value from the byte buffer at the specified index.
*
* @param index The offset in the byte buffer.
* @return The value.
*/
inline int64 getLong (uintptr_t index) { return get< int64>(index); }
inline int64 getLong (std::size_t index) { return get< int64>(index); }
/**
* Get a float value from the byte buffer at the specified index.
*
* @param index The offset in the byte buffer.
* @return The value.
*/
inline float getFloat (uintptr_t index) { return get< float>(index); }
inline float getFloat (std::size_t index) { return get< float>(index); }
/**
* Get a boolean value from the byte buffer at the specified index.
*
* @param double The offset in the byte buffer.
* @return The value.
*/
inline double getDouble (uintptr_t index) { return get<double>(index); }
inline double getDouble (std::size_t index) { return get<double>(index); }
// TODO remove
inline const char* getArray()
@@ -827,7 +827,7 @@ private:
char* _buffer;
char* _position;
char* _limit;
uintptr_t _size;
std::size_t _size;
bool _reverseEndianess;
bool _reverseFloatEndianess;
};
+97 -5
View File
@@ -6,17 +6,27 @@
*/
#ifndef MESSAGEQUEUE_H
#define MESSAGEQUEUE_H
#include <memory>
#include <vector>
#include <cstddef>
#include <stdexcept>
#include <pv/pvType.h>
#include <pv/requester.h>
#include <pv/noDefaultMethods.h>
namespace epics { namespace pvData {
class MessageNode;
class MessageQueue;
typedef std::tr1::shared_ptr<MessageNode> MessageNodePtr;
typedef std::tr1::shared_ptr<MessageQueue> MessageQueuePtr;
class MessageNode {
public:
String getMessage() const;
MessageType getMessageType() const;
void setMessageNull();
String getMessage() const { return message;}
MessageType getMessageType() const {return messageType;}
void setMessageNull() {message=String();}
private:
MessageNode();
~MessageNode();
@@ -27,7 +37,7 @@ private:
class MessageQueue : private NoDefaultMethods {
public:
MessageQueue(int size);
static MessageQueuePtr create(int size);
~MessageQueue();
MessageNode *get();
// must call release before next get
@@ -38,9 +48,91 @@ public:
bool isFull() const;
int getClearOverrun();
private:
class MessageQueuePvt *pImpl;
MessageQueue(std::vector<std::tr1::shared_ptr<MessageNode> > data);
Queue<MessageNode> queue;
MessageNode *lastPut;
MessagreNode *lastGet;
int size;
int overrun;
};
MessageQueuePtr MessageQueue::create(int size)
{
std::vector<std::tr1::shared_ptr<MessageNode> > dataArray;
dataArray.reserve(size);
for(int i=0; i<size; i++) {
dataArray.push_back(
std::tr1::shared_ptr<MessageNode>(new MessageNode()));
}
return std::tr1::shared_ptr<MessageQueue>(new MessageQueue(dataArray));
}
MessageQueue::MessageQueue(std::vector<std::tr1::shared_ptr<MessageNode> > data)
: queue(data),
lastPut(NULL),
lastGet(NULL),
size(data.size()),
overrun(0)
{ }
MessageNode *MessageQueue::get() {
if(lastGet!=NULL) {
throw std::logic_error(
String("MessageQueue::get() but did not release last"));
}
MessageNode node = queue.getUsed();
if(node==NULL) return NULL;
lastGet = node;
return node;
}
void MessageQueue::release() {
if(lastGet==NULL) return;
queue.releaseUsed(lastGet);
lastGet = NULL;
}
bool MessageQueue::put(String message,MessageType messageType,bool replaceLast)
{
MessageNode node = queue.getFree();
if(node!= NULL) {
node->message = message;
node->messageType = messageType;
lastPut = node;
queue.setUsed(node);
return true;
}
overrun++;
if(replaceLast) {
node = lastPut;
node->message = message;
node->messageType = messageType;
}
return false;
}
bool MessageQueue::isEmpty() const
{
int free = queue.getNumberFree();
if(free==size) return true;
return false;
}
bool MessageQueue::isFull() const
{
if(queue.getNumberFree()==0) return true;
return false;
}
int MessageQueue::getClearOverrun()
{
int num = overrun;
overrun = 0;
return num;
}
}}
#endif /* MESSAGEQUEUE_H */
+106 -32
View File
@@ -4,47 +4,121 @@
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*/
#include <vector>
#include <tr1/memory>
#include <cstddef>
#include <stdexcept>
#ifndef QUEUE_H
#define QUEUE_H
#include <pv/queueVoid.h>
namespace epics { namespace pvData {
template <typename T>
class Queue;
template <typename T>
class QueueElement;
template <typename T>
class QueueElement : private QueueElementVoid {
class Queue
{
public:
T *getObject() { return static_cast<T *>(QueueElementVoid::getObject());}
protected:
QueueElement(T *object) : QueueElementVoid(static_cast<void *>(object)){}
~QueueElement() {}
friend class Queue<T>;
typedef std::tr1::shared_ptr<T> queueElementPtr;
Queue(int size);
Queue(std::vector<queueElementPtr> elements);
~Queue(){}
void clear();
int capacity(){return size;}
int getNumberFree(){return numberFree;}
int getNumberUsed(){return numberUsed;}
T * getFree();
void setUsed(T *element);
T * getUsed();
void releaseUsed(T *element);
private:
std::vector<queueElementPtr> elements;
int size;
int numberFree;
int numberUsed;
int nextGetFree;
int nextSetUsed;
int nextGetUsed;
int nextReleaseUsed;
};
template <typename T>
class Queue : private QueueVoid {
public:
Queue(T *array[],int number)
: QueueVoid((ObjectPtr*)array,number)
//: QueueVoid(static_cast<ObjectPtr*>(array),number)
{}
~Queue() {}
void clear() {QueueVoid::clear();}
int getNumberFree() {return QueueVoid::getNumberFree();}
int capacity() {return QueueVoid::capacity();}
QueueElement<T> *getFree() {
return static_cast<QueueElement<T> *>(QueueVoid::getFree());}
void setUsed(QueueElement<T> *queueElement) {
QueueVoid::setUsed(static_cast<QueueElementVoid *>(queueElement));}
QueueElement<T> *getUsed() {
return static_cast<QueueElement<T> *>(QueueVoid::getUsed());}
void releaseUsed(QueueElement<T> *queueElement) {
QueueVoid::releaseUsed(static_cast<QueueElementVoid *>(queueElement));}
};
Queue<T>::Queue(int size)
: elements(size),
size(size),
numberFree(size),
numberUsed(0),
nextGetFree(0),
nextSetUsed(0),
nextGetUsed(0),
nextReleaseUsed(0)
{
for(int i=0; i<size; i++) {
elements[i] = std::tr1::shared_ptr<T>(new T());
}
}
template <typename T>
Queue<T>::Queue(std::vector<queueElementPtr> elements)
: elements(elements),
size(elements.size()),
numberFree(size),
numberUsed(0),
nextGetFree(0),
nextSetUsed(0),
nextGetUsed(0),
nextReleaseUsed(0)
{ }
template <typename T>
void Queue<T>::clear()
{
numberFree = size;
numberUsed = 0;
nextGetFree = 0;
nextSetUsed = 0;
nextGetUsed = 0;
nextReleaseUsed = 0;
}
template <typename T>
T * Queue<T>::getFree()
{
if(numberFree==0) return NULL;
numberFree--;
std::tr1::shared_ptr<T> queueElement = elements[nextGetFree++];
if(nextGetFree>=size) nextGetFree = 0;
return queueElement.get();
}
template <typename T>
void Queue<T>::setUsed(T *element)
{
if(element!=elements[nextSetUsed++].get()) {
throw std::logic_error("not correct queueElement");
}
numberUsed++;
if(nextSetUsed>=size) nextSetUsed = 0;
}
template <typename T>
T * Queue<T>::getUsed()
{
if(numberUsed==0) return 0;
std::tr1::shared_ptr<T> queueElement = elements[nextGetUsed++];
if(nextGetUsed>=size) nextGetUsed = 0;
return queueElement.get();
}
template <typename T>
void Queue<T>::releaseUsed( T *element)
{
if(element!=elements[nextReleaseUsed++].get()) {
throw std::logic_error(
"not queueElement returned by last call to getUsed");
}
if(nextReleaseUsed>=size) nextReleaseUsed = 0;
numberUsed--;
numberFree++;
}
}}
-120
View File
@@ -1,120 +0,0 @@
/* queueVoid.cpp */
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*/
#include <cstddef>
#include <cstdlib>
#include <cstddef>
#include <string>
#include <cstdio>
#include <stdexcept>
#include <pv/lock.h>
#include <pv/pvType.h>
#include <pv/queueVoid.h>
#include <pv/CDRMonitor.h>
namespace epics { namespace pvData {
PVDATA_REFCOUNT_MONITOR_DEFINE(queueElement);
PVDATA_REFCOUNT_MONITOR_DEFINE(queue);
QueueElementVoid::QueueElementVoid(ObjectPtr object)
: object(object)
{
PVDATA_REFCOUNT_MONITOR_CONSTRUCT(queueElement);
}
QueueElementVoid::~QueueElementVoid()
{
PVDATA_REFCOUNT_MONITOR_DESTRUCT(queueElement);
}
ObjectPtr QueueElementVoid::getObject() {
return object;
}
QueueVoid::QueueVoid(ObjectPtr object[],int number)
: array(new QueueElementVoidPtr[number]),number(number),
numberFree(number),numberUsed(0),
nextGetFree(0),nextSetUsed(),
nextGetUsed(0),nextReleaseUsed(0)
{
for(int i=0; i<number; i++) {
array[i] = new QueueElementVoid(object[i]);
}
PVDATA_REFCOUNT_MONITOR_CONSTRUCT(queue);
}
QueueVoid::~QueueVoid()
{
for(int i=0; i<number; i++) {
delete array[i];
}
delete[]array;
PVDATA_REFCOUNT_MONITOR_DESTRUCT(queue);
}
void QueueVoid::clear()
{
numberFree = number;
numberUsed = 0;
nextGetFree = 0;
nextSetUsed = 0;
nextGetUsed = 0;
nextReleaseUsed = 0;
}
int QueueVoid::getNumberFree()
{
return numberFree;
}
int QueueVoid::capacity()
{
return number;
}
QueueElementVoid * QueueVoid::getFree()
{
if(numberFree==0) return 0;
numberFree--;
QueueElementVoid *queueElement = array[nextGetFree++];
if(nextGetFree>=number) nextGetFree = 0;
return queueElement;
}
void QueueVoid::setUsed(QueueElementVoid *queueElement)
{
if(queueElement!=array[nextSetUsed++]) {
throw std::logic_error(String("not correct queueElement"));
}
numberUsed++;
if(nextSetUsed>=number) nextSetUsed = 0;
}
QueueElementVoid * QueueVoid::getUsed()
{
if(numberUsed==0) return 0;
QueueElementVoid *queueElement = array[nextGetUsed++];
if(nextGetUsed>=number) nextGetUsed = 0;
return queueElement;
}
void QueueVoid::releaseUsed(QueueElementVoid *queueElement)
{
if(queueElement!=array[nextReleaseUsed++]) {
throw std::logic_error(String(
"not queueElement returned by last call to getUsed"));
}
if(nextReleaseUsed>=number) nextReleaseUsed = 0;
numberUsed--;
numberFree++;
}
}}
-56
View File
@@ -1,56 +0,0 @@
/* queueVoid.h */
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*/
#ifndef QUEUEVOID_H
#define QUEUEVOID_H
namespace epics { namespace pvData {
class QueueVoid;
class QueueElementVoid;
typedef void * ObjectPtr;
typedef QueueElementVoid * QueueElementVoidPtr;
typedef QueueElementVoidPtr * QueueElementVoidPtrArray;
class QueueElementVoid {
protected:
ObjectPtr getObject();
QueueElementVoid(ObjectPtr object);
~QueueElementVoid();
ObjectPtr object;
friend class QueueVoid;
};
class QueueVoid {
protected:
QueueVoid(ObjectPtr array[],int number);
~QueueVoid();
void clear();
int getNumberFree();
int capacity();
QueueElementVoidPtr getFree();
void setUsed(QueueElementVoid *queueElement);
QueueElementVoid *getUsed();
void releaseUsed(QueueElementVoid *queueElement);
private:
friend class QueueElementVoid;
QueueElementVoidPtrArray array;
int number;
int numberFree;
int numberUsed;
int nextGetFree;
int nextSetUsed;
int nextGetUsed;
int nextReleaseUsed;
};
}}
#endif /* QUEUEVOID_H */
+9 -7
View File
@@ -9,12 +9,14 @@
namespace epics { namespace pvData {
const size_t messageTypeCount = 4;
static std::string typeName[messageTypeCount] = {
String("info"),
String("warning"),
String("error"),
String("fatalError")
};
StringArray messageTypeName = typeName;
StringArray messageTypeName(messageTypeCount);
void Requester::init()
{
messageTypeName[0] = "info";
messageTypeName[1] = "warning";
messageTypeName[2] = "error";
messageTypeName[3] = "fatalError";
}
}}
+2
View File
@@ -27,6 +27,8 @@ public:
virtual ~Requester(){}
virtual String getRequesterName() = 0;
virtual void message(String message,MessageType messageType) = 0;
private:
static void init();
};
}}
+3 -3
View File
@@ -22,7 +22,7 @@ namespace epics { namespace pvData {
public:
virtual ~SerializableControl(){}
virtual void flushSerializeBuffer() =0;
virtual void ensureBuffer(int size) =0;
virtual void ensureBuffer(std::size_t size) =0;
virtual void alignBuffer(int alignment) =0;
virtual void cachedSerialize(std::tr1::shared_ptr<const Field> const & field, ByteBuffer* buffer) = 0;
};
@@ -30,7 +30,7 @@ namespace epics { namespace pvData {
class DeserializableControl {
public:
virtual ~DeserializableControl(){}
virtual void ensureData(int size) =0;
virtual void ensureData(std::size_t size) =0;
virtual void alignData(int alignment) =0;
virtual std::tr1::shared_ptr<const Field> cachedDeserialize(ByteBuffer* buffer) = 0;
};
@@ -58,7 +58,7 @@ namespace epics { namespace pvData {
public:
virtual ~SerializableArray(){}
virtual void serialize(ByteBuffer *buffer,
SerializableControl *flusher, int offset, int count) const = 0;
SerializableControl *flusher, std::size_t offset, std::size_t count) const = 0;
};
}}
+18 -18
View File
@@ -23,13 +23,13 @@ using namespace std;
namespace epics {
namespace pvData {
void SerializeHelper::writeSize(int s, ByteBuffer* buffer,
void SerializeHelper::writeSize(std::size_t s, ByteBuffer* buffer,
SerializableControl* flusher) {
flusher->ensureBuffer(sizeof(int64)+1);
SerializeHelper::writeSize(s, buffer);
}
void SerializeHelper::writeSize(int s, ByteBuffer* buffer) {
void SerializeHelper::writeSize(std::size_t s, ByteBuffer* buffer) {
if(s==-1) // null
buffer->putByte(-1);
else if(s<254)
@@ -41,7 +41,7 @@ namespace epics {
}
}
int SerializeHelper::readSize(ByteBuffer* buffer,
std::size_t SerializeHelper::readSize(ByteBuffer* buffer,
DeserializableControl* control) {
control->ensureData(1);
int8 b = buffer->getByte();
@@ -54,17 +54,17 @@ namespace epics {
return s;
}
else
return (int)(b<0 ? b+256 : b);
return (std::size_t)(b<0 ? b+256 : b);
}
void SerializeHelper::serializeString(const String& value,
ByteBuffer* buffer, SerializableControl* flusher) {
int len = value.length();
std::size_t len = value.length();
SerializeHelper::writeSize(len, buffer, flusher);
if (len<=0) return;
int i = 0;
std::size_t i = 0;
while(true) {
int maxToWrite = min(len-i, (int)buffer->getRemaining());
std::size_t maxToWrite = min(len-i, buffer->getRemaining());
buffer->put(value.data(), i, maxToWrite); // ASCII
i += maxToWrite;
if(i<len)
@@ -75,19 +75,19 @@ namespace epics {
}
void SerializeHelper::serializeSubstring(const String& value,
int offset, int count, ByteBuffer* buffer,
std::size_t offset, std::size_t count, ByteBuffer* buffer,
SerializableControl* flusher) {
if(offset<0)
offset = 0;
else if(offset>(int)value.length()) offset = value.length();
else if(offset>(std::size_t)value.length()) offset = value.length();
if(offset+count>(int)value.length()) count = value.length()-offset;
if(offset+count>(std::size_t)value.length()) count = value.length()-offset;
SerializeHelper::writeSize(count, buffer, flusher);
if (count<=0) return;
int i = 0;
std::size_t i = 0;
while(true) {
int maxToWrite = min(count-i, (int)buffer->getRemaining());
std::size_t maxToWrite = min(count-i, buffer->getRemaining());
buffer->put(value.data(), offset+i, maxToWrite); // ASCII
i += maxToWrite;
if(i<count)
@@ -102,13 +102,13 @@ namespace epics {
String SerializeHelper::deserializeString(ByteBuffer* buffer,
DeserializableControl* control) {
int size = SerializeHelper::readSize(buffer, control);
std::size_t size = SerializeHelper::readSize(buffer, control);
if(size>0)
{
if ((int)buffer->getRemaining()>=size)
if (buffer->getRemaining()>=size)
{
// entire string is in buffer, simply create a string out of it (copy)
int pos = buffer->getPosition();
std::size_t pos = buffer->getPosition();
String str(buffer->getArray()+pos, size);
buffer->setPosition(pos+size);
return str;
@@ -118,10 +118,10 @@ namespace epics {
String str;
str.reserve(size);
try {
int i = 0;
std::size_t i = 0;
while(true) {
int toRead = min(size-i, (int)buffer->getRemaining());
int pos = buffer->getPosition();
std::size_t toRead = min(size-i, buffer->getRemaining());
std::size_t pos = buffer->getPosition();
str.append(buffer->getArray()+pos, toRead);
buffer->setPosition(pos+toRead);
i += toRead;
+5 -5
View File
@@ -31,7 +31,7 @@ namespace epics {
* @param[in] buffer serialization buffer
* @param[in] flusher flusher
*/
static void writeSize(int s, ByteBuffer* buffer,
static void writeSize(std::size_t s, ByteBuffer* buffer,
SerializableControl* flusher);
/**
@@ -40,7 +40,7 @@ namespace epics {
* @param[in] buffer deserialization buffer.
* @returns array size.
*/
static int readSize(ByteBuffer* buffer,
static std::size_t readSize(ByteBuffer* buffer,
DeserializableControl* control);
/**
@@ -62,8 +62,8 @@ namespace epics {
* @param[in] buffer serialization buffer
* @param[in] flusher flusher
*/
static void serializeSubstring(const String& value, int offset,
int count, ByteBuffer* buffer,
static void serializeSubstring(const String& value, std::size_t offset,
std::size_t count, ByteBuffer* buffer,
SerializableControl* flusher);
/**
@@ -93,7 +93,7 @@ namespace epics {
* @param[in] s size to encode
* @param[in] buffer serialization buffer
*/
static void writeSize(int s, ByteBuffer* buffer);
static void writeSize(std::size_t s, ByteBuffer* buffer);
};
+90 -80
View File
@@ -15,92 +15,102 @@
namespace epics { namespace pvData {
typedef std::tr1::shared_ptr<BitSet> BitSetPtr;
class MonitorElement;
typedef std::tr1::shared_ptr<MonitorElement> MonitorElementPtr;
typedef std::vector<MonitorElementPtr> MonitorElementArray;
class Monitor;
typedef std::tr1::shared_ptr<Monitor> MonitorPtr;
/**
* Class instance representing monitor element.
* @author mrk
*/
class MonitorElement {
public:
POINTER_DEFINITIONS(MonitorElement);
virtual ~MonitorElement(){}
/**
* Class instance representing monitor element.
* @author mrk
* Get the PVStructure.
* @return The PVStructure.
*/
class MonitorElement {
public:
POINTER_DEFINITIONS(MonitorElement);
virtual ~MonitorElement(){}
/**
* Get the PVStructure.
* @return The PVStructure.
*/
virtual PVStructure::shared_pointer const & getPVStructure() = 0;
/**
* Get the bitSet showing which fields have changed.
* @return The bitSet.
*/
virtual BitSet::shared_pointer const & getChangedBitSet() = 0;
/**
* Get the bitSet showing which fields have been changed more than once.
* @return The bitSet.
*/
virtual BitSet::shared_pointer const & getOverrunBitSet() = 0;
};
virtual PVStructurePtr getPVStructure() = 0;
/**
* Interface for Monitor.
* @author mrk
* Get the bitSet showing which fields have changed.
* @return The bitSet.
*/
class Monitor : public Destroyable, private NoDefaultMethods {
public:
POINTER_DEFINITIONS(Monitor);
virtual ~Monitor(){}
/**
* Start monitoring.
* @return completion status.
*/
virtual Status start() = 0;
/**
* Stop Monitoring.
* @return completion status.
*/
virtual Status stop() = 0;
/**
* If monitor has occurred return data.
* @return monitorElement for modified data.
* Must call get to determine if data is available.
*/
virtual MonitorElement::shared_pointer const & poll() = 0;
/**
* Release a MonitorElement that was returned by poll.
* @param monitorElement
*/
virtual void release(MonitorElement::shared_pointer const & monitorElement) = 0;
};
virtual BitSetPtr getChangedBitSet() = 0;
/**
* Requester for ChannelMonitor.
* @author mrk
* Get the bitSet showing which fields have been changed more than once.
* @return The bitSet.
*/
class MonitorRequester : public virtual Requester {
public:
POINTER_DEFINITIONS(MonitorRequester);
virtual ~MonitorRequester(){}
/**
* The client and server have both completed the createMonitor request.
* @param status Completion status.
* @param monitor The monitor
* @param structure The structure defining the data.
*/
virtual void monitorConnect(Status const &status,
Monitor::shared_pointer const & monitor, StructureConstPtr const & structure) = 0;
/**
* A monitor event has occurred.
* The requester must call Monitor.poll to get data.
* @param monitor The monitor.
*/
virtual void monitorEvent(Monitor::shared_pointer const &monitor) = 0;
/**
* The data source is no longer available.
* @param monitor The monitor.
*/
virtual void unlisten(Monitor::shared_pointer const &monitor) = 0;
};
virtual BitSetPtr getOverrunBitSet() = 0;
};
/**
* Interface for Monitor.
* @author mrk
*/
class Monitor : public Destroyable, private NoDefaultMethods {
public:
POINTER_DEFINITIONS(Monitor);
virtual ~Monitor(){}
/**
* Start monitoring.
* @return completion status.
*/
virtual Status start() = 0;
/**
* Stop Monitoring.
* @return completion status.
*/
virtual Status stop() = 0;
/**
* If monitor has occurred return data.
* @return monitorElement for modified data.
* Must call get to determine if data is available.
*/
virtual MonitorElementPtr poll() = 0;
/**
* Release a MonitorElement that was returned by poll.
* @param monitorElement
*/
virtual void release(MonitorElementPtr & monitorElement) = 0;
};
/**
* Requester for ChannelMonitor.
* @author mrk
*/
class MonitorRequester : public virtual Requester {
public:
POINTER_DEFINITIONS(MonitorRequester);
virtual ~MonitorRequester(){}
/**
* The client and server have both completed the createMonitor request.
* @param status Completion status.
* @param monitor The monitor
* @param structure The structure defining the data.
*/
virtual void monitorConnect(Status const &status,
MonitorPtr & monitor, StructureConstPtr const & structure) = 0;
/**
* A monitor event has occurred.
* The requester must call Monitor.poll to get data.
* @param monitor The monitor.
*/
virtual void monitorEvent(MonitorPtr const &monitor) = 0;
/**
* The data source is no longer available.
* @param monitor The monitor.
*/
virtual void unlisten(MonitorPtr const &monitor) = 0;
};
}}
#endif /* MONITOR_H */
+7 -7
View File
@@ -31,16 +31,16 @@ public:
void clear();
int getNumberFree();
int capacity();
MonitorElement::shared_pointer const & getFree();
void setUsed(MonitorElement::shared_pointer const & element);
MonitorElement::shared_pointer const & getUsed();
void releaseUsed(MonitorElement::shared_pointer const & element);
MonitorElementPtr & getFree();
void setUsed(MonitorElementPtr & element);
MonitorElementPtr getUsed();
void releaseUsed(MonitorElementPtr & element);
private:
int number;
PVStructureSharedPointerPtrArray structures;
Queue<MonitorElement::shared_pointer> *queue;
MonitorElement::shared_pointer **queueElements;
MonitorElement::shared_pointer nullElement;
Queue<MonitorElementPtr> *queue;
MonitorElementPtr **queueElements;
MonitorElementPtr nullElement;
};
}}
+28 -22
View File
@@ -6,21 +6,13 @@
*/
#include <string>
#include <stdexcept>
#include <pv/lock.h>
#include <pv/pvType.h>
#include <pv/pvIntrospect.h>
#include <pv/pvData.h>
#include <pv/alarm.h>
namespace epics { namespace pvData {
const size_t severityCount = 5;
static String severityNames[severityCount] =
{
String("NONE"),
String("MINOR"),
String("MAJOR"),
String("INVALID"),
String("UNDEFINED")
};
AlarmSeverity AlarmSeverityFunc::getSeverity(int value)
{
@@ -39,6 +31,18 @@ AlarmSeverity AlarmSeverityFunc::getSeverity(int value)
StringArray AlarmSeverityFunc::getSeverityNames()
{
static size_t severityCount = 5;
static StringArray severityNames;
static Mutex mutex;
Lock xx(mutex);
if(severityNames.size()==0) {
severityNames.reserve(severityCount);
severityNames.push_back("NONE");
severityNames.push_back("MINOR");
severityNames.push_back("MAJOR");
severityNames.push_back("INVALID");
severityNames.push_back("UNDEFINED");
}
return severityNames;
}
@@ -54,19 +58,6 @@ AlarmSeverity Alarm::getSeverity() const
throw std::logic_error(String("should never get here"));
}
const size_t statusCount = 8;
static String statusNames[statusCount] =
{
String("NONE"),
String("DEVICE"),
String("DRIVER"),
String("RECORD"),
String("DB"),
String("CONF"),
String("UNDEFINED"),
String("CLIENT")
};
AlarmStatus AlarmStatusFunc::getStatus(int value)
{
if(value<0 || value>7) {
@@ -87,6 +78,21 @@ AlarmStatus AlarmStatusFunc::getStatus(int value)
StringArray AlarmStatusFunc::getStatusNames()
{
static size_t statusCount = 8;
static StringArray statusNames;
static Mutex mutex;
Lock xx(mutex);
if(statusNames.size()==0) {
statusNames.reserve(statusCount);
statusNames.push_back("NONE");
statusNames.push_back("DEVICE");
statusNames.push_back("DRIVER");
statusNames.push_back("RECORD");
statusNames.push_back("DB");
statusNames.push_back("CONF");
statusNames.push_back("UNDEFINED");
statusNames.push_back("CLIENT");
}
return statusNames;
}
+23 -39
View File
@@ -12,71 +12,55 @@
#include <pv/pvAlarm.h>
namespace epics { namespace pvData {
using std::tr1::static_pointer_cast;
static String noAlarmFound("No alarm structure found");
static String notAttached("Not attached to an alarm structure");
bool PVAlarm::attach(PVField *pvField)
bool PVAlarm::attach(PVFieldPtr pvField)
{
PVStructure *pvStructure = 0;
if(pvField->getField()->getFieldName().compare("alarm")!=0) {
if(pvField->getField()->getFieldName().compare("value")!=0) {
pvField->message(noAlarmFound,errorMessage);
return false;
}
PVStructure *pvParent = pvField->getParent();
if(pvParent==0) {
pvField->message(noAlarmFound,errorMessage);
return false;
}
pvStructure = pvParent->getStructureField(String("alarm"));
if(pvStructure==0) {
pvField->message(noAlarmFound,errorMessage);
return false;
}
} else {
if(pvField->getField()->getType()!=structure) {
pvField->message(noAlarmFound,errorMessage);
return false;
}
pvStructure = static_cast<PVStructure*>(pvField);
}
PVInt *pvInt = pvStructure->getIntField(String("severity"));
if(pvInt==0) {
if(pvField->getField()->getType()!=structure) {
pvField->message(noAlarmFound,errorMessage);
return false;
}
pvSeverity = pvInt;
pvInt = pvStructure->getIntField(String("status"));
if(pvInt==0) {
PVStructurePtr pvStructure = static_pointer_cast<PVStructure>(pvField);
pvSeverity = pvStructure->getIntField("severity");
if(pvSeverity.get()==NULL) {
pvField->message(noAlarmFound,errorMessage);
return false;
}
pvStatus = pvInt;
PVString *pvString = pvStructure->getStringField(String("message"));
if(pvInt==0) {
pvStatus = pvStructure->getIntField("status");
if(pvStatus.get()==NULL) {
pvField->message(noAlarmFound,errorMessage);
pvSeverity.reset();
return false;
}
pvMessage = pvStructure->getStringField("message");
if(pvMessage.get()==NULL) {
pvField->message(noAlarmFound,errorMessage);
pvSeverity.reset();
pvStatus.reset();
return false;
}
pvMessage = pvString;
return true;
}
void PVAlarm::detach()
{
pvSeverity = 0;
pvStatus = 0;
pvMessage = 0;
pvSeverity.reset();
pvStatus.reset();
pvMessage.reset();
}
bool PVAlarm::isAttached()
{
if(pvSeverity==0 || pvMessage==0) return false;
if(pvSeverity.get()==NULL) return false;
return true;
}
void PVAlarm::get(Alarm & alarm) const
{
if(pvSeverity==0 || pvMessage==0) {
if(pvSeverity.get()==NULL) {
throw std::logic_error(notAttached);
}
alarm.setSeverity(AlarmSeverityFunc::getSeverity(pvSeverity->get()));
@@ -86,7 +70,7 @@ void PVAlarm::get(Alarm & alarm) const
bool PVAlarm::set(Alarm const & alarm)
{
if(pvSeverity==0 || pvMessage==0) {
if(pvSeverity.get()==NULL) {
throw std::logic_error(notAttached);
}
if(pvSeverity->isImmutable() || pvMessage->isImmutable()) return false;
+5 -5
View File
@@ -15,11 +15,11 @@ namespace epics { namespace pvData {
class PVAlarm {
public:
PVAlarm() : pvSeverity(0),pvStatus(0),pvMessage(0) {}
PVAlarm() {}
//default constructors and destructor are OK
//returns (false,true) if pvField(isNot, is valid enumerated structure
//An automatic detach is issued if already attached.
bool attach(PVField *pvField);
bool attach(PVFieldPtr pvField);
void detach();
bool isAttached();
// each of the following throws logic_error is not attached to PVField
@@ -27,9 +27,9 @@ public:
void get(Alarm & alarm) const;
bool set(Alarm const & alarm);
private:
PVInt *pvSeverity;
PVInt *pvStatus;
PVString *pvMessage;
PVIntPtr pvSeverity;
PVIntPtr pvStatus;
PVStringPtr pvMessage;
};
}}
+15 -33
View File
@@ -12,64 +12,46 @@
#include <pv/pvControl.h>
namespace epics { namespace pvData {
using std::tr1::static_pointer_cast;
static String noControlFound("No control structure found");
static String notAttached("Not attached to an control structure");
bool PVControl::attach(PVField *pvField)
bool PVControl::attach(PVFieldPtr pvField)
{
PVStructure *pvStructure = 0;
if(pvField->getField()->getFieldName().compare("control")!=0) {
if(pvField->getField()->getFieldName().compare("value")!=0) {
if(pvField->getField()->getType()!=structure) {
pvField->message(noControlFound,errorMessage);
return false;
}
PVStructure *pvParent = pvField->getParent();
if(pvParent==0) {
pvField->message(noControlFound,errorMessage);
return false;
}
pvStructure = pvParent->getStructureField(String("control"));
if(pvStructure==0) {
pvField->message(noControlFound,errorMessage);
return false;
}
} else {
if(pvField->getField()->getType()!=structure) {
pvField->message(noControlFound,errorMessage);
return false;
}
pvStructure = static_cast<PVStructure*>(pvField);
}
PVDouble *pvDouble = pvStructure->getDoubleField(String("limit.low"));
if(pvDouble==0) {
PVStructurePtr pvStructure = static_pointer_cast<PVStructure>(pvField);
pvLow = pvStructure->getDoubleField("limitLow");
if(pvLow.get()==NULL) {
pvField->message(noControlFound,errorMessage);
return false;
}
pvLow = pvDouble;
pvDouble = pvStructure->getDoubleField(String("limit.high"));
if(pvDouble==0) {
pvLow = 0;
pvHigh = pvStructure->getDoubleField(String("limitHigh"));
if(pvHigh.get()==NULL) {
pvLow.reset();
pvField->message(noControlFound,errorMessage);
return false;
}
pvHigh = pvDouble;
return true;
}
void PVControl::detach()
{
pvLow = 0;
pvHigh = 0;
pvLow.reset();
pvHigh.reset();
}
bool PVControl::isAttached(){
if(pvLow==0 || pvHigh==0) return false;
if(pvLow.get()==NULL) return false;
return true;
}
void PVControl::get(Control &control) const
{
if(pvLow==0 || pvHigh==0) {
if(pvLow.get()==NULL) {
throw std::logic_error(notAttached);
}
control.setLow(pvLow->get());
@@ -78,7 +60,7 @@ void PVControl::get(Control &control) const
bool PVControl::set(Control const & control)
{
if(pvLow==0 || pvHigh==0) {
if(pvLow.get()==NULL) {
throw std::logic_error(notAttached);
}
if(pvLow->isImmutable() || pvHigh->isImmutable()) return false;
+4 -4
View File
@@ -12,11 +12,11 @@ namespace epics { namespace pvData {
class PVControl {
public:
PVControl() : pvLow(0),pvHigh(0) {}
PVControl(){}
//default constructors and destructor are OK
//returns (false,true) if pvField(isNot, is valid enumerated structure
//An automatic detach is issued if already attached.
bool attach(PVField *pvField);
bool attach(PVFieldPtr pvField);
void detach();
bool isAttached();
// each of the following throws logic_error is not attached to PVField
@@ -24,8 +24,8 @@ public:
void get(Control &) const;
bool set(Control const & control);
private:
PVDouble *pvLow;
PVDouble *pvHigh;
PVDoublePtr pvLow;
PVDoublePtr pvHigh;
};
}}
+23 -41
View File
@@ -12,59 +12,43 @@
#include <pv/pvDisplay.h>
namespace epics { namespace pvData {
using std::tr1::static_pointer_cast;
static String noDisplayFound("No display structure found");
static String notAttached("Not attached to an display structure");
bool PVDisplay::attach(PVField *pvField)
bool PVDisplay::attach(PVFieldPtr pvField)
{
PVStructure *pvStructure = 0;
if(pvField->getField()->getFieldName().compare("display")!=0) {
if(pvField->getField()->getFieldName().compare("value")!=0) {
if(pvField->getField()->getType()!=structure) {
pvField->message(noDisplayFound,errorMessage);
return false;
}
PVStructure *pvParent = pvField->getParent();
if(pvParent==0) {
pvField->message(noDisplayFound,errorMessage);
return false;
}
pvStructure = pvParent->getStructureField(String("display"));
if(pvStructure==0) {
pvField->message(noDisplayFound,errorMessage);
return false;
}
} else {
if(pvField->getField()->getType()!=structure) {
pvField->message(noDisplayFound,errorMessage);
return false;
}
pvStructure = static_cast<PVStructure*>(pvField);
}
pvDescription = pvStructure->getStringField(String("description"));
if(pvDescription==0) {
PVStructurePtr pvStructure = static_pointer_cast<PVStructure>(pvField);
pvDescription = pvStructure->getStringField("description");
if(pvDescription.get()==NULL) {
pvField->message(noDisplayFound,errorMessage);
return false;
}
pvFormat = pvStructure->getStringField(String("format"));
if(pvFormat==0) {
pvFormat = pvStructure->getStringField("format");
if(pvFormat.get()==NULL) {
pvField->message(noDisplayFound,errorMessage);
detach();
return false;
}
pvUnits = pvStructure->getStringField(String("units"));
if(pvUnits==0) {
pvUnits = pvStructure->getStringField("units");
if(pvUnits.get()==NULL) {
pvField->message(noDisplayFound,errorMessage);
detach();
return false;
}
pvLow = pvStructure->getDoubleField(String("limit.low"));
if(pvLow==0) {
pvLow = pvStructure->getDoubleField(String("limitLow"));
if(pvLow.get()==NULL) {
pvField->message(noDisplayFound,errorMessage);
detach();
return false;
}
pvHigh = pvStructure->getDoubleField(String("limit.high"));
if(pvHigh==0) {
pvHigh = pvStructure->getDoubleField(String("limitHigh"));
if(pvHigh.get()==NULL) {
pvField->message(noDisplayFound,errorMessage);
detach();
return false;
@@ -74,22 +58,21 @@ bool PVDisplay::attach(PVField *pvField)
void PVDisplay::detach()
{
pvDescription = 0;
pvFormat = 0;
pvUnits = 0;
pvLow = 0;
pvHigh = 0;
pvDescription.reset();
pvFormat.reset();
pvUnits.reset();
pvLow.reset();
pvHigh.reset();
}
bool PVDisplay::isAttached() {
if(pvDescription==0 || pvFormat==0 || pvUnits==0 || pvLow==0 || pvHigh==0)
return false;
if(pvDescription.get()) return false;
return true;
}
void PVDisplay::get(Display & display) const
{
if(pvDescription==0 || pvFormat==0 || pvUnits==0 || pvLow==0 || pvHigh==0) {
if(pvDescription.get()==NULL) {
throw std::logic_error(notAttached);
}
display.setDescription(pvDescription->get());
@@ -101,13 +84,12 @@ void PVDisplay::get(Display & display) const
bool PVDisplay::set(Display const & display)
{
if(pvDescription==0 || pvFormat==0 || pvUnits==0 || pvLow==0 || pvHigh==0) {
if(pvDescription.get()==NULL) {
throw std::logic_error(notAttached);
}
if(pvDescription->isImmutable() || pvFormat->isImmutable()) return false;
if(pvUnits->isImmutable() || pvLow->isImmutable() || pvHigh->isImmutable())
return false;
pvDescription->put(display.getDescription());
pvFormat->put(display.getFormat());
pvUnits->put(display.getUnits());
+7 -8
View File
@@ -14,11 +14,10 @@ namespace epics { namespace pvData {
class PVDisplay {
public:
PVDisplay()
: pvDescription(0),pvFormat(),pvUnits(),pvLow(),pvHigh() {}
PVDisplay() {}
//default constructors and destructor are OK
//An automatic detach is issued if already attached.
bool attach(PVField *pvField);
bool attach(PVFieldPtr pvField);
void detach();
bool isAttached();
// each of the following throws logic_error is not attached to PVField
@@ -26,11 +25,11 @@ public:
void get(Display &) const;
bool set(Display const & display);
private:
PVString *pvDescription;
PVString *pvFormat;
PVString *pvUnits;
PVDouble *pvLow;
PVDouble *pvHigh;
PVStringPtr pvDescription;
PVStringPtr pvFormat;
PVStringPtr pvUnits;
PVDoublePtr pvLow;
PVDoublePtr pvHigh;
};
}}
+31 -31
View File
@@ -12,48 +12,48 @@
#include <pv/pvEnumerated.h>
namespace epics { namespace pvData {
using std::tr1::static_pointer_cast;
static String notStructure("field is not a structure");
static String notEnumerated("field is not an enumerated structure");
static String notFound("No enumerated structure found");
static String notAttached("Not attached to an enumerated structure");
bool PVEnumerated::attach(PVField *pvField)
bool PVEnumerated::attach(PVFieldPtr pvField)
{
if(pvField->getField()->getType()!=structure) {
pvField->message(notStructure,errorMessage);
pvField->message(notFound,errorMessage);
return false;
}
PVStructurePtr pvStructure = static_pointer_cast<PVStructure>(pvField);
pvIndex = pvStructure->getIntField("index");
if(pvIndex.get()==NULL) {
pvField->message(notFound,errorMessage);
return false;
}
PVStructure *pvStructure = static_cast<PVStructure*>(pvField);
PVInt *pvInt = pvStructure->getIntField(String("index"));
if(pvInt==0) {
pvField->message(notEnumerated,errorMessage);
PVScalarArrayPtr pvScalarArray = pvStructure->getScalarArrayField(
"choices",pvString);
if(pvScalarArray.get()==NULL) {
pvIndex.reset();
pvField->message(notFound,errorMessage);
return false;
}
PVScalarArray *pvScalarArray = pvStructure->getScalarArrayField(
String("choices"),pvString);
if(pvScalarArray==0) {
pvField->message(notEnumerated,errorMessage);
return false;
}
pvIndex = pvInt;
pvChoices = static_cast<PVStringArray *>(pvScalarArray);
pvChoices = static_pointer_cast<PVStringArray>(pvScalarArray);
return true;
}
void PVEnumerated::detach()
{
pvIndex = 0;
pvChoices = 0;
pvIndex.reset();
pvChoices.reset();
}
bool PVEnumerated::isAttached() {
if(pvIndex==0 || pvChoices==0) return false;
if(pvIndex.get()==NULL) return false;
return true;
}
bool PVEnumerated::setIndex(int32 index)
{
if(pvIndex==0 || pvChoices==0) {
if(pvIndex.get()==NULL ) {
throw std::logic_error(notAttached);
}
if(pvIndex->isImmutable()) return false;
@@ -63,7 +63,7 @@ bool PVEnumerated::setIndex(int32 index)
int32 PVEnumerated::getIndex()
{
if(pvIndex==0 || pvChoices==0) {
if(pvIndex.get()==NULL ) {
throw std::logic_error(notAttached);
}
return pvIndex->get();
@@ -71,48 +71,48 @@ int32 PVEnumerated::getIndex()
String PVEnumerated::getChoice()
{
if(pvIndex==0 || pvChoices==0) {
if(pvIndex.get()==NULL ) {
throw std::logic_error(notAttached);
}
int index = pvIndex->get();
StringArrayData data;
pvChoices->get(0,pvChoices->getLength(),&data);
pvChoices->get(0,pvChoices->getLength(),data);
return data.data[index];
}
bool PVEnumerated::choicesMutable()
{
if(pvIndex==0 || pvChoices==0) {
if(pvIndex.get()==NULL ) {
throw std::logic_error(notAttached);
}
return pvChoices->isImmutable();
}
StringArray PVEnumerated:: getChoices()
StringArray& PVEnumerated:: getChoices()
{
if(pvIndex==0 || pvChoices==0) {
if(pvIndex.get()==NULL ) {
throw std::logic_error(notAttached);
}
StringArrayData data;
pvChoices->get(0,pvChoices->getLength(),&data);
pvChoices->get(0,pvChoices->getLength(),data);
return data.data;
}
int32 PVEnumerated::getNumberChoices()
{
if(pvIndex==0 || pvChoices==0) {
if(pvIndex.get()==NULL ) {
throw std::logic_error(notAttached);
}
return pvChoices->getLength();
}
bool PVEnumerated:: setChoices(StringArray choices,int32 numberChoices)
bool PVEnumerated:: setChoices(StringArray & choices)
{
if(pvIndex==0 || pvChoices==0) {
if(pvIndex.get()==NULL ) {
throw std::logic_error(notAttached);
}
if(pvChoices->isImmutable()) return false;
pvChoices->put(0,numberChoices,choices,0);
pvChoices->put(0,choices.size(),get(choices),0);
return true;
}
+6 -6
View File
@@ -13,12 +13,12 @@ namespace epics { namespace pvData {
class PVEnumerated {
public:
PVEnumerated() : pvIndex(0), pvChoices(0) {}
PVEnumerated() {}
//default constructors and destructor are OK
//This class should not be extended
//returns (false,true) if pvField(isNot, is valid enumerated structure
//An automatic detach is issued if already attached.
bool attach(PVField *pvField);
bool attach(PVFieldPtr pvField);
void detach();
bool isAttached();
// each of the following throws logic_error is not attached to PVField
@@ -27,12 +27,12 @@ public:
int32 getIndex();
String getChoice();
bool choicesMutable();
StringArray getChoices();
StringArray & getChoices();
int32 getNumberChoices();
bool setChoices(StringArray choices,int32 numberChoices);
bool setChoices(StringArray & choices);
private:
PVInt *pvIndex;
PVStringArray *pvChoices;
PVIntPtr pvIndex;
PVStringArrayPtr pvChoices;
};
}}
+26 -52
View File
@@ -12,78 +12,52 @@
#include <pv/pvTimeStamp.h>
namespace epics { namespace pvData {
using std::tr1::static_pointer_cast;
static String noTimeStamp("No timeStamp structure found");
static String notAttached("Not attached to a timeStamp structure");
bool PVTimeStamp::attach(PVField *pvField)
bool PVTimeStamp::attach(PVFieldPtr pvField)
{
PVStructure *pvStructure = 0;
if(pvField->getField()->getFieldName().compare("timeStamp")!=0) {
PVStructure *pvParent = pvField->getParent();
if(pvParent==0) {
pvField->message(noTimeStamp,errorMessage);
return false;
}
if(pvField->getField()->getFieldName().compare("value")!=0) {
if(pvField->getField()->getType()!=structure) {
pvField->message(noTimeStamp,errorMessage);
return false;
}
PVStructurePtr xxx = static_pointer_cast<PVStructure>(pvField);
PVStructure* pvStructure = xxx.get();
while(true) {
PVLongPtr pvLong = pvStructure->getLongField("secondsPastEpoch");
if(pvLong.get()!=NULL) {
pvSecs = pvLong;
pvNano = pvStructure->getIntField("nanoSeconds");
pvUserTag = pvStructure->getIntField("userTag");
}
if(pvSecs.get()!=NULL
&& pvNano.get()!=NULL
&& pvUserTag.get()!=NULL) return true;
detach();
// look up the tree for a timeSyamp
while(pvParent!=0) {
PVStructure *pvs = pvParent->getStructureField(String("timeStamp"));
if(pvs!=0) {
pvStructure = pvs;
break;
}
pvParent = pvParent->getParent();
}
if(pvStructure==0) {
pvField->message(noTimeStamp,errorMessage);
return false;
}
} else {
if(pvField->getField()->getType()!=structure) {
pvField->message(noTimeStamp,errorMessage);
return false;
}
pvStructure = static_cast<PVStructure*>(pvField);
pvStructure = pvStructure->getParent();
if(pvStructure==NULL) break;
}
PVLong *pvLong = pvStructure->getLongField(String("secondsPastEpoch"));
if(pvLong==0) {
pvField->message(noTimeStamp,errorMessage);
return false;
}
pvSecs = pvLong;
PVInt *pvInt = pvStructure->getIntField(String("nanoSeconds"));
if(pvLong==0) {
pvField->message(noTimeStamp,errorMessage);
return false;
}
pvNano = pvInt;
pvInt = pvStructure->getIntField(String("userTag"));
if(pvInt==0) {
pvField->message(noTimeStamp,errorMessage);
return false;
}
pvUserTag = pvInt;
return true;
return false;
}
void PVTimeStamp::detach()
{
pvSecs = 0;
pvUserTag = 0;
pvNano = 0;
pvSecs.reset();
pvUserTag.reset();
pvNano.reset();
}
bool PVTimeStamp::isAttached() {
if(pvSecs==0 || pvNano==0) return false;
if(pvSecs.get()==NULL) return false;
return true;
}
void PVTimeStamp::get(TimeStamp & timeStamp) const
{
if(pvSecs==0 || pvNano==0) {
if(pvSecs.get()==NULL) {
throw std::logic_error(notAttached);
}
timeStamp.put(pvSecs->get(),pvNano->get());
@@ -92,7 +66,7 @@ void PVTimeStamp::get(TimeStamp & timeStamp) const
bool PVTimeStamp::set(TimeStamp const & timeStamp)
{
if(pvSecs==0 || pvNano==0 || pvUserTag==0) {
if(pvSecs.get()==NULL) {
throw std::logic_error(notAttached);
}
if(pvSecs->isImmutable() || pvNano->isImmutable()) return false;
+5 -5
View File
@@ -15,12 +15,12 @@ namespace epics { namespace pvData {
class PVTimeStamp {
public:
PVTimeStamp() : pvSecs(0),pvUserTag(0), pvNano(0) {}
PVTimeStamp(){}
//default constructors and destructor are OK
//This class should not be extended
//returns (false,true) if pvField(isNot, is valid timeStamp structure
bool attach(PVField *pvField);
bool attach(PVFieldPtr pvField);
void detach();
bool isAttached();
// following throw logic_error is not attached to PVField
@@ -28,9 +28,9 @@ public:
void get(TimeStamp &) const;
bool set(TimeStamp const & timeStamp);
private:
PVLong* pvSecs;
PVInt* pvUserTag;
PVInt* pvNano;
PVLongPtr pvSecs;
PVIntPtr pvUserTag;
PVIntPtr pvNano;
};
}}
+242 -63
View File
@@ -61,16 +61,27 @@ static inline bool operator!=(const StructureArray& a, const StructureArray& b)
* <p>All from methods put data into a PVField, e.g. from means where the PVField gets it's data.</p>
*/
class Convert : NoDefaultMethods {
class Convert;
typedef std::tr1::shared_ptr<Convert> ConvertPtr;
class Convert {
public:
Convert();
static ConvertPtr getConvert();
~Convert();
/**
* Get the full fieldName for the pvField.
* @param builder The builder that will have the result.
* @param pvField The pvField.
*/
void getFullName(StringBuilder buf,PVField *pvField);
void getFullName(StringBuilder buf,PVFieldPtr & pvField);
/**
* Do fields have the same definition.
*
* @param First field
* @param Second field
* @return (false, true) if the fields (are not, are) the same.
*/
bool equals(PVFieldPtr &a,PVFieldPtr &b);
/**
* Do fields have the same definition.
*
@@ -79,6 +90,21 @@ public:
* @return (false, true) if the fields (are not, are) the same.
*/
bool equals(PVField &a,PVField &b);
/**
* Convert a PVField to a string.
* @param buf buffer for the result
* @param pv a PVField to convert to a string.
* If a PVField is a structure or array be prepared for a very long string.
* @param indentLevel indentation level
*/
void getString(StringBuilder buf,PVFieldPtr & pvField,int indentLevel);
/**
* Convert a PVField to a string.
* param buf buffer for the result
* @param pv The PVField to convert to a string.
* If the PVField is a structure or array be prepared for a very long string.
*/
void getString(StringBuilder buf,PVFieldPtr & pvField);
/**
* Convert a PVField to a string.
* @param buf buffer for the result
@@ -93,7 +119,7 @@ public:
* @param pv The PVField to convert to a string.
* If the PVField is a structure or array be prepared for a very long string.
*/
void getString(StringBuilder buf,PVField *pvField);
void getString(StringBuilder buf,PVField * pvField);
/**
* Convert from an array of String to a PVScalar
* @param pv The PV.
@@ -101,14 +127,14 @@ public:
* @param fromStartIndex The first element if the array of strings.
* @throws std::logic_error if the array of String does not have a valid values.
*/
int fromString(PVStructure *pv, std::vector<String>& from, int fromStartIndex = 0);
std::size_t fromString(PVStructurePtr &pv, StringArray const & from, std::size_t fromStartIndex = 0);
/**
* Convert from a String to a PVScalar
* @param pv The PV.
* @param from The String value to convert and put into a PV.
* @throws std::logic_error if the String does not have a valid value.
*/
void fromString(PVScalar *pv, String from);
void fromString(PVScalarPtr & pv, String from);
/**
* Convert from a String to a PVScalarArray.
* The String must be a comma separated set of values optionally enclosed in []
@@ -118,7 +144,7 @@ public:
* @throws std::invalid_argument if the element Type is not a scalar.
* @throws std::logic_error if the String does not have a valid array values.
*/
int fromString(PVScalarArray *pv, String from);
std::size_t fromString(PVScalarArrayPtr & pv, String from);
/**
* Convert a PVScalarArray from a String array.
* The array element type must be a scalar.
@@ -131,8 +157,8 @@ public:
* @throws std::invalid_argument if the element Type is not a scalar.
* @throws std::logic_error if the String does not have a valid value.
*/
int fromStringArray(PVScalarArray *pv, int offset, int length,
StringArray from, int fromOffset);
std::size_t fromStringArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length,
StringArray const & from, std::size_t fromOffset);
/**
* Convert a PVScalarArray to a String array.
* @param pv The PV.
@@ -142,8 +168,8 @@ public:
* @param toOffset Starting element in the string array.
* @return Number of elements converted.
*/
int toStringArray(PVScalarArray *pv, int offset, int length,
StringArray to, int toOffset);
std::size_t toStringArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length,
StringArray const & to, std::size_t toOffset);
/**
* Are from and to valid arguments to copy.
* This first checks of both arguments have the same Type.
@@ -153,7 +179,7 @@ public:
* @param to The destination.
* @return (false,true) is the arguments (are not, are) compatible.
*/
bool isCopyCompatible(FieldConstPtr from, FieldConstPtr to);
bool isCopyCompatible(FieldConstPtr & from, FieldConstPtr & to);
/**
* Copy from a PVField to another PVField.
* This calls one on copyScalar, copyArray, copyStructure.
@@ -162,7 +188,7 @@ public:
* @param to The destination
* @throws std::invalid_argument if the arguments are not compatible.
*/
void copy(PVField *from,PVField *to);
void copy(PVFieldPtr & from,PVFieldPtr & to);
/**
* Are from and to valid arguments to copyScalar.
* false will be returned if either argument is not a scalar as defined by Type.isScalar().
@@ -177,14 +203,14 @@ public:
* @return (false,true) If the arguments (are not, are) compatible.
*/
bool isCopyScalarCompatible(
ScalarConstPtr from, ScalarConstPtr to);
ScalarConstPtr & from, ScalarConstPtr & to);
/**
* Copy from a scalar pv to another scalar pv.
* @param from the source.
* @param to the destination.
* @throws std::invalid_argument if the arguments are not compatible.
*/
void copyScalar(PVScalar *from, PVScalar *to);
void copyScalar(PVScalarPtr & from, PVScalarPtr & to);
/**
* Are from and to valid arguments to copyArray.
* The results are like isCopyScalarCompatible except that the tests are made on the elementType.
@@ -192,8 +218,8 @@ public:
* @param to The to array.
* @return (false,true) If the arguments (are not, are) compatible.
*/
bool isCopyScalarArrayCompatible(ScalarArrayConstPtr from,
ScalarArrayConstPtr to);
bool isCopyScalarArrayCompatible(ScalarArrayConstPtr & from,
ScalarArrayConstPtr & to);
/**
* Convert from a source PV array to a destination PV array.
* @param from The source array.
@@ -204,8 +230,8 @@ public:
* @return Number of elements converted.
* @throws std::invalid_argument if the arguments are not compatible.
*/
int copyScalarArray(PVScalarArray *from, int offset,
PVScalarArray *to, int toOffset, int length);
std::size_t copyScalarArray(PVScalarArrayPtr & from, std::size_t offset,
PVScalarArrayPtr & to, std::size_t toOffset, std::size_t length);
/**
* Are from and to valid arguments for copyStructure.
* They are only compatible if they have the same Structure description.
@@ -214,7 +240,7 @@ public:
* @return (false,true) If the arguments (are not, are) compatible.
*/
bool isCopyStructureCompatible(
StructureConstPtr from, StructureConstPtr to);
StructureConstPtr & from, StructureConstPtr & to);
/**
* Copy from a structure pv to another structure pv.
* NOTE: Only compatible nodes are copied. This means:
@@ -228,7 +254,7 @@ public:
* @param to The destination.
* @throws std::invalid_argument if the arguments are not compatible.
*/
void copyStructure(PVStructure *from, PVStructure *to);
void copyStructure(PVStructurePtr & from, PVStructurePtr & to);
/**
* Are from and to valid for copyStructureArray.
* @param from The from StructureArray.
@@ -236,103 +262,158 @@ public:
* @return (false,true) If the arguments (are not, are) compatible.
*/
bool isCopyStructureArrayCompatible(
StructureArrayConstPtr from, StructureArrayConstPtr to);
StructureArrayConstPtr & from, StructureArrayConstPtr & to);
/**
* Copy from a structure array to another structure array.
* @param from The source array.
* @param to The destination array.
*/
void copyStructureArray(
PVStructureArray *from, PVStructureArray *to);
PVStructureArrayPtr & from, PVStructureArrayPtr & to);
/**
* Convert a PV to a <byte>.
* @param pv a PV
* @return converted value
*/
int8 toByte(PVScalar *pv);
int8 toByte(PVScalarPtr & pv);
/**
* Convert a PV to a short.
* @param pv a PV
* @return converted value
* @throws std::invalid_argument if the Type is not a numeric scalar
*/
int16 toShort(PVScalar *pv);
int16 toShort(PVScalarPtr & pv);
/**
* Convert a PV to a short.
* Convert a PV to a int.
* @param pv a PV
* @return converted value
* @throws std::invalid_argument if the Type is not a numeric scalar
*/
int32 toInt(PVScalar *pv);
int32 toInt(PVScalarPtr & pv);
/**
* Convert a PV to an int
* Convert a PV to an long
* @param pv a PV
* @return converted value
* @throws std::invalid_argument if the Type is not a numeric scalar
*/
int64 toLong(PVScalar *pv);
int64 toLong(PVScalarPtr & pv);
/**
* Convert a PV to a ubyte.
* @param pv a PV
* @return converted value
*/
uint8 toUByte(PVScalarPtr & pv);
/**
* Convert a PV to a ushort.
* @param pv a PV
* @return converted value
* @throws std::invalid_argument if the Type is not a numeric scalar
*/
uint16 toUShort(PVScalarPtr & pv);
/**
* Convert a PV to a uint.
* @param pv a PV
* @return converted value
* @throws std::invalid_argument if the Type is not a numeric scalar
*/
uint32 toUInt(PVScalarPtr & pv);
/**
* Convert a PV to an ulong
* @param pv a PV
* @return converted value
* @throws std::invalid_argument if the Type is not a numeric scalar
*/
uint64 toULong(PVScalarPtr & pv);
/**
* Convert a PV to a float
* @param pv a PV
* @return converted value
* @throws std::invalid_argument if the Type is not a numeric scalar
*/
float toFloat(PVScalar *pv);
float toFloat(PVScalarPtr & pv);
/**
* Convert a PV to a double
* @param pv a PV
* @return converted value
* @throws std::invalid_argument if the Type is not a numeric scalar
*/
double toDouble(PVScalar *pv);
double toDouble(PVScalarPtr & pv);
/**
* Convert a PV to a String
* @param pv a PV
* @return converted value
*/
String toString(PVScalar *pv);
String toString(PVScalarPtr & pv);
/**
* Convert a PV from a byte
* @param pv a PV
* @param from value to put into PV
* @throws std::invalid_argument if the Type is not a numeric scalar
*/
void fromByte(PVScalar *pv,int8 from);
void fromByte(PVScalarPtr & pv,int8 from);
/**
* Convert a PV from a short
* @param pv a PV
* @param from value to put into PV
* @throws std::invalid_argument if the Type is not a numeric scalar
*/
void fromShort(PVScalar *pv,int16 from);
void fromShort(PVScalarPtr & pv,int16 from);
/**
* Convert a PV from an int
* @param pv a PV
* @param from value to put into PV
* @throws std::invalid_argument if the Type is not a numeric scalar
*/
void fromInt(PVScalar *pv, int32 from);
void fromInt(PVScalarPtr & pv, int32 from);
/**
* Convert a PV from a long
* @param pv a PV
* @param from value to put into PV
* @throws std::invalid_argument if the Type is not a numeric scalar
*/
void fromLong(PVScalar *pv, int64 from);
void fromLong(PVScalarPtr & pv, int64 from);
/**
* Convert a PV from a ubyte
* @param pv a PV
* @param from value to put into PV
* @throws std::invalid_argument if the Type is not a numeric scalar
*/
void fromUByte(PVScalarPtr & pv,uint8 from);
/**
* Convert a PV from a ushort
* @param pv a PV
* @param from value to put into PV
* @throws std::invalid_argument if the Type is not a numeric scalar
*/
void fromUShort(PVScalarPtr & pv,uint16 from);
/**
* Convert a PV from an uint
* @param pv a PV
* @param from value to put into PV
* @throws std::invalid_argument if the Type is not a numeric scalar
*/
void fromUInt(PVScalarPtr & pv, uint32 from);
/**
* Convert a PV from a ulong
* @param pv a PV
* @param from value to put into PV
* @throws std::invalid_argument if the Type is not a numeric scalar
*/
void fromULong(PVScalarPtr & pv, uint64 from);
/**
* Convert a PV from a float
* @param pv a PV
* @param from value to put into PV
* @throws std::invalid_argument if the Type is not a numeric scalar
*/
void fromFloat(PVScalar* pv, float from);
void fromFloat(PVScalarPtr & pv, float from);
/**
* Convert a PV from a double
* @param pv a PV
* @param from value to put into PV
* @throws std::invalid_argument if the Type is not a numeric scalar
*/
void fromDouble(PVScalar *pv, double from);
void fromDouble(PVScalarPtr & pv, double from);
/**
* Convert a PV array to a byte array.
* @param pv a PV
@@ -343,8 +424,8 @@ public:
* @return number of elements converted
* @throws std::invalid_argument if the element type is not numeric
*/
int toByteArray(PVScalarArray *pv, int offset, int length,
ByteArray to, int toOffset);
std::size_t toByteArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length,
int8* to, std::size_t toOffset);
/**
* Convert a PV array to a short array.
* @param pv a PV
@@ -355,8 +436,8 @@ public:
* @return number of elements converted
* @throws std::invalid_argument if the element type is not numeric
*/
int toShortArray(PVScalarArray *pv, int offset, int length,
ShortArray to, int toOffset);
std::size_t toShortArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length,
int16* to, std::size_t toOffset);
/**
* Convert a PV array to an int array.
* @param pv a PV
@@ -367,8 +448,8 @@ public:
* @return number of elements converted
* @throws std::invalid_argument if the element type is not numeric
*/
int toIntArray(PVScalarArray *pv, int offset, int length,
IntArray to, int toOffset);
std::size_t toIntArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length,
int32* to, std::size_t toOffset);
/**
* Convert a PV array to a long array.
* @param pv a PV
@@ -379,8 +460,56 @@ public:
* @return number of elements converted
* @throws std::invalid_argument if the element type is not numeric
*/
int toLongArray(PVScalarArray *pv, int offset, int length,
LongArray to, int toOffset);
std::size_t toLongArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length,
int64* to, std::size_t toOffset);
/**
* Convert a PV array to a ubyte array.
* @param pv a PV
* @param offset starting element in a PV
* @param length number of elements to transfer
* @param to where to put the PV data
* @param toOffset starting element in the array
* @return number of elements converted
* @throws std::invalid_argument if the element type is not numeric
*/
std::size_t toUByteArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length,
uint8* to, std::size_t toOffset);
/**
* Convert a PV array to a ushort array.
* @param pv a PV
* @param offset starting element in a PV
* @param length number of elements to transfer
* @param to where to put the PV data
* @param toOffset starting element in the array
* @return number of elements converted
* @throws std::invalid_argument if the element type is not numeric
*/
std::size_t toUShortArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length,
uint16* to, std::size_t toOffset);
/**
* Convert a PV array to an uint array.
* @param pv a PV
* @param offset starting element in a PV
* @param length number of elements to transfer
* @param to where to put the PV data
* @param toOffset starting element in the array
* @return number of elements converted
* @throws std::invalid_argument if the element type is not numeric
*/
std::size_t toUIntArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length,
uint32* to, std::size_t toOffset);
/**
* Convert a PV array to a ulong array.
* @param pv a PV
* @param offset starting element in a PV
* @param length number of elements to transfer
* @param to where to put the PV data
* @param toOffset starting element in the array
* @return number of elements converted
* @throws std::invalid_argument if the element type is not numeric
*/
std::size_t toULongArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length,
uint64* to, std::size_t toOffset);
/**
* Convert a PV array to a float array.
* @param pv a PV
@@ -391,8 +520,8 @@ public:
* @return number of elements converted
* @throws std::invalid_argument if the element type is not numeric
*/
int toFloatArray(PVScalarArray *pv, int offset, int length,
FloatArray to, int toOffset);
std::size_t toFloatArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length,
float* to, std::size_t toOffset);
/**
* Convert a PV array to a double array.
* @param pv a PV
@@ -403,8 +532,8 @@ public:
* @return number of elements converted
* @throws std::invalid_argument if the element type is not numeric
*/
int toDoubleArray(PVScalarArray *pv, int offset, int length,
DoubleArray to, int toOffset);
std::size_t toDoubleArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length,
double* to, std::size_t toOffset);
/**
* Convert a PV array from a byte array.
* @param pv a PV
@@ -415,8 +544,8 @@ public:
* @return number of elements converted
* @throws std::invalid_argument if the element type is not numeric
*/
int fromByteArray(PVScalarArray *pv, int offset, int length,
ByteArray from, int fromOffset);
std::size_t fromByteArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length,
int8* frim, std::size_t fromOffset);
/**
* Convert a PV array from a short array.
* @param pv a PV
@@ -427,8 +556,8 @@ public:
* @return number of elements converted
* @throws std::invalid_argument if the element type is not numeric
*/
int fromShortArray(PVScalarArray *pv, int offset, int length,
ShortArray from, int fromOffset);
std::size_t fromShortArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length,
int16* frim, std::size_t fromOffset);
/**
* Convert a PV array from an int array.
* @param pv a PV
@@ -439,8 +568,8 @@ public:
* @return number of elements converted
* @throws std::invalid_argument if the element type is not numeric
*/
int fromIntArray(PVScalarArray *pv, int offset, int length,
IntArray from, int fromOffset);
std::size_t fromIntArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length,
int32* frim, std::size_t fromOffset);
/**
* Convert a PV array from a long array.
* @param pv a PV
@@ -451,8 +580,56 @@ public:
* @return number of elements converted
* @throws std::invalid_argument if the element type is not numeric
*/
int fromLongArray(PVScalarArray *pv, int offset, int length,
LongArray from, int fromOffset);
std::size_t fromLongArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length,
int64* frim, std::size_t fromOffset);
/**
* Convert a PV array from a ubyte array.
* @param pv a PV
* @param offset starting element in a PV
* @param length number of elements to transfer
* @param from value to put into PV
* @param fromOffset
* @return number of elements converted
* @throws std::invalid_argument if the element type is not numeric
*/
std::size_t fromUByteArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length,
uint8* frim, std::size_t fromOffset);
/**
* Convert a PV array from a ushort array.
* @param pv a PV
* @param offset starting element in a PV
* @param length number of elements to transfer
* @param from value to put into PV
* @param fromOffset starting element in the source array
* @return number of elements converted
* @throws std::invalid_argument if the element type is not numeric
*/
std::size_t fromUShortArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length,
uint16* frim, std::size_t fromOffset);
/**
* Convert a PV array from an uint array.
* @param pv a PV
* @param offset starting element in a PV
* @param length number of elements to transfer
* @param from value to put into PV
* @param fromOffset starting element in the source array
* @return number of elements converted
* @throws std::invalid_argument if the element type is not numeric
*/
std::size_t fromUIntArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length,
uint32* frim, std::size_t fromOffset);
/**
* Convert a PV array from a ulong array.
* @param pv a PV
* @param offset starting element in a PV
* @param length number of elements to transfer
* @param from value to put into PV
* @param fromOffset starting element in the source array
* @return number of elements converted
* @throws std::invalid_argument if the element type is not numeric
*/
std::size_t fromULongArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length,
uint64* frim, std::size_t fromOffset);
/**
* Convert a PV array from a float array.
* @param pv a PV
@@ -463,8 +640,8 @@ public:
* @return number of elements converted
* @throws std::invalid_argument if the element type is not numeric
*/
int fromFloatArray(PVScalarArray *pv, int offset, int length,
FloatArray from, int fromOffset);
std::size_t fromFloatArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length,
float* frim, std::size_t fromOffset);
/**
* Convert a PV array from a double array.
* @param pv a PV
@@ -475,8 +652,8 @@ public:
* @return number of elements converted
* @throws std::invalid_argument if the element type is not numeric
*/
int fromDoubleArray(PVScalarArray *pv, int offset, int length,
DoubleArray from, int fromOffset);
std::size_t fromDoubleArray(PVScalarArrayPtr & pv, std::size_t offset, std::size_t length,
double* frim, std::size_t fromOffset);
/**
* Convenience method for implementing toString.
* It generates a newline and inserts blanks at the beginning of the newline.
@@ -484,9 +661,11 @@ public:
* @param indentLevel Indent level, Each level is four spaces.
*/
void newLine(StringBuilder buf, int indentLevel);
private:
Convert();
};
extern Convert * getConvert();
extern ConvertPtr getConvert();
}}
#endif /* CONVERT_H */
+266 -151
View File
@@ -8,13 +8,10 @@
#ifndef PVDATA_H
#define PVDATA_H
#include <string>
#include <map>
#include <stdexcept>
#include <pv/pvType.h>
#include <pv/pvIntrospect.h>
#include <pv/noDefaultMethods.h>
#include <pv/requester.h>
#include <pv/byteBuffer.h>
#include <pv/serialize.h>
namespace epics { namespace pvData {
class PVAuxInfo;
@@ -31,19 +28,39 @@ class PVStructureArray;
/**
* typedef for a pointer to a PVStructure.
*/
typedef PVStructure * PVStructurePtr;
typedef std::tr1::shared_ptr<PVStructure> PVStructurePtr;
/**
* typedef for a pointer to a array of pointer to PVStructure.
*/
typedef PVStructurePtr* PVStructurePtrArray;
typedef std::vector<PVStructurePtr> PVStructurePtrArray;
typedef std::vector<PVStructurePtr>::iterator PVStructurePtrArray_iterator;
typedef std::vector<PVStructurePtr>::const_iterator PVStructurePtrArray_const__iterator;
/**
* typedef for a pointer to a PVField.
*/
typedef PVField* PVFieldPtr;
typedef std::tr1::shared_ptr<PVField> PVFieldPtr;
/**
* typedef for a pointer to a PVScalar.
*/
typedef std::tr1::shared_ptr<PVScalar> PVScalarPtr;
/**
* typedef for a pointer to a PVScalarArray.
*/
typedef std::tr1::shared_ptr<PVScalarArray> PVScalarArrayPtr;
/**
* typedef for a pointer to a PVStructureArray.
*/
typedef std::tr1::shared_ptr<PVStructureArray> PVStructureArrayPtr;
/**
* typedef for a pointer to a array of pointer to PVField.
*/
typedef PVFieldPtr * PVFieldPtrArray;
typedef std::vector<PVFieldPtr> PVFieldPtrArray;
typedef std::vector<PVFieldPtr>::iterator PVFieldPtrArray_iterator;
typedef std::vector<PVFieldPtr>::const_iterator PVFieldPtrArray_const__iterator;
/**
* typedef for a pointer to a PVAuxInfo.
*/
typedef std::tr1::shared_ptr<PVAuxInfo> PVAuxInfoPtr;
/**
* This class provides auxillary information about a PVField.
@@ -52,6 +69,10 @@ typedef PVFieldPtr * PVFieldPtrArray;
*/
class PVAuxInfo : private NoDefaultMethods {
public:
typedef std::map<String,PVScalarPtr> PVInfoMap;
typedef std::map<String,PVScalarPtr>::iterator PVInfoIter;
typedef std::pair<String,PVScalarPtr> PVInfoPair;
/**
* Constructor
* @param The fields to which the Auxinfo is attached.
@@ -70,25 +91,20 @@ public:
* Add a new auxiliary item or retrieve the interface to an existing item.
*
* @param key The key.
* @param scalarType The scalrType for the new item being added/
* @param scalarType The scalarType for the new item being added/
* @return The new PVScalar that has been added to the Auxinfo.
*/
PVScalar * createInfo(String key,ScalarType scalarType);
/**
* Get the number of PVScalars in the Auxinfo.
* @return The number.
*/
int getNumberInfo();
PVScalarPtr createInfo(String key,ScalarType scalarType);
/**
* Get the Auxinfo with the specified key.
* @return The PVScalar or null if it does not exist.
*/
PVScalar * getInfo(String key);
PVScalarPtr & getInfo(String key);
/**
* Get the Auxinfo with the specified index.
* @return The PVScalar or null if it does not exist.
* Get the map for the info.
* @return The map;
*/
PVScalar * getInfo(int index);
PVInfoMap & getInfoMap();
/**
* Convert the Auxinfo to a string and add it to builder.
* @param builder The string builder.
@@ -101,10 +117,8 @@ public:
*/
void toString(StringBuilder buf,int indentLevel);
private:
PVField *pvField;
int lengthInfo;
int numberInfo;
PVScalar **pvInfos; // ptr to array of PVscalar *
PVField * pvField;
PVInfoMap pvInfos;
friend class PVDataCreate;
};
@@ -129,7 +143,7 @@ public:
*/
class PVField
: virtual public Serializable,
private NoDefaultMethods
public std::tr1::enable_shared_from_this<PVField>
{
public:
POINTER_DEFINITIONS(PVField);
@@ -143,6 +157,11 @@ public:
* @param messageType The message type.
*/
virtual void message(String message,MessageType messageType) ;
/**
* Get the fieldName for this field.
* @return The name or empty string if top level field.
*/
String getFieldName();
/**
* Register the message requester.
* At most one requester can be registered.
@@ -157,24 +176,24 @@ public:
* The other offsets are determined by recursively traversing each structure of the tree.
* @return The offset.
*/
int getFieldOffset() ;
std::size_t getFieldOffset() ;
/**
* Get the next offset. If the field is a scalar or array field then this is just offset + 1.
* If the field is a structure it is the offset of the next field after this structure.
* Thus (nextOffset - offset) is always equal to the number of fields within the field.
* @return The offset.
*/
int getNextFieldOffset() ;
std::size_t getNextFieldOffset() ;
/**
* Get the total number of fields in this field.
* This is equal to nextFieldOffset - fieldOffset.
*/
int getNumberFields() ;
std::size_t getNumberFields() ;
/**
* Get the PVAuxInfo interface for the PVField.
* @return The PVAuxInfo interface.
*/
PVAuxInfo * getPVAuxInfo();
PVAuxInfoPtr & getPVAuxInfo();
/**
* Is the field immutable, i.e. does it not allow changes.
* @return (false,true) if it (is not, is) immutable.
@@ -189,17 +208,22 @@ public:
* Get the <i>Field</i> that describes the field.
* @return Field, which is the reflection interface.
*/
FieldConstPtr getField() ;
FieldConstPtr & getField() ;
/**
* Get the parent of this field.
* @return The parent interface or null if this is PVRecord
*/
PVStructure * getParent() ;
/**
* Replace the data implementation for the field.
* @param newPVField The new implementation
*/
void replacePVField(PVFieldPtr& newPVField);
/**
* Rename the field name.
* @param newName The new name.
*/
bool renameField(String newName);
void renameField(String newName);
/**
* postPut. Called when the field is updated by the implementation.
*/
@@ -229,13 +253,23 @@ public:
*/
virtual void toString(StringBuilder buf,int indentLevel) ;
protected:
PVField(PVStructure *parent,FieldConstPtr field);
void setParent(PVStructure * parent);
PVField(FieldConstPtr field);
void setParent(PVStructure *parent);
void replaceField(FieldConstPtr &field);
private:
void message(String fieldName,String message,MessageType messageType);
class PVFieldPvt *pImpl;
static void computeOffset(PVField *pvField);
static void computeOffset(PVField *pvField,int offset);
static void computeOffset(PVField *pvField,std::size_t offset);
PVAuxInfoPtr pvAuxInfo;
String fieldName;
PVStructure *parent;
FieldConstPtr field;
size_t fieldOffset;
size_t nextFieldOffset;
bool immutable;
Requester *requester;
PostHandler *postHandler;
std::tr1::shared_ptr<class Convert> convert;
friend class PVDataCreate;
friend class PVStructure;
};
@@ -250,13 +284,15 @@ public:
* Destructor
*/
virtual ~PVScalar();
typedef PVScalar &reference;
typedef const PVScalar& const_reference;
/**
* Get the Scalar introspection interface for the PVScalar.
* @return the interface.
*/
ScalarConstPtr getScalar() ;
protected:
PVScalar(PVStructure *parent,ScalarConstPtr scalar);
PVScalar(ScalarConstPtr scalar);
};
/**
@@ -284,21 +320,37 @@ public:
*/
virtual void put(T value) = 0;
protected:
PVScalarValue(PVStructure *parent,ScalarConstPtr scalar)
: PVScalar(parent,scalar) {}
PVScalarValue(ScalarConstPtr scalar)
: PVScalar(scalar) {}
private:
friend class PVDataCreate;
};
/**
* typedefs for the various possible scalar types.
*/
typedef PVScalarValue<bool> PVBoolean;
typedef PVScalarValue<boolean> PVBoolean;
typedef PVScalarValue<int8> PVByte;
typedef PVScalarValue<int16> PVShort;
typedef PVScalarValue<int32> PVInt;
typedef PVScalarValue<int64> PVLong;
typedef PVScalarValue<uint8> PVUByte;
typedef PVScalarValue<uint16> PVUShort;
typedef PVScalarValue<uint32> PVUInt;
typedef PVScalarValue<uint64> PVULong;
typedef PVScalarValue<float> PVFloat;
typedef PVScalarValue<double> PVDouble;
typedef std::tr1::shared_ptr<PVBoolean> PVBooleanPtr;
typedef std::tr1::shared_ptr<PVByte> PVBytePtr;
typedef std::tr1::shared_ptr<PVShort> PVShortPtr;
typedef std::tr1::shared_ptr<PVInt> PVIntPtr;
typedef std::tr1::shared_ptr<PVLong> PVLongPtr;
typedef std::tr1::shared_ptr<PVUByte> PVUBytePtr;
typedef std::tr1::shared_ptr<PVUShort> PVUShortPtr;
typedef std::tr1::shared_ptr<PVUInt> PVUIntPtr;
typedef std::tr1::shared_ptr<PVULong> PVULongPtr;
typedef std::tr1::shared_ptr<PVFloat> PVFloatPtr;
typedef std::tr1::shared_ptr<PVDouble> PVDoublePtr;
/**
* PVString is special case, since it implements SerializableArray
@@ -310,9 +362,10 @@ public:
*/
virtual ~PVString() {}
protected:
PVString(PVStructure *parent,ScalarConstPtr scalar)
: PVScalarValue<String>(parent,scalar) {}
PVString(ScalarConstPtr & scalar)
: PVScalarValue<String>(scalar) {}
};
typedef std::tr1::shared_ptr<PVString> PVStringPtr;
/**
@@ -329,17 +382,17 @@ public:
* Get the array length.
* @return The length.
*/
int getLength() const;
std::size_t getLength() const;
/**
* Set the array length.
* @param The length.
*/
void setLength(int length);
void setLength(std::size_t length);
/**
* Get the array capacity.
* @return The capacity.
*/
int getCapacity() const;
std::size_t getCapacity() const;
/**
* Can the capacity be changed.
* @return (false,true) if (can not, can) be changed.
@@ -354,12 +407,13 @@ public:
* Set the array capacity.
* @param The capacity.
*/
virtual void setCapacity(int capacity) = 0;
virtual void setCapacity(std::size_t capacity) = 0;
protected:
PVArray(PVStructure *parent,FieldConstPtr field);
void setCapacityLength(int capacity,int length);
PVArray(FieldConstPtr field);
void setCapacityLength(std::size_t capacity,std::size_t length);
private:
class PVArrayPvt * pImpl;
friend class PVDataCreate;
};
/**
@@ -367,6 +421,8 @@ private:
*/
template<typename T>
class PVArrayData {
private:
std::vector<T> init;
public:
POINTER_DEFINITIONS(PVArrayData);
typedef T value_type;
@@ -375,11 +431,14 @@ public:
/**
* The data array.
*/
pointer data;
std::vector<T> & data;
/**
* The offset. This is the offset into the actual array of the first element in data,
*/
int offset;
std::size_t offset;
PVArrayData()
: data(init)
{}
};
@@ -393,6 +452,8 @@ public:
* Destructor
*/
virtual ~PVScalarArray();
typedef PVScalarArray &reference;
typedef const PVScalarArray& const_reference;
/**
* Get the introspection interface
* @return The interface.
@@ -400,8 +461,9 @@ public:
ScalarArrayConstPtr getScalarArray() ;
protected:
PVScalarArray(PVStructure *parent,ScalarArrayConstPtr scalarArray);
PVScalarArray(ScalarArrayConstPtr scalarArray);
private:
friend class PVDataCreate;
};
/**
@@ -412,43 +474,53 @@ typedef PVArrayData<PVStructurePtr> StructureArrayData;
/**
* Data class for a structureArray
*/
class PVStructureArray : public PVArray {
class PVStructureArray : public PVArray
{
public:
POINTER_DEFINITIONS(PVStructureArray);
typedef PVStructurePtr value_type;
typedef PVStructurePtr* pointer;
typedef const PVStructurePtr* const_pointer;
typedef PVArrayData<PVStructurePtr> ArrayDataType;
typedef std::vector<PVStructurePtr> vector;
typedef std::tr1::shared_ptr<vector> shared_vector;
typedef PVStructureArray &reference;
typedef const PVStructureArray& const_reference;
/**
* Destructor
*/
virtual ~PVStructureArray() {}
virtual void setCapacity(size_t capacity);
/**
* Get the introspection interface
* @return The interface.
*/
virtual StructureArrayConstPtr getStructureArray() = 0;
virtual StructureArrayConstPtr getStructureArray();
/**
* Append new elements to the end of the array.
* @param number The number of elements to add.
* @return the new length of the array.
*/
virtual int append(int number) = 0;
virtual std::size_t append(std::size_t number);
/**
* Remove elements from the array.
* @param offset The offset of the first element to remove.
* @param number The number of elements to remove.
* @return (false,true) if the elements were removed.
*/
virtual bool remove(int offset,int number) = 0;
virtual bool remove(std::size_t offset,std::size_t number);
/**
* Compress. This removes all null elements from the array.
*/
virtual void compress() = 0;
virtual void compress();
/**
* Get array elements
* @param offset The offset of the first element,
* @param length The number of elements to get.
* @param data The place where the data is placed.
*/
virtual int get(int offset, int length,
StructureArrayData *data) = 0;
virtual std::size_t get(std::size_t offset, std::size_t length,
StructureArrayData &data);
/**
* Put data into the array.
* @param offset The offset of the first element,
@@ -457,64 +529,82 @@ public:
* @param fromOffset The offset in from.
* @return The number of elements put into the array.
*/
virtual int put(int offset,int length,
PVStructurePtrArray from, int fromOffset) = 0;
virtual std::size_t put(std::size_t offset,std::size_t length,
pointer const from, std::size_t fromOffset);
/**
* Share data from another source.
* @param value The data to share.
* @param capacity The capacity of the array.
* @param length The length of the array.
*/
virtual void shareData( PVStructurePtrArray value,int capacity,int length) = 0;
virtual void shareData(
shared_vector const & value,
std::size_t capacity,
std::size_t length);
virtual void serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher) const;
virtual void deserialize(ByteBuffer *buffer,
DeserializableControl *pflusher);
virtual void serialize(ByteBuffer *pbuffer,
SerializableControl *pflusher, std::size_t offset, std::size_t count) const ;
virtual pointer get() { return &((*value.get())[0]); }
virtual pointer get() const { return &((*value.get())[0]); }
virtual vector const & getVector() {return *value;}
virtual shared_vector const & getSharedVector() {return value;}
protected:
PVStructureArray(PVStructure *parent, StructureArrayConstPtr structureArray)
: PVArray(parent,structureArray) {}
PVStructureArray( StructureArrayConstPtr structureArray);
private:
StructureArrayConstPtr structureArray;
shared_vector value;
friend class PVDataCreate;
};
class PVStructure : public PVField,public BitSetSerializable {
class PVStructure : public PVField, public BitSetSerializable
{
public:
POINTER_DEFINITIONS(PVStructure);
/**
* Destructor
*/
virtual ~PVStructure();
typedef PVStructure & reference;
typedef const PVStructure & const_reference;
/**
* Get the introspection interface
* @return The interface.
*/
StructureConstPtr getStructure();
StructureConstPtr & getStructure();
/**
* Get the array of pointers to the subfields in the structure.
* @return The array.
*/
PVFieldPtrArray getPVFields();
PVFieldPtrArray & getPVFields();
/**
* Get the subfield with the specified name.
* @param fieldName The name of the field.
* @return Pointer to the field or null if field does not exist.
*/
PVField *getSubField(String fieldName);
PVFieldPtr & getSubField(String fieldName);
/**
* Get the subfield with the specified offset.
* @param fieldOffset The offset.
* @return Pointer to the field or null if field does not exist.
*/
PVField *getSubField(int fieldOffset);
PVFieldPtr & getSubField(std::size_t fieldOffset);
/**
* Append a field to the structure.
* @param fieldName The name of the field to append.
* @param pvField The field to append.
*/
void appendPVField(PVField *pvField);
void appendPVField(String fieldName,PVFieldPtr & pvField);
/**
* Append fields to the structure.
* @param numberFields The number of fields.
* @param fieldNames The names of the fields to add.
* @param pvFields The fields to append.
* @return Pointer to the field or null if field does not exist.
*/
void appendPVFields(int numberFields,PVFieldPtrArray pvFields);
void appendPVFields(StringArray & fieldNames,PVFieldPtrArray & pvFields);
/**
* Remove a field from the structure.
* @param fieldName The name of the field to remove.
@@ -525,69 +615,93 @@ public:
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVBoolean *getBooleanField(String fieldName);
PVBooleanPtr getBooleanField(String fieldName);
/**
* Get a byte field with the specified name.
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVByte *getByteField(String fieldName);
PVBytePtr getByteField(String fieldName);
/**
* Get a short field with the specified name.
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVShort *getShortField(String fieldName);
PVShortPtr getShortField(String fieldName);
/**
* Get a int field with the specified name.
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVInt *getIntField(String fieldName);
PVIntPtr getIntField(String fieldName);
/**
* Get a long field with the specified name.
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVLong *getLongField(String fieldName);
PVLongPtr getLongField(String fieldName);
/**
* Get an unsigned byte field with the specified name.
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVUBytePtr getUByteField(String fieldName);
/**
* Get an unsigned short field with the specified name.
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVUShortPtr getUShortField(String fieldName);
/**
* Get an unsigned int field with the specified name.
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVUIntPtr getUIntField(String fieldName);
/**
* Get an unsigned long field with the specified name.
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVULongPtr getULongField(String fieldName);
/**
* Get a float field with the specified name.
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVFloat *getFloatField(String fieldName);
PVFloatPtr getFloatField(String fieldName);
/**
* Get a double field with the specified name.
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVDouble *getDoubleField(String fieldName);
PVDoublePtr getDoubleField(String fieldName);
/**
* Get a string field with the specified name.
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVString *getStringField(String fieldName);
PVStringPtr getStringField(String fieldName);
/**
* Get a structure field with the specified name.
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVStructure *getStructureField(String fieldName);
PVStructurePtr getStructureField(String fieldName);
/**
* Get a scalarArray field with the specified name.
* @param fieldName The name of the field to get.
* @param elementType The element type.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVScalarArray *getScalarArrayField(
PVScalarArrayPtr getScalarArrayField(
String fieldName,ScalarType elementType);
/**
* Get a structureArray field with the specified name.
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVStructureArray *getStructureArrayField(String fieldName);
PVStructureArrayPtr getStructureArrayField(String fieldName);
/**
* Get the name if this structure extends another structure.
* @return The string which may be null.
@@ -605,7 +719,7 @@ public:
* @param pflusher Interface to call when buffer is full.
*/
virtual void serialize(
ByteBuffer *pbuffer,SerializableControl *pflusher) const;
ByteBuffer *pbuffer,SerializableControl *pflusher) const ;
/**
* Deserialize
* @param pbuffer The byte buffer.
@@ -631,23 +745,20 @@ public:
DeserializableControl*pflusher,BitSet *pbitSet);
/**
* Constructor
* @param parent The parent structure.
* @param structure The introspection interface.
*/
PVStructure(PVStructure *parent,StructureConstPtr structure);
PVStructure(StructureConstPtr & structure);
/**
* Constructor
* @param parent The parent structure.
* @param structure The introspection interface.
* @param pvFields The array of fields for the structure.
*/
PVStructure(
PVStructure *parent,
StructureConstPtr structure,
PVFieldPtrArray pvFields);
PVStructure(StructureConstPtr structure,PVFieldPtrArray & pvFields);
private:
void setParentPvt(PVField *pvField,PVStructure *parent);
class PVStructurePvt * pImpl;
PVFieldPtrArray pvFields;
StructureConstPtr structurePtr;
String extendsStructureName;
friend class PVDataCreate;
};
template<typename T>
@@ -658,6 +769,10 @@ public:
typedef T* pointer;
typedef const T* const_pointer;
typedef PVArrayData<T> ArrayDataType;
typedef std::vector<T> vector;
typedef std::tr1::shared_ptr<vector> shared_vector;
typedef PVValueArray & reference;
typedef const PVValueArray & const_reference;
/**
* Destructor
@@ -669,7 +784,8 @@ public:
* @param length The number of elements to get.
* @param data The place where the data is placed.
*/
virtual int get(int offset, int length, ArrayDataType *data) = 0;
virtual std::size_t get(
std::size_t offset, std::size_t length, ArrayDataType &data) = 0;
/**
* Put data into the array.
* @param offset The offset of the first element,
@@ -678,170 +794,169 @@ public:
* @param fromOffset The offset in from.
* @return The number of elements put into the array.
*/
virtual int put(int offset,int length, pointer from, int fromOffset) = 0;
virtual std::size_t put(std::size_t offset,
std::size_t length, pointer const from, std::size_t fromOffset) = 0;
/**
* Share data from another source.
* @param value The data to share.
* @param capacity The capacity of the array.
* @param length The length of the array.
*/
virtual void shareData(pointer value,int capacity,int length) = 0;
virtual void shareData(
shared_vector const & value,
std::size_t capacity,
std::size_t length) = 0;
virtual pointer get() = 0;
virtual pointer get() const = 0;
virtual vector const & getVector() = 0;
virtual shared_vector const & getSharedVector() = 0;
protected:
PVValueArray(PVStructure *parent,ScalarArrayConstPtr scalar)
: PVScalarArray(parent,scalar) {}
private:
PVValueArray(ScalarArrayConstPtr scalar)
: PVScalarArray(scalar) {}
friend class PVDataCreate;
};
/**
* Definitions for the various scalarArray types.
*/
typedef PVArrayData<bool> BooleanArrayData;
typedef PVValueArray<bool> PVBooleanArray;
typedef PVArrayData<boolean> BooleanArrayData;
typedef PVValueArray<boolean> PVBooleanArray;
typedef std::tr1::shared_ptr<PVBooleanArray> PVBooleanArrayPtr;
typedef PVArrayData<int8> ByteArrayData;
typedef PVValueArray<int8> PVByteArray;
typedef std::tr1::shared_ptr<PVByteArray> PVByteArrayPtr;
typedef PVArrayData<int16> ShortArrayData;
typedef PVValueArray<int16> PVShortArray;
typedef std::tr1::shared_ptr<PVShortArray> PVShortArrayPtr;
typedef PVArrayData<int32> IntArrayData;
typedef PVValueArray<int32> PVIntArray;
typedef std::tr1::shared_ptr<PVIntArray> PVIntArrayPtr;
typedef PVArrayData<int64> LongArrayData;
typedef PVValueArray<int64> PVLongArray;
typedef std::tr1::shared_ptr<PVLongArray> PVLongArrayPtr;
typedef PVArrayData<uint8> UByteArrayData;
typedef PVValueArray<uint8> PVUByteArray;
typedef std::tr1::shared_ptr<PVUByteArray> PVUByteArrayPtr;
typedef PVArrayData<uint16> UShortArrayData;
typedef PVValueArray<uint16> PVUShortArray;
typedef std::tr1::shared_ptr<PVUShortArray> PVUShortArrayPtr;
typedef PVArrayData<uint32> UIntArrayData;
typedef PVValueArray<uint32> PVUIntArray;
typedef std::tr1::shared_ptr<PVUIntArray> PVUIntArrayPtr;
typedef PVArrayData<uint64> ULongArrayData;
typedef PVValueArray<uint64> PVULongArray;
typedef std::tr1::shared_ptr<PVULongArray> PVULongArrayPtr;
typedef PVArrayData<float> FloatArrayData;
typedef PVValueArray<float> PVFloatArray;
typedef std::tr1::shared_ptr<PVFloatArray> PVFloatArrayPtr;
typedef PVArrayData<double> DoubleArrayData;
typedef PVValueArray<double> PVDoubleArray;
typedef std::tr1::shared_ptr<PVDoubleArray> PVDoubleArrayPtr;
typedef PVArrayData<String> StringArrayData;
typedef PVValueArray<String> PVStringArray;
typedef std::tr1::shared_ptr<PVStringArray> PVStringArrayPtr;
class PVDataCreate;
typedef std::tr1::shared_ptr<PVDataCreate> PVDataCreatePtr;
/**
* This is a singlton class for creating data instances.
*/
class PVDataCreate {
public:
static PVDataCreatePtr getPVDataCreate();
/**
* Create a PVField using given Field introspection data.
* @param parent The parent interface.
* @param field The introspection data to be used to create PVField.
* @return The PVField implementation.
*/
PVField *createPVField(PVStructure *parent,
FieldConstPtr field);
PVFieldPtr createPVField(FieldConstPtr & field);
/**
* Create a PVField using given a PVField to clone.
* This method calls the appropriate createPVScalar, createPVArray, or createPVStructure.
* @param parent The parent interface.
* @param fieldToClone The field to clone.
* @return The PVField implementation
*/
PVField *createPVField(PVStructure *parent,
String fieldName,PVField * fieldToClone);
PVFieldPtr createPVField(PVFieldPtr & fieldToClone);
/**
* Create an implementation of a scalar field reusing the Scalar introspection interface.
* @param parent The parent.
* @param scalar The introspection interface.
* @return The PVScalar implementation.
*/
PVScalar *createPVScalar(PVStructure *parent,ScalarConstPtr scalar);
PVScalarPtr createPVScalar(ScalarConstPtr & scalar);
/**
* Create an implementation of a scalar field. A Scalar introspection interface is created.
* @param parent The parent interface.
* @param fieldName The field name.
* @param fieldType The field type.
* @return The PVScalar implementation.
*/
PVScalar *createPVScalar(PVStructure *parent,
String fieldName,ScalarType scalarType);
PVScalarPtr createPVScalar(ScalarType scalarType);
/**
* Create an implementation of a scalar field by cloning an existing PVScalar.
* The new PVScalar will have the same value and auxInfo as the original.
* @param parent The parent interface.
* @param fieldName The field name.
* @param scalarToClone The PVScalar to clone.
* @return The PVScalar implementation.
*/
PVScalar *createPVScalar(PVStructure *parent,
String fieldName,PVScalar * scalarToClone);
PVScalarPtr createPVScalar(PVScalarPtr & scalarToClone);
/**
* Create an implementation of an array field reusing the Array introspection interface.
* @param parent The parent interface.
* @param array The introspection interface.
* @return The PVScalarArray implementation.
*/
PVScalarArray *createPVScalarArray(PVStructure *parent,
ScalarArrayConstPtr scalarArray);
PVScalarArrayPtr createPVScalarArray(ScalarArrayConstPtr & scalarArray);
/**
* Create an implementation for an array field. An Array introspection interface is created.
* @param parent The parent interface.
* @param fieldName The field name.
* @param elementType The element type.
* @return The PVScalarArray implementation.
*/
PVScalarArray *createPVScalarArray(PVStructure *parent,
String fieldName,ScalarType elementType);
PVScalarArrayPtr createPVScalarArray(
ScalarType elementType);
/**
* Create an implementation of an array field by cloning an existing PVArray.
* The new PVArray will have the same value and auxInfo as the original.
* @param parent The parent interface.
* @param fieldName The field name.
* @param arrayToClone The PVScalarArray to clone.
* @return The PVScalarArray implementation.
*/
PVScalarArray *createPVScalarArray(PVStructure *parent,
String fieldName,PVScalarArray * scalarArrayToClone);
PVScalarArrayPtr createPVScalarArray(PVScalarArrayPtr & scalarArrayToClone);
/**
* Create an implementation of an array with structure elements.
* @param parent The parent interface.
* @param structureArray The introspection interface.
* All elements share the same introspection interface.
* @return The PVStructureArray implementation.
*/
PVStructureArray *createPVStructureArray(PVStructure *parent,
StructureArrayConstPtr structureArray);
PVStructureArrayPtr createPVStructureArray(StructureArrayConstPtr & structureArray);
/**
* Create implementation for PVStructure.
* @param parent The parent interface.
* @param structure The introspection interface.
* @return The PVStructure implementation
*/
PVStructure *createPVStructure(PVStructure *parent,
StructureConstPtr structure);
PVStructurePtr createPVStructure(StructureConstPtr & structure);
/**
* Create implementation for PVStructure.
* @param parent The parent interface.
* @param fieldName The field name.
* @param fields Array of reflection interfaces for the subFields.
* @return The PVStructure implementation
*/
PVStructure *createPVStructure(PVStructure *parent,
String fieldName,int numberFields,FieldConstPtrArray fields);
/**
* Create implementation for PVStructure.
* @param parent The parent interface.
* @param fieldName The field name.
* @param fieldNames The field names.
* @param pvFields Array of PVFields
* @return The PVStructure implementation
*/
PVStructure *createPVStructure(PVStructure *parent,
String fieldName,int numberFields,PVFieldPtrArray pvFields);
PVStructurePtr createPVStructure(
StringArray & fieldNames,PVFieldPtrArray & pvFields);
/**
* Create implementation for PVStructure.
* @param parent The parent interface.
* @param fieldName The field name.
* @param structToClone A structure. Each subfield and any auxInfo is cloned and added to the newly created structure.
* @return The PVStructure implementation.
*/
PVStructure *createPVStructure(PVStructure *parent,
String fieldName,PVStructure *structToClone);
protected:
PVStructurePtr createPVStructure(PVStructurePtr & structToClone);
private:
PVDataCreate();
friend PVDataCreate * getPVDataCreate();
};
/**
@@ -849,7 +964,7 @@ protected:
* @param The PVDataCreate factory.
*/
extern PVDataCreate * getPVDataCreate();
extern PVDataCreatePtr getPVDataCreate();
}}
#endif /* PVDATA_H */
+98 -68
View File
@@ -31,7 +31,7 @@ typedef std::tr1::shared_ptr<const Field> FieldConstPtr;
/**
* typedef for an array of shared pointer to an immutable Field.
*/
typedef FieldConstPtr * FieldConstPtrArray;
typedef std::vector<FieldConstPtr> FieldConstPtrArray;
/**
* typedef for a shared pointer to an immutable Scalar.
*/
@@ -113,6 +113,22 @@ enum ScalarType {
* The type is long, i. e. a 64 bit signed integer.
*/
pvLong,
/**
* The type is unsigned byte, i. e. a 8 bit unsigned integer.
*/
pvUByte,
/**
* The type is unsigned short, i. e. a 16 bit unsigned integer.
*/
pvUShort,
/**
* The type is unsigned int, i. e. a 32 bit unsigned integer.
*/
pvUInt,
/**
* The type is unsigned long, i. e. a 64 bit unsigned integer.
*/
pvULong,
/**
* The type is float, i. e. 32 bit IEEE floating point,
*/
@@ -132,11 +148,17 @@ enum ScalarType {
*/
namespace ScalarTypeFunc {
/**
* Is the type an integer, i. e. is it one of byte,...long
* Is the type an integer, i. e. is it one of byte,...ulong
* @param scalarType The type.
* @return (false,true) if the scalarType is an integer.
*/
bool isInteger(ScalarType scalarType);
/**
* Is the type an unsigned integer, i. e. is it one of ubyte,...ulong
* @param scalarType The type.
* @return (false,true) if the scalarType is an integer.
*/
bool isUInteger(ScalarType scalarType);
/**
* Is the type numeric, i. e. is it one of byte,...,double
* @param scalarType The type.
@@ -182,11 +204,6 @@ public:
* Destructor.
*/
virtual ~Field();
/**
* Get the name of the field.
* @return The field name.
*/
String getFieldName() const{return m_fieldName;}
/**
* Get the field type.
* @return The type.
@@ -203,21 +220,13 @@ public:
* @param indentLevel The number of blanks at the beginning of new lines.
*/
virtual void toString(StringBuilder builder,int indentLevel) const;
/**
* Rename the field.
* @param newName The new name.
* This MUST not be called after the field is put into use!!!
*/
void renameField(String newName);
protected:
/**
* Constructor
* @param fieldName The field name.
* @param fieldName The field type.
*/
Field(String fieldName,Type type);
Field(Type type);
private:
String m_fieldName;
Type m_fieldType;
friend class StructureArray;
@@ -264,7 +273,7 @@ public:
virtual void deserialize(ByteBuffer *buffer, DeserializableControl *flusher);
protected:
Scalar(String fieldName,ScalarType scalarType);
Scalar(ScalarType scalarType);
private:
ScalarType scalarType;
friend class FieldCreate;
@@ -276,10 +285,14 @@ private:
class ScalarArray : public Field{
public:
POINTER_DEFINITIONS(ScalarArray);
ScalarArray(String fieldName,ScalarType scalarType);
typedef ScalarArray& reference;
typedef const ScalarArray& const_reference;
/**
* Constructor
* @param scalarType The scalarType for the field.
*/
ScalarArray(ScalarType scalarType);
/**
* Get the scalarType for the elements.
* @return the scalarType
@@ -339,10 +352,9 @@ public:
protected:
/**
* Constructor.
* @param fieldName The name for the field.
* @param structure The introspection interface for the elements.
*/
StructureArray(String fieldName,StructureConstPtr structure);
StructureArray(StructureConstPtr structure);
/**
* Destructor.
*/
@@ -369,41 +381,45 @@ public:
* Get the number of immediate subfields in the structure/
* @return The number of fields.
*/
int getNumberFields() const {return numberFields;}
std::size_t getNumberFields() const {return fieldNames.size();}
/**
* Get the field for the specified fieldName.
* @param fieldName The name of the field to get;
* @return The introspection interface.
* This will hold a null pointer if the field is not in the structure.
*/
FieldConstPtr getField(String fieldName) const;
/**
* Get the field for the specified fieldName.
* @param fieldName The index of the field to get;
* @return The introspection interface.
* This will hold a null pointer if the field is not in the structure.
*/
FieldConstPtr getField(std::size_t index) {return fields[index];}
/**
* Get the field index for the specified fieldName.
* @return The introspection interface.
* This will be -1 if the field is not in the structure.
*/
int getFieldIndex(String fieldName) const;
std::size_t getFieldIndex(String fieldName) const;
/**
* Get the fields in the structure.
* @return The array of fields.
*/
FieldConstPtrArray getFields() const {return fields;}
FieldConstPtrArray const & getFields() const {return fields;}
/**
* Append a field to the structure.
* @param field The field to append.
* Get the names of the fields in the structure.
* @return The array of fieldNames.
*/
void appendField(FieldConstPtr field);
StringArray const & getFieldNames() const {return fieldNames;}
void renameField(std::size_t fieldIndex,String newName)
{fieldNames[fieldIndex] = newName;}
/**
* Append an array of fields to the structure.
* @param field The fields to append.
* The array MUST be allocated on the heap.
* The structure takes ownership of the field array.
* Get the name of the field with the specified index;
* @param fieldIndex The index of the desired field.
* @return The fieldName.
*/
void appendFields(int numberFields,FieldConstPtrArray fields);
/**
* Remove a field from the structure.
* @param field The field to remove.
*/
void removeField(int index);
String getFieldName(std::size_t fieldIndex){return fieldNames[fieldIndex];}
/**
* Convert the structure to a string and add it to builder.
* @param builder The string builder.
@@ -420,76 +436,90 @@ public:
virtual void deserialize(ByteBuffer *buffer, DeserializableControl *flusher);
protected:
Structure(String fieldName, int numberFields,FieldConstPtrArray fields);
Structure(StringArray fieldNames,FieldConstPtrArray fields);
private:
int numberFields;
FieldConstPtrArray fields;
void toStringCommon(StringBuilder buf,int indentLevel) const;
StringArray fieldNames;
FieldConstPtrArray fields;
friend class FieldCreate;
};
/**
* This is a singlton class for creating introspection interfaces.
*/
class FieldCreate : NoDefaultMethods {
class FieldCreate;
typedef std::tr1::shared_ptr<FieldCreate> FieldCreatePtr;
class FieldCreate {
public:
/**
* Create a new Field like an existing field but with a different name.
* @param fieldName The field name.
* @param field An existing field
* @return a {@code Field} interface for the newly created object.
*/
FieldConstPtr create(String fieldName,FieldConstPtr field) const;
static FieldCreatePtr getFieldCreate();
/**
* Create a {@code ScalarField}.
* @param fieldName The field name.
* @param scalarType The scalar type.
* @return a {@code Scalar} interface for the newly created object.
* @throws An {@code IllegalArgumentException} if an illegal type is specified.
*/
ScalarConstPtr createScalar(String fieldName,ScalarType scalarType) const;
ScalarConstPtr createScalar(ScalarType scalarType) const;
/**
* Create an {@code Array} field.
* @param fieldName The field name
* @param elementType The {@code scalarType} for array elements
* @return An {@code Array} Interface for the newly created object.
*/
ScalarArrayConstPtr createScalarArray(String fieldName,
ScalarType elementType) const;
ScalarArrayConstPtr createScalarArray(ScalarType elementType) const;
/**
* Create an {@code Array} field that is has element type <i>Structure</i>
* @param fieldName The field name
* @param elementStructure The {@code Structure} for each array element.
* @return An {@code Array} Interface for the newly created object.
*/
StructureConstPtr createStructure (String fieldName,
int numberFields,FieldConstPtrArray fields) const;
StructureArrayConstPtr createStructureArray(StructureConstPtr structure) const;
/**
* Create a {@code Structure} field.
* @param fieldName The field name
* @param fields The array of {@code Field}s for the structure.
* @param fieldNames The array of {@code fieldNames} for the structure
* @param fields The array of {@code fields} for the structure.
* @return a {@code Structure} interface for the newly created object.
*/
StructureArrayConstPtr createStructureArray(String fieldName,
StructureConstPtr structure) const;
/**
* Deserialize {@code Field} instance from given byte buffer.
* @param buffer Buffer containing serialized {@code Field} instance.
* @param control Deserialization control instance.
* @return a deserialized {@code Field} instance.
*/
FieldConstPtr deserialize(ByteBuffer* buffer, DeserializableControl* control) const;
StructureConstPtr createStructure (
StringArray const & fieldNames,
FieldConstPtrArray const & fields) const;
/**
* Append a field to a structure.
* @param structure The structure to which the field is appended.
* @param fieldName The name of the field.
* @param field The field.
* @return a {@code Structure} interface for the newly created object.
*/
StructureConstPtr appendField(
StructureConstPtr structure,
String fieldName, FieldConstPtr field) const;
/**
* Append fields to a structure.
* @param structure The structure to which the fields appended.
* @param fieldName The names of the fields.
* @param field The fields.
* @return a {@code Structure} interface for the newly created object.
*/
StructureConstPtr appendFields(
StructureConstPtr structure,
StringArray const & fieldNames,
FieldConstPtrArray const & fields) const;
/**
* Deserialize {@code Field} instance from given byte buffer.
* @param buffer Buffer containing serialized {@code Field} instance.
* @param control Deserialization control instance.
* @return a deserialized {@code Field} instance.
*/
FieldConstPtr deserialize(ByteBuffer* buffer, DeserializableControl* control) const;
private:
FieldCreate();
friend FieldCreate * getFieldCreate();
};
/**
* Get the single class that implemnents FieldCreate,
* @param The fieldCreate factory.
*/
extern FieldCreate * getFieldCreate();
extern FieldCreatePtr getFieldCreate();
}}
#endif /* PVINTROSPECT_H */
+110 -10
View File
@@ -13,6 +13,7 @@
#ifndef PVTYPE_H
#define PVTYPE_H
#include <string>
#include <vector>
#include <stdint.h>
namespace epics { namespace pvData {
@@ -24,7 +25,7 @@ namespace epics { namespace pvData {
/**
* boolean, i.e. can only have the values {@code false} or {@code true}
*/
typedef bool boolean;
typedef uint8_t boolean;
/**
* A 8 bit signed integer
*/
@@ -41,6 +42,14 @@ typedef int32_t int32;
* A 64 bit signed integer
*/
typedef int64_t int64;
/**
* A 8 bit unsigned integer
*/
typedef uint8_t uint8;
/**
* A 16 bit unsigned integer
*/
typedef uint16_t uint16;
/**
* A 32 bit unsigned integer
*/
@@ -60,40 +69,131 @@ typedef std::string String;
/**
* A boolean array.
*/
typedef bool * BooleanArray;
typedef std::vector<boolean> BooleanArray;
// get will be the same as for UByte
/*
inline boolean * get(BooleanArray value)
{
return const_cast<boolean *>(&value[0]);
}
*/
typedef std::vector<uint8>::iterator BooleanArray_iterator;
typedef std::vector<uint8>::const_iterator BooleanArray_const_iterator;
/**
* A byte array.
*/
typedef int8 * ByteArray;
typedef std::vector<int8> ByteArray;
inline int8 * get(ByteArray value)
{
return const_cast<int8 *>(&value[0]);
}
typedef std::vector<int8>::iterator ByteArray_iterator;
typedef std::vector<int8>::const_iterator ByteArray_const_iterator;
/**
* A short array.
*/
typedef int16 * ShortArray;
typedef std::vector<int16> ShortArray;
inline int16 * get(ShortArray value)
{
return const_cast<int16 *>(&value[0]);
}
typedef std::vector<int16>::iterator ShortArray_iterator;
typedef std::vector<int16>::const_iterator ShortArray_const_iterator;
/**
* A int array.
*/
typedef int32 * IntArray;
typedef std::vector<int32> IntArray;
inline int32 * get(IntArray value)
{
return const_cast<int32 *>(&value[0]);
}
typedef std::vector<int32>::iterator IntArray_iterator;
typedef std::vector<int32>::const_iterator IntArray_const_iterator;
/**
* A long array.
*/
typedef int64 * LongArray;
typedef std::vector<int64> LongArray;
inline int64 * get(LongArray value)
{
return const_cast<int64 *>(&value[0]);
}
typedef std::vector<int64>::iterator LongArray_iterator;
typedef std::vector<int64>::const_iterator LongArray_const_iterator;
/**
* An unsigned byte array.
*/
typedef std::vector<uint8> UByteArray;
inline uint8 * get(UByteArray value)
{
return const_cast<uint8 *>(&value[0]);
}
typedef std::vector<uint8>::iterator UByteArray_iterator;
typedef std::vector<uint8>::const_iterator UByteArray_const_iterator;
/**
* An unsigned short array.
*/
typedef std::vector<uint16> UShortArray;
inline uint16 * get(UShortArray value)
{
return const_cast<uint16 *>(&value[0]);
}
typedef std::vector<uint16>::iterator UShortArray_iterator;
typedef std::vector<uint16>::const_iterator UShortArray_const_iterator;
/**
* An unsigned int array.
*/
typedef std::vector<uint32> UIntArray;
inline uint32 * get(UIntArray value)
{
return const_cast<uint32 *>(&value[0]);
}
typedef std::vector<uint32>::iterator UIntArray_iterator;
typedef std::vector<uint32>::const_iterator UIntArray_const_iterator;
/**
* An unsigned long array.
*/
typedef std::vector<uint64> ULongArray;
inline uint64 * get(ULongArray value)
{
return const_cast<uint64 *>(&value[0]);
}
typedef std::vector<uint64>::iterator ULongArray_iterator;
typedef std::vector<uint64>::const_iterator ULongArray_const_iterator;
/**
* A float array.
*/
typedef float * FloatArray;
typedef std::vector<float> FloatArray;
inline float * get(FloatArray value)
{
return const_cast<float *>(&value[0]);
}
typedef std::vector<float>::iterator FloatArray_iterator;
typedef std::vector<float>::const_iterator FloatArray_const_iterator;
/**
* A double array.
*/
typedef double * DoubleArray;
typedef std::vector<double> DoubleArray;
inline double * get(DoubleArray value)
{
return const_cast<double *>(&value[0]);
}
typedef std::vector<double>::iterator DoubleArray_iterator;
typedef std::vector<double>::const_iterator DoubleArray_const_iterator;
/**
* A string array.
*/
typedef String* StringArray;
typedef std::vector<String> StringArray;
inline String * get(StringArray value)
{
return const_cast<String *>(&value[0]);
}
typedef std::vector<String>::iterator StringArray_iterator;
typedef std::vector<String>::const_iterator StringArray_const_iterator;
/**
* A convenience definition for toString methods
*/
typedef std::string * StringBuilder;
typedef String * StringBuilder;
}}
#endif /* PVTYPE_H */
+12 -31
View File
@@ -48,37 +48,18 @@ namespace epics { namespace pvData {
* }
*/
class StandardField : private NoDefaultMethods {
class StandardField;
typedef std::tr1::shared_ptr<StandardField> StandardFieldPtr;
class StandardField {
public:
StandardField();
static StandardFieldPtr getStandardField();
~StandardField();
ScalarConstPtr scalar(String fieldName,ScalarType type);
StructureConstPtr scalar(String fieldName,
ScalarType type,String properties);
ScalarArrayConstPtr scalarArray(String fieldName,
ScalarType elementType);
StructureConstPtr scalarArray(String fieldName,
ScalarType elementType, String properties);
StructureArrayConstPtr structureArray(String fieldName,
StructureConstPtr structure);
StructureConstPtr structureArray(String fieldName,
StructureConstPtr structure,String properties);
StructureConstPtr structure(String fieldName,
int numFields,FieldConstPtrArray fields);
StructureConstPtr enumerated(String fieldName);
StructureConstPtr enumerated(String fieldName, String properties);
ScalarConstPtr scalarValue(ScalarType type);
StructureConstPtr scalarValue(ScalarType type,String properties);
ScalarArrayConstPtr scalarArrayValue(ScalarType elementType);
StructureConstPtr scalarArrayValue(ScalarType elementType,
String properties);
StructureArrayConstPtr structureArrayValue(StructureConstPtr structure);
StructureConstPtr structureArrayValue(StructureConstPtr structure,
String properties);
StructureConstPtr structureValue(
int numFields,FieldConstPtrArray fields);
StructureConstPtr enumeratedValue();
StructureConstPtr enumeratedValue(String properties);
StructureConstPtr scalar(ScalarType type,String properties);
StructureConstPtr scalarArray(ScalarType elementType, String properties);
StructureConstPtr structureArray(StructureConstPtr & structure,String properties);
StructureConstPtr enumerated();
StructureConstPtr enumerated(String properties);
StructureConstPtr alarm();
StructureConstPtr timeStamp();
StructureConstPtr display();
@@ -92,10 +73,10 @@ public:
StructureConstPtr doubleAlarm();
StructureConstPtr enumeratedAlarm();
private:
static void init();
StandardField();
};
extern StandardField * getStandardField();
extern StandardFieldPtr getStandardField();
}}
#endif /* STANDARDFIELD_H */
+12 -45
View File
@@ -25,56 +25,23 @@ namespace epics { namespace pvData {
* }
*/
class StandardPVField;
typedef std::tr1::shared_ptr<StandardPVField> StandardPVFieldPtr;
class StandardPVField : private NoDefaultMethods {
public:
StandardPVField();
static StandardPVFieldPtr getStandardPVField();
~StandardPVField();
PVScalar * scalar(PVStructure *parent,String fieldName,ScalarType type);
PVStructure * scalar(PVStructure *parent,
String fieldName,ScalarType type,String properties);
PVScalarArray * scalarArray(PVStructure *parent,
String fieldName,ScalarType elementType);
PVStructure * scalarArray(PVStructure *parent,
String fieldName,ScalarType elementType, String properties);
PVStructureArray * structureArray(PVStructure *parent,
String fieldName,StructureConstPtr structure);
PVStructure* structureArray(PVStructure *parent,
String fieldName,StructureConstPtr structure,String properties);
PVStructure * enumerated(PVStructure *parent,
String fieldName,StringArray choices, int number);
PVStructure * enumerated(PVStructure *parent,
String fieldName,StringArray choices, int number, String properties);
PVScalar * scalarValue(PVStructure *parent,ScalarType type);
PVStructure * scalarValue(PVStructure *parent,
ScalarType type,String properties);
PVScalarArray * scalarArrayValue(
PVStructure *parent,ScalarType elementType);
PVStructure * scalarArrayValue(PVStructure *parent,
ScalarType elementType, String properties);
PVStructureArray * structureArrayValue(PVStructure *parent,
StructureConstPtr structure);
PVStructure * structureArrayValue(PVStructure *parent,
StructureConstPtr structure,String properties);
PVStructure * enumeratedValue(
PVStructure *parent,StringArray choices,int number);
PVStructure * enumeratedValue(PVStructure *parent,
StringArray choices,int number, String properties);
PVStructure * alarm(PVStructure *parent);
PVStructure * timeStamp(PVStructure *parent);
PVStructure * display(PVStructure *parent);
PVStructure * control(PVStructure *parent);
PVStructure * booleanAlarm(PVStructure *parent);
PVStructure * byteAlarm(PVStructure *parent);
PVStructure * shortAlarm(PVStructure *parent);
PVStructure * intAlarm(PVStructure *parent);
PVStructure * longAlarm(PVStructure *parent);
PVStructure * floatAlarm(PVStructure *parent);
PVStructure * doubleAlarm(PVStructure *parent);
PVStructure * enumeratedAlarm(PVStructure *parent);
PVStructure * powerSupply(PVStructure *parent);
PVStructurePtr scalar(ScalarType type,String properties);
PVStructurePtr scalarArray(ScalarType elementType, String properties);
PVStructurePtr structureArray(StructureConstPtr structure,String properties);
PVStructurePtr enumerated(StringArray choices);
PVStructurePtr enumerated(StringArray choices, String properties);
private:
StandardPVField();
};
extern StandardPVField * getStandardPVField();
extern StandardPVFieldPtr getStandardPVField();
}}
#endif /* STANDARDPVFIELD_H */
+2 -2
View File
@@ -28,7 +28,7 @@ static bool checkBitSetPVField(
}
PVStructure *pvStructure = static_cast<PVStructure *>(pvField);
while(offset<initialOffset + nbits) {
PVField *pvSubField = pvStructure->getSubField(offset);
PVField *pvSubField = pvStructure->getSubField(offset).get();
int nbitsNow = pvSubField->getNumberFields();
if(nbitsNow==1) {
if(bitSet->get(offset)) {
@@ -44,7 +44,7 @@ static bool checkBitSetPVField(
pvSubStructure->getPVFields();
int num = pvSubStructure->getStructure()->getNumberFields();
for(int i=0; i<num; i++) {
PVField *pvSubSubField = pvSubStructureFields[i];
PVField *pvSubSubField = pvSubStructureFields[i].get();
bool result = checkBitSetPVField(pvSubSubField,bitSet,offset);
if(result) {
atLeastOneBitSet = true;
+17 -18
View File
@@ -3,10 +3,10 @@
There is a logic_error
On line 68 of ../testBaseException.cpp
../bin/linux-x86/testBaseException[0x80497b9]
../bin/linux-x86/testBaseException[0x8049a54]
/lib/libc.so.6(__libc_start_main+0xe6)[0x126e36]
../bin/linux-x86/testBaseException[0x80490e1]
../bin/linux-x86_64/testBaseException[0x401cdb]
../bin/linux-x86_64/testBaseException[0x4016d4]
/lib64/libc.so.6(__libc_start_main+0xed)[0x366dc2169d]
../bin/linux-x86_64/testBaseException[0x40172d]
To translate run 'addr2line -e execname 0xXXXXXXX ...'
Note: Must be compiled with debug symbols
@@ -14,20 +14,19 @@ To translate run 'addr2line -e execname 0xXXXXXXX ...'
There is another logic_error
On line 75 of ../testBaseException.cpp
../bin/linux-x86/testBaseException() [0x8049cec]
../bin/linux-x86/testBaseException() [0x8049923]
../bin/linux-x86/testBaseException() [0x8049a54]
/lib/libc.so.6(__libc_start_main+0xe6) [0x126e36]
../bin/linux-x86/testBaseException() [0x80490e1]
../bin/linux-x86_64/testBaseException() [0x401e99]
../bin/linux-x86_64/testBaseException() [0x4016d4]
/lib64/libc.so.6(__libc_start_main+0xed) [0x366dc2169d]
../bin/linux-x86_64/testBaseException() [0x40172d]
testBaseException...
all is OK
On line 48 of ../testBaseException.cpp
../bin/linux-x86/testBaseException() [0x8049581]
../bin/linux-x86/testBaseException() [0x8049a5c]
/lib/libc.so.6(__libc_start_main+0xe6) [0x126e36]
../bin/linux-x86/testBaseException() [0x80490e1]
../bin/linux-x86_64/testBaseException() [0x401a79]
../bin/linux-x86_64/testBaseException() [0x4016dc]
/lib64/libc.so.6(__libc_start_main+0xed) [0x366dc2169d]
../bin/linux-x86_64/testBaseException() [0x40172d]
@@ -35,11 +34,11 @@ On line 48 of ../testBaseException.cpp
exception 2
On line 57 of ../testBaseException.cpp
../bin/linux-x86/testBaseException() [0x80491ec]
../bin/linux-x86/testBaseException() [0x80496f9]
../bin/linux-x86/testBaseException() [0x8049a5c]
/lib/libc.so.6(__libc_start_main+0xe6) [0x126e36]
../bin/linux-x86/testBaseException() [0x80490e1]
../bin/linux-x86_64/testBaseException() [0x40184c]
../bin/linux-x86_64/testBaseException() [0x401c30]
../bin/linux-x86_64/testBaseException() [0x4016dc]
/lib64/libc.so.6(__libc_start_main+0xed) [0x366dc2169d]
../bin/linux-x86_64/testBaseException() [0x40172d]
+20 -21
View File
@@ -1,15 +1,15 @@
--- testBaseExceptionGold 2011-04-27 13:11:55.000000000 -0400
+++ testBaseException 2011-12-12 08:58:22.000000000 -0500
@@ -1,37 +1,46 @@
--- testBaseExceptionGold 2012-01-21 13:09:44.864000461 -0500
+++ testBaseException 2012-04-03 13:59:48.689551975 -0400
@@ -1,37 +1,45 @@
+
+
+There is a logic_error
+
+On line 68 of ../testBaseException.cpp
+../bin/linux-x86/testBaseException[0x80497b9]
+../bin/linux-x86/testBaseException[0x8049a54]
+/lib/libc.so.6(__libc_start_main+0xe6)[0x126e36]
+../bin/linux-x86/testBaseException[0x80490e1]
+../bin/linux-x86_64/testBaseException[0x401cdb]
+../bin/linux-x86_64/testBaseException[0x4016d4]
+/lib64/libc.so.6(__libc_start_main+0xed)[0x366dc2169d]
+../bin/linux-x86_64/testBaseException[0x40172d]
+To translate run 'addr2line -e execname 0xXXXXXXX ...'
+ Note: Must be compiled with debug symbols
+
@@ -17,11 +17,10 @@
+There is another logic_error
+
+On line 75 of ../testBaseException.cpp
+../bin/linux-x86/testBaseException() [0x8049cec]
+../bin/linux-x86/testBaseException() [0x8049923]
+../bin/linux-x86/testBaseException() [0x8049a54]
+/lib/libc.so.6(__libc_start_main+0xe6) [0x126e36]
+../bin/linux-x86/testBaseException() [0x80490e1]
+../bin/linux-x86_64/testBaseException() [0x401e99]
+../bin/linux-x86_64/testBaseException() [0x4016d4]
+/lib64/libc.so.6(__libc_start_main+0xed) [0x366dc2169d]
+../bin/linux-x86_64/testBaseException() [0x40172d]
+
testBaseException...
@@ -32,10 +31,10 @@
- /lib/libc.so.6: __libc_start_main()+0xe6
- ../bin/linux-x86/testBaseException
+On line 48 of ../testBaseException.cpp
+../bin/linux-x86/testBaseException() [0x8049581]
+../bin/linux-x86/testBaseException() [0x8049a5c]
+/lib/libc.so.6(__libc_start_main+0xe6) [0x126e36]
+../bin/linux-x86/testBaseException() [0x80490e1]
+../bin/linux-x86_64/testBaseException() [0x401a79]
+../bin/linux-x86_64/testBaseException() [0x4016dc]
+/lib64/libc.so.6(__libc_start_main+0xed) [0x366dc2169d]
+../bin/linux-x86_64/testBaseException() [0x40172d]
+
@@ -64,11 +63,11 @@
- /lib/libc.so.6: __libc_start_main()+0xe6
- ../bin/linux-x86/testBaseException
+On line 57 of ../testBaseException.cpp
+../bin/linux-x86/testBaseException() [0x80491ec]
+../bin/linux-x86/testBaseException() [0x80496f9]
+../bin/linux-x86/testBaseException() [0x8049a5c]
+/lib/libc.so.6(__libc_start_main+0xe6) [0x126e36]
+../bin/linux-x86/testBaseException() [0x80490e1]
+../bin/linux-x86_64/testBaseException() [0x40184c]
+../bin/linux-x86_64/testBaseException() [0x401c30]
+../bin/linux-x86_64/testBaseException() [0x4016dc]
+/lib64/libc.so.6(__libc_start_main+0xed) [0x366dc2169d]
+../bin/linux-x86_64/testBaseException() [0x40172d]
+
+12 -12
View File
@@ -1,20 +1,20 @@
Time test
diff 22.467672 milliSeconds
time per iteration 22.467672 microseconds
time per addTail/removeHead 0.011234 microseconds
diff 11.656314 milliSeconds
time per iteration 11.656314 microseconds
time per addTail/removeHead 0.005828 microseconds
Time test locked
diff 203.349351 milliSeconds
time per iteration 203.349351 microseconds
time per addTail/removeHead 0.101675 microseconds
diff 65.416815 milliSeconds
time per iteration 65.416815 microseconds
time per addTail/removeHead 0.032708 microseconds
Time std::list test
diff 628.939624 milliSeconds
time per iteration 628.939624 microseconds
time per addTail/removeHead 0.314470 microseconds
diff 710.298088 milliSeconds
time per iteration 710.298088 microseconds
time per addTail/removeHead 0.355149 microseconds
Time std::list test locked
diff 780.516186 milliSeconds
time per iteration 780.516186 microseconds
time per addTail/removeHead 0.390258 microseconds
diff 779.708944 milliSeconds
time per iteration 779.708944 microseconds
time per addTail/removeHead 0.389854 microseconds
+1 -1
View File
@@ -1 +1 @@
2011.12.12 08:58:27 851342349 nanoSeconds isDst false userTag 32
2012.04.03 13:59:53 794513188 nanoSeconds isDst true userTag 32
+1 -1
View File
@@ -1 +1 @@
time per call 39.476176 microseconds
time per call 8.641072 microseconds
+4 -4
View File
@@ -1,5 +1,5 @@
current 1323698306 842810605 milliSec 1323698306842
2011.12.12 08:58:26 842810605 nanoSeconds isDst false
current 1333475992 901534689 milliSec 1333475992901
2012.04.03 13:59:52 901534689 nanoSeconds isDst true
fromTime_t
current 1323698306 0 milliSec 1323698306000
2011.12.12 08:58:26 0 nanoSeconds isDst false
current 1333475992 0 milliSec 1333475992000
2012.04.03 13:59:52 0 nanoSeconds isDst true
+6 -6
View File
@@ -1,6 +1,6 @@
one requested 0.400000 diff 0.400209 seconds
two requested 0.200000 diff 0.200265 seconds
one requested 0.200000 diff 0.200253 seconds
two requested 0.400000 diff 0.400278 seconds
one requested 0.000000 diff 0.000039 seconds
two requested 0.000000 diff 0.000060 seconds
one requested 0.400000 diff 0.400133 seconds
two requested 0.200000 diff 0.200132 seconds
one requested 0.200000 diff 0.200114 seconds
two requested 0.400000 diff 0.400123 seconds
one requested 0.000000 diff 0.000059 seconds
two requested 0.000000 diff 0.000066 seconds
+15 -19
View File
@@ -2,22 +2,6 @@ TOP=../..
include $(TOP)/configure/CONFIG
PROD_HOST += testTimeStamp
testTimeStamp_SRCS += testTimeStamp.cpp
testTimeStamp_LIBS += pvData Com
PROD_HOST += testLinkedList
testLinkedList_SRCS += testLinkedList.cpp
testLinkedList_LIBS += pvData Com
PROD_HOST += testQueue
testQueue_SRCS += testQueue.cpp
testQueue_LIBS += pvData Com
PROD_HOST += testMessageQueue
testMessageQueue_SRCS += testMessageQueue.cpp
testMessageQueue_LIBS += pvData Com
PROD_HOST += testThread
testThread_SRCS += testThread.cpp
testThread_LIBS += pvData Com
@@ -42,9 +26,21 @@ PROD_HOST += testBaseException
testBaseException_SRCS += testBaseException.cpp
testBaseException_LIBS += pvData
PROD_HOST += testSerialization
testSerialization_SRCS += testSerialization.cpp
testSerialization_LIBS += pvData Com
#PROD_HOST += testSerialization
#testSerialization_SRCS += testSerialization.cpp
#testSerialization_LIBS += pvData Com
PROD_HOST += testTimeStamp
testTimeStamp_SRCS += testTimeStamp.cpp
testTimeStamp_LIBS += pvData Com
PROD_HOST += testQueue
testQueue_SRCS += testQueue.cpp
testQueue_LIBS += pvData Com
#PROD_HOST += testMessageQueue
#testMessageQueue_SRCS += testMessageQueue.cpp
#testMessageQueue_LIBS += pvData Com
include $(TOP)/configure/RULES
#----------------------------------------
+27 -26
View File
@@ -37,18 +37,17 @@ struct Data {
static const int numElements = 5;
typedef QueueElement<Data> DataElement;
typedef Queue<Data> DataQueue;
class Sink : public Runnable {
public:
Sink(DataQueue *queue,FILE *auxfd);
Sink(DataQueue &queue,FILE *auxfd);
~Sink();
void stop();
void look();
virtual void run();
private:
DataQueue *queue;
DataQueue queue;
FILE *auxfd;
bool isStopped;
Event *wait;
@@ -58,7 +57,7 @@ private:
Thread *thread;
};
Sink::Sink(DataQueue *queue,FILE *auxfd)
Sink::Sink(DataQueue &queue,FILE *auxfd)
: queue(queue),
auxfd(auxfd),
isStopped(false),
@@ -97,49 +96,51 @@ void Sink::run()
wait->wait();
if(isStopped) break;
while(true) {
DataElement *element = queue->getUsed();
if(element==0) {
Data *data = queue.getUsed();
if(data==NULL) {
waitEmpty->signal();
break;
}
Data *data = element->getObject();
fprintf(auxfd," sink a %d b %d\n",data->a,data->b);
queue->releaseUsed(element);
queue.releaseUsed(data);
}
}
stopped->signal();
}
static void testBasic(FILE * fd,FILE *auxfd ) {
Data *dataArray[numElements];
for(int i=0; i<numElements; i++) {
dataArray[i] = new Data();
dataArray[i]->a = i;
dataArray[i]->b = i*10;
std::vector<std::tr1::shared_ptr<Data> >dataArray;
dataArray.reserve(numElements);
for(int i=0; i<numElements; i++) {
dataArray.push_back(std::tr1::shared_ptr<Data>(new Data()));
}
DataQueue *queue = new DataQueue(dataArray,numElements);
Sink *sink = new Sink(queue,auxfd);
DataQueue queue(dataArray);
Data *pdata = queue.getFree();
int value = 0;
while(pdata!=NULL) {
pdata->a = value;
pdata->b = value*10;
value++;
queue.setUsed(pdata);
pdata = queue.getFree();
}
std::tr1::shared_ptr<Sink> sink = std::tr1::shared_ptr<Sink>(new Sink(queue,auxfd));
while(true) {
DataElement *element = queue->getFree();
if(element==0) break;
Data *data = element->getObject();
Data * data = queue.getFree();
if(data==NULL) break;
fprintf(auxfd,"source a %d b %d\n",data->a,data->b);
queue->setUsed(element);
queue.setUsed(data);
}
sink->look();
// now alternate
for(int i=0; i<numElements; i++) {
DataElement *element = queue->getFree();
assert(element!=0);
Data *data = element->getObject();
Data *data = queue.getFree();
assert(data!=NULL);
fprintf(auxfd,"source a %d b %d\n",data->a,data->b);
queue->setUsed(element);
queue.setUsed(data);
sink->look();
}
sink->stop();
delete sink;
delete queue;
for(int i=0; i<numElements; i++) delete dataArray[i];
}
int main(int argc, char *argv[]) {
+3 -3
View File
@@ -2,9 +2,9 @@ TOP=../..
include $(TOP)/configure/CONFIG
PROD_HOST += testProperty
testProperty_SRCS += testProperty.cpp
testProperty_LIBS += pvData Com
#PROD_HOST += testProperty
#testProperty_SRCS += testProperty.cpp
#testProperty_LIBS += pvData Com
include $(TOP)/configure/RULES
+20 -22
View File
@@ -31,38 +31,40 @@
#include <pv/pvDisplay.h>
#include <pv/pvEnumerated.h>
#include <pv/pvTimeStamp.h>
#include <pv/CDRMonitor.h>
using namespace epics::pvData;
static FieldCreate * fieldCreate = 0;
static PVDataCreate * pvDataCreate = 0;
static StandardField *standardField = 0;
static StandardPVField *standardPVField = 0;
static Convert *convert = 0;
static String builder("");
static FieldCreatePtr fieldCreate;
static PVDataCreatePtr pvDataCreate;
static StandardFieldPtr standardField;
static StandardPVFieldPtr standardPVField;
static ConvertPtr convert;
static String builder;
static String alarmTimeStamp("alarm,timeStamp");
static String allProperties("alarm,timeStamp,display,control");
static PVStructure *doubleRecord = 0;
static PVStructure *enumeratedRecord = 0;
static PVStructurePtr doubleRecord;
static PVStructurePtr enumeratedRecord;
static void createRecords(FILE * fd,FILE *auxfd)
{
doubleRecord = standardPVField->scalarValue(0,pvDouble,allProperties);
doubleRecord = standardPVField->scalar(pvDouble,allProperties);
builder.clear();
doubleRecord->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
String choices[4] = {
String("0"),String("1"),String("2"),String("3")
};
enumeratedRecord = standardPVField->enumeratedValue(0,choices,4,alarmTimeStamp);
StringArray choices;
choices.reserve(4);
choices.push_back("1");
choices.push_back("2");
choices.push_back("3");
choices.push_back("4");
enumeratedRecord = standardPVField->enumerated(choices,alarmTimeStamp);
builder.clear();
enumeratedRecord->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
}
static void deleteRecords(FILE * fd,FILE *auxfd)
static void printRecords(FILE * fd,FILE *auxfd)
{
fprintf(fd,"doubleRecord\n");
builder.clear();
@@ -72,8 +74,6 @@ static void deleteRecords(FILE * fd,FILE *auxfd)
builder.clear();
enumeratedRecord->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
delete doubleRecord;
delete enumeratedRecord;
}
static void testAlarm(FILE * fd,FILE *auxfd)
@@ -82,8 +82,8 @@ static void testAlarm(FILE * fd,FILE *auxfd)
Alarm alarm;
PVAlarm pvAlarm;
bool result;
PVField *pvField = doubleRecord->getSubField(String("alarm"));
if(pvField==0) {
PVFieldPtr pvField = doubleRecord->getSubField(String("alarm"));
if(pvField.get()==0) {
printf("testAlarm ERROR did not find field alarm\n");
return;
}
@@ -250,9 +250,7 @@ int main(int argc,char *argv[])
testControl(fd,auxfd);
testDisplay(fd,auxfd);
testEnumerated(fd,auxfd);
deleteRecords(fd,auxfd);
epicsExitCallAtExits();
CDRMonitor::get().show(fd);
printRecords(fd,auxfd);
return(0);
}
+3 -7
View File
@@ -2,9 +2,9 @@ TOP=../..
include $(TOP)/configure/CONFIG
PROD_HOST += temp
temp_SRCS += temp.cpp
temp_LIBS += pvData Com
PROD_HOST += testIntrospect
testIntrospect_SRCS += testIntrospect.cpp
testIntrospect_LIBS += pvData Com
PROD_HOST += testPVAppend
testPVAppend_SRCS += testPVAppend.cpp
@@ -18,10 +18,6 @@ PROD_HOST += testPVAuxInfo
testPVAuxInfo_SRCS += testPVAuxInfo.cpp
testPVAuxInfo_LIBS += pvData Com
PROD_HOST += testIntrospect
testIntrospect_SRCS += testIntrospect.cpp
testIntrospect_LIBS += pvData Com
PROD_HOST += testPVData
testPVData_SRCS += testPVData.cpp
testPVData_LIBS += pvData Com
-149
View File
@@ -1,149 +0,0 @@
/* testPVAppend.cpp */
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*/
/* Author: Marty Kraimer Date: 2010.11 */
#include <cstddef>
#include <cstdlib>
#include <cstddef>
#include <string>
#include <cstdio>
#include <epicsAssert.h>
#include <epicsExit.h>
#include <pv/requester.h>
#include <pv/pvIntrospect.h>
#include <pv/pvData.h>
#include <pv/convert.h>
#include <pv/standardField.h>
#include <pv/standardPVField.h>
#include <pv/CDRMonitor.h>
using namespace epics::pvData;
static FieldCreate * fieldCreate = 0;
static PVDataCreate * pvDataCreate = 0;
static StandardField *standardField = 0;
static StandardPVField *standardPVField = 0;
static Convert *convert = 0;
static String builder("");
static String alarmTimeStamp("alarm,timeStamp");
static String alarmTimeStampValueAlarm("alarm,timeStamp,valueAlarm");
static String allProperties("alarm,timeStamp,display,control,valueAlarm");
static void testAppendSimple(FILE * fd)
{
FieldConstPtrArray fields = new FieldConstPtr[0];
PVStructure *pvParent = pvDataCreate->createPVStructure(
0,String("request"),0,fields);
PVString* pvStringField = static_cast<PVString*>(
pvDataCreate->createPVScalar(pvParent, "fieldList", pvString));
pvStringField->put(String("value,timeStamp"));
pvParent->appendPVField(pvStringField);
builder.clear();
pvParent->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
pvStringField = static_cast<PVString*>(
pvDataCreate->createPVScalar(pvParent, "extra", pvString));
pvStringField->put(String("junk"));
pvParent->appendPVField(pvStringField);
builder.clear();
pvParent->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
delete pvParent;
}
static void testAppendMore(FILE * fd)
{
PVStructure* pvStructure = pvDataCreate->createPVStructure(
0,"parent", 0);
PVStructure* pvChild1 = pvDataCreate->createPVStructure(
pvStructure, "child1", 0);
PVString *pvStringField = static_cast<PVString*>(
pvDataCreate->createPVScalar(pvChild1,"value", pvString));
pvStringField->put("bla");
pvChild1->appendPVField(pvStringField);
pvStructure->appendPVField(pvChild1);
PVStructure* pvChild2 = pvDataCreate->createPVStructure(
pvStructure, "child2", 0);
pvStringField = static_cast<PVString*>(
pvDataCreate->createPVScalar(pvChild2,"value", pvString));
pvStringField->put("bla");
pvChild2->appendPVField(pvStringField);
pvStructure->appendPVField(pvChild2);
builder.clear();
pvStructure->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
delete pvStructure;
}
static void append2(PVStructure* pvStructure,
const char *oneName,const char *twoName,
const char *oneValue,const char *twoValue)
{
PVField* array[2];
PVString *pvStringField = static_cast<PVString*>(
pvDataCreate->createPVScalar(0,oneName, pvString));
pvStringField->put(oneValue);
array[0] = pvStringField;
pvStringField = static_cast<PVString*>(
pvDataCreate->createPVScalar(0,twoName, pvString));
pvStringField->put(twoValue);
array[1] = pvStringField;
pvStructure->appendPVFields(2,array);
}
static void testAppends(FILE * fd)
{
PVField** array = new PVField*[2];
PVStructure* pvChild = pvDataCreate->createPVStructure(
0, "child1", 0);
append2(pvChild,"Joe","Mary","Good Guy","Good Girl");
array[0] = pvChild;
pvChild = pvDataCreate->createPVStructure(
0, "child2", 0);
append2(pvChild,"Bill","Jane","Bad Guy","Bad Girl");
array[1] = pvChild;
PVStructure* pvStructure = pvDataCreate->createPVStructure(
0,"parent", 2,array);
builder.clear();
pvStructure->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
PVField *pvField = pvStructure->getSubField("child2.Bill");
assert(pvField!=0);
bool ok = pvField->renameField("Joe");
assert(ok);
builder.clear();
pvStructure->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
pvField->getParent()->removePVField("Joe");
builder.clear();
pvStructure->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
delete pvStructure;
}
int main(int argc,char *argv[])
{
char *fileName = 0;
if(argc>1) fileName = argv[1];
FILE * fd = stdout;
if(fileName!=0 && fileName[0]!=0) {
fd = fopen(fileName,"w+");
}
fieldCreate = getFieldCreate();
pvDataCreate = getPVDataCreate();
standardField = getStandardField();
standardPVField = getStandardPVField();
convert = getConvert();
//testAppendSimple(fd);
//testAppendMore(fd);
testAppends(fd);
epicsExitCallAtExits();
CDRMonitor::get().show(fd);
return(0);
}
+40 -41
View File
@@ -24,15 +24,15 @@
using namespace epics::pvData;
static FieldCreate * fieldCreate = 0;
static PVDataCreate * pvDataCreate = 0;
static StandardField *standardField = 0;
static FieldCreatePtr fieldCreate;
static PVDataCreatePtr pvDataCreate;
static StandardFieldPtr standardField;
static String builder("");
static void testScalarCommon(FILE * fd,String fieldName,ScalarType stype,
static void testScalarCommon(FILE * fd,ScalarType stype,
bool isInteger,bool isNumeric,bool isPrimitive)
{
ScalarConstPtr pscalar = standardField->scalar(fieldName,stype);
ScalarConstPtr pscalar = fieldCreate->createScalar(stype);
Type type = pscalar->getType();
assert(type==scalar);
builder.clear();
@@ -47,26 +47,25 @@ static void testScalarCommon(FILE * fd,String fieldName,ScalarType stype,
pscalar->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
// create tempory PVField so that memory can be released
PVField *pvField = pvDataCreate->createPVField(0,pscalar);
delete pvField;
PVFieldPtr pvField = pvDataCreate->createPVScalar(pscalar);
}
static void testScalar(FILE * fd) {
fprintf(fd,"\ntestScalar\n");
testScalarCommon(fd,String("boolean"),pvBoolean,false,false,true);
testScalarCommon(fd,String("byte"),pvByte,true,true,true);
testScalarCommon(fd,String("short"),pvShort,true,true,true);
testScalarCommon(fd,String("int"),pvInt,true,true,true);
testScalarCommon(fd,String("long"),pvLong,true,true,true);
testScalarCommon(fd,String("float"),pvFloat,false,true,true);
testScalarCommon(fd,String("double"),pvDouble,false,true,true);
testScalarCommon(fd,String("string"),pvString,false,false,false);
testScalarCommon(fd,pvBoolean,false,false,true);
testScalarCommon(fd,pvByte,true,true,true);
testScalarCommon(fd,pvShort,true,true,true);
testScalarCommon(fd,pvInt,true,true,true);
testScalarCommon(fd,pvLong,true,true,true);
testScalarCommon(fd,pvFloat,false,true,true);
testScalarCommon(fd,pvDouble,false,true,true);
testScalarCommon(fd,pvString,false,false,false);
}
static void testScalarArrayCommon(FILE * fd,String fieldName,ScalarType stype,
static void testScalarArrayCommon(FILE * fd,ScalarType stype,
bool isInteger,bool isNumeric,bool isPrimitive)
{
ScalarArrayConstPtr pscalar = standardField->scalarArray(fieldName,stype);
ScalarArrayConstPtr pscalar = fieldCreate->createScalarArray(stype);
Type type = pscalar->getType();
assert(type==scalarArray);
builder.clear();
@@ -81,51 +80,53 @@ static void testScalarArrayCommon(FILE * fd,String fieldName,ScalarType stype,
pscalar->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
// create tempory PVField so that memory can be released
PVField *pvField = pvDataCreate->createPVField(0,pscalar);
delete pvField;
PVFieldPtr pvField = pvDataCreate->createPVScalarArray(pscalar);
}
static void testScalarArray(FILE * fd) {
fprintf(fd,"\ntestScalarArray\n");
testScalarArrayCommon(fd,String("boolean"),pvBoolean,false,false,true);
testScalarArrayCommon(fd,String("byte"),pvByte,true,true,true);
testScalarArrayCommon(fd,String("short"),pvShort,true,true,true);
testScalarArrayCommon(fd,String("int"),pvInt,true,true,true);
testScalarArrayCommon(fd,String("long"),pvLong,true,true,true);
testScalarArrayCommon(fd,String("float"),pvFloat,false,true,true);
testScalarArrayCommon(fd,String("double"),pvDouble,false,true,true);
testScalarArrayCommon(fd,String("string"),pvString,false,false,false);
testScalarArrayCommon(fd,pvBoolean,false,false,true);
testScalarArrayCommon(fd,pvByte,true,true,true);
testScalarArrayCommon(fd,pvShort,true,true,true);
testScalarArrayCommon(fd,pvInt,true,true,true);
testScalarArrayCommon(fd,pvLong,true,true,true);
testScalarArrayCommon(fd,pvFloat,false,true,true);
testScalarArrayCommon(fd,pvDouble,false,true,true);
testScalarArrayCommon(fd,pvString,false,false,false);
}
static void testSimpleStructure(FILE * fd) {
fprintf(fd,"\ntestSimpleStructure\n");
String properties("alarm,timeStamp,display,control,valueAlarm");
StructureConstPtr ptop = standardField->scalarValue(pvDouble,properties);
StructureConstPtr ptop = standardField->scalar(pvDouble,properties);
builder.clear();
ptop->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
// create tempory PVField so that memory can be released
PVField *pvField = pvDataCreate->createPVField(0,ptop);
delete pvField;
PVStructurePtr pvStructure = pvDataCreate->createPVStructure(ptop);
}
static StructureConstPtr createPowerSupply() {
size_t nfields = 3;
String properties("alarm");
FieldConstPtrArray powerSupply = new FieldConstPtr[3];
powerSupply[0] = standardField->scalar(
String("voltage"),pvDouble,properties);
powerSupply[1] = standardField->scalar(
String("power"),pvDouble,properties);
powerSupply[2] = standardField->scalar(
String("current"),pvDouble,properties);
return standardField->structure( String("powerSupply"),3,powerSupply);
StringArray names;
names.reserve(nfields);
FieldConstPtrArray powerSupply;
powerSupply.reserve(nfields);
names.push_back("voltage");
powerSupply.push_back(standardField->scalar(pvDouble,properties));
names.push_back("power");
powerSupply.push_back(standardField->scalar(pvDouble,properties));
names.push_back("current");
powerSupply.push_back(standardField->scalar(pvDouble,properties));
return fieldCreate->createStructure(names,powerSupply);
}
static void testStructureArray(FILE * fd) {
fprintf(fd,"\ntestStructureArray\n");
String properties("alarm,timeStamp");
StructureConstPtr powerSupply = createPowerSupply();
StructureConstPtr top = standardField->structureArrayValue(
StructureConstPtr top = standardField->structureArray(
powerSupply,properties);
builder.clear();
top->toString(&builder);
@@ -147,8 +148,6 @@ int main(int argc,char *argv[])
testScalarArray(fd);
testSimpleStructure(fd);
testStructureArray(fd);
epicsExitCallAtExits();
CDRMonitor::get().show(fd,true);
return(0);
}
+69 -63
View File
@@ -21,15 +21,15 @@
#include <pv/convert.h>
#include <pv/standardField.h>
#include <pv/standardPVField.h>
#include <pv/CDRMonitor.h>
using namespace epics::pvData;
using std::tr1::static_pointer_cast;
static FieldCreate * fieldCreate = 0;
static PVDataCreate * pvDataCreate = 0;
static StandardField *standardField = 0;
static StandardPVField *standardPVField = 0;
static Convert *convert = 0;
static FieldCreatePtr fieldCreate;
static PVDataCreatePtr pvDataCreate;
static StandardFieldPtr standardField;
static StandardPVFieldPtr standardPVField;
static ConvertPtr convert;
static String builder("");
static String alarmTimeStamp("alarm,timeStamp");
static String alarmTimeStampValueAlarm("alarm,timeStamp,valueAlarm");
@@ -37,87 +37,96 @@ static String allProperties("alarm,timeStamp,display,control,valueAlarm");
static void testAppendSimple(FILE * fd)
{
FieldConstPtrArray fields = new FieldConstPtr[0];
PVStructure *pvParent = pvDataCreate->createPVStructure(
0,String("request"),0,fields);
PVString* pvStringField = static_cast<PVString*>(
pvDataCreate->createPVScalar(pvParent, "fieldList", pvString));
PVFieldPtrArray fields;
StringArray names;
PVStructurePtr pvParent = pvDataCreate->createPVStructure(names,fields);
PVStringPtr pvStringField = static_pointer_cast<PVString>(
pvDataCreate->createPVScalar(pvString));
pvStringField->put(String("value,timeStamp"));
pvParent->appendPVField(pvStringField);
builder.clear();
pvParent->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
pvStringField = static_cast<PVString*>(
pvDataCreate->createPVScalar(pvParent, "extra", pvString));
PVFieldPtr pvField = pvStringField;
pvParent->appendPVField("fieldlist",pvField);
pvStringField = static_pointer_cast<PVString>(
pvDataCreate->createPVScalar(pvString));
pvStringField->put(String("junk"));
pvParent->appendPVField(pvStringField);
pvField = pvStringField;
pvParent->appendPVField("extra",pvField);
builder.clear();
pvParent->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
delete pvParent;
}
static void testAppendMore(FILE * fd)
{
PVStructure* pvStructure = pvDataCreate->createPVStructure(
0,"parent", 0);
PVStructure* pvChild1 = pvDataCreate->createPVStructure(
pvStructure, "child1", 0);
PVString *pvStringField = static_cast<PVString*>(
pvDataCreate->createPVScalar(pvChild1,"value", pvString));
PVFieldPtrArray fields;
StringArray names;
PVStructurePtr pvStructure = pvDataCreate->createPVStructure(names,fields);
PVStructurePtr pvChild1 = pvDataCreate->createPVStructure(names,fields);
PVStringPtr pvStringField = static_pointer_cast<PVString>(
pvDataCreate->createPVScalar(pvString));
pvStringField->put("bla");
pvChild1->appendPVField(pvStringField);
pvStructure->appendPVField(pvChild1);
PVStructure* pvChild2 = pvDataCreate->createPVStructure(
pvStructure, "child2", 0);
pvStringField = static_cast<PVString*>(
pvDataCreate->createPVScalar(pvChild2,"value", pvString));
pvStringField->put("bla");
pvChild2->appendPVField(pvStringField);
pvStructure->appendPVField(pvChild2);
PVFieldPtr pvField = pvStringField;
pvChild1->appendPVField("value",pvField);
pvField = pvChild1;
pvStructure->appendPVField("child1",pvField);
PVStructurePtr pvChild2 = pvDataCreate->createPVStructure(names,fields);
pvStringField = static_pointer_cast<PVString>(
pvDataCreate->createPVScalar(pvString));
pvStringField->put("blabla");
pvField = pvStringField;
pvChild2->appendPVField("value",pvField);
pvField = pvChild2;
pvStructure->appendPVField("child2",pvField);
builder.clear();
pvStructure->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
delete pvStructure;
}
static void append2(PVStructure* pvStructure,
static void append2(PVStructurePtr pvStructure,
const char *oneName,const char *twoName,
const char *oneValue,const char *twoValue)
{
PVField* array[2];
// make parent null to test setParent
PVString *pvStringField = static_cast<PVString*>(
pvDataCreate->createPVScalar(0,oneName, pvString));
pvStringField->put(oneValue);
array[0] = pvStringField;
pvStringField = static_cast<PVString*>(
pvDataCreate->createPVScalar(0,twoName, pvString));
pvStringField->put(twoValue);
array[1] = pvStringField;
pvStructure->appendPVFields(2,array);
PVFieldPtrArray pvFields;
pvFields.reserve(2);
StringArray names;
names.reserve(2);
PVStringPtr pvStringField = static_pointer_cast<PVString>(
pvDataCreate->createPVScalar(pvString));
pvStringField->put(oneValue);
names.push_back(oneName);
pvFields.push_back(pvStringField);
pvStringField = static_pointer_cast<PVString>(
pvDataCreate->createPVScalar(pvString));
pvStringField->put(twoValue);
names.push_back(twoName);
pvFields.push_back(pvStringField);
pvStructure->appendPVFields(names,pvFields);
}
static void testAppends(FILE * fd)
{
PVField** array = new PVField*[2];
// make parent null to test setParent
PVStructure* pvChild = pvDataCreate->createPVStructure(
0, "child1", 0);
PVFieldPtrArray emptyPVFields;
StringArray emptyNames;
PVFieldPtrArray pvFields;
pvFields.reserve(2);
StringArray names;
names.reserve(2);
names.push_back("child1");
PVStructurePtr pvChild = pvDataCreate->createPVStructure(
emptyNames,emptyPVFields);
append2(pvChild,"Joe","Mary","Good Guy","Good Girl");
array[0] = pvChild;
pvFields.push_back(pvChild);
names.push_back("child2");
pvChild = pvDataCreate->createPVStructure(
0, "child2", 0);
emptyNames,emptyPVFields);
append2(pvChild,"Bill","Jane","Bad Guy","Bad Girl");
array[1] = pvChild;
PVStructure* pvStructure = pvDataCreate->createPVStructure(
0,"parent", 2,array);
pvFields.push_back(pvChild);
PVStructurePtr pvStructure = pvDataCreate->createPVStructure(
names,pvFields);
builder.clear();
pvStructure->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
PVField *pvField = pvStructure->getSubField("child2.Bill");
assert(pvField!=0);
bool ok = pvField->renameField("Joe");
assert(ok);
PVFieldPtr pvField = pvStructure->getSubField("child2.Bill");
assert(pvField.get()!=0);
pvField->renameField("Joe");
builder.clear();
pvStructure->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
@@ -125,7 +134,6 @@ static void testAppends(FILE * fd)
builder.clear();
pvStructure->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
delete pvStructure;
}
int main(int argc,char *argv[])
@@ -144,8 +152,6 @@ int main(int argc,char *argv[])
testAppendSimple(fd);
testAppendMore(fd);
testAppends(fd);
epicsExitCallAtExits();
CDRMonitor::get().show(fd,true);
return(0);
}
+31 -33
View File
@@ -21,34 +21,35 @@
#include <pv/convert.h>
#include <pv/standardField.h>
#include <pv/standardPVField.h>
#include <pv/CDRMonitor.h>
using namespace epics::pvData;
using std::tr1::static_pointer_cast;
static FieldCreate * fieldCreate = 0;
static PVDataCreate * pvDataCreate = 0;
static StandardField *standardField = 0;
static StandardPVField *standardPVField = 0;
static Convert *convert = 0;
static String buffer("");
static FieldCreatePtr fieldCreate;
static PVDataCreatePtr pvDataCreate;
static StandardFieldPtr standardField;
static StandardPVFieldPtr standardPVField;
static ConvertPtr convert;
static String buffer;
static void printOffsets(PVStructure *pvStructure,FILE *fd)
static void printOffsets(PVStructurePtr pvStructure,FILE *fd)
{
fprintf(fd,"%s offset %d next %d number %d\n",
pvStructure->getField()->getFieldName().c_str(),
pvStructure->getFieldOffset(),
pvStructure->getNextFieldOffset(),
pvStructure->getNumberFields());
fprintf(fd,"%s offset %lu next %lu number %lu\n",
pvStructure->getFieldName().c_str(),
(long unsigned)pvStructure->getFieldOffset(),
(long unsigned)pvStructure->getNextFieldOffset(),
(long unsigned)pvStructure->getNumberFields());
PVFieldPtrArray fields = pvStructure->getPVFields();
int number = pvStructure->getStructure()->getNumberFields();
for(int i=0; i<number; i++) {
PVField *pvField = fields[i];
PVFieldPtr pvField = fields[i];
if(pvField->getField()->getType()==structure) {
printOffsets((PVStructure *)pvField,fd);
PVStructurePtr xxx = static_pointer_cast<PVStructure>(pvField);
printOffsets(xxx,fd);
continue;
}
fprintf(fd,"%s offset %d next %d number %d\n",
pvField->getField()->getFieldName().c_str(),
pvField->getFieldName().c_str(),
pvField->getFieldOffset(),
pvField->getNextFieldOffset(),
pvField->getNumberFields());
@@ -57,26 +58,25 @@ static void printOffsets(PVStructure *pvStructure,FILE *fd)
static void testPVAuxInfo(FILE * fd) {
fprintf(fd,"\ntestPVAuxInfo\n");
PVStructure * pvStructure = standardPVField->scalar(
0,String("value"),pvDouble,String("alarm,timeStamp,display,control"));
PVStructure *displayLimit = pvStructure->getStructureField(
String("display.limit"));
assert(displayLimit!=0);
PVAuxInfo *auxInfo = displayLimit->getPVAuxInfo();
auxInfo->createInfo(String("factory"),pvString);
auxInfo->createInfo(String("junk"),pvDouble);
PVScalar *pscalar = auxInfo->getInfo(String("factory"));
assert(pscalar!=0);
convert->fromString(pscalar,String("factoryName"));
pscalar = auxInfo->getInfo(String("junk"));
assert(pscalar!=0);
convert->fromString(pscalar,String("3.0"));
PVStructurePtr pvStructure = standardPVField->scalar(
pvDouble,"alarm,timeStamp,display,control");
PVStructurePtr display
= pvStructure->getStructureField("display");
assert(display.get()!=NULL);
PVAuxInfoPtr auxInfo = display->getPVAuxInfo();
auxInfo->createInfo("factory",pvString);
auxInfo->createInfo("junk",pvDouble);
PVScalarPtr pscalar = auxInfo->getInfo(String("factory"));
assert(pscalar.get()!=0);
convert->fromString(pscalar,"factoryName");
pscalar = auxInfo->getInfo("junk");
assert(pscalar.get()!=0);
convert->fromString(pscalar,"3.0");
buffer.clear();
pvStructure->toString(&buffer);
fprintf(fd,"%s\n",buffer.c_str());
// now show field offsets
printOffsets(pvStructure,fd);
delete pvStructure;
}
int main(int argc,char *argv[])
@@ -93,8 +93,6 @@ int main(int argc,char *argv[])
standardPVField = getStandardPVField();
convert = getConvert();
testPVAuxInfo(fd);
epicsExitCallAtExits();
CDRMonitor::get().show(fd,true);
return(0);
}
+78 -70
View File
@@ -21,15 +21,15 @@
#include <pv/convert.h>
#include <pv/standardField.h>
#include <pv/standardPVField.h>
#include <pv/CDRMonitor.h>
using namespace epics::pvData;
using std::tr1::static_pointer_cast;
static FieldCreate * fieldCreate = 0;
static PVDataCreate * pvDataCreate = 0;
static StandardField *standardField = 0;
static StandardPVField *standardPVField = 0;
static Convert *convert = 0;
static FieldCreatePtr fieldCreate;
static PVDataCreatePtr pvDataCreate;
static StandardFieldPtr standardField;
static StandardPVFieldPtr standardPVField;
static ConvertPtr convert;
static String builder("");
static String alarmTimeStamp("alarm,timeStamp");
static String alarmTimeStampValueAlarm("alarm,timeStamp,valueAlarm");
@@ -37,38 +37,43 @@ static String allProperties("alarm,timeStamp,display,control,valueAlarm");
static void testAppend(FILE * fd)
{
FieldConstPtrArray fields = new FieldConstPtr[0];
PVStructure *pvParent = pvDataCreate->createPVStructure(
0,String("request"),0,fields);
PVString* pvStringField = static_cast<PVString*>(
pvDataCreate->createPVScalar(pvParent, "fieldList", pvString));
PVFieldPtrArray pvFields;
StringArray fieldNames;
PVStructurePtr pvParent = pvDataCreate->createPVStructure(
fieldNames,pvFields);
PVStringPtr pvStringField = static_pointer_cast<PVString>(
pvDataCreate->createPVScalar(pvString));
pvStringField->put(String("value,timeStamp"));
pvParent->appendPVField(pvStringField);
PVFieldPtr pvField = pvStringField;
pvParent->appendPVField("request",pvField);
builder.clear();
pvParent->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
delete pvParent;
}
static void testCreatePVStructure(FILE * fd)
{
PVStructure * pv0 = standardPVField->scalarValue(
0,pvDouble,alarmTimeStampValueAlarm);
PVScalar *pv1 = standardPVField->scalar(0,String("extra"),pvString);
PVFieldPtr *pvFields = new PVFieldPtr[2];
pvFields[0] = pv0;
pvFields[1] = pv1;
PVStructure *pvParent = pvDataCreate->createPVStructure(
0,String("top"),2,pvFields);
PVStructurePtr pv0 = standardPVField->scalar(
pvDouble,alarmTimeStampValueAlarm);
PVScalarPtr pv1 = pvDataCreate->createPVScalar(pvString);
PVFieldPtrArray pvFields;
StringArray fieldNames;
pvFields.reserve(2);
fieldNames.reserve(2);
fieldNames.push_back("value");
fieldNames.push_back("extra");
pvFields.push_back(pv0);
pvFields.push_back(pv1);
PVStructurePtr pvParent = pvDataCreate->createPVStructure(
fieldNames,pvFields);
builder.clear();
pvParent->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
delete pvParent;
}
static void testPVScalarCommon(FILE * fd,String fieldName,ScalarType stype)
{
PVScalar *pvScalar = standardPVField->scalar(0,fieldName,stype);
PVScalarPtr pvScalar = pvDataCreate->createPVScalar(stype);
if(stype==pvBoolean) {
convert->fromString(pvScalar,String("true"));
} else {
@@ -77,57 +82,56 @@ static void testPVScalarCommon(FILE * fd,String fieldName,ScalarType stype)
builder.clear();
pvScalar->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
delete pvScalar;
}
static void testPVScalarWithProperties(
FILE * fd,String fieldName,ScalarType stype)
{
PVStructure *pvStructure = 0;
PVStructurePtr pvStructure;
bool hasValueAlarm = false;
bool hasDisplayControl = false;
switch(stype) {
case pvBoolean: {
pvStructure = standardPVField->scalar(
0,fieldName,stype,alarmTimeStampValueAlarm);
stype,alarmTimeStampValueAlarm);
hasValueAlarm = true;
PVBoolean *pvField = pvStructure->getBooleanField(String("value"));
PVBooleanPtr pvField = pvStructure->getBooleanField("value");
pvField->put(true);
break;
}
case pvByte: {
pvStructure = standardPVField->scalar(
0,fieldName,stype,allProperties);
stype,allProperties);
hasValueAlarm = true;
hasDisplayControl = true;
PVByte *pvField = pvStructure->getByteField(String("value"));
PVBytePtr pvField = pvStructure->getByteField("value");
pvField->put(127);
break;
}
case pvShort: {
pvStructure = standardPVField->scalar(
0,fieldName,stype,allProperties);
stype,allProperties);
hasValueAlarm = true;
hasDisplayControl = true;
PVShort *pvField = pvStructure->getShortField(String("value"));
PVShortPtr pvField = pvStructure->getShortField("value");
pvField->put(32767);
break;
}
case pvInt: {
pvStructure = standardPVField->scalar(
0,fieldName,stype,allProperties);
stype,allProperties);
hasValueAlarm = true;
hasDisplayControl = true;
PVInt *pvField = pvStructure->getIntField(String("value"));
PVIntPtr pvField = pvStructure->getIntField("value");
pvField->put((int)0x80000000);
break;
}
case pvLong: {
pvStructure = standardPVField->scalar(
0,fieldName,stype,allProperties);
stype,allProperties);
hasValueAlarm = true;
hasDisplayControl = true;
PVLong *pvField = pvStructure->getLongField(String("value"));
PVLongPtr pvField = pvStructure->getLongField("value");
int64 value = 0x80000000;
value <<= 32;
value |= 0xffffffff;
@@ -136,79 +140,81 @@ static void testPVScalarWithProperties(
}
case pvFloat: {
pvStructure = standardPVField->scalar(
0,fieldName,stype,allProperties);
stype,allProperties);
hasValueAlarm = true;
hasDisplayControl = true;
PVFloat *pvField = pvStructure->getFloatField(String("value"));
PVFloatPtr pvField = pvStructure->getFloatField("value");
pvField->put(1.123e8);
break;
}
case pvDouble: {
pvStructure = standardPVField->scalar(
0,fieldName,stype,allProperties);
stype,allProperties);
hasValueAlarm = true;
hasDisplayControl = true;
PVDouble *pvField = pvStructure->getDoubleField(String("value"));
PVDoublePtr pvField = pvStructure->getDoubleField("value");
pvField->put(1.123e35);
break;
}
case pvString: {
pvStructure = standardPVField->scalar(
0,fieldName,stype,alarmTimeStamp);
PVString *pvField = pvStructure->getStringField(String("value"));
stype,allProperties);
PVStringPtr pvField = pvStructure->getStringField("value");
pvField->put(String("this is a string"));
break;
}
}
PVLong *seconds = pvStructure->getLongField(
PVLongPtr seconds = pvStructure->getLongField(
String("timeStamp.secondsPastEpoch"));
assert(seconds!=0);
seconds->put(123456789);
PVInt *nano = pvStructure->getIntField(String("timeStamp.nanoSeconds"));
PVIntPtr nano = pvStructure->getIntField(String("timeStamp.nanoSeconds"));
assert(nano!=0);
nano->put(1000000);
PVInt *severity = pvStructure->getIntField(String("alarm.severity"));
PVIntPtr severity = pvStructure->getIntField(String("alarm.severity"));
assert(severity!=0);
severity->put(2);
PVString *message = pvStructure->getStringField(String("alarm.message"));
PVStringPtr message = pvStructure->getStringField(String("alarm.message"));
assert(message!=0);
message->put(String("messageForAlarm"));
if(hasDisplayControl) {
PVString *desc = pvStructure->getStringField(
PVStringPtr desc = pvStructure->getStringField(
String("display.description"));
assert(desc!=0);
desc->put(String("this is a description"));
PVString *format = pvStructure->getStringField(
PVStringPtr format = pvStructure->getStringField(
String("display.format"));
assert(format!=0);
format->put(String("f10.2"));
PVString *units = pvStructure->getStringField(
PVStringPtr units = pvStructure->getStringField(
String("display.units"));
assert(units!=0);
units->put(String("SomeUnits"));
PVDouble *limit = pvStructure->getDoubleField(
String("display.limit.low"));
PVDoublePtr limit = pvStructure->getDoubleField(
String("display.limitLow"));
assert(limit!=0);
limit->put(0.0);
limit = pvStructure->getDoubleField(
String("display.limit.high"));
String("display.limitHigh"));
assert(limit!=0);
limit->put(10.0);
limit = pvStructure->getDoubleField(
String("control.limit.low"));
String("control.limitLow"));
assert(limit!=0);
limit->put(1.0);
limit = pvStructure->getDoubleField(
String("control.limit.high"));
String("control.limitHigh"));
assert(limit!=0);
limit->put(9.0);
PVScalar *pvtemp = (PVScalar *)pvStructure->getSubField(
PVFieldPtr pvField = pvStructure->getSubField(
String("valueAlarm.lowAlarmLimit"));
assert(pvtemp!=0);
PVScalarPtr pvtemp = static_pointer_cast<PVScalar>(pvField);
assert(pvtemp.get()!=0);
convert->fromDouble(pvtemp,1.0);
pvtemp = (PVScalar *)pvStructure->getSubField(
pvField = pvStructure->getSubField(
String("valueAlarm.highAlarmLimit"));
assert(pvtemp!=0);
pvtemp = static_pointer_cast<PVScalar>(pvField);
assert(pvtemp.get()!=0);
convert->fromDouble(pvtemp,9.0);
severity = pvStructure->getIntField(
String("valueAlarm.lowAlarmSeverity"));
@@ -218,7 +224,7 @@ static void testPVScalarWithProperties(
String("valueAlarm.highAlarmSeverity"));
assert(severity!=0);
severity->put(2);
PVBoolean *active = pvStructure->getBooleanField(
PVBooleanPtr active = pvStructure->getBooleanField(
String("valueAlarm.active"));
assert(active!=0);
active->put(true);
@@ -226,7 +232,6 @@ static void testPVScalarWithProperties(
builder.clear();
pvStructure->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
delete pvStructure;
}
static void testPVScalar(FILE * fd) {
@@ -250,24 +255,30 @@ static void testPVScalar(FILE * fd) {
testPVScalarWithProperties(fd,String("string"),pvString);
}
static void testScalarArrayCommon(FILE * fd,String fieldName,ScalarType stype)
{
PVStructure *pvStructure = standardPVField->scalarArray(
0,fieldName,stype,alarmTimeStamp);
PVScalarArray *scalarArray = pvStructure->getScalarArrayField(
String("value"),stype);
assert(scalarArray!=0);
PVStructurePtr pvStructure = standardPVField->scalarArray(
stype,alarmTimeStamp);
PVScalarArrayPtr scalarArray = pvStructure->getScalarArrayField(
"value",stype);
assert(scalarArray.get()!=0);
if(stype==pvBoolean) {
String values[] = {String("true"),String("false"),String("true")};
StringArray values(3);
values[0] = "true";
values[1] = "false";
values[2] = "true";
convert->fromStringArray(scalarArray, 0,3,values,0);
} else {
String values[] = {String("0"),String("1"),String("2")};
StringArray values(3);
values[0] = "0";
values[1] = "1";
values[2] = "2";
convert->fromStringArray(scalarArray, 0,3,values,0);
}
builder.clear();
pvStructure->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
delete pvStructure;
}
static void testScalarArray(FILE * fd) {
@@ -282,7 +293,6 @@ static void testScalarArray(FILE * fd) {
testScalarArrayCommon(fd,String("string"),pvString);
}
int main(int argc,char *argv[])
{
char *fileName = 0;
@@ -300,8 +310,6 @@ int main(int argc,char *argv[])
testCreatePVStructure(fd);
testPVScalar(fd);
testScalarArray(fd);
epicsExitCallAtExits();
CDRMonitor::get().show(fd,true);
return(0);
}
+21 -22
View File
@@ -20,36 +20,38 @@
#include <pv/pvData.h>
#include <pv/standardField.h>
#include <pv/standardPVField.h>
#include <pv/CDRMonitor.h>
using namespace epics::pvData;
static FieldCreate * fieldCreate = 0;
static PVDataCreate * pvDataCreate = 0;
static StandardField *standardField = 0;
static StandardPVField *standardPVField = 0;
static String buffer("");
static FieldCreatePtr fieldCreate;
static PVDataCreatePtr pvDataCreate;
static StandardFieldPtr standardField;
static StandardPVFieldPtr standardPVField;
static String buffer;
StructureConstPtr getPowerSupplyStructure() {
String properties("alarm");
FieldConstPtrArray powerSupply = new FieldConstPtr[3];
powerSupply[0] = standardField->scalar(
String("voltage"),pvDouble,properties);
powerSupply[1] = standardField->scalar(
String("power"),pvDouble,properties);
powerSupply[2] = standardField->scalar(
String("current"),pvDouble,properties);
StructureConstPtr structure = standardField->structure(
String("powerSupply"),3,powerSupply);
FieldConstPtrArray fields;
StringArray fieldNames;
fields.reserve(3);
fieldNames.reserve(3);
fieldNames.push_back("voltage");
fieldNames.push_back("power");
fieldNames.push_back("current");
fields.push_back(standardField->scalar(pvDouble,properties));
fields.push_back(standardField->scalar(pvDouble,properties));
fields.push_back(standardField->scalar(pvDouble,properties));
StructureConstPtr structure = fieldCreate->createStructure(
fieldNames,fields);
return structure;
}
void testPowerSupplyArray(FILE * fd) {
PVStructure* powerSupplyArrayStruct = standardPVField->structureArray(
0,"powerSupply",getPowerSupplyStructure(),String("alarm,timeStamp"));
PVStructureArray * powerSupplyArray =
PVStructurePtr powerSupplyArrayStruct = standardPVField->structureArray(
getPowerSupplyStructure(),String("alarm,timeStamp"));
PVStructureArrayPtr powerSupplyArray =
powerSupplyArrayStruct->getStructureArrayField(String("value"));
assert(powerSupplyArray!=0);
assert(powerSupplyArray.get()!=NULL);
int offset = powerSupplyArray->append(5);
powerSupplyArray->setLength(offset);
buffer.clear();
@@ -64,7 +66,6 @@ void testPowerSupplyArray(FILE * fd) {
buffer.clear();
powerSupplyArrayStruct->toString(&buffer);
fprintf(fd,"after compress%s\n",buffer.c_str());
delete powerSupplyArrayStruct;
}
int main(int argc,char *argv[])
@@ -80,8 +81,6 @@ int main(int argc,char *argv[])
standardField = getStandardField();
standardPVField = getStandardPVField();
testPowerSupplyArray(fd);
epicsExitCallAtExits();
CDRMonitor::get().show(fd,true);
return(0);
}