Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

LineBuffer.h
Go to the documentation of this file.
1 
33 #pragma once
34 
35 #include <ogdf/basic/basic.h>
36 #include <ogdf/basic/ArrayBuffer.h>
37 
38 
39 namespace ogdf {
40 
49 
50 private:
51 
54 
59 
62 
63 public:
64 
67  m_lineNumber(0),
68  m_lineUpdateCount(0),
69  m_linePosition(0)
70  { }
71 
74  int lineNumber,
75  int lineUpdateCount,
76  int linePosition);
77 
79  LineBufferPosition(const LineBufferPosition &position);
80 
82  inline int getLineNumber() const {
83  return m_lineNumber;
84  }
85 
87  inline int getLineUpdateCount() const {
88  return m_lineUpdateCount;
89  }
90 
92  inline int getLinePosition() const {
93  return m_linePosition;
94  }
95 
97  void set(int lineNumber, int lineUpdateCount, int linePosition);
98 
100  void incrementPosition();
101 
103  bool operator!=(const LineBufferPosition &position) const;
104 
106  LineBufferPosition &operator=(const LineBufferPosition &position);
107 
108 }; // LineBufferPosition
109 
110 
115 
116 private:
117 
119  istream *m_pIs;
120 
123 
126 
129 
136 
139 
140 public:
141 
143  explicit LineBuffer(istream &is);
144 
146  ~LineBuffer();
147 
150  return m_currentPosition;
151  }
152 
154  inline char getCurrentCharacter() const {
155  if (m_currentPosition.getLineNumber() >= m_linBuf.size()
156  || m_currentPosition.getLinePosition() > (int)m_linBuf[m_currentPosition.getLineNumber()].size()) {
157  return EOF;
158  }
159  return m_linBuf[m_currentPosition.getLineNumber()][m_currentPosition.getLinePosition()];
160  }
161 
163  inline int getInputFileLineCounter() const {
164  return m_inputFileLineCounter;
165  }
166 
173  char moveToNextCharacter();
174 
181  bool setCurrentPosition(const LineBufferPosition &newPosition);
182 
186  void skipWhitespace();
187 
197  bool extractString(
198  const LineBufferPosition &startPostion,
199  const LineBufferPosition &endPosition,
200  string &targetString);
201 
202 private:
203 
205  bool isValidPosition(const LineBufferPosition &position) const;
206 
207 }; // class LineBuffer
208 
209 } // end namespace ogdf
int getInputFileLineCounter() const
Returns line number of the most recently read line of the input file.
Definition: LineBuffer.h:163
ArrayBuffer< string > m_linBuf
Pointer to the line buffer.
Definition: LineBuffer.h:125
static void skipWhitespace(B &in)
Definition: ParseUtils.h:71
int m_inputFileLineCounter
Contains the current line number of the input file;.
Definition: LineBuffer.h:138
This class maintains the input file and provides a convenient interface to handle it...
Definition: LineBuffer.h:114
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:99
Declaration and implementation of ArrayBuffer class.
int getLineNumber() const
Get the line number.
Definition: LineBuffer.h:82
LineBufferPosition()
Default Constructor.
Definition: LineBuffer.h:66
int getLineUpdateCount() const
Get the update count of the line.
Definition: LineBuffer.h:87
int m_lineUpdateCount
Contains the number of times line m_lineNumber has been overwritten by new data; Range [0 ...
Definition: LineBuffer.h:58
int m_lineNumber
Contains the lineNumber.
Definition: LineBuffer.h:53
ArrayBuffer< int > m_lineUpdateCountArray
Contains for each line of the line buffer its update count.
Definition: LineBuffer.h:122
istream * m_pIs
Handle to the input file.
Definition: LineBuffer.h:119
int m_linePosition
Contains the position in line m_lineNumber.
Definition: LineBuffer.h:61
LineBufferPosition m_currentPosition
The current position in m_linBuf.
Definition: LineBuffer.h:128
int getLinePosition() const
Get the position in the line.
Definition: LineBuffer.h:92
int m_numberOfMostRecentlyReadLine
The line which has been read from the file most recently; this does not have to be equal to m_current...
Definition: LineBuffer.h:135
This class characterizes uniquely a position in the line buffer.
Definition: LineBuffer.h:48
INDEX size() const
Returns number of elements in the buffer.
Definition: ArrayBuffer.h:117
Basic declarations, included by all source files.
LineBufferPosition getCurrentPosition() const
Returns the current position (as a copy)
Definition: LineBuffer.h:149
The namespace for all OGDF objects.
char getCurrentCharacter() const
Returns the character which is currently pointed to.
Definition: LineBuffer.h:154
bool operator!=(const Tuple2< E1, E2 > &t1, const Tuple2< E1, E2 > &t2)
Inequality operator for 2-tuples.
Definition: tuples.h:82