diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-03-02 20:43:10 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-03-18 19:58:55 +0100 |
commit | bce577e663e28e1942fda371235eba091a6ea8e2 (patch) | |
tree | a54ce0b47eae92b760ddd763036ff3609d1415ef | |
parent | 20afba1adc84dd0e859605250c5a44a111045c2b (diff) | |
download | mana-bce577e663e28e1942fda371235eba091a6ea8e2.tar.gz mana-bce577e663e28e1942fda371235eba091a6ea8e2.tar.bz2 mana-bce577e663e28e1942fda371235eba091a6ea8e2.tar.xz mana-bce577e663e28e1942fda371235eba091a6ea8e2.zip |
Removed some 'const' keywords from value returns
It makes no sense to mark a return value as const when it is returned by
value. This only makes sense if the return value is passed by reference, in
order to prevent the receiver from modifying the value.
Also made some other small adjustments. A std::string does not need to be
initialized to "" explicitly and getSafeUtf8String could take its parameter by
reference.
Reviewed-by: Yohann Ferreira
-rw-r--r-- | src/gui/equipmentwindow.cpp | 2 | ||||
-rw-r--r-- | src/gui/equipmentwindow.h | 2 | ||||
-rw-r--r-- | src/gui/truetypefont.cpp | 4 | ||||
-rw-r--r-- | src/map.cpp | 6 | ||||
-rw-r--r-- | src/map.h | 6 | ||||
-rw-r--r-- | src/properties.h | 4 | ||||
-rw-r--r-- | src/resources/beinginfo.cpp | 2 | ||||
-rw-r--r-- | src/resources/iteminfo.cpp | 2 | ||||
-rw-r--r-- | src/resources/userpalette.cpp | 2 | ||||
-rw-r--r-- | src/utils/stringutils.cpp | 8 | ||||
-rw-r--r-- | src/utils/stringutils.h | 6 |
11 files changed, 22 insertions, 22 deletions
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 4aa76c2f..85a4c766 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -197,7 +197,7 @@ Item *EquipmentWindow::getItem(int x, int y) const return 0; } -const std::string EquipmentWindow::getSlotName(int x, int y) const +std::string EquipmentWindow::getSlotName(int x, int y) const { for (int i = 0; i < mBoxesNumber; ++i) { diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h index 0f1d19fa..29814dc5 100644 --- a/src/gui/equipmentwindow.h +++ b/src/gui/equipmentwindow.h @@ -93,7 +93,7 @@ class EquipmentWindow : public Window, public gcn::ActionListener void mouseMoved(gcn::MouseEvent &event); Item *getItem(int x, int y) const; - const std::string getSlotName(int x, int y) const; + std::string getSlotName(int x, int y) const; void setSelected(int index); diff --git a/src/gui/truetypefont.cpp b/src/gui/truetypefont.cpp index 5f85ea68..620ba191 100644 --- a/src/gui/truetypefont.cpp +++ b/src/gui/truetypefont.cpp @@ -57,7 +57,7 @@ class TextChunk sdlCol.r = color.r; sdlCol.g = color.g; - const char* str = getSafeUtf8String(text); + const char *str = getSafeUtf8String(text); SDL_Surface *surface = TTF_RenderUTF8_Blended( font, str, sdlCol); delete[] str; @@ -179,7 +179,7 @@ int TrueTypeFont::getWidth(const std::string &text) const } int w, h; - const char* str = getSafeUtf8String(text); + const char *str = getSafeUtf8String(text); TTF_SizeUTF8(mFont, str, &w, &h); delete[] str; return w; diff --git a/src/map.cpp b/src/map.cpp index 8c748bbc..fa3d9a4c 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -644,12 +644,12 @@ void Map::removeActor(Actors::iterator iterator) mActors.erase(iterator); } -const std::string Map::getMusicFile() const +std::string Map::getMusicFile() const { return getProperty("music"); } -const std::string Map::getName() const +std::string Map::getName() const { if (hasProperty("name")) return getProperty("name"); @@ -657,7 +657,7 @@ const std::string Map::getName() const return getProperty("mapname"); } -const std::string Map::getFilename() const +std::string Map::getFilename() const { std::string fileName = getProperty("_filename"); int lastSlash = fileName.rfind("/") + 1; @@ -275,13 +275,13 @@ class Map : public Properties */ Vector getTileCenter(int x, int y); - const std::string getMusicFile() const; - const std::string getName() const; + std::string getMusicFile() const; + std::string getName() const; /** * Gives the map id based on filepath (ex: 009-1) */ - const std::string getFilename() const; + std::string getFilename() const; /** * Check the current position against surrounding blocking tiles, and diff --git a/src/properties.h b/src/properties.h index b6ef5d80..59318b80 100644 --- a/src/properties.h +++ b/src/properties.h @@ -42,8 +42,8 @@ class Properties * @return the value of the given property or the given default when it * doesn't exist. */ - const std::string getProperty(const std::string &name, - const std::string &def = "") const + std::string getProperty(const std::string &name, + const std::string &def = "") const { PropertyMap::const_iterator i = mProperties.find(name); return (i != mProperties.end()) ? i->second : def; diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp index 8683e7bc..5a277770 100644 --- a/src/resources/beinginfo.cpp +++ b/src/resources/beinginfo.cpp @@ -84,7 +84,7 @@ void BeingInfo::addSound(SoundEvent event, const std::string &filename) const std::string &BeingInfo::getSound(SoundEvent event) const { - static std::string empty(""); + static const std::string empty; SoundEvents::const_iterator i = mSounds.find(event); return (i == mSounds.end()) ? empty : diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp index 22be274a..3583bb27 100644 --- a/src/resources/iteminfo.cpp +++ b/src/resources/iteminfo.cpp @@ -33,7 +33,7 @@ const std::string &ItemInfo::getSprite(Gender gender) const } else { - static const std::string empty = ""; + static const std::string empty; std::map<int, std::string>::const_iterator i = mAnimationFiles.find(gender); diff --git a/src/resources/userpalette.cpp b/src/resources/userpalette.cpp index 12ea3f8d..073f5b03 100644 --- a/src/resources/userpalette.cpp +++ b/src/resources/userpalette.cpp @@ -32,7 +32,7 @@ #include <math.h> -const std::string ColorTypeNames[] = { +static const std::string ColorTypeNames[] = { "ColorBeing", "ColorPlayer", "ColorSelf", diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 5a51ef66..4f27d41b 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -157,8 +157,8 @@ bool isWordSeparator(char chr) return (chr == ' ' || chr == ',' || chr == '.' || chr == '"'); } -const std::string findSameSubstring(const std::string &str1, - const std::string &str2) +std::string findSameSubstring(const std::string &str1, + const std::string &str2) { int minLength = str1.length() > str2.length() ? str2.length() : str1.length(); for (int f = 0; f < minLength; f ++) @@ -171,9 +171,9 @@ const std::string findSameSubstring(const std::string &str1, return str1.substr(0, minLength); } -const char* getSafeUtf8String(std::string text) +const char *getSafeUtf8String(const std::string &text) { - char* buf = new char[text.size() + UTF8_MAX_SIZE]; + char *buf = new char[text.size() + UTF8_MAX_SIZE]; memcpy(buf, text.c_str(), text.size()); memset(buf + text.size(), 0, UTF8_MAX_SIZE); return buf; diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 74365491..b83bc580 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -125,10 +125,10 @@ int compareStrI(const std::string &a, const std::string &b); */ bool isWordSeparator(char chr); -const std::string findSameSubstring(const std::string &str1, - const std::string &str2); +std::string findSameSubstring(const std::string &str1, + const std::string &str2); -const char* getSafeUtf8String(std::string text); +const char *getSafeUtf8String(const std::string &text); /** * Returns a bool value depending on the given string value. |