diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/config-manager.h | 27 | ||||
-rw-r--r-- | common/ini-file.cpp (renamed from common/config-file.cpp) | 60 | ||||
-rw-r--r-- | common/ini-file.h (renamed from common/config-file.h) | 29 | ||||
-rw-r--r-- | common/math.h | 8 | ||||
-rw-r--r-- | common/module.mk | 2 | ||||
-rw-r--r-- | common/scummsys.h | 57 | ||||
-rw-r--r-- | common/util.h | 8 |
7 files changed, 124 insertions, 67 deletions
diff --git a/common/config-manager.h b/common/config-manager.h index d43a7bec51..6bf56749c5 100644 --- a/common/config-manager.h +++ b/common/config-manager.h @@ -24,7 +24,6 @@ #define COMMON_CONFIG_MANAGER_H #include "common/array.h" -//#include "common/config-file.h" #include "common/hashmap.h" #include "common/singleton.h" #include "common/str.h" @@ -47,12 +46,33 @@ class ConfigManager : public Singleton<ConfigManager> { public: - class Domain : public StringMap { + class Domain { private: + StringMap _entries; StringMap _keyValueComments; String _domainComment; public: + typedef StringMap::const_iterator const_iterator; + const_iterator begin() const { return _entries.begin(); } + const_iterator end() const { return _entries.end(); } + + bool empty() const { return _entries.empty(); } + + bool contains(const String &key) const { return _entries.contains(key); } + + String &operator[](const String &key) { return _entries[key]; } + const String &operator[](const String &key) const { return _entries[key]; } + + void setVal(const String &key, const String &value) { _entries.setVal(key, value); } + + String &getVal(const String &key) { return _entries.getVal(key); } + const String &getVal(const String &key) const { return _entries.getVal(key); } + + void clear() { _entries.clear(); } + + void erase(const String &key) { _entries.erase(key); } + void setDomainComment(const String &comment); const String &getDomainComment() const; @@ -143,7 +163,8 @@ public: bool hasMiscDomain(const String &domName) const; const DomainMap & getGameDomains() const { return _gameDomains; } - DomainMap & getGameDomains() { return _gameDomains; } + DomainMap::iterator beginGameDomains() { return _gameDomains.begin(); } + DomainMap::iterator endGameDomains() { return _gameDomains.end(); } static void defragment(); // move in memory to reduce fragmentation void copyFrom(ConfigManager &source); diff --git a/common/config-file.cpp b/common/ini-file.cpp index 0ce6dcf0c8..be5247dcfb 100644 --- a/common/config-file.cpp +++ b/common/ini-file.cpp @@ -20,7 +20,7 @@ * */ -#include "common/config-file.h" +#include "common/ini-file.h" #include "common/file.h" #include "common/savefile.h" #include "common/system.h" @@ -28,24 +28,24 @@ namespace Common { -bool ConfigFile::isValidName(const String &name) { +bool INIFile::isValidName(const String &name) { const char *p = name.c_str(); while (*p && (isAlnum(*p) || *p == '-' || *p == '_' || *p == '.')) p++; return *p == 0; } -ConfigFile::ConfigFile() { +INIFile::INIFile() { } -ConfigFile::~ConfigFile() { +INIFile::~INIFile() { } -void ConfigFile::clear() { +void INIFile::clear() { _sections.clear(); } -bool ConfigFile::loadFromFile(const String &filename) { +bool INIFile::loadFromFile(const String &filename) { File file; if (file.open(filename)) return loadFromStream(file); @@ -53,7 +53,7 @@ bool ConfigFile::loadFromFile(const String &filename) { return false; } -bool ConfigFile::loadFromSaveFile(const char *filename) { +bool INIFile::loadFromSaveFile(const char *filename) { assert(g_system); SaveFileManager *saveFileMan = g_system->getSavefileManager(); SeekableReadStream *loadFile; @@ -67,7 +67,7 @@ bool ConfigFile::loadFromSaveFile(const char *filename) { return status; } -bool ConfigFile::loadFromStream(SeekableReadStream &stream) { +bool INIFile::loadFromStream(SeekableReadStream &stream) { Section section; KeyValue kv; String comment; @@ -112,9 +112,9 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) { p++; if (*p == '\0') - error("ConfigFile::loadFromStream: missing ] in line %d", lineno); + error("INIFile::loadFromStream: missing ] in line %d", lineno); else if (*p != ']') - error("ConfigFile::loadFromStream: Invalid character '%c' occurred in section name in line %d", *p, lineno); + error("INIFile::loadFromStream: Invalid character '%c' occurred in section name in line %d", *p, lineno); // Previous section is finished now, store it. if (!section.name.empty()) @@ -140,7 +140,7 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) { // If no section has been set, this config file is invalid! if (section.name.empty()) { - error("ConfigFile::loadFromStream: Key/value pair found outside a section in line %d", lineno); + error("INIFile::loadFromStream: Key/value pair found outside a section in line %d", lineno); } // Split string at '=' into 'key' and 'value'. First, find the "=" delimeter. @@ -173,7 +173,7 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) { return (!stream.err() || stream.eos()); } -bool ConfigFile::saveToFile(const String &filename) { +bool INIFile::saveToFile(const String &filename) { DumpFile file; if (file.open(filename)) return saveToStream(file); @@ -181,7 +181,7 @@ bool ConfigFile::saveToFile(const String &filename) { return false; } -bool ConfigFile::saveToSaveFile(const char *filename) { +bool INIFile::saveToSaveFile(const char *filename) { assert(g_system); SaveFileManager *saveFileMan = g_system->getSavefileManager(); WriteStream *saveFile; @@ -195,7 +195,7 @@ bool ConfigFile::saveToSaveFile(const char *filename) { return status; } -bool ConfigFile::saveToStream(WriteStream &stream) { +bool INIFile::saveToStream(WriteStream &stream) { for (List<Section>::iterator i = _sections.begin(); i != _sections.end(); ++i) { // Write out the section comment, if any if (! i->comment.empty()) { @@ -226,7 +226,7 @@ bool ConfigFile::saveToStream(WriteStream &stream) { return !stream.err(); } -void ConfigFile::addSection(const String §ion) { +void INIFile::addSection(const String §ion) { Section *s = getSection(section); if (s) return; @@ -236,7 +236,7 @@ void ConfigFile::addSection(const String §ion) { _sections.push_back(newSection); } -void ConfigFile::removeSection(const String §ion) { +void INIFile::removeSection(const String §ion) { assert(isValidName(section)); for (List<Section>::iterator i = _sections.begin(); i != _sections.end(); ++i) { if (section.equalsIgnoreCase(i->name)) { @@ -246,13 +246,13 @@ void ConfigFile::removeSection(const String §ion) { } } -bool ConfigFile::hasSection(const String §ion) const { +bool INIFile::hasSection(const String §ion) const { assert(isValidName(section)); const Section *s = getSection(section); return s != 0; } -void ConfigFile::renameSection(const String &oldName, const String &newName) { +void INIFile::renameSection(const String &oldName, const String &newName) { assert(isValidName(oldName)); assert(isValidName(newName)); @@ -262,7 +262,7 @@ void ConfigFile::renameSection(const String &oldName, const String &newName) { // HACK: For now we just print a warning, for more info see the TODO // below. if (ns) - warning("ConfigFile::renameSection: Section name \"%s\" already used", newName.c_str()); + warning("INIFile::renameSection: Section name \"%s\" already used", newName.c_str()); else os->name = newName; } @@ -274,7 +274,7 @@ void ConfigFile::renameSection(const String &oldName, const String &newName) { } -bool ConfigFile::hasKey(const String &key, const String §ion) const { +bool INIFile::hasKey(const String &key, const String §ion) const { assert(isValidName(key)); assert(isValidName(section)); @@ -284,7 +284,7 @@ bool ConfigFile::hasKey(const String &key, const String §ion) const { return s->hasKey(key); } -void ConfigFile::removeKey(const String &key, const String §ion) { +void INIFile::removeKey(const String &key, const String §ion) { assert(isValidName(key)); assert(isValidName(section)); @@ -293,7 +293,7 @@ void ConfigFile::removeKey(const String &key, const String §ion) { s->removeKey(key); } -bool ConfigFile::getKey(const String &key, const String §ion, String &value) const { +bool INIFile::getKey(const String &key, const String §ion, String &value) const { assert(isValidName(key)); assert(isValidName(section)); @@ -307,7 +307,7 @@ bool ConfigFile::getKey(const String &key, const String §ion, String &value) return true; } -void ConfigFile::setKey(const String &key, const String §ion, const String &value) { +void INIFile::setKey(const String &key, const String §ion, const String &value) { assert(isValidName(key)); assert(isValidName(section)); // TODO: Verify that value is valid, too. In particular, it shouldn't @@ -329,13 +329,13 @@ void ConfigFile::setKey(const String &key, const String §ion, const String & } } -const ConfigFile::SectionKeyList ConfigFile::getKeys(const String §ion) const { +const INIFile::SectionKeyList INIFile::getKeys(const String §ion) const { const Section *s = getSection(section); return s->getKeys(); } -ConfigFile::Section *ConfigFile::getSection(const String §ion) { +INIFile::Section *INIFile::getSection(const String §ion) { for (List<Section>::iterator i = _sections.begin(); i != _sections.end(); ++i) { if (section.equalsIgnoreCase(i->name)) { return &(*i); @@ -344,7 +344,7 @@ ConfigFile::Section *ConfigFile::getSection(const String §ion) { return 0; } -const ConfigFile::Section *ConfigFile::getSection(const String §ion) const { +const INIFile::Section *INIFile::getSection(const String §ion) const { for (List<Section>::const_iterator i = _sections.begin(); i != _sections.end(); ++i) { if (section.equalsIgnoreCase(i->name)) { return &(*i); @@ -353,11 +353,11 @@ const ConfigFile::Section *ConfigFile::getSection(const String §ion) const { return 0; } -bool ConfigFile::Section::hasKey(const String &key) const { +bool INIFile::Section::hasKey(const String &key) const { return getKey(key) != 0; } -const ConfigFile::KeyValue* ConfigFile::Section::getKey(const String &key) const { +const INIFile::KeyValue* INIFile::Section::getKey(const String &key) const { for (List<KeyValue>::const_iterator i = keys.begin(); i != keys.end(); ++i) { if (key.equalsIgnoreCase(i->key)) { return &(*i); @@ -366,7 +366,7 @@ const ConfigFile::KeyValue* ConfigFile::Section::getKey(const String &key) const return 0; } -void ConfigFile::Section::setKey(const String &key, const String &value) { +void INIFile::Section::setKey(const String &key, const String &value) { for (List<KeyValue>::iterator i = keys.begin(); i != keys.end(); ++i) { if (key.equalsIgnoreCase(i->key)) { i->value = value; @@ -380,7 +380,7 @@ void ConfigFile::Section::setKey(const String &key, const String &value) { keys.push_back(newKV); } -void ConfigFile::Section::removeKey(const String &key) { +void INIFile::Section::removeKey(const String &key) { for (List<KeyValue>::iterator i = keys.begin(); i != keys.end(); ++i) { if (key.equalsIgnoreCase(i->key)) { keys.erase(i); diff --git a/common/config-file.h b/common/ini-file.h index 8bba851110..1d94ce7bdc 100644 --- a/common/config-file.h +++ b/common/ini-file.h @@ -20,8 +20,8 @@ * */ -#ifndef COMMON_CONFIG_FILE_H -#define COMMON_CONFIG_FILE_H +#ifndef COMMON_INI_FILE_H +#define COMMON_INI_FILE_H #include "common/hash-str.h" #include "common/list.h" @@ -34,9 +34,6 @@ class WriteStream; /** * This class allows reading/writing INI style config files. - * It is used by the ConfigManager for storage, but can also - * be used by other code if it needs to read/write custom INI - * files. * * Lines starting with a '#' are ignored (i.e. treated as comments). * Some effort is made to preserve comments, though. @@ -47,10 +44,8 @@ class WriteStream; * from/to files, but of course is not appropriate for fast access. * The main reason is that this class is indeed geared toward doing precisely * that! - * If you need fast access to the game config, use higher level APIs, like the - * one provided by ConfigManager. */ -class ConfigFile { +class INIFile { public: struct KeyValue { String key; @@ -60,12 +55,12 @@ public: typedef List<KeyValue> SectionKeyList; - /** A section in a config file. I.e. corresponds to something like this: + /** A section in a ini file. I.e. corresponds to something like this: * [mySection] * key=value * * Comments are also stored, to keep users happy who like editing their - * config files manually. + * ini files manually. */ struct Section { String name; @@ -82,8 +77,8 @@ public: typedef List<Section> SectionList; public: - ConfigFile(); - ~ConfigFile(); + INIFile(); + ~INIFile(); // TODO: Maybe add a copy constructor etc.? @@ -95,7 +90,7 @@ public: */ static bool isValidName(const String &name); - /** Reset everything stored in this config file. */ + /** Reset everything stored in this ini file. */ void clear(); bool loadFromFile(const String &filename); @@ -127,14 +122,6 @@ private: const Section *getSection(const String §ion) const; }; -/* -- ConfigMan owns a config file -- allow direct access to that config file (for the launcher) -- simplify and unify the regular ConfigMan API in exchange - - -*/ - } // End of namespace Common #endif diff --git a/common/math.h b/common/math.h index b85ec0d22a..ba137101e4 100644 --- a/common/math.h +++ b/common/math.h @@ -52,14 +52,6 @@ #endif #endif -#ifndef M_SQRT1_2 - #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ -#endif - -#ifndef M_PI - #define M_PI 3.14159265358979323846 -#endif - #ifndef FLT_MIN #define FLT_MIN 1E-37 #endif diff --git a/common/module.mk b/common/module.mk index 9f9126c8ef..1b34d151d0 100644 --- a/common/module.mk +++ b/common/module.mk @@ -2,7 +2,6 @@ MODULE := common MODULE_OBJS := \ archive.o \ - config-file.o \ config-manager.o \ coroutines.o \ dcl.o \ @@ -15,6 +14,7 @@ MODULE_OBJS := \ gui_options.o \ hashmap.o \ iff_container.o \ + ini-file.o \ installshield_cab.o \ language.o \ localization.o \ diff --git a/common/scummsys.h b/common/scummsys.h index 291de87dc9..3e9d5ef063 100644 --- a/common/scummsys.h +++ b/common/scummsys.h @@ -144,6 +144,63 @@ #endif #endif +// The following math constants are usually defined by the system math.h header, but +// they are not part of the ANSI C++ standards and so can NOT be relied upon to be +// present i.e. when -std=c++11 is passed to GCC, enabling strict ANSI compliance. +// As we rely on these being present, we define them if they are not set. + +#ifndef M_E + #define M_E 2.7182818284590452354 /* e */ +#endif + +#ifndef M_LOG2E + #define M_LOG2E 1.4426950408889634074 /* log_2 e */ +#endif + +#ifndef M_LOG10E + #define M_LOG10E 0.43429448190325182765 /* log_10 e */ +#endif + +#ifndef M_LN2 + #define M_LN2 0.69314718055994530942 /* log_e 2 */ +#endif + +#ifndef M_LN10 + #define M_LN10 2.30258509299404568402 /* log_e 10 */ +#endif + +#ifndef M_PI + #define M_PI 3.14159265358979323846 /* pi */ +#endif + +#ifndef M_PI_2 + #define M_PI_2 1.57079632679489661923 /* pi/2 */ +#endif + +#ifndef M_PI_4 + #define M_PI_4 0.78539816339744830962 /* pi/4 */ +#endif + +#ifndef M_1_PI + #define M_1_PI 0.31830988618379067154 /* 1/pi */ +#endif + +#ifndef M_2_PI + #define M_2_PI 0.63661977236758134308 /* 2/pi */ +#endif + +#ifndef M_2_SQRTPI + #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ +#endif + +#ifndef M_SQRT2 + #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ +#endif + +#ifndef M_SQRT1_2 + #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ +#endif + // Include our C++11 compatability header for pre-C++11 compilers. #if __cplusplus < 201103L #include "common/c++11-compat.h" diff --git a/common/util.h b/common/util.h index 4ca1c42929..392ced1ffe 100644 --- a/common/util.h +++ b/common/util.h @@ -41,10 +41,10 @@ #undef MAX #endif -template<typename T> inline T ABS (T x) { return (x>=0) ? x : -x; } -template<typename T> inline T MIN (T a, T b) { return (a<b) ? a : b; } -template<typename T> inline T MAX (T a, T b) { return (a>b) ? a : b; } -template<typename T> inline T CLIP (T v, T amin, T amax) +template<typename T> inline T ABS(T x) { return (x >= 0) ? x : -x; } +template<typename T> inline T MIN(T a, T b) { return (a < b) ? a : b; } +template<typename T> inline T MAX(T a, T b) { return (a > b) ? a : b; } +template<typename T> inline T CLIP(T v, T amin, T amax) { if (v < amin) return amin; else if (v > amax) return amax; else return v; } /** |