core/file: Move get_version() function out of the file struct

This is now a simple function for accessing the current version of the
file.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-09-10 08:10:38 -04:00
parent 1dcc56c87e
commit ce94680d4d
5 changed files with 14 additions and 16 deletions

View File

@ -94,7 +94,7 @@ void deck :: init()
if (!deck_file.open(OPEN_READ))
return;
if (deck_file.get_version() == 0) {
if (file_version(&deck_file) == 0) {
upgrade_v0();
upgraded = true;
}

View File

@ -41,11 +41,11 @@ const std::string file :: get_filepath()
return res;
}
const unsigned int file :: get_version()
const unsigned int file_version(struct file *file)
{
if (f_mode == OPEN_READ)
return f_prev;
return f_version;
if (file->f_mode == OPEN_READ)
return file->f_prev;
return file->f_version;
}
bool file :: exists()

View File

@ -70,13 +70,6 @@ struct file : public std::fstream {
*/
const std::string get_filepath();
/**
* @return The version number of the file. If File::_mode is
* ::OPEN_READ then File::_prev_version is returned.
* File::_version is returned in all other cases.
*/
const unsigned int get_version();
/**
* @return True if the file exists on disk, False otherwise.
*/
@ -119,4 +112,9 @@ struct file : public std::fstream {
std::string getline();
};
/* Returns the version number of the file. */
const unsigned int file_version(struct file *);
#endif /* OCARINA_CORE_FILE_H */

View File

@ -39,7 +39,7 @@ static void test_init()
* Test that we saved the deck in the new format
*/
f.open(OPEN_READ);
test_equal(f.get_version(), (unsigned)1);
test_equal(file_version(&f), (unsigned)1);
f >> val; /* number of queues */
test_equal(val, (unsigned)2);

View File

@ -12,10 +12,10 @@ static void test_filepath()
file a("", 0);
file b("file.txt", 0);
test_equal(a.get_version(), (unsigned)0);
test_equal(file_version(&a), (unsigned)0);
test_equal((std::string)a.get_filepath(), (std::string)"");
test_equal(b.get_version(), (unsigned)0);
test_equal(file_version(&b), (unsigned)0);
test_equal((std::string)b.get_filepath(), filepath);
test_equal(a.exists(), false);
@ -55,7 +55,7 @@ static void test_io()
std::string res;
test_equal(b.open(OPEN_READ), true);
test_equal(b.get_version(), (unsigned)1);
test_equal(file_version(&b), (unsigned)1);
b >> res;
test_equal(res, (std::string)"ABCDE");
b >> res;