#ifndef FILE_H
#define FILE_H

#include "common.h"

// Closed, read, write variations
#define OPEN_C 0
#define OPEN_R 1
#define OPEN_RW 3

class myfile
{
private:
 int            chandle     = 0;        // Chandle is choices handle (different from file handle due to files can be closed and opened ad-hoc)
 int            open        = OPEN_C;   // Open uses OPEN_... to store the types, if not zero handle should have the file handle filled in
 FILE*          fhandle;                // File handle if open
 std::string    filename    = "";
 std::string    dirname     = "";
 bool           madedir     = 0;
 int            count       = 0;        // Count how many times this has been opened, shouldn't lose details until all have released
 myfile*        next_file   = 0;
 char*          rtn_string  = NULL;


public:
 myfile*        find(int);
 int            matched(std::string,std::string);
 void           close(int);
 void           close(myfile*);
 void           closeall(void);
 void           print(void);
 int            candelete(void);
 int            openw();
 // The read/write functions are in dataread/write.cc
 int            setblock(std::string name,int size);
 void           writeint4(std::string,int);
 void           writes(std::string,std::string);
 void           writef(std::string,void* mem,FloatFormat);
 void           writemem(std::string,regint,regint);
 void           readmem(std::string,regint,regint);
 int            readint4(std::string,int);
 char*          reads(std::string,std::string);
 void           readf(std::string,void* mem,FloatFormat);
 int            exist(std::string);
 int            size(std::string);
 void           del(std::string);
 void           enumerate(int,regs&);
 // in compact.cc and compact.h
 void           compact(myfile*);

 myfile(int,std::string,std::string);
 ~myfile();
};


int fileopen(regs &r);
void fileclose(regs &r);
void fileprint(void);
void setfilelength(char*,int);

#endif