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

Iterator for string types. More...

#include <StringDataIterator.h>

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

Public Member Functions

 StringClassDataIterator (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

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::StringClassDataIterator< STRType >

Iterator for string types.

Definition at line 89 of file StringDataIterator.h.

Constructor & Destructor Documentation

◆ StringClassDataIterator()

template<class STRType >
Leviathan::StringClassDataIterator< STRType >::StringClassDataIterator ( 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 95 of file StringDataIterator.h.

95  : OurString(str), Current(0), End(str.size()){
96  // If the first character is a newline the line number needs to be incremented immediately //
97  if(OurString.size() && OurString[0] == '\n'){
98 
100  }
101 
102  }
size_t CurrentLineNumber
The current line number, the amount of characters.
ITType End
The end of the string.
ITType Current
The current position of the iterator.

Member Function Documentation

◆ CurrentIteratorPosition()

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

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

Implements Leviathan::StringDataIterator.

Definition at line 137 of file StringDataIterator.h.

137  {
138  return Current;
139  }
ITType Current
The current position of the iterator.

◆ GetLastValidIteratorPosition()

template<class STRType >
virtual size_t Leviathan::StringClassDataIterator< 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 147 of file StringDataIterator.h.

147  {
148 
149  return End-1;
150  }
ITType End
The end of the string.

◆ GetNextCharCode()

template<class STRType >
virtual bool Leviathan::StringClassDataIterator< 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 104 of file StringDataIterator.h.

104  {
105  if(Current+forward >= End)
106  return false;
107  // Copy the character //
108  codepointreceiver = static_cast<int>(OurString[Current+forward]);
109  return true;
110  }
ITType End
The end of the string.
ITType Current
The current position of the iterator.

◆ GetPreviousCharacter()

template<class STRType >
virtual bool Leviathan::StringClassDataIterator< 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 112 of file StringDataIterator.h.

112  {
113  if(Current-1 >= End)
114  return false;
115 
116  // Copy the character //
117  receiver = static_cast<int>(OurString[Current-1]);
118  return true;
119  }
ITType End
The end of the string.
ITType Current
The current position of the iterator.

◆ IsPositionValid()

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

Returns true when the iterator is still valid.

Implements Leviathan::StringDataIterator.

Definition at line 141 of file StringDataIterator.h.

141  {
142  if(Current < End)
143  return true;
144  return false;
145  }
ITType End
The end of the string.
ITType Current
The current position of the iterator.

◆ MoveToNextCharacter()

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

Moves the iterator forward.

Implements Leviathan::StringDataIterator.

Definition at line 121 of file StringDataIterator.h.

121  {
122  ++Current;
123  // Don't forget to increment these //
125  // There might be a better way to check this //
126  CheckLineChange();
127  }
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::StringClassDataIterator< STRType >::ReturnSubString ( size_t  startpos,
size_t  endpos,
STRType &  receiver 
)
inlinevirtual

Definition at line 129 of file StringDataIterator.h.

129  {
130  if(startpos >= End || endpos >= End || startpos > endpos)
131  return false;
132 
133  receiver = OurString.substr(startpos, endpos-startpos+1);
134  return true;
135  }
ITType End
The end of the string.

Member Data Documentation

◆ Current

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

The current position of the iterator.

Definition at line 159 of file StringDataIterator.h.

◆ End

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

The end of the string.

Definition at line 161 of file StringDataIterator.h.

◆ OurString

template<class STRType >
STRType Leviathan::StringClassDataIterator< STRType >::OurString
protected

Definition at line 156 of file StringDataIterator.h.


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