This is Unofficial EPICS BASE Doxygen Site
epics::pvData::PVStructure::Formatter Struct Reference

#include "pvData.h"

Public Types

enum  mode_t { Auto, Plain, ANSI }
 
enum  format_t { Raw, NT, JSON }
 

Public Member Functions

 Formatter (const PVStructure &top)
 
FORCE_INLINE Formattershow (const BitSet &set)
 
FORCE_INLINE Formatterhighlight (const BitSet &set)
 
FORCE_INLINE Formattermode (mode_t m)
 
FORCE_INLINE Formatterformat (format_t f)
 

Friends

epicsShareFunc std::ostream & operator<< (std::ostream &strm, const Formatter &format)
 
void printRaw (std::ostream &strm, const PVStructure::Formatter &format, const PVStructure &cur)
 

Detailed Description

Definition at line 874 of file pvData.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

epics::pvData::PVStructure::Formatter::Formatter ( const PVStructure top)
inlineexplicit

Definition at line 892 of file pvData.h.

893  :xtop(top)
894  ,xshow(0)
895  ,xhighlight(0)
896  ,xmode(Auto)
897  ,xfmt(NT)
898  {}

Member Function Documentation

FORCE_INLINE Formatter& epics::pvData::PVStructure::Formatter::format ( format_t  f)
inline

Definition at line 907 of file pvData.h.

907 { xfmt = f; return *this; }
FORCE_INLINE Formatter& epics::pvData::PVStructure::Formatter::highlight ( const BitSet set)
inline

Definition at line 903 of file pvData.h.

903 { xhighlight = &set; return *this; }
FORCE_INLINE Formatter& epics::pvData::PVStructure::Formatter::mode ( mode_t  m)
inline

Definition at line 905 of file pvData.h.

905 { xmode = m; return *this; }
FORCE_INLINE Formatter& epics::pvData::PVStructure::Formatter::show ( const BitSet set)
inline

Definition at line 901 of file pvData.h.

901 { xshow = &set; return *this; }

Friends And Related Function Documentation

epicsShareFunc std::ostream& operator<< ( std::ostream &  strm,
const Formatter format 
)
friend

Definition at line 402 of file printer.cpp.

403 {
405  JSONPrintOptions opts;
406  opts.multiLine = false;
407  printJSON(strm, format.xtop, format.xshow ? *format.xshow : BitSet().set(0), opts);
408  strm<<'\n';
409  return strm;
410 
411  } else if(format.xfmt==PVStructure::Formatter::NT) {
412  std::string id(format.xtop.getStructure()->getID()),
413  idprefix(id.substr(0, id.find_first_of('.')));
414 
415  // NTTable
416  if(idprefix=="epics:nt/NTTable:1") {
417  if(printTable(strm, format.xtop))
418  return strm;
419  } else {
420  //NTScalar, NTScalarArray, NTEnum, or anything with '.value'
421 
422  PVField::const_shared_pointer value(format.xtop.getSubField("value"));
423  if(value) {
424  switch(value->getField()->getType()) {
425  case scalar:
426  strm<<format::indent();
427  printTimeT(strm, format.xtop);
428  strm<<std::setprecision(6)<<*static_cast<const PVScalar*>(value.get())<<' ';
429  printAlarmT(strm, format.xtop);
430  strm<<'\n';
431  return strm;
432 
433  case scalarArray:
434  strm<<format::indent();
435  printTimeT(strm, format.xtop);
436  printAlarmT(strm, format.xtop);
437  strm<<std::setprecision(6)<<*static_cast<const PVScalarArray*>(value.get())<<'\n';
438  return strm;
439 
440  case structure:
441  if(printEnumT(strm, format.xtop, true)) {
442  strm<<'\n';
443  return strm;
444  }
445  break;
446  default:
447  break;
448  }
449  }
450  }
451  }
452  // fall through unhandled as Raw
453 
455 
456  if(format2.xmode==PVStructure::Formatter::Auto)
457  format2.xmode = useEscapes(strm) ? PVStructure::Formatter::ANSI : PVStructure::Formatter::Plain;
458 
459  printRaw(strm, format2, format.xtop);
460 
461  return strm;
462 }
FORCE_INLINE std::tr1::shared_ptr< PVField > getSubField(A a)
Definition: pvData.h:744
Definition: link.h:174
Options used during printing.
Definition: json.h:42
A vector of bits.
Definition: bitSet.h:56
void printJSON(std::ostream &strm, const PVStructure &val, const BitSet &mask, const JSONPrintOptions &opts)
Definition: print.cpp:211
const StructureConstPtr & getStructure() const
Definition: pvData.h:731
friend void printRaw(std::ostream &strm, const PVStructure::Formatter &format, const PVStructure &cur)
Definition: printer.cpp:317
FORCE_INLINE Formatter & format(format_t f)
Definition: pvData.h:907
bool multiLine
include new lines
Definition: json.h:44
void printRaw ( std::ostream &  strm,
const PVStructure::Formatter format,
const PVStructure cur 
)
friend

Definition at line 317 of file printer.cpp.

318 {
319  typedef std::deque<std::pair<const PVField*, size_t> > todo_t;
320  todo_t todo;
322 
323  const long orig_indent = format::indent_value(strm);
324 
325  {
326  if(format.xshow)
327  show = *format.xshow;
328  else
329  show.set(0);
330 
331  if(format.xhighlight)
332  highlight = *format.xhighlight;
333 
334  expandBS(format.xtop, show, true);
335  expandBS(format.xtop, highlight, false);
336  highlight &= show; // can't highlight hidden fields (paranoia)
337  }
338 
339  if(!show.get(0)) return; // nothing to do here...
340 
341  todo.push_front(std::make_pair(&format.xtop, orig_indent));
342 
343  while(!todo.empty()) {
344  todo_t::value_type cur(todo.front());
345  todo.pop_front();
346 
347  format::indent_value(strm) = cur.second;
348 
349  bool hl = highlight.get(cur.first->getFieldOffset()) && format.xmode==PVStructure::Formatter::ANSI;
350  if(hl)
351  strm<<"\x1b[1m"; // Bold
352 
353  switch(cur.first->getField()->getType()) {
354  case structure: {
355  const PVStructure* str = static_cast<const PVStructure*>(cur.first);
356 
357  const PVFieldPtrArray& flds = str->getPVFields();
358 
359  for(PVFieldPtrArray::const_reverse_iterator it(flds.rbegin()), end(flds.rend()); it!=end; ++it) {
360  const PVField *fld = (*it).get();
361  if(!show.get(fld->getFieldOffset())) continue;
362 
363  todo.push_front(std::make_pair(fld, cur.second+1));
364  }
365 
366  std::string id(cur.first->getField()->getID());
367 
368  strm<<format::indent()<<id<<' '<<cur.first->getFieldName();
369  if(id=="alarm_t") {
370  strm.put(' ');
371  printAlarmTx(strm, *str);
372  } else if(id=="time_t") {
373  strm.put(' ');
374  printTimeTx(strm, *str);
375  } else if(id=="enum_t") {
376  strm.put(' ');
377  printEnumT(strm, *str, false);
378  }
379  strm.put('\n');
380  }
381  break;
382  case scalar:
383  case scalarArray:
384  strm<<format::indent()<<cur.first->getField()->getID()<<' '<<cur.first->getFieldName()
385  <<' '<<*cur.first
386  <<'\n';
387  break;
388  case structureArray:
389  case union_:
390  case unionArray:
391  strm<<*cur.first;
392  break;
393  }
394 
395  if(hl)
396  strm<<"\x1b[0m"; // reset
397  }
398 
399  format::indent_value(strm) = orig_indent;
400 }
const std::string & getFieldName() const
Definition: pvData.h:166
const PVFieldPtrArray & getPVFields() const
Definition: pvData.h:736
bool get(uint32 bitIndex) const
Definition: bitSet.cpp:130
const FieldConstPtr & getField() const
Definition: pvData.h:208
A vector of bits.
Definition: bitSet.h:56
#define str(v)
PVField is the base class for each PVData field.
Definition: pvData.h:152
std::size_t getFieldOffset() const
Definition: PVField.cpp:44
std::vector< PVFieldPtr > PVFieldPtrArray
Definition: pvData.h:70
Data interface for a structure,.
Definition: pvData.h:712
FORCE_INLINE Formatter & highlight(const BitSet &set)
Definition: pvData.h:903
long & indent_value(std::ios_base &ios)
Definition: printer.cpp:30
BitSet & set(uint32 bitIndex)
Definition: bitSet.cpp:103
FORCE_INLINE Formatter & show(const BitSet &set)
Definition: pvData.h:901

The documentation for this struct was generated from the following file: