#ifndef FDPROV_H
#define FDPROV_H

#include "dataProvider.h"
#include "easylogging++.h"
#include <string>
#include <iostream>
#include <fstream>

class FileDP:public DataProvider
{
private:
    std::string fname;
    std::ifstream fin;
public:
    FileDP(std::string fn=""):fname(fn){};
    void setFname(std::string fn){fname=fn;};
    virtual int getDataSet(DataList &out){
        DataEntry* e;
        out.clear();
        int fsize;
        fin>>fsize;
        LOG(INFO)<<"Feature size:"<<fsize;
        out.setfSize(fsize);
        while (!fin.eof()) {
            e = new DataEntry;
            fin>>e->rank;
            if (e->rank == 0)
            {
                delete e;
                break;
            }
            fin>>e->qid;
            e->feature.resize(fsize);
            for (int i=0;i<fsize;++i) {
                fin>>e->feature(i);
            }
            out.addEntry(e);
        }
        eof=true;
        return 0;
    }
    virtual int open(){fin.open(fname); eof=false;return 0;};
    virtual int close(){fin.close();return 0;};
};

#endif