diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-05-11 19:39:54 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-05-11 19:39:54 +0300 |
commit | 7b6ae053d36c94d6601276b0c2c8f4b4afaf6422 (patch) | |
tree | 8bcee7e7d47d386bb0c8093dd859bf93445cc090 | |
parent | 87c59212f8590a8dd72fac3e320fcb2ada781355 (diff) | |
download | mv-7b6ae053d36c94d6601276b0c2c8f4b4afaf6422.tar.gz mv-7b6ae053d36c94d6601276b0c2c8f4b4afaf6422.tar.bz2 mv-7b6ae053d36c94d6601276b0c2c8f4b4afaf6422.tar.xz mv-7b6ae053d36c94d6601276b0c2c8f4b4afaf6422.zip |
Add anonimous namespace in playerrelations.
-rw-r--r-- | src/being/playerrelations.cpp | 124 |
1 files changed, 64 insertions, 60 deletions
diff --git a/src/being/playerrelations.cpp b/src/being/playerrelations.cpp index 41d14c2ea..238f96642 100644 --- a/src/being/playerrelations.cpp +++ b/src/being/playerrelations.cpp @@ -36,82 +36,86 @@ #include "debug.h" -static const char *const PLAYER_IGNORE_STRATEGY_NOP = "nop"; -static const char *const PLAYER_IGNORE_STRATEGY_EMOTE0 = "emote0"; -static const char *const DEFAULT_IGNORE_STRATEGY - = PLAYER_IGNORE_STRATEGY_EMOTE0; - -static const char *const NAME = "name"; -static const char *const RELATION = "relation"; - -static const unsigned int IGNORE_EMOTE_TIME = 100; - typedef std::map<std::string, PlayerRelation *> PlayerRelations; typedef PlayerRelations::const_iterator PlayerRelationsCIter; typedef std::list<PlayerRelationsListener *> PlayerRelationListeners; typedef PlayerRelationListeners::const_iterator PlayerRelationListenersCIter; -class SortPlayersFunctor final +namespace { - public: - bool operator() (const std::string &str1, - const std::string &str2) const - { - std::string s1 = str1; - std::string s2 = str2; - toLower(s1); - toLower(s2); - if (s1 == s2) - return str1 < str2; - return s1 < s2; - } -} playersRelSorter; + static const char *const PLAYER_IGNORE_STRATEGY_NOP = "nop"; + static const char *const PLAYER_IGNORE_STRATEGY_EMOTE0 = "emote0"; + static const char *const DEFAULT_IGNORE_STRATEGY + = PLAYER_IGNORE_STRATEGY_EMOTE0; -// (De)serialisation class -class PlayerConfSerialiser final : - public ConfigurationListManager<std::pair<std::string, PlayerRelation *>, - std::map<std::string, PlayerRelation *> *> -{ -public: - ConfigurationObject *writeConfigItem( - const std::pair<std::string, PlayerRelation *> &value, - ConfigurationObject *const cobj) const override final - { - if (!cobj || !value.second) - return nullptr; - cobj->setValue(NAME, value.first); - cobj->setValue(RELATION, toString( - static_cast<int>(value.second->mRelation))); + static const char *const NAME = "name"; + static const char *const RELATION = "relation"; - return cobj; - } + static const unsigned int IGNORE_EMOTE_TIME = 100; - std::map<std::string, PlayerRelation *> * - readConfigItem(const ConfigurationObject *const cobj, - std::map<std::string, PlayerRelation *> - *const container) const override final + class SortPlayersFunctor final { - if (!cobj) - return container; - const std::string name = cobj->getValue(NAME, ""); - if (name.empty()) - return container; + public: + bool operator() (const std::string &str1, + const std::string &str2) const + { + std::string s1 = str1; + std::string s2 = str2; + toLower(s1); + toLower(s2); + if (s1 == s2) + return str1 < str2; + return s1 < s2; + } + } playersRelSorter; + + // (De)serialisation class + class PlayerConfSerialiser final : + public ConfigurationListManager<std::pair<std::string, + PlayerRelation *>, std::map<std::string, PlayerRelation *> *> + { + public: + ConfigurationObject *writeConfigItem( + const std::pair<std::string, PlayerRelation *> &value, + ConfigurationObject *const cobj) const override final + { + if (!cobj || !value.second) + return nullptr; + cobj->setValue(NAME, value.first); + cobj->setValue(RELATION, toString( + static_cast<int>(value.second->mRelation))); - if (!(*container)[name]) + return cobj; + } + + std::map<std::string, PlayerRelation *> * + readConfigItem(const ConfigurationObject *const cobj, + std::map<std::string, PlayerRelation *> + *const container) const override final { - const int v = cobj->getValueInt(RELATION, - static_cast<int>(PlayerRelation::NEUTRAL)); + if (!cobj) + return container; + const std::string name = cobj->getValue(NAME, ""); + if (name.empty()) + return container; + + if (!(*container)[name]) + { + const int v = cobj->getValueInt(RELATION, + static_cast<int>(PlayerRelation::NEUTRAL)); + + (*container)[name] = new PlayerRelation( + static_cast<PlayerRelation::Relation>(v)); + } + // otherwise ignore the duplicate entry - (*container)[name] = new PlayerRelation( - static_cast<PlayerRelation::Relation>(v)); + return container; } - // otherwise ignore the duplicate entry + }; - return container; - } -}; + static PlayerConfSerialiser player_conf_serialiser; // stateless singleton -static PlayerConfSerialiser player_conf_serialiser; // stateless singleton +} // namespace const unsigned int PlayerRelation::RELATION_PERMISSIONS[RELATIONS_NR] = { |