From f29ef3121e9e32f4fcf8f97551be9ff21e792fa4 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Fri, 29 Jun 2018 16:16:38 -0700 Subject: [PATCH] pvtools: compose pvutil_ostream eliminate at least some of the odd-ness which is causing build failures on hosted mingw. --- pvtoolsSrc/eget.cpp | 8 ++++---- pvtoolsSrc/pvget.cpp | 12 ++++++------ pvtoolsSrc/pvutils.h | 28 ++++++++++++---------------- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/pvtoolsSrc/eget.cpp b/pvtoolsSrc/eget.cpp index 589ef06..d05fb94 100644 --- a/pvtoolsSrc/eget.cpp +++ b/pvtoolsSrc/eget.cpp @@ -863,7 +863,7 @@ void formatNT(std::ostream& o, PVFieldPtr const & pv) { std::cerr << "non-normative type" << std::endl; //o << *(pv.get()) << std::endl; - pvutil_ostream myos(std::cout.rdbuf()); + pvutil_ostream myos(std::cout); myos << *(pv.get()) << std::endl; } @@ -872,7 +872,7 @@ void formatNT(std::ostream& o, PVFieldPtr const & pv) } // no ID, just dump - pvutil_ostream myos(std::cout.rdbuf()); + pvutil_ostream myos(std::cout); myos << *(pv.get()) << std::endl; } @@ -882,7 +882,7 @@ void dumpValue(std::string const & channelName, PVField::shared_pointer const & std::cout << channelName << std::endl; //std::cout << *(pv.get()) << std::endl << std::endl; - pvutil_ostream myos(std::cout.rdbuf()); + pvutil_ostream myos(std::cout); if (pv->getField()->getType() == structure) myos << *(TR1::static_pointer_cast(pv).get()) << std::endl << std::endl; else @@ -1897,7 +1897,7 @@ int main (int argc, char *argv[]) else { //std::cout << *(rpcRequesterImpl->getLastResponse().get()) << std::endl; - pvutil_ostream myos(std::cout.rdbuf()); + pvutil_ostream myos(std::cout); myos << *(rpcRequesterImpl->getLastResponse().get()) << std::endl; } } diff --git a/pvtoolsSrc/pvget.cpp b/pvtoolsSrc/pvget.cpp index c4ad4b5..fe6c878 100644 --- a/pvtoolsSrc/pvget.cpp +++ b/pvtoolsSrc/pvget.cpp @@ -81,7 +81,7 @@ void printValue(std::string const & channelName, PVStructure::shared_pointer con if (value.get() == 0) { std::cerr << "no 'value' field\n"; - pvutil_ostream myos(std::cout.rdbuf()); + pvutil_ostream myos(std::cout); myos << channelName << "\n" << *(pv.get()) << "\n\n"; } else @@ -99,7 +99,7 @@ void printValue(std::string const & channelName, PVStructure::shared_pointer con } else { - pvutil_ostream myos(std::cout.rdbuf()); + pvutil_ostream myos(std::cout); myos << channelName << '\n' << *(pv.get()) << "\n\n"; } } @@ -120,7 +120,7 @@ void printValue(std::string const & channelName, PVStructure::shared_pointer con terseStructure(std::cout, pv) << '\n'; else { - pvutil_ostream myos(std::cout.rdbuf()); + pvutil_ostream myos(std::cout); myos << channelName << '\n' << *(pv.get()) << "\n\n"; } } @@ -278,7 +278,7 @@ struct MonitorRequesterImpl : public MonitorRequester, public Tracker { std::cerr << "no 'value' field" << '\n'; std::cout << m_channelName << '\n'; - pvutil_ostream myos(std::cout.rdbuf()); + pvutil_ostream myos(std::cout); myos << *(element->pvStructurePtr.get()) << "\n\n"; } else @@ -297,7 +297,7 @@ struct MonitorRequesterImpl : public MonitorRequester, public Tracker else { std::cout << m_channelName << '\n'; - pvutil_ostream myos(std::cout.rdbuf()); + pvutil_ostream myos(std::cout); myos << *(element->pvStructurePtr.get()) << "\n\n"; } } @@ -321,7 +321,7 @@ struct MonitorRequesterImpl : public MonitorRequester, public Tracker else { std::cout << m_channelName << '\n'; - pvutil_ostream myos(std::cout.rdbuf()); + pvutil_ostream myos(std::cout); myos << *(element->pvStructurePtr.get()) << "\n\n"; } diff --git a/pvtoolsSrc/pvutils.h b/pvtoolsSrc/pvutils.h index 73439ac..9377f4d 100644 --- a/pvtoolsSrc/pvutils.h +++ b/pvtoolsSrc/pvutils.h @@ -83,13 +83,14 @@ std::ostream& operator<<(std::ostream& os, const dump_stack_only_on_debug& d); #include #include -// usage: pvutil_ostream myos(std::cout.rdbuf()); +// usage: pvutil_ostream myos(std::cout); -class pvutil_ostream : private std::ostream +class pvutil_ostream { + std::ostream& strm; public: - pvutil_ostream(std::streambuf* sb) - : std::ostream(sb) + pvutil_ostream(std::ostream& os) + : strm(os) {} template @@ -99,11 +100,6 @@ public: // Additional overload to handle ostream specific io manipulators friend pvutil_ostream& operator<<(pvutil_ostream&, std::ostream& (*)(std::ostream&)); - - // Accessor function to get a reference to the ostream - std::ostream& get_ostream() { - return *this; - } }; @@ -111,7 +107,7 @@ template inline pvutil_ostream& operator<<(pvutil_ostream& out, const T& value) { - static_cast(out) << value; + out.strm << value; return out; } @@ -119,7 +115,7 @@ operator<<(pvutil_ostream& out, const T& value) inline pvutil_ostream& operator<<(pvutil_ostream& out, std::ostream& (*func)(std::ostream&)) { - static_cast(out) << func; + out.strm << func; return out; } @@ -143,7 +139,7 @@ operator<<(pvutil_ostream& o, const epics::pvData::PVStructure::shared_pointer & { o << epics::pvData::format::indent() << value->getStructure()->getID() << ' ' << value->getFieldName() << ' '; //" # "; - formatTType(o, value); + formatTType(o.strm, value); o << std::endl; //dumpPVStructure(o, *value, false); return o; @@ -161,7 +157,7 @@ operator<<(pvutil_ostream& o, const epics::pvData::PVStructureArray::shared_poin size_t length = value->getLength(); if (length > 0) { - epics::pvData::format::indent_scope s(o); + epics::pvData::format::indent_scope s(o.strm); epics::pvData::PVStructureArray::const_svector data(value->view()); for (size_t i = 0; i < length; i++) @@ -183,7 +179,7 @@ operator<<(pvutil_ostream& o, const epics::pvData::PVUnionArray::shared_pointer size_t length = value->getLength(); if (length > 0) { - epics::pvData::format::indent_scope s(o); + epics::pvData::format::indent_scope s(o.strm); epics::pvData::PVUnionArray::const_svector data(value->view()); for (size_t i = 0; i < length; i++) @@ -203,7 +199,7 @@ operator<<(pvutil_ostream& o, const epics::pvData::PVUnion::shared_pointer & val o << epics::pvData::format::indent() << value->getUnion()->getID() << ' ' << value->getFieldName() << std::endl; { - epics::pvData::format::indent_scope s(o); + epics::pvData::format::indent_scope s(o.strm); epics::pvData::PVFieldPtr fieldField = value->get(); if (fieldField.get() == NULL) @@ -246,7 +242,7 @@ dumpPVStructure(pvutil_ostream& o, const epics::pvData::PVStructure & value, boo } { - epics::pvData::format::indent_scope s(o); + epics::pvData::format::indent_scope s(o.strm); epics::pvData::PVFieldPtrArray const & fieldsData = value.getPVFields(); if (fieldsData.size() != 0) {