Update of /cvsroot/robotflow/RobotFlow/MARIE/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31995
Modified Files:
extractMarieCommandBehavior.cpp
Log Message:
Output composite instead of vectors
Index: extractMarieCommandBehavior.cpp
===================================================================
RCS file: /cvsroot/robotflow/RobotFlow/MARIE/src/extractMarieCommandBehavior.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** extractMarieCommandBehavior.cpp 31 Jan 2005 20:48:33 -0000 1.3
--- extractMarieCommandBehavior.cpp 6 Feb 2005 14:51:23 -0000 1.4
***************
*** 27,30 ****
--- 27,32 ----
#include "Vector.h"
#include "MarieDataNull.h"
+ #include "CompositeType.h"
+ #include <map>
using namespace std;
***************
*** 46,56 ****
* @input_description The MarieCommandBehavior object
*
! * @output_name RF_ACTIVATION_VECTOR
! * @output_description RobotFlow activation vector
! * @output_type Vector<int>
*
! * @output_name PARAMS_VECTOR
! * @output_description Parameters (String format) vector
! * @output_type Vector<String>
*
END*/
--- 48,58 ----
* @input_description The MarieCommandBehavior object
*
! * @output_name ACTIVATIONS
! * @output_description Composite <behavior name, activation>
! * @output_type COMPOSITE
*
! * @output_name PARAMS
! * @output_description Composite <behavior name, parameters> (parameters in string format seperated by space)
! * @output_type COMPOSITE
*
END*/
***************
*** 82,89 ****
//outputs
! m_activationID = addOutput("RF_ACTIVATION_VECTOR");
//outputs
! m_parametersID = addOutput("PARAMS_VECTOR");
}
--- 84,91 ----
//outputs
! m_activationID = addOutput("ACTIVATIONS");
//outputs
! m_parametersID = addOutput("PARAMS");
}
***************
*** 94,128 ****
RCPtr<MarieCommandBehavior> command = getInput(m_behaviorCommandID,count);
! //create behavior activation vector (RobotFlow)
! Vector<int> *vectActivations = Vector<int>::alloc(Behavior::get_behavior_size());
! //create behavior activation vector (RobotFlow)
! Vector<String> *vectParams = Vector<String>::alloc(Behavior::get_behavior_size());
! //get known behavior names
! vector<string>& behaviorNames = Behavior::get_behaviors();
!
! const std::map<std::string, bool> &activationMap = command->getActivationMap();
! const std::map<std::string, std::string> ¶metersMap = command->getParametersMap();
!
! //copy activation values if they exists, else set activation to false (0)
! for (int i = 0; i < vectActivations->size(); i++)
! {
! //check if behavior exists
! if (activationMap.find(behaviorNames[i]) != activationMap.end())
! {
! (*vectActivations)[i] = (int) command->getActivation(behaviorNames[i]);
! }
! else
! {
! //default, not activated
! (*vectActivations)[i] = 0;
! }
!
! (*vectParams)[i] = command->getParameters(behaviorNames[i]);
! }
! //output result
! (*outputs[m_activationID].buffer)[count] = ObjectRef(vectActivations);
! (*outputs[m_parametersID].buffer)[count] = ObjectRef(vectParams);
--- 96,138 ----
RCPtr<MarieCommandBehavior> command = getInput(m_behaviorCommandID,count);
! CompositeType* activationsComposite = new CompositeType();
! CompositeType* paramsComposite = new CompositeType();
! std::map<std::string, bool>::const_iterator iterActivations = command->getActivationMap().begin();
!
! std::map<std::string, string>::const_iterator iterParameters = command->getParametersMap().begin();
!
! for( ; iterActivations != command->getActivationMap().end(); iterActivations++)
! {
! stringstream key((*iterActivations).first);
! activationsComposite->addField(key.str(), ObjectRef(Bool::alloc((*iterActivations).second)));
! }
!
! for( ; iterParameters != command->getParametersMap().end(); iterParameters++)
! {
! stringstream key((*iterParameters).first);
! stringstream value((*iterParameters).second);
! try
! {
! //try to read FlowDesigner object
! ObjectRef ObjectValue;
!
! value >> ObjectValue;
!
! paramsComposite->addField(key.str(), ObjectValue);
! }
! catch(...)
! {
! //unable to read FlowDesigner Object
! //output standard string
! ObjectRef ObjectValue(new String(value.str()));
! paramsComposite->addField(key.str(),ObjectValue);
! }
! }
!
! //output result
! (*outputs[m_activationID].buffer)[count] = ObjectRef(activationsComposite);
! (*outputs[m_parametersID].buffer)[count] = ObjectRef(paramsComposite);
|