#include #include #include #include #include "Database.h" #include "Entry.h" using namespace std; Database::~Database() { } void Database::initialize(std::string file) { string line; datafile.open(file.c_str()); if(datafile.good()){ while(!datafile.eof()) { getline(datafile, line); vector v = split(line, v); Entry *entry = new Entry(); entry->setType(*v[0]); entry->setTitle(*v[1]); entry->setInterpret(*v[2]); entry->setInfo(*v[3]); entryList.push_back(entry); } /* for( vector< Entry* >::iterator it = list.begin(); it != list.end(); ++it ) cout << ( *it )->getTitle(); */ datafile.close(); } else { cout << "couldn't open datafile"; } } std::vector Database::find(std::string search) { } void Database::add(std::string entry){ } void Database::close() { datafile.close(); } std::vector split( string const& in) { vector *out = new vector(); string::const_iterator start = in.begin(); string::const_iterator stop; bool done = false; while( !done ) { while( ( *start ) != '"' && start != in.end() ) ++start; if( start != in.end() ) { stop = start; ++stop; while( ( *stop ) != '"' && stop != in.end() ) ++stop; if( stop != in.end() ) { out->push_back( new string( start, ++stop ) ); start = stop; } else done = true; } else done = true; } return *out; }