61 lines
1.0 KiB
C++
61 lines
1.0 KiB
C++
/*
|
|
* Copyright 2013 (c) Anna Schumaker.
|
|
*/
|
|
#ifndef OCARINA_DATABASE_H
|
|
#define OCARINA_DATABASE_H
|
|
|
|
#include <file.h>
|
|
#include <print.h>
|
|
|
|
#include <map>
|
|
#include <vector>
|
|
|
|
|
|
class DatabaseEntry {
|
|
public:
|
|
bool valid;
|
|
|
|
DatabaseEntry();
|
|
virtual const std::string primary_key() = 0;
|
|
virtual void write(File &) = 0;
|
|
virtual void read(File &) = 0;
|
|
};
|
|
|
|
|
|
|
|
template <class T>
|
|
class Database {
|
|
private:
|
|
std::vector<T> _db;
|
|
std::map<const std::string, unsigned int> _keys;
|
|
unsigned int _size;
|
|
bool _autosave;
|
|
File _file;
|
|
|
|
public:
|
|
typedef typename std::vector<T>::iterator iterator;
|
|
typedef typename std::vector<T>::const_iterator const_iterator;
|
|
|
|
Database(std::string, bool);
|
|
~Database();
|
|
void save();
|
|
void autosave();
|
|
void load();
|
|
|
|
unsigned int insert(T);
|
|
void remove(unsigned int);
|
|
unsigned int size();
|
|
unsigned int actual_size();
|
|
|
|
iterator begin();
|
|
iterator end();
|
|
iterator next(iterator &);
|
|
|
|
iterator at(unsigned int);
|
|
iterator find(const std::string &);
|
|
};
|
|
|
|
#include "database.hpp"
|
|
|
|
#endif /* OCARINA_DATABASE_H */
|