From 7e9eb9e7d2108bea301e53a4c4be7c23bd69e2cd Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Thu, 10 Sep 2015 08:23:09 -0400 Subject: [PATCH] core/file: Move exists() out of the file struct Signed-off-by: Anna Schumaker --- core/audio.cpp | 2 +- core/file.cpp | 6 +++--- include/core/database.hpp | 2 +- include/core/file.h | 8 +++----- tests/core/file.cpp | 6 +++--- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/core/audio.cpp b/core/audio.cpp index a1912a66..c2f6307f 100644 --- a/core/audio.cpp +++ b/core/audio.cpp @@ -79,7 +79,7 @@ void audio :: init() { unsigned int id; - if (f_cur_track.exists()) { + if (file_exists(&f_cur_track)) { f_cur_track.open(OPEN_READ); f_cur_track >> id; f_cur_track.close(); diff --git a/core/file.cpp b/core/file.cpp index d265327d..c94ccafb 100644 --- a/core/file.cpp +++ b/core/file.cpp @@ -48,14 +48,14 @@ const unsigned int file_version(struct file *file) return file->f_version; } -bool file :: exists() +bool file_exists(struct file *file) { - return g_file_test(file_path(this).c_str(), G_FILE_TEST_EXISTS); + return g_file_test(file_path(file).c_str(), G_FILE_TEST_EXISTS); } bool file :: _open_read() { - if (!exists()) + if (!file_exists(this)) return false; std::fstream::open(file_path(this).c_str(), std::fstream::in); diff --git a/include/core/database.hpp b/include/core/database.hpp index 75cb4b56..ae7be39f 100644 --- a/include/core/database.hpp +++ b/include/core/database.hpp @@ -54,7 +54,7 @@ void Database :: load() unsigned int db_size; bool valid; - if (_file.exists() == false) + if (file_exists(&_file) == false) return; else if (_file.open(OPEN_READ) == false) return; diff --git a/include/core/file.h b/include/core/file.h index de60f779..261a5b7c 100644 --- a/include/core/file.h +++ b/include/core/file.h @@ -64,11 +64,6 @@ struct file : public std::fstream { */ ~file(); - /** - * @return True if the file exists on disk, False otherwise. - */ - bool exists(); - /** * Call to open a file for either reading or writing. * @@ -113,5 +108,8 @@ const std::string file_path(struct file *); /* Returns the version number of the file. */ const unsigned int file_version(struct file *); +/* Returns true if the file exists on disk and false otherwise. */ +bool file_exists(struct file *); + #endif /* OCARINA_CORE_FILE_H */ diff --git a/tests/core/file.cpp b/tests/core/file.cpp index 10a211bd..8b6ce057 100644 --- a/tests/core/file.cpp +++ b/tests/core/file.cpp @@ -18,8 +18,8 @@ static void test_filepath() test_equal(file_version(&b), (unsigned)0); test_equal((std::string)file_path(&b), filepath); - test_equal(a.exists(), false); - test_equal(b.exists(), false); + test_equal(file_exists(&a), false); + test_equal(file_exists(&b), false); test_equal(test_data_file_exists(NULL), false); g_free(filepath); @@ -49,7 +49,7 @@ static void test_io() test_equal(a.open(OPEN_WRITE), true); a << "ABCDE FGHIJ KLMNO PQRST UVWXYZ" << std::endl; a.close(); - test_equal(a.exists(), true); + test_equal(file_exists(&a), true); file b("file.txt", 0); std::string res;