The Parametric Pseudo-Manifold (PPS) Library 1.0
offlib::Lexer Class Reference

This class represents a lexical analyzer for scanning tokens from an OFF file describing a triangle mesh. More...

#include <lexer.h>

List of all members.

Public Member Functions

 Lexer (std::istream &is)
 Creates an instance of this class.
bool get_string (std::string &s)
 Reads in a string from the input stream.
bool get_integer (int &x)
 Reads in a non-negative integer from the input stream.
bool get_double (double &d)
 Reads in a double precision number from the input stream.
int get_line_counter () const
 Returns the value of the file line counter.
int get_char_counter () const
 Returns the value of the file char counter.

Private Member Functions

void increment_line ()
 Increments the file line counter.
void increment_char ()
 Increments the file char counter.
void decrement_char ()
 Decrements the file char counter.
void reset_char_counter ()
 Assigns the value zero to the file char counter.
bool skip_space ()
 Reads in the input stream until a character or digit shows up.

Private Attributes

std::istream & _realstr
 The input stream.
int _line_counter
 The file line counter.
int _char_counter
 The file char counter.

Detailed Description

This class represents a lexical analyzer for scanning tokens from an OFF file describing a triangle mesh.

Definition at line 55 of file lexer.h.


Constructor & Destructor Documentation

offlib::Lexer::Lexer ( std::istream &  is) [inline]

Creates an instance of this class.

Parameters:
isAn input stream for an OFF file.

Definition at line 70 of file lexer.h.

References _char_counter, and _line_counter.

                           : _realstr( is )
    {
      _line_counter = 0 ;
      _char_counter = 0 ;
    }

Member Function Documentation

int offlib::Lexer::get_char_counter ( ) const [inline]

Returns the value of the file char counter.

Returns:
The value of the file char counter.

Definition at line 128 of file lexer.h.

References _char_counter.

    { 
      return _char_counter ; 
    }
bool offlib::Lexer::get_double ( double &  d)

Reads in a double precision number from the input stream.

Parameters:
dA reference to a double precision number.

Definition at line 162 of file lexer.cpp.

References _realstr, and skip_space().

Referenced by offlib::Reader::read_vertices().

  {
    if ( !skip_space() ) {
      return false ;
    }

    char c ;
    if ( !_realstr.get( c ) ) {
      return false ;
    }
   
    _realstr.putback( c ) ;

    assert( ( _realstr >> d ) ) ;

    return true;
  }
bool offlib::Lexer::get_integer ( int &  x)

Reads in a non-negative integer from the input stream.

Parameters:
xA reference to an integer.

Definition at line 109 of file lexer.cpp.

References _realstr, increment_char(), and skip_space().

Referenced by offlib::Reader::read_faces(), and offlib::Reader::read_header().

  {
    if ( !skip_space() ) {
      return false ;
    }

    char c ;
    if ( !_realstr.get( c ) ) {
      return false ;
    }

    if ( isdigit( c ) ) {
      char str[ 256 ] ;
      int i = 0 ;
      do {
        str[ i ] = c ;

        if ( !_realstr.get( c ) ) {
          return false ;
        }

        increment_char() ;

        ++i ;
      } 
      while ( isdigit( c ) && ( i < 255 ) ) ;

      str[ i ] = '\0' ;

      assert( !isdigit( c ) ) ;

      x = atoi( str ) ;

      _realstr.putback( c ) ;
    }
    else {
      _realstr.putback( c ) ;

      return false;
    }

    return true;
  }
int offlib::Lexer::get_line_counter ( ) const [inline]

Returns the value of the file line counter.

Returns:
The value of the file line counter.

Definition at line 115 of file lexer.h.

References _line_counter.

    { 
      return _line_counter ; 
    }
bool offlib::Lexer::get_string ( std::string &  s)

Reads in a string from the input stream.

Parameters:
sA reference to a string.
sA string read in from the input stream.

Definition at line 57 of file lexer.cpp.

References _realstr, increment_char(), and skip_space().

Referenced by offlib::Reader::read_header().

  {
    if ( !skip_space() ) {
      return false;
    }

    char c;
    if ( !_realstr.get( c ) ) {
      return false ;
    }

    if ( isalpha( c ) ) {
      char str[ 256 ] ;
      int i = 0 ;
      do {
        str[i] = c ;

        if ( !_realstr.get( c ) ) {
          return false ;
        }

        increment_char() ;

        ++i ;
      } 
      while ( isalnum( c ) && ( i < 255 ) ) ;

      str[ i ] = '\0' ;

      assert( !isalnum( c ) ) ;

      s = str ;
      _realstr.putback( c ) ;
    }
    else {
      _realstr.putback( c ) ;

      return false ;
    }

    return true ;
  }

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