diff --git a/pvDataApp/Makefile b/pvDataApp/Makefile index 50c3f87..0acf9b9 100644 --- a/pvDataApp/Makefile +++ b/pvDataApp/Makefile @@ -92,9 +92,7 @@ LIBSRCS += bitSetUtil.cpp SRC_DIRS += $(PVDATA)/monitor INC += monitor.h - -LIBRARY=pvData - +LIBRARY = pvData pvData_LIBS += Com include $(TOP)/configure/RULES diff --git a/pvDataApp/factory/Convert.cpp b/pvDataApp/factory/Convert.cpp index e24c5b6..40aa52a 100644 --- a/pvDataApp/factory/Convert.cpp +++ b/pvDataApp/factory/Convert.cpp @@ -2721,7 +2721,7 @@ void convertStructure(StringBuilder buffer,PVStructure const *data,int indentLev } } -void convertArray(StringBuilder buffer,PVScalarArray const * xxx,int indentLevel) +void convertArray(StringBuilder buffer,PVScalarArray const * xxx,int /*indentLevel*/) { PVScalarArray *pv = const_cast(xxx); ScalarArrayConstPtr array = pv->getScalarArray(); diff --git a/pvDataApp/factory/FieldCreateFactory.cpp b/pvDataApp/factory/FieldCreateFactory.cpp index 108b12f..c3eee33 100644 --- a/pvDataApp/factory/FieldCreateFactory.cpp +++ b/pvDataApp/factory/FieldCreateFactory.cpp @@ -39,7 +39,7 @@ Field::~Field() { } -void Field::toString(StringBuilder buffer,int indentLevel) const{ +void Field::toString(StringBuilder /*buffer*/,int /*indentLevel*/) const{ } @@ -54,7 +54,7 @@ struct ScalarArrayHashFunction { }; struct StructureHashFunction { - size_t operator() (const Structure& structure) const { return 0; } + size_t operator() (const Structure& /*structure*/) const { return 0; } // TODO // final int PRIME = 31; // return PRIME * Arrays.hashCode(fieldNames) + Arrays.hashCode(fields); @@ -70,7 +70,7 @@ Scalar::Scalar(ScalarType scalarType) Scalar::~Scalar(){} -void Scalar::toString(StringBuilder buffer,int indentLevel) const{ +void Scalar::toString(StringBuilder buffer,int /*indentLevel*/) const{ *buffer += getID(); } @@ -119,7 +119,7 @@ void Scalar::serialize(ByteBuffer *buffer, SerializableControl *control) const { buffer->putByte(getTypeCodeLUT()); } -void Scalar::deserialize(ByteBuffer *buffer, DeserializableControl *control) { +void Scalar::deserialize(ByteBuffer */*buffer*/, DeserializableControl */*control*/) { // must be done via FieldCreate throw std::runtime_error("not valid operation, use FieldCreate::deserialize instead"); } @@ -213,7 +213,7 @@ String ScalarArray::getID() const return getIDScalarArrayLUT(); } -void ScalarArray::toString(StringBuilder buffer,int indentLevel) const{ +void ScalarArray::toString(StringBuilder buffer,int /*indentLevel*/) const{ *buffer += getID(); } @@ -222,7 +222,7 @@ void ScalarArray::serialize(ByteBuffer *buffer, SerializableControl *control) co buffer->putByte(0x10 | getTypeCodeLUT()); } -void ScalarArray::deserialize(ByteBuffer *buffer, DeserializableControl *control) { +void ScalarArray::deserialize(ByteBuffer */*buffer*/, DeserializableControl */*control*/) { throw std::runtime_error("not valid operation, use FieldCreate::deserialize instead"); } @@ -252,7 +252,7 @@ void StructureArray::serialize(ByteBuffer *buffer, SerializableControl *control) control->cachedSerialize(pstructure, buffer); } -void StructureArray::deserialize(ByteBuffer *buffer, DeserializableControl *control) { +void StructureArray::deserialize(ByteBuffer */*buffer*/, DeserializableControl */*control*/) { throw std::runtime_error("not valid operation, use FieldCreate::deserialize instead"); } @@ -357,7 +357,7 @@ void Structure::serialize(ByteBuffer *buffer, SerializableControl *control) cons serializeStructureField(this, buffer, control); } -void Structure::deserialize(ByteBuffer *buffer, DeserializableControl *control) { +void Structure::deserialize(ByteBuffer */*buffer*/, DeserializableControl */*control*/) { throw std::runtime_error("not valid operation, use FieldCreate::deserialize instead"); } diff --git a/pvDataApp/factory/PVArray.cpp b/pvDataApp/factory/PVArray.cpp index cba18ff..89dd863 100644 --- a/pvDataApp/factory/PVArray.cpp +++ b/pvDataApp/factory/PVArray.cpp @@ -97,4 +97,9 @@ PVArray::~PVArray() pImpl->capacity = capacity; } +std::ostream& operator<<(format::array_at_internal const& manip, const PVArray& array) +{ + return array.dumpValue(manip.stream, manip.index); +} + }} diff --git a/pvDataApp/factory/PVDataCreateFactory.cpp b/pvDataApp/factory/PVDataCreateFactory.cpp index 95de04f..f18dfbe 100644 --- a/pvDataApp/factory/PVDataCreateFactory.cpp +++ b/pvDataApp/factory/PVDataCreateFactory.cpp @@ -147,9 +147,9 @@ void BasePVString::serialize(ByteBuffer *pbuffer, { // check bounds 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; + /*if (offset < 0) offset = 0; + else*/ if (offset > length) offset = length; + //if (count < 0) count = length; const size_t maxCount = length - offset; if (count > maxCount) @@ -271,7 +271,7 @@ size_t DefaultPVArray::get(size_t offset, size_t len, PVArrayData &data) size_t length = this->getLength(); if(offset+len > length) { n = length-offset; - if(n<0) n = 0; + //if(n<0) n = 0; } data.data = *value.get(); data.offset = offset; @@ -331,8 +331,8 @@ template void DefaultPVArray::deserialize(ByteBuffer *pbuffer, DeserializableControl *pcontrol) { size_t size = SerializeHelper::readSize(pbuffer, pcontrol); - // if (size>0) { pcontrol->ensureData(sizeof(T)-1); pbuffer->align(sizeof(T)); } - if(size>=0) { + // alignment 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); // set new length @@ -356,7 +356,7 @@ void DefaultPVArray::deserialize(ByteBuffer *pbuffer, } // inform about the change? PVField::postPut(); - } + //} // TODO null arrays (size == -1) not supported } @@ -367,10 +367,10 @@ void DefaultPVArray::serialize(ByteBuffer *pbuffer, size_t length = this->getLength(); // check bounds - if(offset<0) + /*if(offset<0) offset = 0; - else if(offset>length) offset = length; - if(count<0) count = length; + else*/ if(offset>length) offset = length; + //if(count<0) count = length; size_t maxCount = length-offset; if(count>maxCount) count = maxCount; @@ -406,7 +406,7 @@ template<> void DefaultPVArray::deserialize(ByteBuffer *pbuffer, DeserializableControl *pcontrol) { size_t size = SerializeHelper::readSize(pbuffer, pcontrol); - if(size>=0) { + //if(size>=0) { // prepare array, if necessary if(size>getCapacity()) setCapacity(size); // set new length @@ -419,7 +419,7 @@ void DefaultPVArray::deserialize(ByteBuffer *pbuffer, } // inform about the change? postPut(); - } + //} // TODO null arrays (size == -1) not supported } @@ -429,10 +429,10 @@ void DefaultPVArray::serialize(ByteBuffer *pbuffer, size_t length = getLength(); // check bounds - if(offset<0) + /*if(offset<0) offset = 0; - else if(offset>length) offset = length; - if(count<0) count = length; + else*/ if(offset>length) offset = length; + //if(count<0) count = length; size_t maxCount = length-offset; if(count>maxCount) count = maxCount; diff --git a/pvDataApp/factory/PVField.cpp b/pvDataApp/factory/PVField.cpp index da8575e..e4574d9 100644 --- a/pvDataApp/factory/PVField.cpp +++ b/pvDataApp/factory/PVField.cpp @@ -194,17 +194,34 @@ void PVField::toString(StringBuilder buf,int indentLevel) if(pvAuxInfo.get()!=NULL) pvAuxInfo->toString(buf,indentLevel); } -std::ostream& PVField::dumpValue(std::ostream& o) const +std::ostream& operator<<(std::ostream& o, const PVField& f) { - // default implementation - // each PVField class should implement it to avoid switch statement - // and string reallocation - String tmp; - convert->getString(&tmp,this,0); - return o << tmp; -} + std::ostream& ro = f.dumpValue(o); + // TODO I do not want to call getPVAuxInfo() since it lazily creates a new instance of it + //if (f.pvAuxInfo.get()!=NULL) ro << *(f.pvAuxInfo.get()); + return ro; +}; -std::ostream& operator<<(std::ostream& o, const PVField& f) { return f.dumpValue(o); }; +namespace format +{ + std::ostream& operator<<(std::ostream& os, indent_level const& indent) + { + indent_value(os) = indent.level; + return os; + } + + std::ostream& operator<<(std::ostream& os, indent const&) + { + long il = indent_value(os); + std::size_t spaces = static_cast(il) * 4; + return os << std::string(spaces, ' '); + } + + array_at_internal operator<<(std::ostream& str, array_at const& manip) + { + return array_at_internal(manip.index, str); + } +}; void PVField::computeOffset(const PVField * pvField) { const PVStructure * pvTop = pvField->getParent(); diff --git a/pvDataApp/factory/PVStructure.cpp b/pvDataApp/factory/PVStructure.cpp index dc25165..850f6be 100644 --- a/pvDataApp/factory/PVStructure.cpp +++ b/pvDataApp/factory/PVStructure.cpp @@ -702,4 +702,31 @@ static PVFieldPtr findSubField( return PVFieldPtr(); } +std::ostream& PVStructure::dumpValue(std::ostream& o) const +{ + o << format::indent() << getStructure()->getID() << ' ' << getFieldName(); + String extendsName = getExtendsStructureName(); + if(extendsName.length()>0) { + o << " extends " << extendsName; + } + o << std::endl; + { + format::indent_scope s(o); + + PVFieldPtrArray const & fieldsData = getPVFields(); + if (fieldsData.size() != 0) { + size_t length = getStructure()->getNumberFields(); + for(size_t i=0; igetField()->getType(); + if (type == scalar || type == scalarArray) + o << format::indent() << fieldField->getField()->getID() << ' ' << fieldField->getFieldName() << ' ' << *(fieldField.get()) << std::endl; + else + o << *(fieldField.get()); + } + } + } + return o; +} + }} diff --git a/pvDataApp/factory/PVStructureArray.cpp b/pvDataApp/factory/PVStructureArray.cpp index fa941ef..d08b6a4 100644 --- a/pvDataApp/factory/PVStructureArray.cpp +++ b/pvDataApp/factory/PVStructureArray.cpp @@ -133,7 +133,7 @@ size_t PVStructureArray::get( size_t length = getLength(); if(offset+len > length) { n = length - offset; - if(n<0) n = 0; + //if(n<0) n = 0; } data.data = *value.get(); data.offset = offset; @@ -197,7 +197,7 @@ void PVStructureArray::serialize(ByteBuffer *pbuffer, void PVStructureArray::deserialize(ByteBuffer *pbuffer, DeserializableControl *pcontrol) { size_t size = SerializeHelper::readSize(pbuffer, pcontrol); - if(size>=0) { + //if(size>=0) { // prepare array, if necessary if(size>getCapacity()) setCapacity(size); setLength(size); @@ -217,7 +217,7 @@ void PVStructureArray::deserialize(ByteBuffer *pbuffer, } } postPut(); - } + //} } void PVStructureArray::serialize(ByteBuffer *pbuffer, @@ -226,10 +226,10 @@ void PVStructureArray::serialize(ByteBuffer *pbuffer, size_t length = getLength(); // check bounds - if(offset<0) + /*if(offset<0) offset = 0; - else if(offset>length) offset = length; - if(count<0) count = length; + else*/ if(offset>length) offset = length; + //if(count<0) count = length; size_t maxCount = length-offset; if(count>maxCount) count = maxCount; @@ -250,4 +250,27 @@ void PVStructureArray::serialize(ByteBuffer *pbuffer, } } +std::ostream& PVStructureArray::dumpValue(std::ostream& o) const +{ + o << format::indent() << getStructureArray()->getID() << ' ' << getFieldName() << std::endl; + size_t length = getLength(); + if (length > 0) + { + format::indent_scope s(o); + + for (size_t i = 0; i < length; i++) + dumpValue(o, i); + } + + return o; +} + +std::ostream& PVStructureArray::dumpValue(std::ostream& o, std::size_t index) const +{ + PVStructurePtrArray pvArray = *value.get(); + PVStructurePtr pvStructure = pvArray[index]; + return o << *(pvStructure.get()); + return o; +} + }} diff --git a/pvDataApp/misc/bitSet.cpp b/pvDataApp/misc/bitSet.cpp index 4576ddb..bccb391 100644 --- a/pvDataApp/misc/bitSet.cpp +++ b/pvDataApp/misc/bitSet.cpp @@ -331,7 +331,7 @@ namespace epics { namespace pvData { return !(*this == set); } - void BitSet::toString(StringBuilder buffer, int indentLevel) const + void BitSet::toString(StringBuilder buffer, int /*indentLevel*/) const { *buffer += '{'; int32 i = nextSetBit(0); diff --git a/pvDataApp/misc/serializeHelper.cpp b/pvDataApp/misc/serializeHelper.cpp index d067765..75804ea 100644 --- a/pvDataApp/misc/serializeHelper.cpp +++ b/pvDataApp/misc/serializeHelper.cpp @@ -77,14 +77,14 @@ namespace epics { void SerializeHelper::serializeSubstring(const String& value, std::size_t offset, std::size_t count, ByteBuffer* buffer, SerializableControl* flusher) { - if(offset<0) + /*if(offset<0) offset = 0; - else if(offset>(std::size_t)value.length()) offset = value.length(); + else*/ if(offset>value.length()) offset = value.length(); - if(offset+count>(std::size_t)value.length()) count = value.length()-offset; + if(offset+count>value.length()) count = value.length()-offset; SerializeHelper::writeSize(count, buffer, flusher); - if (count<=0) return; + /*if (count<=0)*/ return; std::size_t i = 0; while(true) { std::size_t maxToWrite = min(count-i, buffer->getRemaining()); diff --git a/pvDataApp/misc/status.cpp b/pvDataApp/misc/status.cpp index 789b03b..2ddc4fe 100644 --- a/pvDataApp/misc/status.cpp +++ b/pvDataApp/misc/status.cpp @@ -117,7 +117,7 @@ String Status::toString() const return str; } -void Status::toString(StringBuilder buffer, int indentLevel) const +void Status::toString(StringBuilder buffer, int /*indentLevel*/) const { *buffer += "Status [type="; *buffer += StatusTypeName[m_statusType]; diff --git a/pvDataApp/pv/pvData.h b/pvDataApp/pv/pvData.h index b04d737..4f15742 100644 --- a/pvDataApp/pv/pvData.h +++ b/pvDataApp/pv/pvData.h @@ -14,10 +14,74 @@ #include #include #include +#include +#include #include #include namespace epics { namespace pvData { + +namespace format { + +struct indent_level +{ + long level; + + indent_level(long l) : level(l) {} +}; + +inline long& indent_value(std::ios_base& ios) +{ + static int indent_index = std::ios_base::xalloc(); + return ios.iword(indent_index); +} + +std::ostream& operator<<(std::ostream& os, indent_level const& indent); +struct indent_scope +{ + long saved_level; + std::ios_base& stream; + + indent_scope(std::ios_base& ios) : + stream(ios) + { + long& l = indent_value(ios); + saved_level = l; + l = saved_level + 1; + } + + ~indent_scope() + { + indent_value(stream) = saved_level; + } +}; + +struct indent +{ +}; + +std::ostream& operator<<(std::ostream& os, indent const&); + +struct array_at +{ + std::size_t index; + + array_at(std::size_t ix) : index(ix) {} +}; + +struct array_at_internal +{ + std::size_t index; + std::ostream& stream; + + array_at_internal(std::size_t ix, std::ostream& str) : index(ix), stream(str) {} +}; + +array_at_internal operator<<(std::ostream& str, array_at const& manip); + +}; + + class PVAuxInfo; class PostHandler; @@ -277,7 +341,7 @@ public: * @param o output stream. * @return The output stream. */ - virtual std::ostream& dumpValue(std::ostream& o) const; + virtual std::ostream& dumpValue(std::ostream& o) const = 0; protected: PVField::shared_pointer getPtrSelf() @@ -359,6 +423,20 @@ public: return o << get(); } + // get operator + // double value; doubleField >>= value; + void operator>>=(T& value) const + { + value = get(); + } + + // put operator + // double value = 12.8; doubleField <<= value; + void operator<<=(T value) + { + put(value); + } + protected: PVScalarValue(ScalarConstPtr const & scalar) : PVScalar(scalar) {} @@ -453,6 +531,9 @@ public: * @param The capacity. */ virtual void setCapacity(std::size_t capacity) = 0; + + virtual std::ostream& dumpValue(std::ostream& o, std::size_t index) const = 0; + protected: PVArray(FieldConstPtr const & field); void setCapacityLength(std::size_t capacity,std::size_t length); @@ -461,6 +542,8 @@ private: friend class PVDataCreate; }; +std::ostream& operator<<(format::array_at_internal const& manip, const PVArray& array); + /** * Class provided by caller of get */ @@ -505,8 +588,6 @@ public: */ const ScalarArrayConstPtr getScalarArray() const ; - virtual std::ostream& dumpValue(std::ostream& o, size_t index) const = 0; - protected: PVScalarArray(ScalarArrayConstPtr const & scalarArray); private: @@ -608,6 +689,10 @@ public: virtual pointer get() const { return &((*value.get())[0]); } virtual vector const & getVector() {return *value;} virtual shared_vector const & getSharedVector() {return value;} + + virtual std::ostream& dumpValue(std::ostream& o) const; + virtual std::ostream& dumpValue(std::ostream& o, std::size_t index) const; + protected: PVStructureArray(StructureArrayConstPtr const & structureArray); private: @@ -816,6 +901,9 @@ public: * @param pvFields The array of fields for the structure. */ PVStructure(StructureConstPtr const & structure,PVFieldPtrArray const & pvFields); + + virtual std::ostream& dumpValue(std::ostream& o) const; + private: void fixParentStructure(); static PVFieldPtr nullPVField; @@ -896,7 +984,7 @@ public: std::ostream& dumpValue(std::ostream& o) const { - o << "["; + o << '['; std::size_t len = getLength(); bool first = true; for (std::size_t i = 0; i < len; i++) @@ -904,10 +992,10 @@ public: if (first) first = false; else - o << ","; + o << ','; dumpValue(o, i); } - return o << "]"; + return o << ']'; } std::ostream& dumpValue(std::ostream& o, size_t index) const diff --git a/testApp/misc/Makefile b/testApp/misc/Makefile index 3b66c17..077f4eb 100644 --- a/testApp/misc/Makefile +++ b/testApp/misc/Makefile @@ -24,7 +24,7 @@ testByteBuffer_LIBS += pvData Com PROD_HOST += testBaseException testBaseException_SRCS += testBaseException.cpp -testBaseException_LIBS += pvData +testBaseException_LIBS += pvData Com PROD_HOST += testSerialization testSerialization_SRCS += testSerialization.cpp diff --git a/testApp/misc/testBaseException.cpp b/testApp/misc/testBaseException.cpp index cf9cd49..2a00995 100644 --- a/testApp/misc/testBaseException.cpp +++ b/testApp/misc/testBaseException.cpp @@ -27,11 +27,11 @@ struct Unroller }; template<> -void Unroller::unroll<0>(double d) { +void Unroller::unroll<0>(double /*d*/) { THROW_BASE_EXCEPTION("the root cause"); } -void internalTestBaseException(int unused = 0) +void internalTestBaseException(int /*unused*/ = 0) { try { // NOTE: 5, 4, 3, 2, 1 calls will be optimized and not shown diff --git a/testApp/misc/testMessageQueue.cpp b/testApp/misc/testMessageQueue.cpp index 67ce0a5..dac867b 100644 --- a/testApp/misc/testMessageQueue.cpp +++ b/testApp/misc/testMessageQueue.cpp @@ -30,7 +30,7 @@ using namespace epics::pvData; -static void testBasic(FILE * fd,FILE *auxfd ) { +static void testBasic(FILE * fd,FILE */*auxfd*/) { int queueSize = 3; StringArray messages; messages.reserve(5); diff --git a/testApp/misc/testSerialization.cpp b/testApp/misc/testSerialization.cpp index 41045f0..238bd7f 100644 --- a/testApp/misc/testSerialization.cpp +++ b/testApp/misc/testSerialization.cpp @@ -24,22 +24,24 @@ #include -#define BYTE_MAX_VALUE 127 -#define BYTE_MIN_VALUE -128 -#define UBYTE_MAX_VALUE 255 -#define SHORT_MAX_VALUE 32767 -#define SHORT_MIN_VALUE -32768 -#define USHORT_MAX_VALUE 65535 -#define INT_MAX_VALUE 2147483647 -#define INT_MIN_VALUE (-INT_MAX_VALUE - 1) -#define UINT_MAX_VALUE 4294967295ULL -#define LONG_MAX_VALUE 9223372036854775807LL -#define LONG_MIN_VALUE (-LONG_MAX_VALUE - 1LL) -#define ULONG_MAX_VALUE 18446744073709549999ULL -#define FLOAT_MAX_VALUE 3.4028235E38 -#define FLOAT_MIN_VALUE 1.4E-45 -#define DOUBLE_MAX_VALUE 1.7976931348623157E308 -#define DOUBLE_MIN_VALUE 4.9E-324 +#include + +#define BYTE_MAX_VALUE std::numeric_limits::max() +#define BYTE_MIN_VALUE std::numeric_limits::min() +#define UBYTE_MAX_VALUE std::numeric_limits::max() +#define SHORT_MAX_VALUE std::numeric_limits::max() +#define SHORT_MIN_VALUE std::numeric_limits::min() +#define USHORT_MAX_VALUE std::numeric_limits::max() +#define INT_MAX_VALUE std::numeric_limits::max() +#define INT_MIN_VALUE std::numeric_limits::min() +#define UINT_MAX_VALUE std::numeric_limits::max() +#define LONG_MAX_VALUE std::numeric_limits::max() +#define LONG_MIN_VALUE std::numeric_limits::min() +#define ULONG_MAX_VALUE std::numeric_limits::max() +#define FLOAT_MAX_VALUE std::numeric_limits::max() +#define FLOAT_MIN_VALUE std::numeric_limits::min() +#define DOUBLE_MAX_VALUE std::numeric_limits::max() +#define DOUBLE_MIN_VALUE std::numeric_limits::min() using namespace epics::pvData; @@ -54,7 +56,7 @@ public: virtual void flushSerializeBuffer() { } - virtual void ensureBuffer(std::size_t size) { + virtual void ensureBuffer(std::size_t /*size*/) { } virtual void alignBuffer(std::size_t alignment) { @@ -76,7 +78,7 @@ public: class DeserializableControlImpl : public DeserializableControl, public NoDefaultMethods { public: - virtual void ensureData(size_t size) { + virtual void ensureData(size_t /*size*/) { } virtual void alignData(size_t alignment) { diff --git a/testApp/monitor/testMonitor.cpp b/testApp/monitor/testMonitor.cpp index f5adfa3..ce33e7a 100644 --- a/testApp/monitor/testMonitor.cpp +++ b/testApp/monitor/testMonitor.cpp @@ -50,7 +50,7 @@ public: printf("poll called\n"); return emptyElement; } - virtual void release(MonitorElementPtr const & monitorElement) + virtual void release(MonitorElementPtr const & /*monitorElement*/) { printf("release called\n"); } @@ -70,7 +70,7 @@ static void testMonitor() } -int main(int argc,char *argv[]) +int main(int, char **) { testMonitor(); return(0); diff --git a/testApp/property/testProperty.cpp b/testApp/property/testProperty.cpp index 23eb465..923276c 100644 --- a/testApp/property/testProperty.cpp +++ b/testApp/property/testProperty.cpp @@ -48,7 +48,7 @@ static String allProperties("alarm,timeStamp,display,control"); static PVStructurePtr doubleRecord; static PVStructurePtr enumeratedRecord; -static void createRecords(FILE * fd,FILE *auxfd) +static void createRecords(FILE * fd,FILE */*auxfd*/) { doubleRecord = standardPVField->scalar(pvDouble,allProperties); if(debug) { @@ -70,7 +70,7 @@ static void createRecords(FILE * fd,FILE *auxfd) } } -static void printRecords(FILE * fd,FILE *auxfd) +static void printRecords(FILE * fd,FILE */*auxfd*/) { fprintf(fd,"doubleRecord\n"); builder.clear(); @@ -82,7 +82,7 @@ static void printRecords(FILE * fd,FILE *auxfd) fprintf(fd,"%s\n",builder.c_str()); } -static void testAlarm(FILE * fd,FILE *auxfd) +static void testAlarm(FILE * fd,FILE */*auxfd*/) { if(debug) fprintf(fd,"testAlarm\n"); Alarm alarm; @@ -155,7 +155,7 @@ static void testTimeStamp(FILE * fd,FILE *auxfd) fprintf(fd,"testTimeStamp PASSED\n"); } -static void testControl(FILE * fd,FILE *auxfd) +static void testControl(FILE * fd,FILE */*auxfd*/) { if(debug) fprintf(fd,"testControl\n"); Control control; @@ -182,7 +182,7 @@ static void testControl(FILE * fd,FILE *auxfd) fprintf(fd,"testControl PASSED\n"); } -static void testDisplay(FILE * fd,FILE *auxfd) +static void testDisplay(FILE * fd,FILE */*auxfd*/) { if(debug) fprintf(fd,"testDisplay\n"); Display display; @@ -215,7 +215,7 @@ static void testDisplay(FILE * fd,FILE *auxfd) fprintf(fd,"testDisplay PASSED\n"); } -static void testEnumerated(FILE * fd,FILE *auxfd) +static void testEnumerated(FILE * fd,FILE */*auxfd*/) { if(debug) fprintf(fd,"testEnumerated\n"); PVEnumerated pvEnumerated; diff --git a/testApp/pv/Makefile b/testApp/pv/Makefile index 7893a3e..558e4c0 100644 --- a/testApp/pv/Makefile +++ b/testApp/pv/Makefile @@ -42,6 +42,10 @@ PROD_HOST += testPVStructureArray testPVStructureArray_SRCS += testPVStructureArray.cpp testPVStructureArray_LIBS += pvData Com +PROD_HOST += testOperators +testOperators_SRCS += testOperators.cpp +testOperators_LIBS += pvData Com + include $(TOP)/configure/RULES #---------------------------------------- # ADD RULES AFTER THIS LINE diff --git a/testApp/pv/testOperators.cpp b/testApp/pv/testOperators.cpp new file mode 100644 index 0000000..3cc3fb6 --- /dev/null +++ b/testApp/pv/testOperators.cpp @@ -0,0 +1,91 @@ +/* testOperators.cpp */ +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * EPICS pvData is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. + */ +/* Author: Matej Sekoranja Date: 2013.02 */ + +#include + +#include +#include +#include + +#include + +using namespace epics::pvData; + +static PVDataCreatePtr pvDataCreate = getPVDataCreate(); +static StandardFieldPtr standardField = getStandardField(); +static StandardPVFieldPtr standardPVField = getStandardPVField(); + +int main(int, char*) +{ + PVStructurePtr pvStructure = standardPVField->scalar(pvDouble, + "alarm,timeStamp,display,control,valueAlarm"); + + const double testDV = 12.8; + + PVDoublePtr pvValue = pvStructure->getDoubleField("value"); + *pvValue <<= testDV; + + double dv; + *pvValue >>= dv; + assert(testDV == dv); + + + const std::string testSV = "test message"; + + PVStringPtr pvMessage = pvStructure->getStringField("alarm.message"); + *pvMessage <<= testSV; + + std::string sv; + *pvMessage >>= sv; + assert(testSV == sv); + + // + // to stream tests + // + + std::cout << *pvValue << std::endl; + std::cout << *pvMessage << std::endl; + std::cout << *pvStructure << std::endl; + + + StringArray choices; + choices.reserve(3); + choices.push_back("one"); + choices.push_back("two"); + choices.push_back("three"); + pvStructure = standardPVField->enumerated(choices, "alarm,timeStamp,valueAlarm"); + std::cout << *pvStructure << std::endl; + + + + pvStructure = standardPVField->scalarArray(pvDouble,"alarm,timeStamp"); + std::cout << *pvStructure << std::endl; + + double values[] = { 1.1, 2.2, 3.3 }; + PVDoubleArrayPtr darray = std::tr1::dynamic_pointer_cast(pvStructure->getScalarArrayField("value", pvDouble)); + darray->put(0, 3, values, 0); + std::cout << *darray << std::endl; + std::cout << format::array_at(1) << *darray << std::endl; + + + StructureConstPtr structure = standardField->scalar(pvDouble, "alarm,timeStamp"); + pvStructure = standardPVField->structureArray(structure,"alarm,timeStamp"); + size_t num = 2; + PVStructurePtrArray pvStructures; + pvStructures.reserve(num); + for(size_t i=0; icreatePVStructure(structure)); + } + PVStructureArrayPtr pvStructureArray = pvStructure->getStructureArrayField("value"); + pvStructureArray->put(0, num, pvStructures, 0); + std::cout << *pvStructure << std::endl; + + return 0; +} + diff --git a/testApp/pv/testPVData.cpp b/testApp/pv/testPVData.cpp index bb60a2a..71654da 100644 --- a/testApp/pv/testPVData.cpp +++ b/testApp/pv/testPVData.cpp @@ -77,7 +77,7 @@ static void testCreatePVStructure(FILE * fd) fprintf(fd,"testCreatePVStructure PASSED\n"); } -static void testPVScalarCommon(FILE * fd,String fieldName,ScalarType stype) +static void testPVScalarCommon(FILE * fd,String /*fieldName*/,ScalarType stype) { PVScalarPtr pvScalar = pvDataCreate->createPVScalar(stype); if(stype==pvBoolean) { @@ -91,7 +91,7 @@ static void testPVScalarCommon(FILE * fd,String fieldName,ScalarType stype) } static void testPVScalarWithProperties( - FILE * fd,String fieldName,ScalarType stype) + FILE * fd,String /*fieldName*/,ScalarType stype) { PVStructurePtr pvStructure; bool hasValueAlarm = false; @@ -335,7 +335,7 @@ static void testPVScalar(FILE * fd) { } -static void testScalarArrayCommon(FILE * fd,String fieldName,ScalarType stype) +static void testScalarArrayCommon(FILE * fd,String /*fieldName*/,ScalarType stype) { PVStructurePtr pvStructure = standardPVField->scalarArray( stype,alarmTimeStamp); diff --git a/testApp/pv/testStandardField.cpp b/testApp/pv/testStandardField.cpp index efae647..661caa1 100644 --- a/testApp/pv/testStandardField.cpp +++ b/testApp/pv/testStandardField.cpp @@ -35,7 +35,7 @@ static void print(String name) if(debug) printf("\n%s\n%s\n",name.c_str(),builder.c_str()); } -int main(int argc,char *argv[]) +int main(int, char **) { StructureConstPtr doubleValue = standardField->scalar(pvDouble, "alarm,timeStamp,display,control,valueAlarm"); diff --git a/testApp/pv/testStandardPVField.cpp b/testApp/pv/testStandardPVField.cpp index 675cf15..7c19ccd 100644 --- a/testApp/pv/testStandardPVField.cpp +++ b/testApp/pv/testStandardPVField.cpp @@ -37,7 +37,7 @@ static void print(String name) if(debug) printf("\n%s\n%s\n",name.c_str(),builder.c_str()); } -int main(int argc,char *argv[]) +int main(int, char **) { PVStructurePtr pvStructure = standardPVField->scalar(pvDouble, "alarm,timeStamp,display,control,valueAlarm");