SFCGAL  2.3.0
Public Types | Public Member Functions | List of all members
SFCGAL::tools::BasicInputStreamReader< CharType > Class Template Reference

Helper class to parse data from stream. More...

#include <InputStreamReader.h>

Public Types

using char_type = CharType
 Character type for the reader. More...
 
using string_type = typename std::basic_string< char_type >
 String type for the reader. More...
 
using istream_type = typename std::basic_istream< char_type >
 Input stream type. More...
 
using pos_type = typename std::basic_istream< char_type >::pos_type
 Stream position type. More...
 

Public Member Functions

 BasicInputStreamReader (istream_type &s, bool skipWhiteSpaces=true)
 Constructor with an input stream. More...
 
auto match (char_type const &c) -> bool
 Try to match a char in the input stream. More...
 
auto imatch (char_type const &c) -> bool
 Try to match a char in the input stream, case-insensitive variant. More...
 
auto match (string_type const &str) -> bool
 Try to match a string in the input stream. More...
 
auto imatch (string_type const &str) -> bool
 Try to match a string in the input stream, case-insensitive variant. More...
 
template<typename T >
bool read (T &value)
 Try to read a value in the input stream, restore state if read fails. More...
 
auto readBytes (std::string &buffer, size_t bytesToRead) -> void
 Read bytes from input stream into buffer. More...
 
void begin ()
 save input stream state (read position) More...
 
void commit ()
 validate read from input stream More...
 
void rollback ()
 restore stream state (read position) More...
 
bool eof () const
 Test if read is complete (either tried to read after eof, either on eof) More...
 
istream_type & s ()
 Returns the wrapped stream. More...
 
istream_type const & s () const
 Returns the wrapped stream. More...
 
string_type context (size_t nMax=20)
 Returns a string corresponding to the current state. More...
 

Detailed Description

template<typename CharType>
class SFCGAL::tools::BasicInputStreamReader< CharType >

Helper class to parse data from stream.

Member Typedef Documentation

template<typename CharType >
using SFCGAL::tools::BasicInputStreamReader< CharType >::char_type = CharType

Character type for the reader.

template<typename CharType >
using SFCGAL::tools::BasicInputStreamReader< CharType >::istream_type = typename std::basic_istream<char_type>

Input stream type.

template<typename CharType >
using SFCGAL::tools::BasicInputStreamReader< CharType >::pos_type = typename std::basic_istream<char_type>::pos_type

Stream position type.

template<typename CharType >
using SFCGAL::tools::BasicInputStreamReader< CharType >::string_type = typename std::basic_string<char_type>

String type for the reader.

Constructor & Destructor Documentation

template<typename CharType >
SFCGAL::tools::BasicInputStreamReader< CharType >::BasicInputStreamReader ( istream_type &  s,
bool  skipWhiteSpaces = true 
)
inline

Constructor with an input stream.

Parameters
sThe input stream to read from
skipWhiteSpacesWhether to skip white spaces during parsing

Member Function Documentation

template<typename CharType >
void SFCGAL::tools::BasicInputStreamReader< CharType >::begin ( )
inline

save input stream state (read position)

template<typename CharType >
void SFCGAL::tools::BasicInputStreamReader< CharType >::commit ( )
inline

validate read from input stream

template<typename CharType >
string_type SFCGAL::tools::BasicInputStreamReader< CharType >::context ( size_t  nMax = 20)
inline

Returns a string corresponding to the current state.

Parameters
nMaxMaximum number of characters to include in context
Returns
String showing current stream context
template<typename CharType >
bool SFCGAL::tools::BasicInputStreamReader< CharType >::eof ( ) const
inline

Test if read is complete (either tried to read after eof, either on eof)

Returns
True if at end of stream
template<typename CharType >
auto SFCGAL::tools::BasicInputStreamReader< CharType >::imatch ( char_type const &  c) -> bool
inline

Try to match a char in the input stream, case-insensitive variant.

Parameters
cThe character to match
Returns
True if character matches (case-insensitive)
template<typename CharType >
auto SFCGAL::tools::BasicInputStreamReader< CharType >::imatch ( string_type const &  str) -> bool
inline

Try to match a string in the input stream, case-insensitive variant.

Parameters
strThe string to match
Returns
True if string matches (case-insensitive)
template<typename CharType >
auto SFCGAL::tools::BasicInputStreamReader< CharType >::match ( char_type const &  c) -> bool
inline

Try to match a char in the input stream.

Parameters
cThe character to match
Returns
True if character matches
template<typename CharType >
auto SFCGAL::tools::BasicInputStreamReader< CharType >::match ( string_type const &  str) -> bool
inline

Try to match a string in the input stream.

Parameters
strThe string to match
Returns
True if string matches
template<typename CharType >
template<typename T >
bool SFCGAL::tools::BasicInputStreamReader< CharType >::read ( T &  value)
inline

Try to read a value in the input stream, restore state if read fails.

Parameters
valueReference to store the read value
Returns
True if read was successful
template<typename CharType >
auto SFCGAL::tools::BasicInputStreamReader< CharType >::readBytes ( std::string &  buffer,
size_t  bytesToRead 
) -> void
inline

Read bytes from input stream into buffer.

Parameters
bufferString buffer to store read bytes
bytesToReadNumber of bytes to read
template<typename CharType >
void SFCGAL::tools::BasicInputStreamReader< CharType >::rollback ( )
inline

restore stream state (read position)

template<typename CharType >
istream_type& SFCGAL::tools::BasicInputStreamReader< CharType >::s ( )
inline

Returns the wrapped stream.

Returns
Reference to the input stream
template<typename CharType >
istream_type const& SFCGAL::tools::BasicInputStreamReader< CharType >::s ( ) const
inline

Returns the wrapped stream.

Returns
Const reference to the input stream