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 // PathWay.cpp: implementation of the PathWay class. 00022 // 00023 ////////////////////////////////////////////////////////////////////// 00024 00025 #include "PathWay.h" 00026 00027 namespace cmlabs { 00028 00029 ////////////////////////////////////////////////////////////////////// 00030 // Construction/Destruction 00031 ////////////////////////////////////////////////////////////////////// 00032 00033 PathWay::PathWay() 00034 { 00035 00036 } 00037 00038 PathWay::PathWay(JString xml) 00039 { 00040 entries = ObjectCollection(xml); 00041 } 00042 00043 PathWay::~PathWay() 00044 { 00045 00046 } 00047 00048 Object* PathWay::clone() const { 00049 PathWay* pw = new PathWay(); 00050 *pw = *this; 00051 return (Object*) pw; 00052 } 00053 00054 JString PathWay::toXML() { 00055 return entries.toXML(); 00056 } 00057 00058 bool PathWay::add(Dictionary entry) { 00059 if (entry.get("name").length() == 0) 00060 return false; 00061 00062 Dictionary* d = new Dictionary(entry); 00063 00064 return entries.add(d); 00065 } 00066 00067 Dictionary PathWay::get(int n) { 00068 Dictionary dict; 00069 Dictionary* d = (Dictionary*) entries.get(n); 00070 if (d == NULL) 00071 dict = Dictionary(); 00072 else 00073 dict = *d; 00074 00075 return dict; 00076 } 00077 00078 JString PathWay::getName(int n) { 00079 Dictionary* d = (Dictionary*) entries.get(n); 00080 if (d == NULL) 00081 return ""; 00082 else 00083 return d->get("name"); 00084 } 00085 00086 int PathWay::getNextFreePos() { 00087 Dictionary* d; 00088 00089 for (int n=0; n<getCount(); n++) { 00090 d = (Dictionary*) entries.get(n); 00091 if (d != NULL) { 00092 if (!d->get("isDone").equalsIgnoreCase("yes")) { 00093 return n; 00094 } 00095 } 00096 00097 } 00098 return -1; 00099 } 00100 00101 int PathWay::getCount() { 00102 return entries.getCount(); 00103 } 00104 00105 00106 00107 } // namespace cmlabs