2014-09-16 08:22:34 -04:00
|
|
|
/**
|
|
|
|
* @file
|
2013-08-07 21:00:09 -04:00
|
|
|
* Copyright 2013 (c) Anna Schumaker.
|
2013-07-27 11:40:16 -04:00
|
|
|
*/
|
2014-06-21 09:37:47 -04:00
|
|
|
#ifndef OCARINA_CORE_FILE_H
|
|
|
|
#define OCARINA_CORE_FILE_H
|
2013-07-27 11:40:16 -04:00
|
|
|
|
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
|
|
|
|
2014-09-16 08:22:34 -04:00
|
|
|
/**
|
|
|
|
* Enum for how files could be open.
|
|
|
|
*/
|
2013-07-28 19:57:07 -04:00
|
|
|
enum OpenMode {
|
2014-09-16 08:22:34 -04:00
|
|
|
/** File is open for reading. */
|
2013-07-28 19:57:07 -04:00
|
|
|
OPEN_READ,
|
2014-09-16 08:22:34 -04:00
|
|
|
|
|
|
|
/** File is open for writing. */
|
2013-07-28 19:57:07 -04:00
|
|
|
OPEN_WRITE,
|
2014-09-16 08:22:34 -04:00
|
|
|
|
|
|
|
/** File is not open. */
|
2013-07-28 19:57:07 -04:00
|
|
|
NOT_OPEN,
|
|
|
|
};
|
|
|
|
|
2014-05-26 12:10:36 -04:00
|
|
|
|
2014-09-16 08:22:34 -04:00
|
|
|
/**
|
|
|
|
* Class for modifying files in the Ocarina directory.
|
|
|
|
*/
|
2013-07-28 22:33:40 -04:00
|
|
|
class File : public std::fstream {
|
2013-07-27 11:40:16 -04:00
|
|
|
private:
|
2013-07-28 19:57:07 -04:00
|
|
|
OpenMode mode;
|
2014-04-26 13:31:22 -04:00
|
|
|
std::string filename;
|
2013-07-28 19:57:07 -04:00
|
|
|
unsigned int version;
|
2014-05-26 12:10:36 -04:00
|
|
|
unsigned int prev_version;
|
2013-07-28 19:57:07 -04:00
|
|
|
|
2014-05-18 10:15:51 -04:00
|
|
|
const std::string find_dir();
|
2014-03-09 10:34:06 -04:00
|
|
|
bool open_read();
|
|
|
|
bool open_write();
|
2013-07-27 11:40:16 -04:00
|
|
|
|
|
|
|
public:
|
2014-05-26 12:10:36 -04:00
|
|
|
|
2014-09-16 08:22:34 -04:00
|
|
|
/**
|
|
|
|
* Set up a new file object.
|
|
|
|
*
|
|
|
|
* @param name The name of the file.
|
|
|
|
* @param version The file version of the new file.
|
|
|
|
*/
|
2014-05-26 12:10:36 -04:00
|
|
|
File(const std::string &, unsigned int);
|
2014-09-16 08:22:34 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* File class destructor.
|
|
|
|
*/
|
2013-07-28 19:57:07 -04:00
|
|
|
~File();
|
2014-09-16 08:22:34 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return The full filepath of the file.
|
|
|
|
*/
|
2014-05-18 10:15:51 -04:00
|
|
|
const std::string get_filepath();
|
2014-09-16 08:22:34 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return The version number of the file.
|
|
|
|
*/
|
2013-07-28 22:33:40 -04:00
|
|
|
const unsigned int get_version();
|
2014-09-16 08:22:34 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return True if the file exists on disk, False otherwise.
|
|
|
|
*/
|
2013-07-28 19:57:07 -04:00
|
|
|
bool exists();
|
2014-09-16 08:22:34 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Open a file.
|
|
|
|
*
|
|
|
|
* @param mode How the file should be opened.
|
|
|
|
* @return True if the open succeeded, False otherwise.
|
|
|
|
*/
|
2014-03-09 10:34:06 -04:00
|
|
|
bool open(OpenMode);
|
2014-09-16 08:22:34 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Close an open file.
|
|
|
|
*/
|
2013-12-29 21:12:32 -05:00
|
|
|
void close();
|
2014-09-16 08:22:34 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return A string containing the rest of the line.
|
|
|
|
*/
|
2013-07-28 22:33:40 -04:00
|
|
|
std::string getline();
|
2013-07-27 11:40:16 -04:00
|
|
|
};
|
|
|
|
|
2014-06-21 09:37:47 -04:00
|
|
|
#endif /* OCARINA_CORE_FILE_H */
|