00001 #include "mateparser.h"
00002 #include <sstream>
00003 #include <iostream>
00004
00005 using namespace std;
00006
00007 MateParser::MateParser() : pInFile(0)
00008 {
00009
00010 }
00011
00012 MateParser::~MateParser()
00013 {
00014 if ( pInFile ) {
00015 pInFile->close();
00016 delete pInFile;
00017 }
00018 }
00019
00020 void MateParser::set_file(string file_name)
00021 {
00022 if ( pInFile ) {
00023
00024 cleanup();
00025 }
00026 pInFile = new ifstream( file_name.c_str() );
00027 line_num = 0;
00028 }
00029
00030 bool MateParser::parse_line(string& name_1, string& name_2, size_t& length)
00031 {
00032 if ( pInFile ) {
00033 string line;
00034 if ( getline(*pInFile, line) ) {
00035 line_num++;
00036 istringstream is(line);
00037 if ( !(is>>name_1 && is>>name_2 && is>> length) ) {
00038 cerr<<"MateParser::parse_line(), input error"<<endl;
00039 cerr<<"line "<<line_num<<": "<<line<<"\nis ill formated"<<endl;
00040 cleanup();
00041 return false;
00042 }
00043
00044 return true;
00045 }
00046
00047 cleanup();
00048 }
00049 else {
00050 cerr<<"No file handle in MateParser::parse_line()"<<endl;
00051 }
00052 return false;
00053 }
00054
00055 void MateParser::cleanup()
00056 {
00057 if (pInFile) {
00058
00059 pInFile->close();
00060 delete pInFile;
00061 pInFile = 0;
00062
00063 }
00064
00065 }
00066