/* * 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; } } } }