enhanced printout, enum_t/time_t support

This commit is contained in:
Matej Sekoranja
2014-10-15 16:10:41 +02:00
parent 66f2995a71
commit cfbbe577db
4 changed files with 209 additions and 36 deletions

View File

@@ -864,7 +864,9 @@ void formatNT(std::ostream& o, PVFieldPtr const & pv)
else
{
std::cerr << "non-normative type" << std::endl;
o << *(pv.get()) << std::endl;
//o << *(pv.get()) << std::endl;
pvutil_ostream myos(std::cout.rdbuf());
myos << *(pv.get()) << std::endl;
}
return;
@@ -872,14 +874,21 @@ void formatNT(std::ostream& o, PVFieldPtr const & pv)
}
// no ID, just dump
o << *(pv.get()) << std::endl;
pvutil_ostream myos(std::cout.rdbuf());
myos << *(pv.get()) << std::endl;
}
void dumpValue(std::string const & channelName, PVField::shared_pointer const & pv)
{
if (!channelName.empty())
std::cout << channelName << std::endl;
std::cout << *(pv.get()) << std::endl << std::endl;
//std::cout << *(pv.get()) << std::endl << std::endl;
pvutil_ostream myos(std::cout.rdbuf());
if (pv->getField()->getType() == structure)
myos << *(static_pointer_cast<PVStructure>(pv).get()) << std::endl << std::endl;
else
myos << *(pv.get()) << std::endl << std::endl;
}
void printValue(std::string const & channelName, PVStructure::shared_pointer const & pv, bool forceTerseWithName = false)
@@ -2085,7 +2094,11 @@ int main (int argc, char *argv[])
if (rpcRequesterImpl->getLastResponse().get() == 0)
std::cout << "(null)" << std::endl;
else
std::cout << *(rpcRequesterImpl->getLastResponse().get()) << std::endl;
{
//std::cout << *(rpcRequesterImpl->getLastResponse().get()) << std::endl;
pvutil_ostream myos(std::cout.rdbuf());
myos << *(rpcRequesterImpl->getLastResponse().get()) << std::endl;
}
}
else
formatNT(std::cout, rpcRequesterImpl->getLastResponse());

View File

@@ -71,16 +71,30 @@ void printValue(std::string const & channelName, PVStructure::shared_pointer con
if (value.get() == 0)
{
std::cerr << "no 'value' field" << std::endl;
std::cout << channelName << std::endl << *(pv.get()) << std::endl << std::endl;
//std::cout << channelName << std::endl << *(pv.get()) << std::endl << std::endl;
pvutil_ostream myos(std::cout.rdbuf());
myos << channelName << std::endl << *(pv.get()) << std::endl << std::endl;
}
else
{
Type valueType = value->getField()->getType();
if (valueType != scalar && valueType != scalarArray)
{
// switch to structure mode
std::cout << channelName << std::endl << *(pv.get()) << std::endl << std::endl;
}
// switch to structure mode, unless it's NTEnum
if (value->getField()->getID() == "enum_t")
{
std::cout << std::setw(30) << std::left << channelName;
std::cout << fieldSeparator;
printEnumT(std::cout, static_pointer_cast<PVStructure>(value));
std::cout << std::endl;
}
else
{
//std::cout << channelName << std::endl << *(pv.get()) << std::endl << std::endl;
pvutil_ostream myos(std::cout.rdbuf());
myos << channelName << std::endl << *(pv.get()) << std::endl << std::endl;
}
}
else
{
if (fieldSeparator == ' ' && value->getField()->getType() == scalar)
@@ -98,10 +112,9 @@ void printValue(std::string const & channelName, PVStructure::shared_pointer con
terseStructure(std::cout, pv) << std::endl;
else
{
std::cout << channelName << std::endl << *(pv.get()) << std::endl << std::endl;
//pvutil_ostream myos(std::cout.rdbuf());
//myos << channelName << std::endl << *(pv.get()) << std::endl << std::endl;
//std::cout << channelName << std::endl << *(pv.get()) << std::endl << std::endl;
pvutil_ostream myos(std::cout.rdbuf());
myos << channelName << std::endl << *(pv.get()) << std::endl << std::endl;
}
}
@@ -262,17 +275,31 @@ class MonitorRequesterImpl : public MonitorRequester
{
std::cerr << "no 'value' field" << std::endl;
std::cout << m_channelName << std::endl;
std::cout << *(element->pvStructurePtr.get()) << std::endl << std::endl;
//std::cout << *(element->pvStructurePtr.get()) << std::endl << std::endl;
pvutil_ostream myos(std::cout.rdbuf());
myos << *(element->pvStructurePtr.get()) << std::endl << std::endl;
}
else
{
Type valueType = value->getField()->getType();
if (valueType != scalar && valueType != scalarArray)
{
// switch to structure mode
std::cout << m_channelName << std::endl;
std::cout << *(element->pvStructurePtr.get()) << std::endl << std::endl;
}
// switch to structure mode, unless it's NTEnum
if (value->getField()->getID() == "enum_t")
{
std::cout << std::setw(30) << std::left << m_channelName;
std::cout << fieldSeparator;
printEnumT(std::cout, static_pointer_cast<PVStructure>(value));
std::cout << std::endl;
}
else
{
std::cout << m_channelName << std::endl;
//std::cout << *(element->pvStructurePtr.get()) << std::endl << std::endl;
pvutil_ostream myos(std::cout.rdbuf());
myos << *(element->pvStructurePtr.get()) << std::endl << std::endl;
}
}
else
{
if (fieldSeparator == ' ' && value->getField()->getType() == scalar)
@@ -300,7 +327,9 @@ class MonitorRequesterImpl : public MonitorRequester
else
{
std::cout << m_channelName << std::endl;
std::cout << *(element->pvStructurePtr.get()) << std::endl << std::endl;
//std::cout << *(element->pvStructurePtr.get()) << std::endl << std::endl;
pvutil_ostream myos(std::cout.rdbuf());
myos << *(element->pvStructurePtr.get()) << std::endl << std::endl;
}
monitor->release(element);

View File

@@ -112,13 +112,13 @@ std::ostream& terse(std::ostream& o, PVField::shared_pointer const & pv)
}
}
std::ostream& printEnumT(std::ostream& o, epics::pvData::PVStructure::shared_pointer const & pvEnumT)
std::ostream& printEnumT(std::ostream& o, epics::pvData::PVStructure const & pvEnumT)
{
PVInt::shared_pointer pvIndex = pvEnumT->getSubField<PVInt>("index");
PVInt::shared_pointer pvIndex = pvEnumT.getSubField<PVInt>("index");
if (!pvIndex)
throw std::runtime_error("enum_t structure does not have 'int index' field");
PVStringArray::shared_pointer pvChoices = pvEnumT->getSubField<PVStringArray>("choices");
PVStringArray::shared_pointer pvChoices = pvEnumT.getSubField<PVStringArray>("choices");
if (!pvChoices)
throw std::runtime_error("enum_t structure does not have 'string choices[]' field");
@@ -136,6 +136,11 @@ std::ostream& printEnumT(std::ostream& o, epics::pvData::PVStructure::shared_poi
return o;
}
std::ostream& printEnumT(std::ostream& o, epics::pvData::PVStructure::shared_pointer const & pvEnumT)
{
return printEnumT(o, *pvEnumT);
}
std::ostream& printTimeT(std::ostream& o, epics::pvData::PVStructure::shared_pointer const & pvTimeT)
{
#define TIMETEXTLEN 32

View File

@@ -21,6 +21,8 @@ void setEnumPrintMode(EnumMode mode);
void formatTTypes(bool flag);
std::ostream& printEnumT(std::ostream& o, epics::pvData::PVStructure const & pvEnumT);
//std::ostream& printTimeT(std::ostream& o, epics::pvData::PVStructure const & pvTimeT);
std::ostream& printEnumT(std::ostream& o, epics::pvData::PVStructure::shared_pointer const & pvEnumT);
std::ostream& printTimeT(std::ostream& o, epics::pvData::PVStructure::shared_pointer const & pvTimeT);
@@ -113,7 +115,7 @@ std::ostream& operator<<(std::ostream& os, const dump_stack_only_on_debug& d);
/*
#include <ostream>
#include <iostream>
@@ -129,6 +131,8 @@ public:
template <typename T>
friend pvutil_ostream& operator<<(pvutil_ostream&, const T&);
friend pvutil_ostream& dumpPVStructure(pvutil_ostream&, const epics::pvData::PVStructure &, bool);
// Additional overload to handle ostream specific io manipulators
friend pvutil_ostream& operator<<(pvutil_ostream&, std::ostream& (*)(std::ostream&));
@@ -141,7 +145,6 @@ template <typename T>
inline pvutil_ostream&
operator<<(pvutil_ostream& out, const T& value)
{
static_cast<std::ostream&>(out) << '.';
static_cast<std::ostream&>(out) << value;
return out;
}
@@ -150,29 +153,152 @@ operator<<(pvutil_ostream& out, const T& value)
inline pvutil_ostream&
operator<<(pvutil_ostream& out, std::ostream& (*func)(std::ostream&))
{
static_cast<std::ostream&>(out) << '#';
static_cast<std::ostream&>(out) << func;
return out;
}
// overload for PVField
template <>
inline pvutil_ostream&
operator<<(pvutil_ostream& out, const epics::pvData::PVField& value)
operator<<(pvutil_ostream& o, const epics::pvData::PVField::shared_pointer & fieldField);
template <>
inline pvutil_ostream&
operator<<(pvutil_ostream& o, const epics::pvData::PVStructure & value);
template <>
inline pvutil_ostream&
operator<<(pvutil_ostream& o, const epics::pvData::PVUnion::shared_pointer & value);
template <>
inline pvutil_ostream&
operator<<(pvutil_ostream& o, const epics::pvData::PVStructure::shared_pointer & value)
{
static_cast<std::ostream&>(out) << '?';
// static_cast<std::ostream&>(out) << value;
value.dumpValue(out);
return out;
std::string id = value->getStructure()->getID();
if (id == "enum_t")
{
o << epics::pvData::format::indent() << id << ' ' << value->getFieldName() << " # ";
printEnumT(o, value);
o << std::endl;
dumpPVStructure(o, *value, false);
return o;
}
else if (id == "time_t")
{
o << epics::pvData::format::indent() << id << ' ' << value->getFieldName() << " # ";
printTimeT(o, value);
o << std::endl;
dumpPVStructure(o, *value, false);
return o;
}
return o << *value;
}
template <>
inline pvutil_ostream&
operator<<(pvutil_ostream& out, const epics::pvData::PVStructure& value)
operator<<(pvutil_ostream& o, const epics::pvData::PVStructureArray::shared_pointer & value)
{
static_cast<std::ostream&>(out) << '!';
// static_cast<std::ostream&>(out) << value;
value.dumpValue(out);
return out;
o << epics::pvData::format::indent() << value->getStructureArray()->getID()
<< ' ' << value->getFieldName() << std::endl;
size_t length = value->getLength();
if (length > 0)
{
epics::pvData::format::indent_scope s(o);
epics::pvData::PVStructureArray::const_svector data(value->view());
for (size_t i = 0; i < length; i++)
o << data[i];
}
return o;
}
*/
template <>
inline pvutil_ostream&
operator<<(pvutil_ostream& o, const epics::pvData::PVUnionArray::shared_pointer & value)
{
o << epics::pvData::format::indent() << value->getUnionArray()->getID()
<< ' ' << value->getFieldName() << std::endl;
size_t length = value->getLength();
if (length > 0)
{
epics::pvData::format::indent_scope s(o);
epics::pvData::PVUnionArray::const_svector data(value->view());
for (size_t i = 0; i < length; i++)
o << data[i];
}
return o;
}
template <>
inline pvutil_ostream&
operator<<(pvutil_ostream& o, const epics::pvData::PVUnion::shared_pointer & value)
{
o << epics::pvData::format::indent() << value->getUnion()->getID()
<< ' ' << value->getFieldName() << std::endl;
{
epics::pvData::format::indent_scope s(o);
epics::pvData::PVFieldPtr fieldField = value->get();
if (fieldField.get() == NULL)
o << epics::pvData::format::indent() << "(none)" << std::endl;
else
o << fieldField;
}
return o;
}
template <>
inline pvutil_ostream&
operator<<(pvutil_ostream& o, const epics::pvData::PVField::shared_pointer & fieldField)
{
epics::pvData::Type type = fieldField->getField()->getType();
if (type == epics::pvData::scalar || type == epics::pvData::scalarArray)
o << epics::pvData::format::indent() << fieldField->getField()->getID() << ' ' << fieldField->getFieldName() << ' ' << *(fieldField.get()) << std::endl;
else if (type == epics::pvData::structure)
o << std::tr1::static_pointer_cast<epics::pvData::PVStructure>(fieldField);
else if (type == epics::pvData::structureArray)
o << std::tr1::static_pointer_cast<epics::pvData::PVStructureArray>(fieldField);
else if (type == epics::pvData::union_)
o << std::tr1::static_pointer_cast<epics::pvData::PVUnion>(fieldField);
else if (type == epics::pvData::unionArray)
o << std::tr1::static_pointer_cast<epics::pvData::PVUnionArray>(fieldField);
else
throw std::runtime_error("unsupported type");
return o;
}
pvutil_ostream&
dumpPVStructure(pvutil_ostream& o, const epics::pvData::PVStructure & value, bool showHeader)
{
if (showHeader)
{
std::string id = value.getStructure()->getID();
o << epics::pvData::format::indent() << id << ' ' << value.getFieldName();
o << std::endl;
}
{
epics::pvData::format::indent_scope s(o);
epics::pvData::PVFieldPtrArray const & fieldsData = value.getPVFields();
if (fieldsData.size() != 0) {
size_t length = value.getStructure()->getNumberFields();
for(size_t i=0; i<length; i++) {
o << fieldsData[i];
}
}
}
return o;
}
template <>
inline pvutil_ostream&
operator<<(pvutil_ostream& o, const epics::pvData::PVStructure& value)
{
return dumpPVStructure(o, value, true);
}