#ifndef INCLUDED_COMPILER_
#define INCLUDED_COMPILER_

#include <iosfwd>
#include <vector>
#include <thread>
#include <mutex>
#include <string>

#include "../types/types.h"

class CompileFork;

class Compiler: private Types
{
    enum
    {
        MAX_ERROR_LINES = 70
    };

    Map const &d_map;               // received by the constructor
    MapConstIter d_current;         // handle the current map element
    VectConstIter d_fileIter;       // iterates over the current ElementVect
    VectConstIter d_end;            // d_current->_r the current ElementVect

    std::vector<std::thread> d_thread;

    std::mutex d_mutex;
    bool d_OK = true;

    std::string d_pid;              // g_pid w/o the trailing ' '

    
//    static size_t const s_nThreads = 4;
    static size_t const s_nThreads = 2;

    public:
        Compiler(Map const &map);
        bool compile();

    private:
        void setFileIterators();
        int nFiles();               // returns enum-value
        bool nextSource();
        void compileJobs();
        void errorMessage(CompileFork const &compileFork);
        void copy(std::ostream &out, CompileFork const &compileFork);
};
        
#endif

