mummy  1.0.3
MummyLineOrientedTextFileReader.h
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 // MummyLineOrientedTextFileReader.h
3 //
4 // Author(s) : David Cole
5 //
6 // Copyright (C) 2007 Kitware, Inc.
7 //----------------------------------------------------------------------------
8 
9 #ifndef _MummyLineOrientedTextFileReader_h_
10 #define _MummyLineOrientedTextFileReader_h_
11 
12 #include "MummyUtilities.h" // first mummy include for root classes
13 
14 #include "gxsys/stl/string"
15 #include "gxsys/stl/vector"
16 
17 
18 //----------------------------------------------------------------------------
24 class LineData
25 {
26 public:
27  LineData(const gxsys_stl::string &line, const bool isLineComment, const int btxEtxLevel) :
28  Line(line), IsLineComment(isLineComment), BtxEtxLevel(btxEtxLevel)
29  {
30  }
31 
32  gxsys_stl::string Line;
35 };
36 
37 
38 //----------------------------------------------------------------------------
46 {
47 public:
50 
51  //--------------------------------------------------------------------------
56  virtual gxsys_stl::string GetFileName();
57 
58  //--------------------------------------------------------------------------
63  virtual void SetFileName(const char *filename);
64 
65  //--------------------------------------------------------------------------
71  virtual bool GetExcludeMarkedLines();
72 
73  //--------------------------------------------------------------------------
79  virtual void SetExcludeMarkedLines(bool excludeMarkedLines);
80 
81  //--------------------------------------------------------------------------
87  virtual gxsys_stl::string GetBeginExcludeRegex();
88 
89  //--------------------------------------------------------------------------
97  virtual void SetBeginExcludeRegex(const gxsys_stl::string& beginExcludeRegex);
98 
99  //--------------------------------------------------------------------------
105  virtual gxsys_stl::string GetEndExcludeRegex();
106 
107  //--------------------------------------------------------------------------
115  virtual void SetEndExcludeRegex(const gxsys_stl::string& endExcludeRegex);
116 
117  //--------------------------------------------------------------------------
126  virtual void Update();
127 
128  //--------------------------------------------------------------------------
133  virtual unsigned int GetNumberOfLines();
134 
135  //--------------------------------------------------------------------------
143  virtual gxsys_stl::string GetLine(unsigned int lineNumber);
144 
145  //--------------------------------------------------------------------------
152  virtual bool GetIsLineComment(unsigned int lineNumber);
153 
154  //--------------------------------------------------------------------------
164  virtual int GetBtxEtxLevel(unsigned int lineNumber);
165 
166  //--------------------------------------------------------------------------
174  virtual bool IsLineExcluded(unsigned int lineNumber);
175 
176  //--------------------------------------------------------------------------
185 
186  virtual void GetCommentBlockBefore(unsigned int lineNumber, gxsys_stl::vector<gxsys_stl::string>& block, unsigned int smallestAcceptableLineNumber);
187 
188  //--------------------------------------------------------------------------
193  virtual void GetFirstCommentBlock(gxsys_stl::vector<gxsys_stl::string>& block);
194 
195 private:
196  gxsys_stl::string FileName;
197  gxsys_stl::vector<LineData> Lines;
199  gxsys_stl::string BeginExcludeRegex;
200  gxsys_stl::string EndExcludeRegex;
201 };
202 
203 #endif // _MummyLineOrientedTextFileReader_h_
virtual void GetFirstCommentBlock(gxsys_stl::vector< gxsys_stl::string > &block)
Retrieve the first block of comment lines, if any, in the file.
virtual void SetFileName(const char *filename)
Set the filename.
gxsys_stl::string Line
virtual int GetBtxEtxLevel(unsigned int lineNumber)
Get the current nesting level at line number 'lineNumber' of "//BTX - //ETX" style wrapper exclusion ...
virtual bool GetIsLineComment(unsigned int lineNumber)
Query if line number 'lineNumber' is a "line comment." Valid 'lineNumber' values are 1 through GetNum...
virtual void SetEndExcludeRegex(const gxsys_stl::string &endExcludeRegex)
Set the regular expression that delineates a line as the end of a "marked as excluded" block...
virtual gxsys_stl::string GetFileName()
Get the filename.
virtual gxsys_stl::string GetEndExcludeRegex()
Get the regular expression that delineates a line as the end of a "marked as excluded" block...
Internal, implementation detail class that caches information associated with a line in a line orient...
virtual unsigned int GetNumberOfLines()
Retrieve the total number of lines currently cached.
LineData(const gxsys_stl::string &line, const bool isLineComment, const int btxEtxLevel)
virtual void SetExcludeMarkedLines(bool excludeMarkedLines)
Set whether to exclude lines between beginExcludeRegex and endExcludeRegex matching lines when consid...
virtual gxsys_stl::string GetBeginExcludeRegex()
Get the regular expression that delineates a line as the beginning of a "marked as excluded" block...
virtual void SetBeginExcludeRegex(const gxsys_stl::string &beginExcludeRegex)
Set the regular expression that delineates a line as the beginning of a "marked as excluded" block...
virtual bool IsLineExcluded(unsigned int lineNumber)
Query whether the given line number should be excluded based on the exclude flag and the line number'...
Class that reads a text file and caches its lines and information about those lines for quick queries...
virtual void Update()
Read the current text file and cache its lines for subsequent quick lookup by line number...
virtual void GetCommentBlockBefore(unsigned int lineNumber, gxsys_stl::vector< gxsys_stl::string > &block, unsigned int smallestAcceptableLineNumber)
Retrieve the nearest preceding block of comment lines relative to line number 'lineNumber'. Valid 'lineNumber' values are 2 through GetNumberOfLines inclusive.
virtual bool GetExcludeMarkedLines()
Get whether to exclude lines between beginExcludeRegex and endExcludeRegex matching lines when consid...
virtual gxsys_stl::string GetLine(unsigned int lineNumber)
Retrieve line number 'lineNumber' as a string from the currently cached text file. Valid 'lineNumber' values are 1 through GetNumberOfLines inclusive.