votca 2026-dev
Loading...
Searching...
No Matches
resultfile.h
Go to the documentation of this file.
1/*
2 * Copyright 2009-2026 The VOTCA Development Team
3 * (http://www.votca.org)
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License")
6 *
7 * You may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20#pragma once
21#ifndef VOTCA_XTP_RESULTFILE_H
22#define VOTCA_XTP_RESULTFILE_H
23
24// Standard includes
25#include <fstream>
26#include <iomanip>
27#include <sstream>
28#include <stdexcept>
29#include <string>
30
31// VOTCA includes
32#include <votca/tools/types.h>
33
34namespace votca {
35namespace xtp {
36
43 public:
44 explicit ResultFile(const std::string& title) {
45 text_ << "# " << title << "\n# key value unit\n";
46 text_ << std::setprecision(12);
47 }
48
49 void Add(const std::string& key, double value, const std::string& unit) {
50 text_ << key << " " << value << " " << unit << "\n";
51 }
52 void Add(const std::string& key, Index value) {
53 text_ << key << " " << value << " -\n";
54 }
55 void Add(const std::string& key, const std::string& value) {
56 text_ << key << " " << value << " -\n";
57 }
58
59 void Write(const std::string& filename) const {
60 std::ofstream out(filename);
61 if (!out) {
62 throw std::runtime_error("Cannot write " + filename);
63 }
64 out << text_.str();
65 }
66
67 private:
68 std::stringstream text_;
69};
70
71} // namespace xtp
72} // namespace votca
73
74#endif // VOTCA_XTP_RESULTFILE_H
void Add(const std::string &key, const std::string &value)
Definition resultfile.h:55
void Write(const std::string &filename) const
Definition resultfile.h:59
void Add(const std::string &key, Index value)
Definition resultfile.h:52
void Add(const std::string &key, double value, const std::string &unit)
Definition resultfile.h:49
std::stringstream text_
Definition resultfile.h:68
ResultFile(const std::string &title)
Definition resultfile.h:44
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26