diff --git a/core/deck.cpp b/core/deck.cpp index bd1c7c65..636a05bf 100644 --- a/core/deck.cpp +++ b/core/deck.cpp @@ -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; } diff --git a/core/file.cpp b/core/file.cpp index 67085b82..bf40b3a7 100644 --- a/core/file.cpp +++ b/core/file.cpp @@ -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() diff --git a/include/core/file.h b/include/core/file.h index fd30c76a..16e0023c 100644 --- a/include/core/file.h +++ b/include/core/file.h @@ -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 */ diff --git a/tests/core/deck.cpp b/tests/core/deck.cpp index fb8f0583..7cdb631c 100644 --- a/tests/core/deck.cpp +++ b/tests/core/deck.cpp @@ -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); diff --git a/tests/core/file.cpp b/tests/core/file.cpp index 7a583aa9..8eb3e5a8 100644 --- a/tests/core/file.cpp +++ b/tests/core/file.cpp @@ -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;