Public Member Functions | Private Member Functions | Private Attributes

MeshLib::CParser Class Reference

CParser class. More...

#include <parser.h>

Collaboration diagram for MeshLib::CParser:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 CParser (const std::string &str)
 CParser constructor.
 ~CParser ()
std::list< CToken * > & tokens ()
void _toString (std::string &str)
void _removeToken (const std::string &key)

Private Member Functions

char next_char ()
void skip_blank ()
bool end ()

Private Attributes

std::list< CToken * > m_tokens
char m_line [1024]
char m_key [1024]
char m_value [1024]
char * m_pt

Detailed Description

CParser class.

Definition at line 37 of file parser.h.


Constructor & Destructor Documentation

CParser::CParser ( const std::string &  str  ) 

CParser constructor.

Parameters:
str input string

CParser constructor

Parameters:
str input string

Definition at line 31 of file parser.cpp.

{

        //copy string
        unsigned int i;
        for(  i = 0; i < str.length(); i ++ )
        {
                m_line[i] = str.c_str()[i];
        }
        m_line[i] = 0;

        m_pt = m_line;
        
        //while not reaching the end
        while( !end() )
        {
                skip_blank();
                if( end() ) break;

                //copy key

                char * pkey = m_key;
                char   ch = next_char();

                while( ch != ' ' && ch != '=' && !end() )
                {
                        *pkey ++ = ch;
                        ch = next_char();
                }
                if( ch != '=' && ch != ' ')
                        *pkey++ = ch;

                *pkey = 0;

                if( ch == ' ' )
                {
                        skip_blank();
                }

                if( ch != '=' )
                {
                        CToken *        tk = new CToken;
                        assert(tk);
                        tk->m_key  = std::string( m_key );
                        
                        m_tokens.push_back( tk );
                        continue;
                }

                if( end() ) break;

                ch = next_char();

                while( ch != '(' ) ch = next_char();

                char * pvalue = m_value;

                while( ch != ')' && !end() )
                {
                        *pvalue ++ = ch;
                        ch = next_char();
                }
                *pvalue++ = ch;
                *pvalue  = 0;

                CToken *        tk = new CToken;
                assert(tk);
                tk->m_key   = std::string( m_key   );
                tk->m_value = std::string( m_value );
                
                m_tokens.push_back( tk );
                
        }

};

Here is the call graph for this function:

CParser::~CParser (  ) 

CParser Destructor

CParser destruuctor

Definition at line 16 of file parser.cpp.

{
  //release all the tokens

  for( std::list<CToken*>::iterator titer = m_tokens.begin(); titer != m_tokens.end(); titer ++ )
  {
      CToken * pT = *titer;
      delete pT;
  }
  m_tokens.clear();
};


Member Function Documentation

void CParser::_removeToken ( const std::string &  key  ) 

Remove the token key=(...) from the current string

Parameters:
key the key to the token to be removed

Remove the token with the prescribed key in the token list

Definition at line 153 of file parser.cpp.

{
        for( std::list<CToken*>::iterator iter = m_tokens.begin() ; iter != m_tokens.end(); ++ iter )
        {
                  CToken * token = *iter;
                  if( token->m_key == key )
                  {
                          m_tokens.erase( iter );
                          return;
                  }
        }
}

void CParser::_toString ( std::string &  str  ) 

Convert the list of tokens to a string

Parameters:
str the output string

Convert the list of tokens to a string

Definition at line 136 of file parser.cpp.

{
        std::stringstream iss;

        for( std::list<CToken*>::iterator iter = m_tokens.begin() ; iter != m_tokens.end(); ++ iter )
        {
                  CToken * token = *iter;
                  if( iss.str().length() > 0 ) iss << " ";
                  iss << token->m_key << "=" << token->m_value;                   
        }

        str = iss.str();
}

bool CParser::end (  )  [private]

verify if we

Whether the end of the string has been reached

Definition at line 128 of file parser.cpp.

{
        return ( (*m_pt) == 0 );
};

Here is the caller graph for this function:

char CParser::next_char (  )  [private]

get the next char in the current string

Get the next char in the buffer, move the current pointer to the next position

Definition at line 110 of file parser.cpp.

{
        char ch= *m_pt;
        m_pt++;
        return ch;
};

Here is the caller graph for this function:

void CParser::skip_blank (  )  [private]

skip blank spaces

Skip the blank space in the current position, reach the next non-blank char

Definition at line 120 of file parser.cpp.

{
        while( *m_pt == ' ' ) m_pt++;
};

Here is the caller graph for this function:

std::list<CToken*>& MeshLib::CParser::tokens (  )  [inline]

List of tokens extracted from the string

Definition at line 52 of file parser.h.

{ return m_tokens; };

Here is the caller graph for this function:


Member Data Documentation

char MeshLib::CParser::m_key[1024] [private]

current key

Definition at line 91 of file parser.h.

char MeshLib::CParser::m_line[1024] [private]

The buffer to contain the string

Definition at line 87 of file parser.h.

char* MeshLib::CParser::m_pt [private]

current pointer to the char buffer

Definition at line 99 of file parser.h.

std::list<CToken*> MeshLib::CParser::m_tokens [private]

list of tokens

Definition at line 82 of file parser.h.

char MeshLib::CParser::m_value[1024] [private]

current value

Definition at line 95 of file parser.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Defines