OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
SDDSColumnSet.h
Go to the documentation of this file.
1//
2// Class SDDSColumnSet
3// This class writes rows 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 SDDSWRITERCOLUMNSET_H
19#define SDDSWRITERCOLUMNSET_H
20
23
24#include <string>
25#include <ostream>
26#include <vector>
27#include <map>
28
30public:
32
33 void addColumn(const std::string& name,
34 const std::string& type,
35 const std::string& unit,
36 const std::string& desc,
37 std::ios_base::fmtflags flags = std::ios_base::scientific,
38 unsigned short precision = 15);
39
40 template<typename T>
41 void addColumnValue(const std::string& name,
42 const T& val);
43
44 void writeHeader(std::ostream& os,
45 const std::string& indent) const;
46
47 void writeRow(std::ostream& os) const;
48
49 bool hasColumns() const;
50
51private:
52 std::vector<SDDSColumn> columns_m;
53 std::map<std::string, unsigned int> name2idx_m;
54};
55
56
57inline
59{ }
60
61
62template<typename T>
63void SDDSColumnSet::addColumnValue(const std::string& name,
64 const T& val) {
65
66 auto it = name2idx_m.find(name);
67 if (it == name2idx_m.end()) {
68 throw OpalException("SDDSColumnSet::addColumnValue",
69 "column name '" + name + "' doesn't exists");
70 }
71
72 auto & col = columns_m[it->second];
73 col.addValue(val);
74}
75
76
77inline
79 return !name2idx_m.empty();
80}
81
82
83#endif
const std::string name
boost::function< boost::tuple< double, bool >(arguments_t)> type
Definition: function.hpp:21
std::vector< SDDSColumn > columns_m
Definition: SDDSColumnSet.h:52
bool hasColumns() const
Definition: SDDSColumnSet.h:78
std::map< std::string, unsigned int > name2idx_m
Definition: SDDSColumnSet.h:53
void writeRow(std::ostream &os) const
void addColumn(const std::string &name, const std::string &type, const std::string &unit, const std::string &desc, std::ios_base::fmtflags flags=std::ios_base::scientific, unsigned short precision=15)
void addColumnValue(const std::string &name, const T &val)
Definition: SDDSColumnSet.h:63
void writeHeader(std::ostream &os, const std::string &indent) const
The base class for all OPAL exceptions.
Definition: OpalException.h:28