From 2ba5228d0483798a9e122670d15a078c4478898f Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 15 Sep 2009 16:11:54 +0200 Subject: Added UserListManager module --- src/modules/UserListManager/Util.cpp | 70 ++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/modules/UserListManager/Util.cpp (limited to 'src/modules/UserListManager/Util.cpp') 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 + * + * 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 . + */ + +#include "Util.h" +#include "UserList.h" + +#include + +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 details = user->getDetailList(); + for(std::set::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 Util::deserializeUserList(const Common::XmlData *data) { + boost::shared_ptr 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("name"), user->get("group")); + + std::set details = user->getChildren(); + for(std::set::iterator detail = details.begin(); detail != details.end(); ++detail) { + if(*detail == "user" || *detail == "group") + continue; + + entry.setDetail(*detail, user->get(*detail)); + } + + users->push_back(entry); + } + } + + return users; +} + +} +} +} -- cgit v1.2.3