/* * store.c * * Created on: 29.11.2010 * Author: msloup */ #include #include #include #include #include "store.h" #include "util.h" using namespace std; vector database; void store_load(const char *filename) { fstream input; database.clear(); try { input.open(filename, fstream::in); struct item item; while (input >> item.value) { item.ts = 0; database.push_back(item); } input.close(); } catch (ifstream::failure e) { warning("Error while reading database file: %s", e.what()); } } void store_store(const char *filename) { fstream output; try { output.open(filename, fstream::out); vector::iterator it; for(it = database.begin(); it!=database.end(); it++) { output << (*it).value; } output.close(); } catch (ifstream::failure e) { fatal("Error while writing database file: %s", e.what()); } } int store_size() { return database.size(); } void store_set(int index, struct item data) { database.at(index) = data; } struct item store_get(int index) { return database.at(index); } vector::iterator store_begin() { return database.begin(); } vector::iterator store_end() { return database.end(); }