OPAL (Object Oriented Parallel Accelerator Library)  2024.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 
21 #include "Structure/SDDSColumn.h"
23 
24 #include <string>
25 #include <ostream>
26 #include <vector>
27 #include <map>
28 
30 public:
31  SDDSColumnSet();
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 
51 private:
52  std::vector<SDDSColumn> columns_m;
53  std::map<std::string, unsigned int> name2idx_m;
54 };
55 
56 
57 inline
59 { }
60 
61 
62 template<typename T>
63 void 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 
77 inline
79  return !name2idx_m.empty();
80 }
81 
82 
83 #endif
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two distribute and or modify the software for each author s protection and we want to make certain that everyone understands that there is no warranty for this free software If the software is modified by someone else and passed we want its recipients to know that what they have is not the so that any problems introduced by others will not reflect on the original authors reputations any free program is threatened constantly by software patents We wish to avoid the danger that redistributors of a free program will individually obtain patent in effect making the program proprietary To prevent we have made it clear that any patent must be licensed for everyone s free use or not licensed at all The precise terms and conditions for distribution and modification follow GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR DISTRIBUTION AND MODIFICATION This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License The refers to any such program or and a work based on the Program means either the Program or any derivative work under copyright a work containing the Program or a portion of it
Definition: LICENSE:43
std::map< std::string, unsigned int > name2idx_m
Definition: SDDSColumnSet.h:53
bool hasColumns() const
Definition: SDDSColumnSet.h:78
std::vector< SDDSColumn > columns_m
Definition: SDDSColumnSet.h:52
The base class for all OPAL exceptions.
Definition: OpalException.h:28
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
const std::string name
void writeRow(std::ostream &os) const
void addColumnValue(const std::string &name, const T &val)
Definition: SDDSColumnSet.h:63
SDDS1 &description type
Definition: test.stat:4