/** * @file * Copyright 2013 (c) Anna Schumaker. */ #ifndef OCARINA_CORE_FILE_H #define OCARINA_CORE_FILE_H #include #include /** * Enum for how files could be open. */ enum OpenMode { /** File is open for reading. */ OPEN_READ, /** File is open for writing. */ OPEN_WRITE, /** File is not open. */ NOT_OPEN, }; /** * Class for modifying files in the Ocarina directory. */ class File : public std::fstream { private: OpenMode mode; std::string filename; unsigned int version; unsigned int prev_version; const std::string find_dir(); bool open_read(); bool open_write(); public: /** * Set up a new file object. * * @param name The name of the file. * @param version The file version of the new file. */ File(const std::string &, unsigned int); /** * File class destructor. */ ~File(); /** * @return The full filepath of the file. */ const std::string get_filepath(); /** * @return The version number of the file. */ const unsigned int get_version(); /** * @return True if the file exists on disk, False otherwise. */ bool exists(); /** * Open a file. * * @param mode How the file should be opened. * @return True if the open succeeded, False otherwise. */ bool open(OpenMode); /** * Close an open file. */ void close(); /** * @return A string containing the rest of the line. */ std::string getline(); }; #endif /* OCARINA_CORE_FILE_H */