All pastes #399058 Raw Edit

Something

public text v1 · immutable
·published 2007-03-17 18:30 UTC
rendered paste body
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#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<string*> 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<Entry*> Database::find(std::string search) {
	
}

void Database::add(std::string entry){
	
}

void Database::close() {
	datafile.close();	
}

std::vector<string*> split( string const& in) {
	vector<string*> *out = new vector<string*>();
    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;
}