Gl Graph

Gl Graph Source of drawabledatareader.cpp


#include <drawabledatareader.h>
#include <typeinfo>
 
DrawableDataReader::DrawableDataReader(std::string * filename, std::string * format, int maxline,std::unordered_map<std::string, std::string> * args)
{
    this->filename = new std::string(*filename);
    this->format = new std::string(*format);
    this->maxline = maxline;
    this->args=args;
 
    pthread_mutex_init(&mutex, NULL);
 
}
 
DrawableDataReader::~DrawableDataReader()
{
    delete this->filename;
    delete this->format;
}
 
static void * thread_read_file(void *ptr)
{
    DrawableDataReader * reader = (DrawableDataReader *) ptr;
    reader->readFile();
    return 0;
}
 
void DrawableDataReader::stop()
{
    stopRequested=true;
}
 
void DrawableDataReader::readFile()
{
    std::ifstream  file;
    file.open (filename->c_str());
    if (file.is_open())
    {
        readTaskStart=true;
        onFileOpen();
        std::string line;
 
        while (!file.eof() && maxline > this->getElementNb() && !stopRequested)
        {
            getline(file, line);
            if (!line.empty())
            {
                if(!onLineRead(line))
                {
                    const std::type_info &info=typeid(*this);
                    std::cout << info.name() << " :Scan Failed for :" << line << " format :" << *getFormat()<<  std::endl;
                    break;
                }
            }
        }
        onFileClose();
        readTaskDone=true;
        file.close();
    }
    else
        std::cout << "Open failed for " << filename->c_str() << std::endl;
 
}
 
void DrawableDataReader::startReadingThread()
{
    pthread_create(&this->thread, NULL, (void* (*)(void*)) (&thread_read_file), (void *) this);
}