Helios++
Helios software for LiDAR simulations
LineFileReader.h
1 #pragma once
2 
3 #include <filems/read/comps/SimpleFileReader.h>
4 #include <filems/read/strategies/LineReadingStrategy.h>
5 
6 namespace helios { namespace filems{
7 
8 using std::string;
9 using std::make_shared;
10 
18 class LineFileReader : public SimpleFileReader<string> {
19 protected:
20  // *** USING *** //
21  // *************** //
23 
24  // *** ATTRIBUTES *** //
25  // ******************** //
34 
35 public:
36  // *** CONSTRUCTION / DESTRUCTION *** //
37  // ************************************ //
43  string const &path,
44  std::ios_base::openmode openMode = std::ios_base::in,
45  long const maxCharsPerLine = 8192,
46  bool const constructStrategy = true
47  ) :
48  SimpleFileReader<string>(path, openMode),
50  {
51  if(constructStrategy)makeStrategy();
52  }
53  virtual ~LineFileReader() = default;
54 
55 protected:
56  // *** INNER METHODS *** //
57  // *********************** //
62  void makeStrategy() override
63  {readingStrategy = make_shared<LineReadingStrategy>(ifs, maxCharsPerLine);}
64 
65 public:
66  // *** GETTERs and SETTERs *** //
67  // ***************************** //
74  virtual inline long getMaxCharsPerLine() {return maxCharsPerLine;}
82  virtual void setMaxCharsPerLine(long const maxCharsPerLine){
83  this->maxCharsPerLine = maxCharsPerLine;
84  makeStrategy();
85  }
86 };
87 
88 }}
shared_ptr< ReadingStrategy< ReadType > > readingStrategy
The reading strategy to be used by the file reader.
Definition: FileReader.h:32
string path
Path to the file to be read.
Definition: FileReader.h:27
Class supporting line by line reading of text files.
Definition: LineFileReader.h:18
long maxCharsPerLine
The maximum number of characters that a line is expected to have.
Definition: LineFileReader.h:33
void makeStrategy() override
Build a line reading strategy for the line file reader.
Definition: LineFileReader.h:62
virtual void setMaxCharsPerLine(long const maxCharsPerLine)
Set the maximum number of characters per line and update strategy accordingly.
Definition: LineFileReader.h:82
LineFileReader(string const &path, std::ios_base::openmode openMode=std::ios_base::in, long const maxCharsPerLine=8192, bool const constructStrategy=true)
Default constructor for line file reader.
Definition: LineFileReader.h:42
virtual long getMaxCharsPerLine()
Obtain the maximum number of characters per line.
Definition: LineFileReader.h:74
Abstract class defining the fundamental of any file reader that uses standard file input stream as re...
Definition: SimpleFileReader.h:25
ifstream ifs
The input file stream to read from.
Definition: SimpleFileReader.h:37
ios_base::openmode openMode
The open mode flags for the input file stream.
Definition: SimpleFileReader.h:42