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

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-09-10 08:17:53 -04:00
parent ce94680d4d
commit aa21ede894
3 changed files with 11 additions and 14 deletions

View File

@ -30,13 +30,13 @@ file :: ~file()
close();
}
const std::string file :: get_filepath()
const std::string file_path(struct file *file)
{
std::string res = "";
if (f_name != "") {
if (file->f_name != "") {
res = find_ocarina_dir();
res += "/" + f_name;
res += "/" + file->f_name;
}
return res;
}
@ -50,7 +50,7 @@ const unsigned int file_version(struct file *file)
bool file :: exists()
{
return g_file_test(get_filepath().c_str(), G_FILE_TEST_EXISTS);
return g_file_test(file_path(this).c_str(), G_FILE_TEST_EXISTS);
}
bool file :: _open_read()
@ -58,7 +58,7 @@ bool file :: _open_read()
if (!exists())
return false;
std::fstream::open(get_filepath().c_str(), std::fstream::in);
std::fstream::open(file_path(this).c_str(), std::fstream::in);
if (std::fstream::fail())
return false;
@ -73,7 +73,7 @@ bool file :: _open_write()
if (g_mkdir_with_parents(find_ocarina_dir().c_str(), 0755) != 0)
return false;
std::fstream::open(get_filepath().c_str(), std::fstream::out);
std::fstream::open(file_path(this).c_str(), std::fstream::out);
if (std::fstream::fail())
return false;

View File

@ -64,12 +64,6 @@ struct file : public std::fstream {
*/
~file();
/**
* @return The full filepath of the file or an empty string if
* the filename is not set.
*/
const std::string get_filepath();
/**
* @return True if the file exists on disk, False otherwise.
*/
@ -113,6 +107,9 @@ struct file : public std::fstream {
};
/* Returns the full path of the file or an empty string if filename is not set. */
const std::string file_path(struct file *);
/* Returns the version number of the file. */
const unsigned int file_version(struct file *);

View File

@ -13,10 +13,10 @@ static void test_filepath()
file b("file.txt", 0);
test_equal(file_version(&a), (unsigned)0);
test_equal((std::string)a.get_filepath(), (std::string)"");
test_equal((std::string)file_path(&a), (std::string)"");
test_equal(file_version(&b), (unsigned)0);
test_equal((std::string)b.get_filepath(), filepath);
test_equal((std::string)file_path(&b), filepath);
test_equal(a.exists(), false);
test_equal(b.exists(), false);