diff --git a/pvDataApp/factory/PVField.cpp b/pvDataApp/factory/PVField.cpp index b829e73..827ab14 100644 --- a/pvDataApp/factory/PVField.cpp +++ b/pvDataApp/factory/PVField.cpp @@ -193,6 +193,19 @@ void PVField::toString(StringBuilder buf,int indentLevel) if(pvAuxInfo.get()!=NULL) pvAuxInfo->toString(buf,indentLevel); } +std::ostream& PVField::dumpValue(std::ostream& o) const +{ + // default implementation + // each PVField class should implement it to avoid switch statement + // and string reallocation + static ConvertPtr convert = getConvert(); + String tmp; + convert->getString(&tmp,this,0); + return o << tmp; +} + +std::ostream& operator<<(std::ostream& o, const PVField& f) { return f.dumpValue(o); }; + void PVField::computeOffset(const PVField * pvField) { const PVStructure * pvTop = pvField->getParent(); if(pvTop==NULL) { diff --git a/pvDataApp/pv/pvData.h b/pvDataApp/pv/pvData.h index 81f56d5..de791d8 100644 --- a/pvDataApp/pv/pvData.h +++ b/pvDataApp/pv/pvData.h @@ -10,6 +10,9 @@ #include #include #include +#include +#include +#include #include #include namespace epics { namespace pvData { @@ -265,6 +268,14 @@ public: * @param indentLevel The indentation level. */ virtual void toString(StringBuilder buf,int indentLevel) ; + + /** + * Puts the PVField raw value to the stream. + * @param o output stream. + * @return The output stream. + */ + virtual std::ostream& dumpValue(std::ostream& o) const; + protected: PVField::shared_pointer getPtrSelf() { @@ -291,6 +302,8 @@ private: friend class PVStructure; }; +std::ostream& operator<<(std::ostream& o, const PVField& f); + /** * PVScalar is the base class for each scalar field. */ @@ -336,6 +349,12 @@ public: * @param The value. */ virtual void put(T value) = 0; + + std::ostream& dumpValue(std::ostream& o) const + { + return o << get(); + } + protected: PVScalarValue(ScalarConstPtr const & scalar) : PVScalar(scalar) {} @@ -482,6 +501,8 @@ public: */ const ScalarArrayConstPtr getScalarArray() const ; + virtual std::ostream& dumpValue(std::ostream& o, size_t index) const = 0; + protected: PVScalarArray(ScalarArrayConstPtr const & scalarArray); private: @@ -850,6 +871,31 @@ public: virtual pointer get() const = 0; virtual vector const & getVector() = 0; virtual shared_vector const & getSharedVector() = 0; + + std::ostream& dumpValue(std::ostream& o) const + { + o << "["; + pointer iter = get(); + pointer last = iter + getLength(); + if (iter != last) + { + while (true) + { + o << *(iter++); + if (iter == last) + break; + else + o << ","; + } + } + return o << "]"; + } + + std::ostream& dumpValue(std::ostream& o, size_t index) const + { + return o << *(get() + index); + } + protected: PVValueArray(ScalarArrayConstPtr const & scalar) : PVScalarArray(scalar) {}