Helios++
Helios software for LiDAR simulations
LineReadingStrategy.h
1 #pragma once
2 
3 #include <filems/read/strategies/SimpleReadingStrategy.h>
4 #include <filems/read/exceptions/EndOfReadingException.h>
5 
6 #include <fstream>
7 #include <string>
8 
9 namespace helios { namespace filems{
10 
11 using std::fstream;
12 using std::string;
13 
22 protected:
23  // *** USING *** //
24  // *************** //
26 
27  // *** ATTRIBUTES *** //
28  // ******************** //
36  long const &maxCharsPerLine;
40  char *buffer = nullptr;
41 
42 public:
43  // *** CONSTRUCTION / DESTRUCTION *** //
44  // ************************************ //
49  LineReadingStrategy(ifstream &ifs, long const &maxCharsPerLine) :
50  SimpleReadingStrategy<string>(ifs),
52  {
53  buffer = new char[maxCharsPerLine];
54  }
55  virtual ~LineReadingStrategy(){
56  delete[] buffer;
57  }
58 
59  // *** READING STRATEGY METHODS *** //
60  // ********************************** //
67  string read() override{
68  if(ifs.getline(buffer, maxCharsPerLine)) return string(buffer);
69  throw EndOfReadingException();
70  }
71 };
72 
73 }}
Class representing the end of reading exception for FMS readers.
Definition: EndOfReadingException.h:15
Class defining the strategy to read line by line from a file input stream.
Definition: LineReadingStrategy.h:21
char * buffer
Buffer where the read line is stored.
Definition: LineReadingStrategy.h:40
long const & maxCharsPerLine
The maximum number of characters that a line is expected to have.
Definition: LineReadingStrategy.h:36
LineReadingStrategy(ifstream &ifs, long const &maxCharsPerLine)
Default constructor for line reading strategy.
Definition: LineReadingStrategy.h:49
string read() override
Read line from text file.
Definition: LineReadingStrategy.h:67
Class defining the strategy to read from a simple file input stream.
Definition: SimpleReadingStrategy.h:20
ifstream & ifs
Reference to the input file stream to read from.
Definition: SimpleReadingStrategy.h:27