OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
FileSink.h
Go to the documentation of this file.
1 //
2 // Class FileSink
3 //
4 // Copyright (c) 2010 - 2013, Yves Ineichen, ETH Zürich
5 // All rights reserved
6 //
7 // Implemented as part of the PhD thesis
8 // "Toward massively parallel multi-objective optimization with application to
9 // particle accelerators" (https://doi.org/10.3929/ethz-a-009792359)
10 //
11 // This file is part of OPAL.
12 //
13 // OPAL is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation, either version 3 of the License, or
16 // (at your option) any later version.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
20 //
21 #ifndef __TRACE_FILE_SINK_H__
22 #define __TRACE_FILE_SINK_H__
23 
24 #include <sstream>
25 #include <iostream>
26 #include <fstream>
27 
29 
30 class FileSink : public TraceComponent {
31 
32 public:
33 
34 
35  FileSink(std::string filename)
36  : TraceComponent("FileSink")
37  , filename_(filename)
38  {}
39 
40  virtual ~FileSink()
41  {}
42 
43  void execute(std::ostringstream &dump) {
44  std::ofstream file;
45  file.open(filename_.c_str(), std::ios::app);
46  file << dump.str() << std::flush;
47  file.close();
48  }
49 
50 private:
51 
52  std::string filename_;
53 
54 };
55 
56 #endif
std::string filename_
Definition: FileSink.h:52
virtual ~FileSink()
Definition: FileSink.h:40
FileSink(std::string filename)
Definition: FileSink.h:35
void execute(std::ostringstream &dump)
Definition: FileSink.h:43