diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-07-18 01:10:03 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-07-18 01:10:03 +0300 |
commit | 615ce0dd3026d27b0ce88731529a0e58001288c4 (patch) | |
tree | 16ef2ce0dc5f580f44bdd301070960644498c885 /src/resources | |
parent | ddd49c13d9b89e11c900657154e0504c8c8af2a9 (diff) | |
download | manaverse-615ce0dd3026d27b0ce88731529a0e58001288c4.tar.gz manaverse-615ce0dd3026d27b0ce88731529a0e58001288c4.tar.bz2 manaverse-615ce0dd3026d27b0ce88731529a0e58001288c4.tar.xz manaverse-615ce0dd3026d27b0ce88731529a0e58001288c4.zip |
In groupdb store pointers to groups.
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/db/groupdb.cpp | 34 | ||||
-rw-r--r-- | src/resources/db/groupdb.h | 3 | ||||
-rw-r--r-- | src/resources/groupinfo.h | 2 |
3 files changed, 29 insertions, 10 deletions
diff --git a/src/resources/db/groupdb.cpp b/src/resources/db/groupdb.cpp index bd78e117c..00b5c890e 100644 --- a/src/resources/db/groupdb.cpp +++ b/src/resources/db/groupdb.cpp @@ -90,16 +90,29 @@ void GroupDb::loadXmlFile(const std::string &fileName, reportAlways("Empty id field in GroupDb"); continue; } - mGroups[id].name = XML::langProperty(node, + GroupInfosIter it = mGroups.find(id); + GroupInfo *group = nullptr; + if (it != mGroups.end()) + { + reportAlways("GroupDb: group with id %d already added", + id); + group = (*it).second; + } + else + { + group = new GroupInfo; + mGroups[id] = group; + } + group->name = XML::langProperty(node, "name", ""); - mGroups[id].longName = XML::langProperty(node, + group->longName = XML::langProperty(node, "longName", ""); - mGroups[id].badge = XML::langProperty(node, + group->badge = XML::langProperty(node, "badge", paths.getStringValue("gmbadge")); - mGroups[id].showBadge = XML::getBoolProperty(node, + group->showBadge = XML::getBoolProperty(node, "showBadge", false); } @@ -109,6 +122,11 @@ void GroupDb::loadXmlFile(const std::string &fileName, void GroupDb::unload() { mGroups.clear(); + FOR_EACH (GroupInfosIter, it, mGroups) + { + delete (*it).second; + } + mGroups.clear(); mLoaded = false; } @@ -120,7 +138,7 @@ const std::string &GroupDb::getName(const int id) reportAlways("Unknown group id requested: %d", id); return mEmptyGroup.name; } - return (*it).second.name; + return (*it).second->name; } const std::string &GroupDb::getLongName(const int id) @@ -131,7 +149,7 @@ const std::string &GroupDb::getLongName(const int id) reportAlways("Unknown group id requested: %d", id); return mEmptyGroup.longName; } - return (*it).second.longName; + return (*it).second->longName; } bool GroupDb::getShowBadge(const int id) @@ -142,7 +160,7 @@ bool GroupDb::getShowBadge(const int id) reportAlways("Unknown group id requested: %d", id); return mEmptyGroup.showBadge; } - return (*it).second.showBadge; + return (*it).second->showBadge; } const std::string &GroupDb::getBadge(const int id) @@ -153,7 +171,7 @@ const std::string &GroupDb::getBadge(const int id) reportAlways("Unknown group id requested: %d", id); return mEmptyGroup.badge; } - return (*it).second.badge; + return (*it).second->badge; } #ifdef UNITTESTS diff --git a/src/resources/db/groupdb.h b/src/resources/db/groupdb.h index 3db3b1921..0115880bc 100644 --- a/src/resources/db/groupdb.h +++ b/src/resources/db/groupdb.h @@ -43,7 +43,8 @@ namespace GroupDb bool getShowBadge(const int id) A_WARN_UNUSED; const std::string &getBadge(const int id) A_WARN_UNUSED; - typedef std::map<int, GroupInfo> GroupInfos; + typedef std::map<int, GroupInfo*> GroupInfos; + typedef GroupInfos::iterator GroupInfosIter; #ifdef UNITTESTS GroupDb::GroupInfos &getGroups(); diff --git a/src/resources/groupinfo.h b/src/resources/groupinfo.h index 924c71b2d..b2cbf5854 100644 --- a/src/resources/groupinfo.h +++ b/src/resources/groupinfo.h @@ -37,7 +37,7 @@ struct GroupInfo final { GroupInfo(); - A_DEFAULT_COPY(GroupInfo) + A_DELETE_COPY(GroupInfo) ServerCommandEnable::Type mCommands[CAST_SIZE(ServerCommandType::Max)]; Enable mPermissions[CAST_SIZE(ServerPermissionType::Max)]; |