operator<< for all PVField, indent and array_at manipulator

This commit is contained in:
Matej Sekoranja
2013-02-07 22:52:16 +01:00
parent a8a96def97
commit a0de4f126f
5 changed files with 161 additions and 15 deletions

View File

@@ -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<std::size_t>(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();