EntityRepository.h
Dosyayı İndir
#ifndef ENTITYREPOSITORY_H
#define ENTITYREPOSITORY_H
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
#include "RepositoryUtilities.h"
#include "EntityConverter.h"
using namespace std;
class EntityRepository
{
public:
EntityRepository(){
}
EntityRepository(string &filePath) : _filePath(filePath){
}
~EntityRepository(){
_entityVector.clear();
}
string &getFilePath(){
return _filePath;
}
void setFilePath(string &filePath){
_filePath=filePath;
}
void add(EntitySample entity);
void remove(unsigned int index);
void load();
void store();
void print();
private:
string _filePath;
vector<EntitySample> _entityVector;
EntityConverter _entityConverter;
};
void EntityRepository::load(){
ifstream ifs(_filePath.c_str());
read_vector(ifs,_entityVector,_entityConverter);
}
void EntityRepository::store(){
ofstream ofs(_filePath.c_str());
write_vector(ofs,_entityVector,_entityConverter);
ofs.close();
}
void EntityRepository::print(){
write_vector(cout,_entityVector,_entityConverter);
}
void EntityRepository::add(EntitySample entity){
_entityVector.push_back(entity);
}
void EntityRepository::remove(unsigned int index){
if(index>=0 && index<_entityVector.size()){
_entityVector.erase(_entityVector.begin()+index);
}else{
throw out_of_range("Bu s�rada bir ��e yok!" );
}
}
#endif
Dosyayı İndir