#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; v = split_line(line); 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(); } vector* split_line (const string& line) { string::size_type pos = 0; bool inq = false; vector *v; const char *lp, *cp; v = new vector ( ); lp = line.c_str (); for (cp = lp; *cp != '\0'; cp++) { //skip whitespaces outside strings if (*cp == ' ' && inq == false) { continue; } else if (*cp == '"') { string::size_type cpos = cp - lp; if (inq == true) { string::size_type len = cpos - pos; v->push_back (new string (line, pos, len)); } else { pos = cpos + 1; } inq = !inq; } } return v; }