OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
SDDSColumnSet.cpp
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//
19
20void SDDSColumnSet::addColumn(const std::string& name,
21 const std::string& type,
22 const std::string& unit,
23 const std::string& desc,
24 std::ios_base::fmtflags flags,
25 unsigned short prec) {
26
27 if (name2idx_m.find(name) != name2idx_m.end()) {
28 throw OpalException("SDDSColumnSet::addColumn",
29 "column name '" + name + "' already exists");
30 }
31
32 name2idx_m.insert(std::make_pair(name, columns_m.size()));
33 columns_m.emplace_back(SDDSColumn(name, type, unit, desc, flags, prec));
34}
35
36
37void SDDSColumnSet::writeHeader(std::ostream& os,
38 const std::string& indent) const {
39 for (unsigned int i = 0; i < columns_m.size(); ++ i) {
40 auto & col = columns_m[i];
41 col.writeHeader(os, i + 1, indent);
42 }
43}
44
45
46void SDDSColumnSet::writeRow(std::ostream& os) const {
47 for (auto & col: columns_m) {
48 os << col;
49 }
50 os << std::endl;
51}
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
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
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 writeHeader(std::ostream &os, const std::string &indent) const
The base class for all OPAL exceptions.
Definition: OpalException.h:28