summaryrefslogtreecommitdiff
path: root/src/resources/db
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-07-18 01:10:03 +0300
committerAndrei Karas <akaras@inbox.ru>2017-07-18 01:10:03 +0300
commit615ce0dd3026d27b0ce88731529a0e58001288c4 (patch)
tree16ef2ce0dc5f580f44bdd301070960644498c885 /src/resources/db
parentddd49c13d9b89e11c900657154e0504c8c8af2a9 (diff)
downloadplus-615ce0dd3026d27b0ce88731529a0e58001288c4.tar.gz
plus-615ce0dd3026d27b0ce88731529a0e58001288c4.tar.bz2
plus-615ce0dd3026d27b0ce88731529a0e58001288c4.tar.xz
plus-615ce0dd3026d27b0ce88731529a0e58001288c4.zip
In groupdb store pointers to groups.
Diffstat (limited to 'src/resources/db')
-rw-r--r--src/resources/db/groupdb.cpp34
-rw-r--r--src/resources/db/groupdb.h3
2 files changed, 28 insertions, 9 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();