Leviathan  0.8.0.0
Leviathan game engine
Leviathan::StringClassPointerIterator< STRType > Class Template Reference

Iterator that doesn't hold own copy of a string. More...

#include <StringDataIterator.h>

+ Inheritance diagram for Leviathan::StringClassPointerIterator< STRType >:

Public Member Functions

 StringClassPointerIterator (const STRType *str)
 
virtual bool GetNextCharCode (int &codepointreceiver, size_t forward)
 Gets the next character unicode code point (usually an ascii value) More...
 
virtual bool GetPreviousCharacter (int &receiver)
 Gets the previous character code point. More...
 
virtual void MoveToNextCharacter ()
 Moves the iterator forward. More...
 
virtual bool ReturnSubString (size_t startpos, size_t endpos, STRType &receiver)
 
virtual size_t CurrentIteratorPosition () const
 Gets the position of the iterator, for use with ReturnSubString and others. More...
 
virtual bool IsPositionValid () const
 Returns true when the iterator is still valid. More...
 
virtual size_t GetLastValidIteratorPosition () const
 Gets the last valid index of the underlying string (not the last character but the last byte) More...
 
- Public Member Functions inherited from Leviathan::StringDataIterator
DLLEXPORT StringDataIterator ()
 
virtual DLLEXPORT ~StringDataIterator ()
 
virtual DLLEXPORT bool ReturnSubString (size_t startpos, size_t endpos, std::string &receiver)
 
virtual DLLEXPORT bool ReturnSubString (size_t startpos, size_t endpos, std::wstring &receiver)
 
virtual DLLEXPORT size_t GetCurrentCharacterNumber () const
 Returns the 0 based character number (NOT position, number of characters) More...
 
virtual DLLEXPORT size_t GetCurrentLineNumber () const
 Returns the 1 based line number. More...
 

Protected Attributes

const STRType * OurString
 
ITType Current
 The current position of the iterator. More...
 
ITType End
 The end of the string. More...
 
- Protected Attributes inherited from Leviathan::StringDataIterator
size_t CurrentCharacterNumber
 
size_t CurrentLineNumber
 The current line number, the amount of
characters. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Leviathan::StringDataIterator
DLLEXPORT void CheckLineChange ()
 Updates CurrentLineNumber if currently on a line break. More...
 

Detailed Description

template<class STRType>
class Leviathan::StringClassPointerIterator< STRType >

Iterator that doesn't hold own copy of a string.

Definition at line 167 of file StringDataIterator.h.

Constructor & Destructor Documentation

◆ StringClassPointerIterator()

template<class STRType >
Leviathan::StringClassPointerIterator< STRType >::StringClassPointerIterator ( const STRType *  str)
inline

Wraps a string reference for StringIterator

Note
The string should not be changed while the iterator is used

Definition at line 173 of file StringDataIterator.h.

173  : OurString(str), Current(0){
174  End = str ? str->size(): 0;
175 
176  // If the first character is a newline the line number needs to be incremented immediately //
177  if(OurString && OurString->size() && OurString->at(0) == '\n'){
178 
180  }
181  }
ITType End
The end of the string.
size_t CurrentLineNumber
The current line number, the amount of characters.
ITType Current
The current position of the iterator.

Member Function Documentation

◆ CurrentIteratorPosition()

template<class STRType >
virtual size_t Leviathan::StringClassPointerIterator< STRType >::CurrentIteratorPosition ( ) const
inlinevirtual

Gets the position of the iterator, for use with ReturnSubString and others.

Implements Leviathan::StringDataIterator.

Definition at line 216 of file StringDataIterator.h.

216  {
217  return Current;
218  }
ITType Current
The current position of the iterator.

◆ GetLastValidIteratorPosition()

template<class STRType >
virtual size_t Leviathan::StringClassPointerIterator< STRType >::GetLastValidIteratorPosition ( ) const
inlinevirtual

Gets the last valid index of the underlying string (not the last character but the last byte)

Implements Leviathan::StringDataIterator.

Definition at line 226 of file StringDataIterator.h.

226  {
227 
228  return End-1;
229  }
ITType End
The end of the string.

◆ GetNextCharCode()

template<class STRType >
virtual bool Leviathan::StringClassPointerIterator< STRType >::GetNextCharCode ( int &  codepointreceiver,
size_t  forward 
)
inlinevirtual

Gets the next character unicode code point (usually an ascii value)

Parameters
forwardDefines how many characters past the current position the wanted character is. This is usually 0 or 1
Note
This is used to get the next character but also used for peeking so this should not increment the underlying iterator
Returns
Returns true when the input is still valid

Implements Leviathan::StringDataIterator.

Definition at line 183 of file StringDataIterator.h.

183  {
184  if(Current+forward >= End)
185  return false;
186  // Copy the character //
187  codepointreceiver = static_cast<int>(OurString->at(Current+forward));
188  return true;
189  }
ITType End
The end of the string.
ITType Current
The current position of the iterator.

◆ GetPreviousCharacter()

template<class STRType >
virtual bool Leviathan::StringClassPointerIterator< STRType >::GetPreviousCharacter ( int &  receiver)
inlinevirtual

Gets the previous character code point.

Returns
True when succeeded false when this is the first character and there is nothing before it
See also
GetNextCharCode

Implements Leviathan::StringDataIterator.

Definition at line 191 of file StringDataIterator.h.

191  {
192  if(Current-1 >= End)
193  return false;
194 
195  // Copy the character //
196  receiver = static_cast<int>(OurString->at(Current-1));
197  return true;
198  }
ITType End
The end of the string.
ITType Current
The current position of the iterator.

◆ IsPositionValid()

template<class STRType >
virtual bool Leviathan::StringClassPointerIterator< STRType >::IsPositionValid ( ) const
inlinevirtual

Returns true when the iterator is still valid.

Implements Leviathan::StringDataIterator.

Definition at line 220 of file StringDataIterator.h.

220  {
221  if(Current < End)
222  return true;
223  return false;
224  }
ITType End
The end of the string.
ITType Current
The current position of the iterator.

◆ MoveToNextCharacter()

template<class STRType >
virtual void Leviathan::StringClassPointerIterator< STRType >::MoveToNextCharacter ( )
inlinevirtual

Moves the iterator forward.

Implements Leviathan::StringDataIterator.

Definition at line 200 of file StringDataIterator.h.

200  {
201  ++Current;
202  // Don't forget to increment these //
204 
205  CheckLineChange();
206  }
DLLEXPORT void CheckLineChange()
Updates CurrentLineNumber if currently on a line break.
ITType Current
The current position of the iterator.

◆ ReturnSubString()

template<class STRType >
virtual bool Leviathan::StringClassPointerIterator< STRType >::ReturnSubString ( size_t  startpos,
size_t  endpos,
STRType &  receiver 
)
inlinevirtual

Definition at line 208 of file StringDataIterator.h.

208  {
209  if(startpos >= End || endpos >= End || startpos > endpos)
210  return false;
211 
212  receiver = OurString->substr(startpos, endpos-startpos+1);
213  return true;
214  }
ITType End
The end of the string.

Member Data Documentation

◆ Current

template<class STRType >
ITType Leviathan::StringClassPointerIterator< STRType >::Current
protected

The current position of the iterator.

Definition at line 236 of file StringDataIterator.h.

◆ End

template<class STRType >
ITType Leviathan::StringClassPointerIterator< STRType >::End
protected

The end of the string.

Definition at line 238 of file StringDataIterator.h.

◆ OurString

template<class STRType >
const STRType* Leviathan::StringClassPointerIterator< STRType >::OurString
protected

Definition at line 233 of file StringDataIterator.h.


The documentation for this class was generated from the following file: