OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
SDDSColumn.cpp
Go to the documentation of this file.
1 #include "Structure/SDDSColumn.h"
3 
4 #include <iomanip>
5 
6 SDDSColumn::SDDSColumn(const std::string& name,
7  const std::string& type,
8  const std::string& unit,
9  const std::string& desc,
10  std::ios_base::fmtflags flags,
11  unsigned short prec):
12  name_m(name),
13  description_m(std::make_tuple(type, unit, desc)),
14  writeFlags_m(flags),
15  writePrecision_m(prec),
16  set_m(false)
17 { }
18 
19 
20 void SDDSColumn::writeHeader(std::ostream& os,
21  unsigned int colNr,
22  const std::string& indent) const {
23  os << "&column\n"
24  << indent << "name=" << name_m << ",\n"
25  << indent << "type=" << std::get<0>(description_m) << ",\n";
26 
27  if (std::get<1>(description_m) != "")
28  os << indent << "units=" << std::get<1>(description_m) << ",\n";
29 
30  os << indent << "description=\"" << colNr << " " << std::get<2>(description_m) << "\"\n"
31  << "&end\n";
32 }
33 
34 
35 void SDDSColumn::writeValue(std::ostream& os) const {
36  if (!set_m) {
37  throw OpalException("SDDSColumn::writeValue",
38  "value for column '" + name_m + "' isn't set");
39  }
40 
41  os.setf(writeFlags_m);
42  os.precision(writePrecision_m);
43  os << value_m << std::setw(10) << "\t";
44  set_m = false;
45 }
46 
47 std::ostream& operator<<(std::ostream& os,
48  const SDDSColumn& col) {
49  col.writeValue(os);
50 
51  return os;
52 }
std::ostream & operator<<(std::ostream &os, const Attribute &attr)
Definition: Attribute.cpp:167
unsigned short writePrecision_m
Definition: SDDSColumn.h:49
void writeHeader(std::ostream &os, unsigned int colNr, const std::string &indent) const
Definition: SDDSColumn.cpp:20
std::ios_base::fmtflags writeFlags_m
Definition: SDDSColumn.h:48
The base class for all OPAL exceptions.
Definition: OpalException.h:28
SDDSColumn(const std::string &name, const std::string &type, const std::string &unit, const std::string &desc, std::ios_base::fmtflags flags, unsigned short precision)
Definition: SDDSColumn.cpp:6
void writeValue(std::ostream &os) const
Definition: SDDSColumn.cpp:35
desc_t description_m
Definition: SDDSColumn.h:45
std::string name_m
Definition: SDDSColumn.h:44
const std::string name
variant_t value_m
Definition: SDDSColumn.h:46
bool set_m
Definition: SDDSColumn.h:51