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/FeatureVectorList.h" 00024 00025 namespace cmlabs { 00026 00027 FeatureVectorList::FeatureVectorList() { 00028 } 00029 00030 FeatureVectorList::FeatureVectorList(JString xml) { 00031 if (!Object::fromXML(xml)) { 00032 } 00033 } 00034 00035 FeatureVectorList::FeatureVectorList(XMLNode* node) { 00036 if (!fromXML(node)) { 00037 } 00038 } 00039 00040 FeatureVectorList::~FeatureVectorList() {} 00041 00042 Object* FeatureVectorList::clone() const { 00043 FeatureVectorList* fv = new FeatureVectorList(); 00044 *fv = *this; 00045 return fv; 00046 } 00047 00048 JString FeatureVectorList::print() { 00049 JString str = JString::format("List of %d FeatureVectors:\n", list.getCount()); 00050 00051 FeatureVector* vector; 00052 for (int n=0; n<list.getCount(); n++) { 00053 vector = (FeatureVector*) list.get(n); 00054 if (vector != NULL) { 00055 str += JString::format(" %3d: %s\n", n, (char*) vector->print()); 00056 } 00057 } 00058 return str; 00059 } 00060 00061 JString FeatureVectorList::toXML() { 00062 return JString::format("<featurevectorlist>\n%s</featurevectorlist>", (char*) list.toXML().indentXML()); 00063 } 00064 00065 bool FeatureVectorList::fromXML(XMLNode* node) { 00066 if (node == NULL) { 00067 return false; 00068 } 00069 if (!node->getTag().equalsIgnoreCase("featurevectorlist")) 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 FeatureVectorList::addVector(FeatureVector* vector) { 00082 return list.add(vector); 00083 } 00084 00085 bool FeatureVectorList::removeVector(FeatureVector* vector) { 00086 return removeVector(list.getPos(vector)); 00087 } 00088 00089 bool FeatureVectorList::removeVector(int pos) { 00090 return list.remove(pos); 00091 } 00092 00093 bool FeatureVectorList::replaceVector(FeatureVector* oldvector, FeatureVector* newvector) { 00094 return list.replace(list.getPos(oldvector), newvector); 00095 } 00096 00097 bool FeatureVectorList::replaceVector(int pos, FeatureVector* vector) { 00098 return list.replace(pos, vector); 00099 } 00100 00101 FeatureVector* FeatureVectorList::getVector(int pos) { 00102 return (FeatureVector*) list.get(pos); 00103 } 00104 00105 FeatureVector* FeatureVectorList::operator[](int pos) { 00106 return (FeatureVector*) list.get(pos); 00107 } 00108 00109 } // namespace cmlabs