Gl Graph

Gl Graph Source of drawabledatareader.h


#ifndef DRAWABLEDATAREADER_H
#define	DRAWABLEDATAREADER_H
#include <iostream>
#include <fstream>
#include <unordered_map>
#include "pthread.h"
#include <drawabledata.h>
 
class DrawableDataReader : public DrawableData  {
private:
    pthread_mutex_t mutex;
    pthread_t thread;
 
    bool readTaskDone;
    bool readTaskStart;
    bool stopRequested;
 
protected:
    //input
    std::string * filename;
    std::string * format;
    int maxline;
    std::unordered_map<std::string, std::string> * args;
 
public:
    DrawableDataReader() {
        readTaskDone =false;
        readTaskStart= false;
        stopRequested=false;
        args=NULL;
    };
    DrawableDataReader(std::string * filename, std::string * format, int maxline,std::unordered_map<std::string, std::string> * args);
    ~DrawableDataReader();
    void startReadingThread();
    void stop();
    bool isReadTaskDone() {
        return readTaskDone;
    };
 
    void readFile();
 
 
 
 
    std::string * getFilename() const {
        return filename;
    }
 
    std::string * getFormat() const {
        return format;
    }
 
    int getMaxLine() const {
        return maxline;
    }
 
    void lock() const
    {
        pthread_mutex_lock((pthread_mutex_t*)&mutex);
    }
 
    void unlock() const
    {
        pthread_mutex_unlock((pthread_mutex_t*)&mutex);
    }
 
    void waitUntilLoad() {
        pthread_join(this->thread, NULL);
    }
 
    virtual void onFileOpen() {
 
    }
 
    virtual bool onLineRead(std::string  line) = 0;
 
 
    virtual void onFileClose() {
 
    }
};
 
 
#endif