2013-07-27 11:40:16 -04:00
|
|
|
/*
|
|
|
|
* Copyright 2013 (c) Bryan Schumaker.
|
|
|
|
*/
|
|
|
|
#ifndef OCARINA_FILE_H
|
|
|
|
#define OCARINA_FILE_H
|
|
|
|
|
2013-07-28 19:57:07 -04:00
|
|
|
#include <fstream>
|
2013-07-27 11:40:16 -04:00
|
|
|
#include <string>
|
|
|
|
|
2013-07-28 19:57:07 -04:00
|
|
|
#define FILE_VERSION 0
|
|
|
|
|
2013-07-27 11:40:16 -04:00
|
|
|
enum FileLocHint {
|
|
|
|
FILE_TYPE_CONFIG,
|
|
|
|
FILE_TYPE_DATA,
|
|
|
|
FILE_TYPE_LEGACY,
|
|
|
|
};
|
|
|
|
|
2013-07-28 19:57:07 -04:00
|
|
|
enum OpenMode {
|
|
|
|
OPEN_READ,
|
|
|
|
OPEN_WRITE,
|
|
|
|
NOT_OPEN,
|
|
|
|
};
|
|
|
|
|
2013-07-27 11:40:16 -04:00
|
|
|
class File {
|
|
|
|
private:
|
2013-07-28 19:57:07 -04:00
|
|
|
std::fstream stream;
|
|
|
|
OpenMode mode;
|
2013-07-27 11:40:16 -04:00
|
|
|
FileLocHint hint;
|
|
|
|
std::string filepath;
|
2013-07-28 19:57:07 -04:00
|
|
|
unsigned int version;
|
|
|
|
|
|
|
|
void find_dir(std::string &);
|
|
|
|
bool open_read();
|
|
|
|
bool open_write();
|
2013-07-27 11:40:16 -04:00
|
|
|
|
|
|
|
public:
|
|
|
|
File(std::string, FileLocHint);
|
2013-07-28 19:57:07 -04:00
|
|
|
~File();
|
2013-07-27 11:40:16 -04:00
|
|
|
const char *get_filepath();
|
2013-07-28 19:57:07 -04:00
|
|
|
bool exists();
|
|
|
|
bool open(OpenMode);
|
|
|
|
bool close();
|
2013-07-27 11:40:16 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* OCARINA_FILE_H */
|