CEPS  24.01
Cardiac ElectroPhysiology Simulator
FileWriter.hpp
Go to the documentation of this file.
1 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2  This file is part of CEPS.
3 
4  CEPS is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  CEPS is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with CEPS (see file LICENSE at root of project).
16  If not, see <https://www.gnu.org/licenses/>.
17 
18 
19  Copyright 2019-2024 Inria, Universite de Bordeaux
20 
21  Authors, in alphabetical order:
22 
23  Pierre-Elliott BECUE, Florian CARO, Yves COUDIERE(*), Andjela DAVIDOVIC,
24  Charlie DOUANLA-LONTSI, Marc FUENTES, Mehdi JUHOOR, Michael LEGUEBE(*),
25  Pauline MIGERDITICHAN, Valentin PANNETIER(*), Nejib ZEMZEMI.
26  * : currently active authors
27 
28 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
31 #pragma once
32 
33 #include <fstream>
34 #include <iostream>
35 
37 
39 class FileWriter : public CepsObject
40 {
41 
42  public:
43 
47  explicit FileWriter(CepsBool binary = false);
48 
53  explicit FileWriter(const CepsString &file, CepsBool binary = false);
54 
58 // FileWriter (CepsBool binary = false);
59 
61  ~FileWriter() override;
62 
65  getFileName();
66 
68  void
69  open();
70 
72  void
73  close();
74 
76  CepsBool
77  good();
78 
80  void
81  reset();
82 
84  void
85  write(const CepsString& s);
86 
88  template <typename T>
89  FileWriter& operator<<(const T& content)
90  {
91  m_file << content;
92  return *this;
93  }
94 
95 
96  protected:
97 
99  std::ofstream m_file;
101 
102 };
std::basic_string< CepsChar > CepsString
C++ format string.
Definition: CepsTypes.hpp:128
bool CepsBool
Booleans.
Definition: CepsTypes.hpp:124
Base class for other (big) CEPS classes. All classes can get a pointer to this base class and also co...
Definition: CepsObject.hpp:40
Enables the writing of files.
Definition: FileWriter.hpp:40
void open()
Creates file or cleans previous content.
Definition: FileWriter.cpp:59
void reset()
The file stream is placed at the beginning of the file.
Definition: FileWriter.cpp:90
CepsString m_fileName
file to write
Definition: FileWriter.hpp:98
std::ofstream m_file
corresponding stream
Definition: FileWriter.hpp:99
void close()
Close current file.
Definition: FileWriter.cpp:77
FileWriter & operator<<(const T &content)
Writing operator.
Definition: FileWriter.hpp:89
FileWriter(CepsBool binary=false)
Constructor.
Definition: FileWriter.cpp:35
void write(const CepsString &s)
Single line writing.
Definition: FileWriter.cpp:96
CepsString getFileName()
Name of parsed file.
Definition: FileWriter.cpp:53
CepsBool good()
Tells if file is ok.
Definition: FileWriter.cpp:84
CepsBool m_binary
binary output if true
Definition: FileWriter.hpp:100
~FileWriter() override
Constructor.
Definition: FileWriter.cpp:47