OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
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 <map>
25#include <ostream>
26#include <string>
27#include <vector>
28
30public:
32
33 void addColumn(
34 const std::string& name, const std::string& type, const std::string& unit,
35 const std::string& desc, std::ios_base::fmtflags flags = std::ios_base::scientific,
36 unsigned short precision = 15);
37
38 template <typename T>
39 void addColumnValue(const std::string& name, const T& val);
40
41 void writeHeader(std::ostream& os, const std::string& indent) const;
42
43 void writeRow(std::ostream& os) const;
44
45 bool hasColumns() const;
46
47private:
48 std::vector<SDDSColumn> columns_m;
49 std::map<std::string, size_t> name2idx_m;
50};
51
53
54template <typename T>
55void SDDSColumnSet::addColumnValue(const std::string& name, const T& val) {
56 auto it = name2idx_m.find(name);
57 if (it == name2idx_m.end()) {
58 throw OpalException(
59 "SDDSColumnSet::addColumnValue", "column name '" + name + "' doesn't exists");
60 }
61
62 auto& col = columns_m[it->second];
63 col.addValue(val);
64}
65
66inline bool SDDSColumnSet::hasColumns() const { return !name2idx_m.empty(); }
67
68#endif
double T
Definition OPALTypes.h:8
std::map< std::string, size_t > name2idx_m
std::vector< SDDSColumn > columns_m
bool hasColumns() const
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)
void writeHeader(std::ostream &os, const std::string &indent) const