diff options
Diffstat (limited to 'src/modules/UserListManager/Util.cpp')
-rw-r--r-- | src/modules/UserListManager/Util.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/modules/UserListManager/Util.cpp b/src/modules/UserListManager/Util.cpp new file mode 100644 index 0000000..f9b6a55 --- /dev/null +++ b/src/modules/UserListManager/Util.cpp @@ -0,0 +1,70 @@ +/* + * Util.cpp + * + * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de> + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "Util.h" +#include "UserList.h" + +#include <Common/XmlData.h> + +namespace Mad { +namespace Modules { +namespace UserListManager { + +void Util::serializeUserList(const UserList *list, Common::XmlData *data) { + Common::XmlData::List *userList = data->createList("users"); + + for(UserList::const_iterator user = list->begin(); user != list->end(); ++user) { + Common::XmlData::List::iterator entry = userList->addEntry(); + + std::set<std::string> details = user->getDetailList(); + for(std::set<std::string>::iterator detail = details.begin(); detail != details.end(); ++detail) + entry->set(*detail, user->getDetail(*detail)); + + entry->set("name", user->getName()); + entry->set("group", user->getGroup()); + } +} + +boost::shared_ptr<UserList> Util::deserializeUserList(const Common::XmlData *data) { + boost::shared_ptr<UserList> users(new UserList); + + const Common::XmlData::List *userList = data->getList("users"); + + if(userList) { + for(Common::XmlData::List::const_iterator user = userList->begin(); user != userList->end(); ++user) { + UserListEntry entry(user->get<const std::string&>("name"), user->get<const std::string&>("group")); + + std::set<std::string> details = user->getChildren(); + for(std::set<std::string>::iterator detail = details.begin(); detail != details.end(); ++detail) { + if(*detail == "user" || *detail == "group") + continue; + + entry.setDetail(*detail, user->get<const std::string&>(*detail)); + } + + users->push_back(entry); + } + } + + return users; +} + +} +} +} |