diff options
Diffstat (limited to 'src/modules/UserListManager/Util.cpp')
-rw-r--r-- | src/modules/UserListManager/Util.cpp | 113 |
1 files changed, 0 insertions, 113 deletions
diff --git a/src/modules/UserListManager/Util.cpp b/src/modules/UserListManager/Util.cpp deleted file mode 100644 index 9b986d8..0000000 --- a/src/modules/UserListManager/Util.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* - * 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 "UserListDiff.h" - -#include <Common/XmlData.h> - -namespace Mad { -namespace Modules { -namespace UserListManager { - -void Util::serializeUserListEntry(const UserListEntry *user, Common::XmlData::List::iterator entry) { - 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()); -} - -UserListEntry Util::deserializeUserListEntry(Common::XmlData::List::const_iterator entry) { - UserListEntry user(entry->get<const std::string&>("name"), entry->get<const std::string&>("group")); - - std::set<std::string> details = entry->getChildren(); - for(std::set<std::string>::iterator detail = details.begin(); detail != details.end(); ++detail) { - if(*detail == "user" || *detail == "group") - continue; - - user.setDetail(*detail, entry->get<const std::string&>(*detail)); - } - - return user; -} - -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) - serializeUserListEntry(&*user, userList->addEntry()); -} - -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) - users->push_back(deserializeUserListEntry(user)); - } - - return users; -} - -void Util::serializeUserListDiff(const UserListDiff *diff, Common::XmlData *data) { - Common::XmlData::List *userList = data->createList("addedUsers"); - for(std::set<UserListEntry>::const_iterator user = diff->getAddedUsers().begin(); user != diff->getAddedUsers().end(); ++user) - serializeUserListEntry(&*user, userList->addEntry()); - - userList = data->createList("deletedUsers"); - for(std::set<UserListEntry>::const_iterator user = diff->getDeletedUsers().begin(); user != diff->getDeletedUsers().end(); ++user) - serializeUserListEntry(&*user, userList->addEntry()); - - userList = data->createList("unchangedUsers"); - for(std::set<UserListEntry>::const_iterator user = diff->getUnchangedUsers().begin(); user != diff->getUnchangedUsers().end(); ++user) - serializeUserListEntry(&*user, userList->addEntry()); -} - -boost::shared_ptr<UserListDiff> Util::deserializeUserListDiff(const Common::XmlData *data) { - boost::shared_ptr<UserListDiff> diff(new UserListDiff); - - const Common::XmlData::List *userList = data->getList("addedUsers"); - if(userList) { - for(Common::XmlData::List::const_iterator user = userList->begin(); user != userList->end(); ++user) - diff->insertAddedUser(deserializeUserListEntry(user)); - } - - userList = data->getList("deletedUsers"); - if(userList) { - for(Common::XmlData::List::const_iterator user = userList->begin(); user != userList->end(); ++user) - diff->insertDeletedUser(deserializeUserListEntry(user)); - } - - userList = data->getList("unchangedUsers"); - if(userList) { - for(Common::XmlData::List::const_iterator user = userList->begin(); user != userList->end(); ++user) - diff->insertUnchangedUser(deserializeUserListEntry(user)); - } - - return diff; -} - -} -} -} |