reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

commit a0b7c1ea0b81ffefdf8f45e297abd0a44ee0366e
parent 3f8b0c2f4b3e80b48bf2ba38859eb5a1f687be7e
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Sun, 17 Apr 2016 01:04:31 -0400

use unsigned 32-bit values to store numeric configuration values

there is no need for an extra 0-filled 32-bit padding

Diffstat:
Msrc/config.cpp | 22+++++++++++-----------
Msrc/config.hpp | 18+++++++++---------
2 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/src/config.cpp b/src/config.cpp @@ -40,7 +40,7 @@ static const char *SIZE_KEY = "size"; static const char *REMOTES_GRP = "remotes"; static const char *REMOTE_KEY = "remote"; -static string ArrayKey(const string &key, const size_t i) +static string ArrayKey(const string &key, const unsigned int i) { return key + to_string(i); } @@ -55,7 +55,7 @@ Config::Config() void Config::migrate() { - const size_t version = getUInt(GLOBAL_GRP, VERSION_KEY); + const unsigned int version = getUInt(GLOBAL_GRP, VERSION_KEY); switch(version) { case 0: @@ -73,6 +73,7 @@ void Config::migrate() break; default: // configuration is up-to-date, don't write anything now + // keep the version intact in case it comes from a newer version of ReaPack m_version = version; return; }; @@ -124,7 +125,7 @@ void Config::readRemotes() { m_remotesIniSize = getUInt(REMOTES_GRP, SIZE_KEY); - for(size_t i = 0; i < m_remotesIniSize; i++) { + for(unsigned int i = 0; i < m_remotesIniSize; i++) { const string data = getString(REMOTES_GRP, ArrayKey(REMOTE_KEY, i)); m_remotes.add(Remote::fromString(data)); @@ -133,8 +134,8 @@ void Config::readRemotes() void Config::writeRemotes() { - size_t i = 0; - m_remotesIniSize = max(m_remotes.size(), m_remotesIniSize); + unsigned int i = 0; + m_remotesIniSize = max((unsigned int)m_remotes.size(), m_remotesIniSize); for(auto it = m_remotes.begin(); it != m_remotes.end(); it++, i++) { setString(REMOTES_GRP, ArrayKey(REMOTE_KEY, i), it->toString()); @@ -160,13 +161,12 @@ void Config::setString(const char *group, WritePrivateProfileString(group, key.c_str(), val.c_str(), m_path.c_str()); } -size_t Config::getUInt(const char *group, const string &key) const +unsigned int Config::getUInt(const char *group, const string &key) const { - const int i = GetPrivateProfileInt(group, key.c_str(), 0, m_path.c_str()); - return max(0, i); + return GetPrivateProfileInt(group, key.c_str(), 0, m_path.c_str()); } -void Config::setUInt(const char *grp, const string &key, const size_t val) const +void Config::setUInt(const char *grp, const string &key, const unsigned int val) const { setString(grp, key, to_string(val)); } @@ -177,8 +177,8 @@ void Config::deleteKey(const char *group, const string &key) const } void Config::cleanupArray(const char *group, const string &key, - const size_t begin, const size_t end) const + const unsigned int begin, const unsigned int end) const { - for(size_t i = begin; i < end; i++) + for(unsigned int i = begin; i < end; i++) deleteKey(group, ArrayKey(key, i)); } diff --git a/src/config.hpp b/src/config.hpp @@ -24,12 +24,12 @@ class Path; +struct BrowserConfig { + unsigned int typeFilter; +}; + class Config { public: - struct BrowserConfig { - size_t typeFilter; - }; - Config(); void read(const Path &); @@ -44,17 +44,17 @@ public: private: std::string getString(const char *, const std::string &) const; void setString(const char *, const std::string &, const std::string &) const; - size_t getUInt(const char *, const std::string &) const; - void setUInt(const char *, const std::string &, size_t) const; + unsigned int getUInt(const char *, const std::string &) const; + void setUInt(const char *, const std::string &, unsigned int) const; void deleteKey(const char *, const std::string &) const; void cleanupArray(const char *, const std::string &, - size_t begin, size_t end) const; + unsigned int begin, unsigned int end) const; void migrate(); std::string m_path; bool m_isFirstRun; - size_t m_version; + unsigned int m_version; bool m_autoInstall; BrowserConfig m_browser; @@ -62,7 +62,7 @@ private: void restoreSelfRemote(); void writeRemotes(); RemoteList m_remotes; - size_t m_remotesIniSize; + unsigned int m_remotesIniSize; }; #endif