From f030154fe727e25a2afe1f78b3998c2d2dba95e4 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Tue, 18 Aug 2009 09:24:15 +0000 Subject: astyle cleanup, corrects not loading of material textures --- src/filesystem/diskfile.cc | 7 +++-- src/filesystem/diskfile.h | 2 +- src/filesystem/file.cc | 3 +- src/filesystem/file.h | 13 +++++--- src/filesystem/filestream.cc | 15 ++++----- src/filesystem/filestream.h | 10 ++++-- src/filesystem/filesystem.cc | 24 +++++++------- src/filesystem/filesystem.h | 3 +- src/filesystem/inifile.cc | 75 ++++++++++++++++++++++++++------------------ src/filesystem/inifile.h | 22 +++++++++---- 10 files changed, 106 insertions(+), 68 deletions(-) (limited to 'src/filesystem') diff --git a/src/filesystem/diskfile.cc b/src/filesystem/diskfile.cc index 6def055..bab20d9 100644 --- a/src/filesystem/diskfile.cc +++ b/src/filesystem/diskfile.cc @@ -5,9 +5,10 @@ */ #include "filesystem/filesystem.h" -#include "filesystem/diskfile.h" +#include "filesystem/diskfile.h" -namespace filesystem { +namespace filesystem +{ DiskFile::DiskFile() { @@ -25,7 +26,7 @@ FILE *DiskFile::handle() return diskfile_handle; } -bool DiskFile::open(const char *filename) +bool DiskFile::open(const char *filename) { if (diskfile_handle) { con_warn << file_name << " already open!" << std::endl; diff --git a/src/filesystem/diskfile.h b/src/filesystem/diskfile.h index 7da1a88..6a64ce5 100644 --- a/src/filesystem/diskfile.h +++ b/src/filesystem/diskfile.h @@ -14,7 +14,7 @@ #include -namespace filesystem +namespace filesystem { /** diff --git a/src/filesystem/file.cc b/src/filesystem/file.cc index 91ac9f9..628ba22 100644 --- a/src/filesystem/file.cc +++ b/src/filesystem/file.cc @@ -7,7 +7,8 @@ // project headers #include "filesystem/file.h" -namespace filesystem { +namespace filesystem +{ File::File() {} diff --git a/src/filesystem/file.h b/src/filesystem/file.h index daef174..a5daf34 100644 --- a/src/filesystem/file.h +++ b/src/filesystem/file.h @@ -10,7 +10,8 @@ // C++ headers #include -namespace filesystem { +namespace filesystem +{ /** * @brief an abstract interface to handle file access @@ -29,17 +30,21 @@ public: virtual FILE *handle(); - /// read bytes + /// read bytes virtual size_t read(void *buffer, size_t count) = 0; /// skip bytes virtual void skip(size_t count) = 0; /// name of the file in the virtual filesystem - inline const std::string name() const { return file_name; } + inline const std::string name() const { + return file_name; + } /// the path holding the virtual filename - inline const std::string path() const { return file_path; } + inline const std::string path() const { + return file_path; + } protected: std::string file_name; diff --git a/src/filesystem/filestream.cc b/src/filesystem/filestream.cc index cfbaaec..53c72d8 100644 --- a/src/filesystem/filestream.cc +++ b/src/filesystem/filestream.cc @@ -7,7 +7,8 @@ #include "filesystem/filesystem.h" #include "filesystem/filestream.h" -namespace filesystem { +namespace filesystem +{ IFileStream::IFileStream(const char *name) : std::ifstream() { @@ -38,12 +39,12 @@ void IFileStream::open(const char *name) for (SearchPath::iterator path = searchpath().begin(); path != searchpath().end(); path++) { fstream_filename.assign((*path)); fstream_filename.append(fstream_name); -/* -#ifdef _WIN32 - for (size_t i = 0; i < fstream_filename.size(); i++) - if (fstream_filename[i] == '/') fstream_filename[i] = '\\'; -#endif -*/ + /* + #ifdef _WIN32 + for (size_t i = 0; i < fstream_filename.size(); i++) + if (fstream_filename[i] == '/') fstream_filename[i] = '\\'; + #endif + */ if (sys::file_exists(fstream_filename)) { std::ifstream::open(fstream_filename.c_str()); diff --git a/src/filesystem/filestream.h b/src/filesystem/filestream.h index 9739f38..a97d1fb 100644 --- a/src/filesystem/filestream.h +++ b/src/filesystem/filestream.h @@ -9,7 +9,7 @@ #include -namespace filesystem +namespace filesystem { /** @@ -27,10 +27,14 @@ public: void open(const std::string &name); /// name of the file in the virtual filesystem - inline const std::string &name() const { return fstream_name; } + inline const std::string &name() const { + return fstream_name; + } /// actual dilename - inline const std::string &filename() const { return fstream_filename; } + inline const std::string &filename() const { + return fstream_filename; + } private: std::string fstream_name; diff --git a/src/filesystem/filesystem.cc b/src/filesystem/filesystem.cc index d268ccc..4ea715c 100644 --- a/src/filesystem/filesystem.cc +++ b/src/filesystem/filesystem.cc @@ -20,7 +20,7 @@ #include "filesystem/file.h" #include "sys/sys.h" -namespace filesystem +namespace filesystem { SearchPath filesystem_searchpath; @@ -56,17 +56,17 @@ void init(const std::string &binaryname, const std::string & basename, const std filesystem_basename.assign("base"); filesystem_modname.assign(modname); - + #ifndef _WIN32 // UNIX home directory is $HOME/.osirion filesystem_homedir.assign(getenv("HOME")); filesystem_homedir.append("/.osirion"); - + // create homedir if necessary if (!sys::directory_exists(filesystem_homedir)) - sys::mkdir(filesystem_homedir); + sys::mkdir(filesystem_homedir); filesystem_homedir += '/'; - + #else // windows home directory is My Documents\My Games\Osirion char mydocuments[512]; @@ -84,10 +84,10 @@ void init(const std::string &binaryname, const std::string & basename, const std if (!sys::directory_exists(filesystem_homedir)) sys::mkdir(filesystem_homedir); filesystem_homedir.append("\\"); - + } else { con_warn << "using fallback home directory" << std::endl; - + filesystem_homedir.assign("home"); if (!sys::directory_exists(filesystem_homedir)) sys::mkdir(filesystem_homedir); @@ -111,15 +111,15 @@ void init(const std::string &binaryname, const std::string & basename, const std // the data dir set by the configure script std::string package_datadir(PACKAGE_DATADIR); std::string dir; - + // set writedir depending on modname and add home paths to the searchpath filesystem_writedir.assign(filesystem_homedir); if (filesystem_modname.size()) { // append modname to writedir - filesystem_writedir.append(filesystem_modname); + filesystem_writedir.append(filesystem_modname); } else { // append basename to writedir - filesystem_writedir.append(filesystem_basename); + filesystem_writedir.append(filesystem_basename); } // create writedir if necessary @@ -181,7 +181,7 @@ void init(const std::string &binaryname, const std::string & basename, const std for (SearchPath::iterator path = filesystem_searchpath.begin(); path != filesystem_searchpath.end(); ++path) { #ifdef _WIN32 for (size_t i = 0; i < (*path).size(); i++) - if ((*path)[i] == '/') (*path)[i] = '\\'; + if ((*path)[i] == '/')(*path)[i] = '\\'; #endif con_print << " directory " << (*path) << std::endl; } @@ -203,7 +203,7 @@ void shutdown() filesystem_writedir.clear(); } -File *open(const char *filename) +File *open(const char *filename) { // for now, File is always a DiskFile DiskFile *f = new DiskFile(); diff --git a/src/filesystem/filesystem.h b/src/filesystem/filesystem.h index 1bdacaa..5fe97d0 100644 --- a/src/filesystem/filesystem.h +++ b/src/filesystem/filesystem.h @@ -17,7 +17,8 @@ /// The filesystem namespace contains classes and functions for common file operations. /** filesystem is a core subsystem */ -namespace filesystem { +namespace filesystem +{ typedef std::list SearchPath; diff --git a/src/filesystem/inifile.cc b/src/filesystem/inifile.cc index c6cc625..52bf36d 100644 --- a/src/filesystem/inifile.cc +++ b/src/filesystem/inifile.cc @@ -11,7 +11,8 @@ #include -namespace filesystem { +namespace filesystem +{ IniFile::IniFile(const char *ininame) { @@ -25,7 +26,7 @@ IniFile::IniFile(const std::string & ininame) open(ininame.c_str()); } -IniFile::~IniFile() +IniFile::~IniFile() { if (inifile_stream.is_open()) inifile_stream.close(); @@ -65,19 +66,23 @@ bool IniFile::open(const char *ininame) } -bool IniFile::got_section() const { +bool IniFile::got_section() const +{ return last_read_was_section; } -bool IniFile::got_section(const char * sectionlabel) const { +bool IniFile::got_section(const char * sectionlabel) const +{ return (last_read_was_section && (section_current.compare(sectionlabel) == 0)); } -bool IniFile::in_section(const char * sectionlabel) const { +bool IniFile::in_section(const char * sectionlabel) const +{ return ((section_current.compare(sectionlabel) == 0)); } -bool IniFile::getline() { +bool IniFile::getline() +{ char line[1024]; last_read_was_section = false; @@ -103,7 +108,7 @@ bool IniFile::getline() { // section header if (s.size() > 2 && s[0] == '[' && s[s.size()-1] == ']') { // condebug << "Inifile got section header " << s << std::endl; - section_current = s.substr(1, s.size()-2); + section_current = s.substr(1, s.size() - 2); aux::trim(section_current); aux::to_lowercase(section_current); @@ -121,9 +126,9 @@ bool IniFile::getline() { aux::to_lowercase(key_current); if (key_current.size()) { - value_current = s.substr(found+1, s.size() - found - 1); - aux::trim (value_current); - last_read_was_key = true; + value_current = s.substr(found + 1, s.size() - found - 1); + aux::trim(value_current); + last_read_was_key = true; //con_debug << "IniFile got " << key_current << "=" << value_current << std::endl; return true; } @@ -140,8 +145,9 @@ bool IniFile::got_key() const return last_read_was_key; } -bool IniFile::got_key_string(const char * keylabel, std::string & valuestring) { - if (last_read_was_key && (key_current.compare(keylabel) == 0 )) { +bool IniFile::got_key_string(const char * keylabel, std::string & valuestring) +{ + if (last_read_was_key && (key_current.compare(keylabel) == 0)) { valuestring.assign(value_current); return true; } else { @@ -149,14 +155,15 @@ bool IniFile::got_key_string(const char * keylabel, std::string & valuestring) { } } -bool IniFile::got_key_vector3f(const char * keylabel, math::Vector3f & v) { - if (last_read_was_key && (key_current.compare(keylabel) == 0 )) { +bool IniFile::got_key_vector3f(const char * keylabel, math::Vector3f & v) +{ + if (last_read_was_key && (key_current.compare(keylabel) == 0)) { std::istringstream is(value_current); float x, y, z; if ((is >> x) && (is >> y) && (is >> z)) { - v = math::Vector3f(x,y,z); + v = math::Vector3f(x, y, z); } else { - v= math::Vector3f(); + v = math::Vector3f(); } return true; } else { @@ -164,8 +171,9 @@ bool IniFile::got_key_vector3f(const char * keylabel, math::Vector3f & v) { } } -bool IniFile::got_key_float(const char * keylabel, float & f) { - if (last_read_was_key && (key_current.compare(keylabel) == 0 )) { +bool IniFile::got_key_float(const char * keylabel, float & f) +{ + if (last_read_was_key && (key_current.compare(keylabel) == 0)) { std::istringstream is(value_current); if (!(is >> f)) { f = 0; @@ -176,8 +184,9 @@ bool IniFile::got_key_float(const char * keylabel, float & f) { } } -bool IniFile::got_key_long(const char * keylabel, long & l) { - if (last_read_was_key && (key_current.compare(keylabel) == 0 )) { +bool IniFile::got_key_long(const char * keylabel, long & l) +{ + if (last_read_was_key && (key_current.compare(keylabel) == 0)) { std::istringstream is(value_current); if (!(is >> l)) { l = 0; @@ -188,12 +197,14 @@ bool IniFile::got_key_long(const char * keylabel, long & l) { } } -bool IniFile::got_key(const char * keylabel) { - return (last_read_was_key && (key_current.compare(keylabel) == 0 )); +bool IniFile::got_key(const char * keylabel) +{ + return (last_read_was_key && (key_current.compare(keylabel) == 0)); } -bool IniFile::got_key_angle(const char * keylabel, float & f) { - if (last_read_was_key && (key_current.compare(keylabel) == 0 )) { +bool IniFile::got_key_angle(const char * keylabel, float & f) +{ + if (last_read_was_key && (key_current.compare(keylabel) == 0)) { std::istringstream is(value_current); if ((is >> f)) { f = math::degrees360f(f); @@ -206,8 +217,9 @@ bool IniFile::got_key_angle(const char * keylabel, float & f) { } } -bool IniFile::got_key_color(const char * keylabel, math::Color & color) { - if (last_read_was_key && (key_current.compare(keylabel) == 0 )) { +bool IniFile::got_key_color(const char * keylabel, math::Color & color) +{ + if (last_read_was_key && (key_current.compare(keylabel) == 0)) { std::istringstream is(value_current); float r, g, b, a; if ((is >> r) && (is >> g) && (is >> b)) { @@ -215,7 +227,9 @@ bool IniFile::got_key_color(const char * keylabel, math::Color & color) { if (is >> a) { a /= 255.0f; } - r /= 255.0f; g /= 255.0f; b /= 255.0f; + r /= 255.0f; + g /= 255.0f; + b /= 255.0f; } else { if (!(is >> a)) { a = 1.0f; @@ -233,12 +247,13 @@ bool IniFile::got_key_color(const char * keylabel, math::Color & color) { bool IniFile::got_key_bool(const char * keylabel, bool & b) { - if (last_read_was_key && (key_current.compare(keylabel) == 0 )) { + if (last_read_was_key && (key_current.compare(keylabel) == 0)) { std::istringstream is(value_current); unsigned int i; if (is >> i) { - if (i) b = true; else b = false; + if (i) b = true; + else b = false; return true; } @@ -266,7 +281,7 @@ bool IniFile::got_key_bool(const char * keylabel, bool & b) void IniFile::unknown_value() const { - con_warn << name() << " unknown value '" << value() << "' for key '" << key() << "' at line " << line() << std::endl; + con_warn << name() << " unknown value '" << value() << "' for key '" << key() << "' at line " << line() << std::endl; } void IniFile::unkown_key() const diff --git a/src/filesystem/inifile.h b/src/filesystem/inifile.h index fa2d81f..e5423aa 100644 --- a/src/filesystem/inifile.h +++ b/src/filesystem/inifile.h @@ -14,14 +14,16 @@ #include "math/color.h" #include "filesystem/filestream.h" -namespace filesystem { +namespace filesystem +{ /// a class to read .ini files /** The IniFile class provides functions to read .ini files. A .ini file * consists of one or more [section] headers followed by one or more key=value * pairs. Lines starting with # or ; are considered comments */ -class IniFile { +class IniFile +{ public: IniFile(const char *ininame = 0); @@ -97,16 +99,24 @@ public: void unknown_section() const; /// return true of the ini file is open for reading - inline bool is_open() { return inifile_stream.is_open(); } + inline bool is_open() { + return inifile_stream.is_open(); + } /// return true of the ini file is open for reading - inline bool good() { return inifile_stream.good(); } + inline bool good() { + return inifile_stream.good(); + } /// current name in the virtual filesystem - inline std::string const & name() const {return inifile_stream.name(); } + inline std::string const & name() const { + return inifile_stream.name(); + } /// current actual filename - inline std::string const & filename() const { return inifile_stream.filename(); } + inline std::string const & filename() const { + return inifile_stream.filename(); + } /// close the file void close(); -- cgit v1.2.3