00001 /***************************** License ********************************** 00002 00003 Copyright (C) 2008 by Communicative Machines 00004 http://www.cmlabs.com All rights reserved. 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Lesser General Public 00008 License as published by the Free Software Foundation; either 00009 version 2.1 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public 00017 License along with this library; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 00020 ************************************************************************/ 00021 00022 00023 #include "thirdparty/GroupDatabase.h" 00024 00025 namespace cmlabs { 00026 00027 GroupDatabase::GroupDatabase() { 00028 } 00029 00030 GroupDatabase::GroupDatabase(JString xml) { 00031 if (!Object::fromXML(xml)) { 00032 } 00033 } 00034 00035 GroupDatabase::GroupDatabase(XMLNode* node) { 00036 if (!fromXML(node)) { 00037 } 00038 } 00039 00040 GroupDatabase::~GroupDatabase() {} 00041 00042 Object* GroupDatabase::clone() const { 00043 GroupDatabase* fv = new GroupDatabase(); 00044 *fv = *this; 00045 return fv; 00046 } 00047 00048 JString GroupDatabase::print() { 00049 JString str = JString::format("List of %d groups:\n", list.getCount()); 00050 00051 Group* group; 00052 for (int n=0; n<list.getCount(); n++) { 00053 group = (Group*) list.get(n); 00054 if (group != NULL) { 00055 str += JString::format(" %3d: %s\n", n, (char*) group->print()); 00056 } 00057 } 00058 return str; 00059 } 00060 00061 JString GroupDatabase::toXML() { 00062 return JString::format("<GroupDatabase>\n%s</GroupDatabase>", (char*) list.toXML().indentXML()); 00063 } 00064 00065 bool GroupDatabase::fromXML(XMLNode* node) { 00066 if (node == NULL) { 00067 return false; 00068 } 00069 if (!node->getTag().equalsIgnoreCase("GroupDatabase")) 00070 return false; 00071 00072 XMLNode* xmlNode = node->getChildNode("collection"); 00073 if (xmlNode == NULL) 00074 return false; 00075 if (!list.fromXML(xmlNode)) 00076 return false; 00077 00078 return true; 00079 } 00080 00081 bool GroupDatabase::addGroup(Group* group) { 00082 return list.add(group); 00083 } 00084 00085 bool GroupDatabase::removeGroup(Group* group) { 00086 return removeGroup(list.getPos(group)); 00087 } 00088 00089 bool GroupDatabase::removeGroup(int pos) { 00090 return list.remove(pos); 00091 } 00092 00093 bool GroupDatabase::replaceGroup(Group* oldGroup, Group* newGroup) { 00094 return list.replace(list.getPos(oldGroup), newGroup); 00095 } 00096 00097 bool GroupDatabase::replaceGroup(int pos, Group* group) { 00098 return list.replace(pos, group); 00099 } 00100 00101 Group* GroupDatabase::getGroup(int pos) { 00102 return (Group*) list.get(pos); 00103 } 00104 00105 Group* GroupDatabase::operator[](int pos) { 00106 return (Group*) list.get(pos); 00107 } 00108 00109 } // namespace cmlabs 00110