OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
SDDSColumn.h
Go to the documentation of this file.
1 //
2 // Class SDDSColumn
3 // This class writes column entries of SDDS files.
4 //
5 // Copyright (c) 2019, Christof Metzger-Kraus, Open Sourcerer
6 // All rights reserved
7 //
8 // This file is part of OPAL.
9 //
10 // OPAL is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
17 //
18 #ifndef SDDSWRITERCOLUMN_H
19 #define SDDSWRITERCOLUMN_H
20 
21 #include <boost/variant.hpp>
22 
23 #include <ostream>
24 #include <tuple>
25 #include <string>
26 
27 class SDDSColumn {
28 public:
29  SDDSColumn(const std::string& name,
30  const std::string& type,
31  const std::string& unit,
32  const std::string& desc,
33  std::ios_base::fmtflags flags,
34  unsigned short precision);
35 
36  template<typename T>
37  void addValue(const T& val);
38 
39  void writeHeader(std::ostream& os,
40  unsigned int colNr,
41  const std::string& indent) const;
42 
43 protected:
44 
45  void writeValue(std::ostream& os) const;
46 
47 private:
48  friend
49  std::ostream& operator<<(std::ostream& os,
50  const SDDSColumn& col);
51 
52  typedef std::tuple<std::string,
53  std::string,
54  std::string> desc_t;
55 
56  typedef boost::variant<float,
57  double,
58  long unsigned int,
59  char,
60  std::string> variant_t;
61  std::string name_m;
64 
65  std::ios_base::fmtflags writeFlags_m;
66  unsigned short writePrecision_m;
67 
68  mutable bool set_m;
69 };
70 
71 
72 template<typename T>
73 void SDDSColumn::addValue(const T& val) {
74  value_m = val;
75  set_m = true;
76 }
77 
78 
79 std::ostream& operator<<(std::ostream& os,
80  const SDDSColumn& col);
81 
82 #endif
std::ostream & operator<<(std::ostream &os, const SDDSColumn &col)
Definition: SDDSColumn.cpp:95
const std::string name
boost::function< boost::tuple< double, bool >arguments_t)> type
Definition: function.hpp:21
variant_t value_m
Definition: SDDSColumn.h:63
void writeHeader(std::ostream &os, unsigned int colNr, const std::string &indent) const
Definition: SDDSColumn.cpp:68
desc_t description_m
Definition: SDDSColumn.h:62
std::tuple< std::string, std::string, std::string > desc_t
Definition: SDDSColumn.h:54
std::string name_m
Definition: SDDSColumn.h:61
bool set_m
Definition: SDDSColumn.h:68
unsigned short writePrecision_m
Definition: SDDSColumn.h:66
void writeValue(std::ostream &os) const
Definition: SDDSColumn.cpp:83
void addValue(const T &val)
Definition: SDDSColumn.h:73
friend std::ostream & operator<<(std::ostream &os, const SDDSColumn &col)
Definition: SDDSColumn.cpp:95
boost::variant< float, double, long unsigned int, char, std::string > variant_t
Definition: SDDSColumn.h:60
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:24
std::ios_base::fmtflags writeFlags_m
Definition: SDDSColumn.h:65