CEPS  24.01
Cardiac ElectroPhysiology Simulator
FileReader.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 #include <sstream>
36 
38 
43 {
44  public:
46  FileReader ();
47 
55  explicit FileReader (const CepsString &fileName);
56 
58  FileReader (const FileReader &that);
59 
61  FileReader &
62  operator= (const FileReader &that);
63 
65  virtual ~FileReader();
66 
68  void
69  setFileName (const CepsString &fileName);
70 
77  virtual CepsBool
78  open ();
79 
81  virtual void
82  close ();
83 
85  virtual CepsBool
86  good ();
87 
89  void
90  reset ();
91 
95  CepsUInt
96  find (const CepsString &pattern);
97 
101  CepsBool
102  findNext (const CepsString &pattern);
103 
107  CepsUInt
108  findNextOf (const CepsVector<CepsString> &patterns);
109 
111  CepsString
112  getFileName ();
113 
117  CepsUInt
118  skipLines (CepsUInt nbLines);
119 
121  void
122  oneLine (CepsString &line);
123 
125  template <typename T>
127  {
128  m_file >> var;
129  return *this;
130  }
131 
133  CepsInt
134  lineIndex (const CepsString &word);
135 
139  CepsUInt
140  checkEOF ();
141 
142 
143 
144  protected:
146  std::ifstream m_file;
147 };
std::basic_string< CepsChar > CepsString
C++ format string.
Definition: CepsTypes.hpp:128
std::vector< _Type, _Alloc > CepsVector
C++ vector.
Definition: CepsTypes.hpp:155
bool CepsBool
Booleans.
Definition: CepsTypes.hpp:124
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
Definition: CepsTypes.hpp:109
int32_t CepsInt
Need 32 bit integer.
Definition: CepsTypes.hpp:106
Base class that regroups common reader functionalities.
Definition: FileReader.hpp:43
virtual CepsBool good()
true if stream is still readable
Definition: FileReader.cpp:92
FileReader & operator=(const FileReader &that)
Copy constructor.
Definition: FileReader.cpp:51
virtual ~FileReader()
Destructor. Calls FileReader::close.
Definition: FileReader.cpp:58
CepsUInt checkEOF()
Checks if the reader reached end of file.
Definition: FileReader.cpp:228
FileReader & operator>>(T &var)
Reading operator.
Definition: FileReader.hpp:126
CepsInt lineIndex(const CepsString &word)
Index of first line starting with word, search starting from the current stream position.
Definition: FileReader.cpp:209
CepsUInt findNextOf(const CepsVector< CepsString > &patterns)
Advance stream until one of patterns is found.
Definition: FileReader.cpp:154
void reset()
Set file stream to the beginning of the file.
Definition: FileReader.cpp:98
virtual CepsBool open()
Opens the designated file in read mode.
Definition: FileReader.cpp:70
FileReader()
Alternative constructor.
Definition: FileReader.cpp:36
void oneLine(CepsString &line)
Get one line from the stream.
Definition: FileReader.cpp:202
CepsUInt skipLines(CepsUInt nbLines)
Skip given number of lines.
Definition: FileReader.cpp:179
void setFileName(const CepsString &fileName)
Set file to read.
Definition: FileReader.cpp:63
CepsString m_fileName
file to open
Definition: FileReader.hpp:145
CepsBool findNext(const CepsString &pattern)
Advance stream until pattern is found.
Definition: FileReader.cpp:107
CepsString getFileName()
Name of parsed file.
Definition: FileReader.cpp:173
std::ifstream m_file
stream
Definition: FileReader.hpp:146
virtual void close()
Close the file.
Definition: FileReader.cpp:84
CepsUInt find(const CepsString &pattern)
Advance stream until pattern is found.
Definition: FileReader.cpp:131