9 #if defined(__linux__) || defined(__APPLE__) 19 #define epicsExportSharedSymbols 24 namespace epics {
namespace pvData {
28 static int indent_index = std::ios_base::xalloc();
32 return ios.iword(indent_index);
44 for(
long i=0, spaces = il * 4;
i<spaces;
i++)
59 bool useEscapes(std::ostream& strm) {
69 return isatty(fileno(fp))==1;
77 void printAlarmTx(std::ostream& strm,
const PVStructure& sub)
79 PVScalar::const_shared_pointer pvSeverity(sub.
getSubField<
PVInt>(
"severity"));
83 switch(pvSeverity ? pvSeverity->getAs<
int32>() : 0) {
85 case 1: strm<<
"MINOR ";
break;
86 case 2: strm<<
"MAJOR ";
break;
87 case 3: strm<<
"INVALID ";
break;
88 case 4: strm<<
"UNDEFINED ";
break;
89 default: strm<<pvSeverity->getAs<
int32>()<<
' ';
92 switch(pvStatus ? pvStatus->getAs<
int32>() : 0) {
94 case 1: strm<<
"DEVICE ";
break;
95 case 2: strm<<
"DRIVER ";
break;
96 case 3: strm<<
"RECORD ";
break;
97 case 4: strm<<
"DB ";
break;
98 case 5: strm<<
"CONF ";
break;
99 case 6: strm<<
"UNDEFINED ";
break;
100 case 7: strm<<
"CLIENT ";
break;
101 default: strm<<pvStatus->getAs<
int32>()<<
' ';
104 if(pvMessage && !pvMessage->get().empty())
105 strm<<pvMessage->get()<<
' ';
109 void printAlarmT(std::ostream& strm,
const PVStructure& top)
113 printAlarmTx(strm, *sub);
116 void printTimeTx(std::ostream& strm,
const PVStructure& tsubop)
126 epicsTS.
nsec = nsecf ? nsecf->getAs<
int32>() : 0;
134 strm <<std::setw(24) <<std::left <<timeText <<
' ';
143 void printTimeT(std::ostream& strm,
const PVStructure& top)
147 printTimeTx(strm, *sub);
150 bool printEnumT(std::ostream& strm,
const PVStructure& top,
bool fromtop)
152 PVStructure::const_shared_pointer
value;
158 PVScalar::const_shared_pointer idx(value->getSubField<
PVScalar>(
"index"));
159 PVStringArray::const_shared_pointer choices(value->getSubField<
PVStringArray>(
"choices"));
160 if(!idx || !choices)
return false;
164 printTimeT(strm, top);
165 printAlarmT(strm, top);
172 strm<<
" <undefined>";
179 void csvEscape(std::string& S)
183 if(S.find_first_of(
" ,\\")!=S.npos) {
185 temp2.reserve(temp.size()+2);
186 temp2.push_back(
'\"');
188 temp2.push_back(
'\"');
194 bool printTable(std::ostream& strm,
const PVStructure& top)
197 if(!cf)
return false;
201 if(fields.empty())
return false;
202 for(
size_t i=0, N=fields.size();
i<N;
i++) {
215 printTimeT(strm, top);
219 printAlarmT(strm, top);
235 std::vector<shared_vector<std::string> > coldat(columns.size());
237 std::vector<size_t> widths(columns.size());
238 labels.
reserve(columns.size());
240 size_t nrows = size_t(-1);
242 for(
size_t i=0, N=columns.size();
i<N;
i++) {
243 if(
i>=labels.
size()) {
244 labels.
push_back(cf->getStructure()->getFieldName(
i));
246 csvEscape(labels[
i]);
248 widths[
i] = labels[
i].
size();
253 coldat[
i] = thaw(ro);
257 nrows =
std::min(nrows, coldat[
i].size());
259 for(
size_t j=0, M=coldat[
i].size(); j<M; j++) {
260 csvEscape(coldat[
i][j]);
261 widths[
i] =
std::max(widths[
i], coldat[i][j].size());
267 for(
size_t c=0, N=coldat.size(); c<N; c++) {
268 strm<<std::setw(widths[c])<<std::right<<labels[c];
275 for(
size_t r=0; r<nrows; r++) {
276 strm<<format::indent();
277 for(
size_t c=0, N=coldat.size(); c<N; c++) {
278 strm<<std::setw(widths[c])<<std::right<<coldat[c][r];
297 PVField::const_shared_pointer fld = top.
getSubFieldT(idx);
300 for(
size_t i=idx+1, N=fld->getNextFieldOffset();
i<N;
i++)
307 mask.
set(parent->getFieldOffset());
315 namespace epics {
namespace pvData {
319 typedef std::deque<std::pair<const PVField*, size_t> > todo_t;
327 show = *format.xshow;
331 if(format.xhighlight)
332 highlight = *format.xhighlight;
334 expandBS(format.xtop, show,
true);
335 expandBS(format.xtop, highlight,
false);
339 if(!show.
get(0))
return;
341 todo.push_front(std::make_pair(&format.xtop, orig_indent));
343 while(!todo.empty()) {
344 todo_t::value_type cur(todo.front());
353 switch(cur.first->
getField()->getType()) {
359 for(PVFieldPtrArray::const_reverse_iterator it(flds.rbegin()), end(flds.rend()); it!=end; ++it) {
360 const PVField *fld = (*it).get();
363 todo.push_front(std::make_pair(fld, cur.second+1));
366 std::string id(cur.first->
getField()->getID());
371 printAlarmTx(strm, *str);
372 }
else if(
id==
"time_t") {
374 printTimeTx(strm, *str);
375 }
else if(
id==
"enum_t") {
377 printEnumT(strm, *str,
false);
407 printJSON(strm, format.xtop, format.xshow ? *format.xshow :
BitSet().
set(0), opts);
413 idprefix(
id.substr(0,
id.find_first_of(
'.')));
416 if(idprefix==
"epics:nt/NTTable:1") {
417 if(printTable(strm, format.xtop))
424 switch(
value->getField()->getType()) {
427 printTimeT(strm, format.xtop);
428 strm<<std::setprecision(6)<<*static_cast<const PVScalar*>(
value.get())<<
' ';
429 printAlarmT(strm, format.xtop);
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';
441 if(printEnumT(strm, format.xtop,
true)) {
459 printRaw(strm, format2, format.xtop);
464 static char hexdigit(
char c) {
476 std::ostringstream strm;
484 for(
size_t pos = 0, len = Q.orig.size(); pos < len; pos++) {
485 const char C = Q.orig[pos];
486 char quote =
'\\', next;
489 case '\a': next =
'a';
break;
490 case '\b': next =
'b';
break;
491 case '\f': next =
'f';
break;
492 case '\n': next =
'n';
break;
493 case '\r': next =
'r';
break;
494 case '\t': next =
't';
break;
495 case '\v': next =
'v';
break;
496 case '\\': next =
'\\';
break;
497 case '\'': next =
'\'';
break;
498 case '\"': next =
'\"';
if(Q.S==
escape::CSV) quote =
'"';
break;
502 strm<<
"\\x"<<hexdigit(C>>4)<<hexdigit(C);
FORCE_INLINE std::tr1::shared_ptr< PVField > getSubField(A a)
const std::string & getFieldName() const
const PVFieldPtrArray & getPVFields() const
PVScalar is the base class for each scalar field.
bool get(uint32 bitIndex) const
const FieldConstPtr & getField() const
shared_ptr< T > static_pointer_cast(shared_ptr< U > const &r) BOOST_NOEXCEPT
TODO only here because of the Lockable.
void printRaw(std::ostream &strm, const PVStructure::Formatter &format, const PVStructure &cur)
Options used during printing.
PVField is the base class for each PVData field.
std::size_t getFieldOffset() const
epicsUInt32 secPastEpoch
seconds since 0000 Jan 1, 1990
LIBCOM_API size_t epicsStdCall epicsTimeToStrftime(char *pBuff, size_t bufLength, const char *pFormat, const epicsTimeStamp *pTS)
Convert epicsTimeStamp to string. See epicsTime::strftime()
PVString is special case, since it implements SerializableArray.
void push_back(param_type v)
template class for all extensions of PVArray.
Base class for a scalarArray.
int32 nextSetBit(uint32 fromIndex) const
#define POSIX_TIME_AT_EPICS_EPOCH
The EPICS Epoch is 00:00:00 Jan 1, 1990 UTC.
std::vector< FieldConstPtr > FieldConstPtrArray
void printJSON(std::ostream &strm, const PVStructure &val, const BitSet &mask, const JSONPrintOptions &opts)
std::vector< PVFieldPtr > PVFieldPtrArray
Data interface for a structure,.
size_t size() const
Number of elements visible through this vector.
FORCE_INLINE std::tr1::shared_ptr< PVField > getSubFieldT(A a)
std::string str() const
print to string and return. (alloc and copy)
Class that holds the data for each possible scalar type.
EPICS time stamp, for use from C code.
const StructureConstPtr & getStructure() const
EPICS time-stamps (epicsTimeStamp), epicsTime C++ class and C functions for handling wall-clock times...
BitSet & set(uint32 bitIndex)
PVStructure * getParent()
void reserve(size_t i)
Set array capacity.
bool multiLine
include new lines
epicsUInt32 nsec
nanoseconds within second
std::size_t getNumberFields() const