From: Dominic L. <ma...@us...> - 2004-09-22 13:56:02
|
Update of /cvsroot/robotflow/RobotFlow/MARIE/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7120/src Modified Files: Makefile.am Added Files: MarieDataMap.cpp Log Message: Reading MarieDataMap Index: Makefile.am =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/MARIE/src/Makefile.am,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Makefile.am 2 Sep 2004 18:18:12 -0000 1.13 --- Makefile.am 22 Sep 2004 13:55:53 -0000 1.14 *************** *** 21,28 **** MarieCommandCamera.cpp \ MarieCommandMotor.cpp \ ! MarieDataRaw.cpp \ ! MarieCommandJoystick.cpp \ ! MarieDataIR.cpp \ ! MarieDataBumper.cpp install-data-local: --- 21,29 ---- MarieCommandCamera.cpp \ MarieCommandMotor.cpp \ ! MarieDataRaw.cpp \ ! MarieCommandJoystick.cpp \ ! MarieDataIR.cpp \ ! MarieDataBumper.cpp \ ! MarieDataMap.cpp install-data-local: --- NEW FILE: MarieDataMap.cpp --- /* * MARIE - Mobile and Autonomous Robotics Integration Environment * Copyright (C) 2004 Dominic Letourneau * * This library 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 2.1 of the License, or (at your option) any later version. * * This library 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 library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * You can contact MARIE development team at http://marie.sourceforge.net */ #include "MarieDataMap.h" #include <sstream> #include <string> #include "CompositeType.h" #include "MarieXMLDataFactory.h" namespace marie { DECLARE_NODE(MarieDataMap) /*Node * * @name MarieDataMap * @category RobotFlow:MARIE:DATA * @description Read MARIE data maps * * @input_name DATA_MAP * @input_type MarieDataMap * @input_description MarieDataMap Object * * @output_name COMPOSITE * @output_description FlowDesigner CompositeType object (equivalent to DataMap) * @output_type CompositeType * END*/ DECLARE_TYPE2(DataMap::ID,MarieDataMap) using namespace std; MarieDataMap::MarieDataMap() : MarieObject("MarieDataMap",ParameterSet()), m_isNode(false) { } MarieDataMap::MarieDataMap (const DataMap &data) : MarieObject("MarieDataMap",ParameterSet()), DataMap(data), m_isNode(false) { } MarieDataMap::MarieDataMap(string nodeName, ParameterSet params) : MarieObject(nodeName,params), m_isNode(true) { //used as a BufferedNode, create inputs & outputs //inputs m_inputID = addInput("DATA_MAP"); //outputs m_outputID = addOutput("COMPOSITE"); } void MarieDataMap::calculate(int output_id, int count, Buffer &out) { ObjectRef InputValue = getInput(m_inputID,count); if (m_isNode && !InputValue->isNil()) { RCPtr<MarieDataMap> dataMapObject = InputValue; const std::map<std::string, std::string> my_map = dataMapObject->getValues(); CompositeType *cType = new CompositeType(); for (map<string,string>::const_iterator iter = my_map.begin(); iter != my_map.end(); iter++) { stringstream key((*iter).first); stringstream value((*iter).second); try { //try to read FlowDesigner object ObjectRef ObjectValue; value >> ObjectValue; cType->addField(key.str(), ObjectValue); } catch(...) { //unable to read FlowDesigner Object //output standard string ObjectRef ObjectValue(new String(value.str())); cType->addField(key.str(),ObjectValue); } } //output Composite type out[count] = ObjectRef(cType); } else { out[count] = nilObject; } } void MarieDataMap::printOn(ostream &out) const { MarieXMLDataFactory factory; //writing XML data string value = factory.toString((DataMap&) (*this)); out.write(value.c_str(), value.size()); } void MarieDataMap::readFrom(istream &in) { throw new GeneralException("readFrom not supported. Use the MarieLoad Node to read data from the stream.",__FILE__,__LINE__); } void MarieDataMap::copyDataAbstract(DataAbstract *data) { if (data) { DataMap *my_data = dynamic_cast<DataMap*>(data); if (my_data) { this->DataMap::operator=(*my_data); } else { throw new GeneralException(string("Unable to cast into DataMap Abstract : ") + data->getID(),__FILE__,__LINE__); } } } } |