00001 /* $Id: OSrLReader.cpp 4292 2011-09-21 05:47:18Z kmartin $ */ 00015 //#define OSRLREADER_DEBUG 00016 00017 #include "OSrLReader.h" 00018 00019 00020 00021 00022 void yygetOSResult( const char *ch, OSResult* m_osresult, OSrLParserData *m_parserData, OSgLParserData *osglData) throw(ErrorClass); 00023 int osrllex_init(void** ptr_yy_globals); 00024 int osrllex_destroy (void* scanner ); 00025 void osrlset_extra (OSrLParserData* parserData , void* yyscanner ); 00026 00027 00028 OSrLReader::OSrLReader( ) 00029 { 00030 #ifdef OSRLREADER_DEBUG 00031 std::cout << "new OSrLParserData()" << std::endl; 00032 #endif 00033 m_parserData = new OSrLParserData(); 00034 #ifdef OSRLREADER_DEBUG 00035 std::cout << "new OSgLParserData()" << std::endl; 00036 #endif 00037 m_osglData = new OSgLParserData(); 00038 #ifdef OSRLREADER_DEBUG 00039 std::cout << "new OSResult()" << std::endl; 00040 #endif 00041 m_osresult = new OSResult(); 00042 // initialize the lexer and set yyextra 00043 #ifdef OSRLREADER_DEBUG 00044 std::cout << "initialize the lexer" << std::endl; 00045 #endif 00046 osrllex_init( &(m_parserData->scanner) ); 00047 osrlset_extra (m_parserData , m_parserData->scanner); 00048 #ifdef OSRLREADER_DEBUG 00049 std::cout << "done" << std::endl; 00050 #endif 00051 } 00052 00053 OSrLReader::~OSrLReader() 00054 { 00055 // delete the osresult object 00056 #ifdef OSRLREADER_DEBUG 00057 std::cout << "delete m_osresult" << std::endl; 00058 #endif 00059 if(m_osresult != NULL) delete m_osresult; 00060 m_osresult = NULL; 00061 00062 // now delete the scanner that was initialized 00063 #ifdef OSRLREADER_DEBUG 00064 std::cout << "delete scanner" << std::endl; 00065 #endif 00066 osrllex_destroy(m_parserData->scanner ); 00067 00068 // finally delete parser data 00069 #ifdef OSRLREADER_DEBUG 00070 std::cout << "delete parser data" << std::endl; 00071 #endif 00072 if( m_parserData != NULL) delete m_parserData; 00073 m_parserData = NULL; 00074 00075 #ifdef OSRLREADER_DEBUG 00076 std::cout << "delete osglData" << std::endl; 00077 #endif 00078 if( m_osglData != NULL) delete m_osglData; 00079 m_osglData = NULL; 00080 00081 #ifdef OSRLREADER_DEBUG 00082 std::cout << "success!" << std::endl; 00083 #endif 00084 } 00085 00086 OSResult* OSrLReader::readOSrL(const std::string& posrl) throw(ErrorClass) 00087 { 00088 try 00089 { 00090 const char *ch = posrl.c_str(); 00091 yygetOSResult( ch, m_osresult, m_parserData, m_osglData); 00092 return m_osresult; 00093 } 00094 catch(const ErrorClass& eclass) 00095 { 00096 throw ErrorClass( eclass.errormsg); 00097 } 00098 }