From 8765d58b02c9afd00186bae4a0045dff32f7d102 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 26 May 2013 17:47:54 +0200 Subject: Fixed code formatting * moved braces to new lines * fixed some function/variable names * fixed whitespace issues --- src/common/README.txt | 1 + src/common/config.h.cmake | 1 + src/common/event.h | 1 + src/common/global.h | 1 + src/common/image.cpp | 4 +- src/common/image.h | 1 + src/common/iman.cpp | 1 + src/common/iman.h | 1 - src/common/ioutils.h | 1 + src/common/key.h | 1 + src/common/logger.h | 4 +- src/common/misc.h | 1 + src/common/profile.cpp | 32 ++++---- src/common/profile.h | 188 +++++++++++++++++++++++---------------------- src/common/restext.cpp | 1 + src/common/restext.h | 1 + src/common/singleton.h | 1 + src/common/stringutils.cpp | 1 + src/common/stringutils.h | 1 + 19 files changed, 134 insertions(+), 109 deletions(-) (limited to 'src/common') diff --git a/src/common/README.txt b/src/common/README.txt index 25c9fbf..1fc21f1 100644 --- a/src/common/README.txt +++ b/src/common/README.txt @@ -2,3 +2,4 @@ * \dir src/common * \brief Structs and utils shared throughout the application */ + diff --git a/src/common/config.h.cmake b/src/common/config.h.cmake index d5a03b4..76b37b5 100644 --- a/src/common/config.h.cmake +++ b/src/common/config.h.cmake @@ -23,3 +23,4 @@ #define COLOBOT_DEFAULT_DATADIR "@COLOBOT_INSTALL_DATA_DIR@" #define COLOBOT_I18N_DIR "@COLOBOT_INSTALL_I18N_DIR@" + diff --git a/src/common/event.h b/src/common/event.h index b9c6623..97b798a 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -779,3 +779,4 @@ protected: int m_tail; int m_total; }; + diff --git a/src/common/global.h b/src/common/global.h index 716b711..a322057 100644 --- a/src/common/global.h +++ b/src/common/global.h @@ -297,3 +297,4 @@ extern int g_build; // constructible buildings extern int g_researchDone; // research done extern long g_researchEnable; // research available extern float g_unit; // conversion factor + diff --git a/src/common/image.cpp b/src/common/image.cpp index fd55217..a9587ef 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -110,7 +110,8 @@ bool PNGSaveSurface(const char *filename, SDL_Surface *surf) return false; } - if (setjmp(png_jmpbuf(png_ptr))) { + if (setjmp(png_jmpbuf(png_ptr))) + { png_destroy_write_struct(&png_ptr, &info_ptr); fclose(fp); return false; @@ -396,3 +397,4 @@ bool CImage::SavePNG(const std::string& fileName) return true; } + diff --git a/src/common/image.h b/src/common/image.h index f0b50a3..44aedf1 100644 --- a/src/common/image.h +++ b/src/common/image.h @@ -112,3 +112,4 @@ private: //! Image data ImageData* m_data; }; + diff --git a/src/common/iman.cpp b/src/common/iman.cpp index e1400fd..88fbb9b 100644 --- a/src/common/iman.cpp +++ b/src/common/iman.cpp @@ -111,3 +111,4 @@ void CInstanceManager::Compress(ManagedClassType classType) } m_table[classType].usedCount = j; } + diff --git a/src/common/iman.h b/src/common/iman.h index faabd0c..bfa2204 100644 --- a/src/common/iman.h +++ b/src/common/iman.h @@ -93,4 +93,3 @@ protected: ManagedClassInstances m_table[CLASS_MAX]; }; - diff --git a/src/common/ioutils.h b/src/common/ioutils.h index 9a94617..823b720 100644 --- a/src/common/ioutils.h +++ b/src/common/ioutils.h @@ -146,3 +146,4 @@ std::string ReadBinaryString(std::istream &istr) } }; // namespace IOUtils + diff --git a/src/common/key.h b/src/common/key.h index 84ee618..82b3fbd 100644 --- a/src/common/key.h +++ b/src/common/key.h @@ -61,3 +61,4 @@ enum VirtualKmod //! Special value for invalid key bindings const unsigned int KEY_INVALID = SDLK_LAST + 1000; + diff --git a/src/common/logger.h b/src/common/logger.h index 769f548..83a915c 100644 --- a/src/common/logger.h +++ b/src/common/logger.h @@ -125,6 +125,8 @@ private: //! Global function to get Logger instance -inline CLogger* GetLogger() { +inline CLogger* GetLogger() +{ return CLogger::GetInstancePointer(); } + diff --git a/src/common/misc.h b/src/common/misc.h index e2ddc44..bcebf76 100644 --- a/src/common/misc.h +++ b/src/common/misc.h @@ -31,3 +31,4 @@ extern void TimeToAscii(time_t time, char *buffer); extern bool CopyFileListToTemp(char* filename, int* list, int total); extern void AddExt(char* filename, const char* ext); + diff --git a/src/common/profile.cpp b/src/common/profile.cpp index 0bc40cf..c6af6cc 100644 --- a/src/common/profile.cpp +++ b/src/common/profile.cpp @@ -47,8 +47,9 @@ bool CProfile::InitCurrentDirectory() { try { + // TODO: NDEBUG should be replaced with something like BUILD_TYPE == "DEBUG"/"RELEASE" #ifdef NDEBUG - bp::ini_parser::read_ini(GetSystemUtils()->profileFileLocation(), m_propertyTree); + bp::ini_parser::read_ini(GetSystemUtils()->GetProfileFileLocation(), m_propertyTree); #else bp::ini_parser::read_ini("colobot.ini", m_propertyTree); #endif @@ -68,7 +69,7 @@ bool CProfile::SaveCurrentDirectory() try { #ifdef NDEBUG - bp::ini_parser::write_ini(GetSystemUtils()->profileFileLocation(), m_propertyTree); + bp::ini_parser::write_ini(GetSystemUtils()->GetProfileFileLocation(), m_propertyTree); #else bp::ini_parser::write_ini("colobot.ini", m_propertyTree); #endif @@ -209,34 +210,39 @@ std::string CProfile::GetUserBasedPath(std::string dir, std::string default_dir) { std::string path = dir; boost::replace_all(path, "\\", "/"); - if (dir.find("/") == std::string::npos) { + if (dir.find("/") == std::string::npos) + { path = default_dir + "/" + dir; } - - if (m_userDirectory.length() > 0) { + + if (m_userDirectory.length() > 0) + { boost::replace_all(path, "%user%", m_userDirectory); - } else { + } + else + { boost::replace_all(path, "%user%", default_dir); } - + return fs::path(path).make_preferred().string(); } - - + + bool CProfile::CopyFileToTemp(std::string filename) { std::string src, dst; std::string tmp_user_dir = m_userDirectory; - + src = GetUserBasedPath(filename, "textures"); SetUserDir("temp"); dst = GetUserBasedPath(filename, "textures"); SetUserDir(tmp_user_dir); - + fs::create_directory(fs::path(dst).parent_path().make_preferred().string()); fs::copy_file(src, dst, fs::copy_option::overwrite_if_exists); - if (fs::exists(dst)) { - return true; + if (fs::exists(dst)) + { + return true; } return false; diff --git a/src/common/profile.h b/src/common/profile.h index ba797e9..8ea2aee 100644 --- a/src/common/profile.h +++ b/src/common/profile.h @@ -41,101 +41,103 @@ namespace fs = boost::filesystem; */ class CProfile : public CSingleton { - public: - CProfile(); - ~CProfile(); - - /** Loads colobot.ini from current directory - * \return return true on success - */ - bool InitCurrentDirectory(); - - /** Saves colobot.ini to current directory - * \return return true on success - */ - bool SaveCurrentDirectory(); - - /** Sets string value in section under specified key - * \param section - * \param key - * \param value - * \return return true on success - */ - bool SetLocalProfileString(std::string section, std::string key, std::string value); - - /** Gets string value in section under specified key - * \param section - * \param key - * \param buffer - * \return return true on success - */ - bool GetLocalProfileString(std::string section, std::string key, std::string& buffer); - - /** Sets int value in section under specified key - * \param section - * \param key - * \param value - * \return return true on success - */ - bool SetLocalProfileInt(std::string section, std::string key, int value); - - /** Gets int value in section under specified key - * \param section - * \param key - * \param value - * \return return true on success - */ - bool GetLocalProfileInt(std::string section, std::string key, int &value); - - /** Sets float value in section under specified key - * \param section - * \param key - * \param value - * \return return true on success - */ - bool SetLocalProfileFloat(std::string section, std::string key, float value); - - /** Gets float value in section under specified key - * \param section - * \param key - * \param value - * \return return true on success - */ - bool GetLocalProfileFloat(std::string section, std::string key, float &value); - - /** Gets all values in section under specified key - * \param section - * \param key - * \return vector of values - */ - std::vector< std::string > GetLocalProfileSection(std::string section, std::string key); - - /** Sets current user directory - * \param dir - */ - void SetUserDir(std::string dir); - - /** Returns path based on current user. Replaces %user% in path with current user dir or - * uses default_dir param if no user dir is specified - * \param dir - * \param default_dir - * \return path - */ - std::string GetUserBasedPath(std::string dir, std::string default_dir); - - /** opy a file into the temporary folder. - * \param filename - * \return true on success - */ - bool CopyFileToTemp(std::string filename); - - private: - boost::property_tree::ptree m_propertyTree; - bool m_profileNeedSave; - std::string m_userDirectory; +public: + CProfile(); + ~CProfile(); + + /** Loads colobot.ini from current directory + * \return return true on success + */ + bool InitCurrentDirectory(); + + /** Saves colobot.ini to current directory + * \return return true on success + */ + bool SaveCurrentDirectory(); + + /** Sets string value in section under specified key + * \param section + * \param key + * \param value + * \return return true on success + */ + bool SetLocalProfileString(std::string section, std::string key, std::string value); + + /** Gets string value in section under specified key + * \param section + * \param key + * \param buffer + * \return return true on success + */ + bool GetLocalProfileString(std::string section, std::string key, std::string& buffer); + + /** Sets int value in section under specified key + * \param section + * \param key + * \param value + * \return return true on success + */ + bool SetLocalProfileInt(std::string section, std::string key, int value); + + /** Gets int value in section under specified key + * \param section + * \param key + * \param value + * \return return true on success + */ + bool GetLocalProfileInt(std::string section, std::string key, int &value); + + /** Sets float value in section under specified key + * \param section + * \param key + * \param value + * \return return true on success + */ + bool SetLocalProfileFloat(std::string section, std::string key, float value); + + /** Gets float value in section under specified key + * \param section + * \param key + * \param value + * \return return true on success + */ + bool GetLocalProfileFloat(std::string section, std::string key, float &value); + + /** Gets all values in section under specified key + * \param section + * \param key + * \return vector of values + */ + std::vector< std::string > GetLocalProfileSection(std::string section, std::string key); + + /** Sets current user directory + * \param dir + */ + void SetUserDir(std::string dir); + + /** Returns path based on current user. Replaces %user% in path with current user dir or + * uses default_dir param if no user dir is specified + * \param dir + * \param default_dir + * \return path + */ + std::string GetUserBasedPath(std::string dir, std::string default_dir); + + /** opy a file into the temporary folder. + * \param filename + * \return true on success + */ + bool CopyFileToTemp(std::string filename); + +private: + boost::property_tree::ptree m_propertyTree; + bool m_profileNeedSave; + std::string m_userDirectory; }; //! Global function to get profile instance -inline CProfile & GetProfile() { +inline CProfile & GetProfile() +{ return *CProfile::GetInstancePointer(); } + diff --git a/src/common/restext.cpp b/src/common/restext.cpp index ac40dad..ead8ef3 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -920,3 +920,4 @@ bool GetResource(ResType type, int num, char* text) PutKeyName(text, tmpl); return true; } + diff --git a/src/common/restext.h b/src/common/restext.h index 1c99473..e4659e2 100644 --- a/src/common/restext.h +++ b/src/common/restext.h @@ -158,3 +158,4 @@ void InitializeRestext(); void SetGlobalGamerName(std::string name); bool SearchKey(const char *cmd, InputSlot& slot); bool GetResource(ResType type, int num, char* text); + diff --git a/src/common/singleton.h b/src/common/singleton.h index 25e1648..841759d 100644 --- a/src/common/singleton.h +++ b/src/common/singleton.h @@ -74,3 +74,4 @@ private: CSingleton& operator=(const CSingleton &); CSingleton(const CSingleton &); }; + diff --git a/src/common/stringutils.cpp b/src/common/stringutils.cpp index db486f0..953abba 100644 --- a/src/common/stringutils.cpp +++ b/src/common/stringutils.cpp @@ -142,3 +142,4 @@ size_t StrUtils::Utf8StringLength(const std::string &str) } return result; } + diff --git a/src/common/stringutils.h b/src/common/stringutils.h index 064351d..c60bfb0 100644 --- a/src/common/stringutils.h +++ b/src/common/stringutils.h @@ -78,3 +78,4 @@ int Utf8CharSizeAt(const std::string &str, unsigned int pos); size_t Utf8StringLength(const std::string &str); }; // namespace StrUtil + -- cgit v1.2.3-1-g7c22