MTIncomingAnalogMessageDispatcher.cpp

Go to the documentation of this file.
00001 #include "MTIncomingAnalogMessageDispatcher.h"
00002 
00003 using std::make_pair;
00004 
00005 MTIncomingAnalogMessageDispatcher::MTIncomingAnalogMessageDispatcher()
00006 {
00007     initialized = false;
00008     port_sources_positions = new sources_positions_type;
00009     field_sources_positions = new sources_positions_type;
00010 }
00011 
00012 MTIncomingAnalogMessageDispatcher::~MTIncomingAnalogMessageDispatcher()
00013 {
00014     if (!initialized) {
00015         delete port_sources_positions;
00016         delete field_sources_positions;
00017     }
00018 }
00019 
00020 
00021 void MTIncomingAnalogMessageDispatcher::addAnalogMessage(AnalogDelayObject *src, analog_port_id_t src_port, SimObject *dest, analog_port_id_t dest_port)
00022 {
00023     sources_positions_type::const_iterator pos_it;
00024     pair< AnalogDelayObject *, analog_port_id_t> src_pair(src, src_port);
00025     int position;
00026     if ((pos_it = port_sources_positions->find(src_pair)) != port_sources_positions->end() ) {
00027         position = pos_it->second;
00028     } else {
00029         position = port_msg_sources.size();
00030         port_sources_positions->insert(make_pair(src_pair, position));
00031         port_msg_destinations.push_back(vector< pair<SimObject *,analog_port_id_t> >());
00032         port_msg_sources.push_back(src_pair);
00033     }
00034     port_msg_destinations[position].push_back(make_pair(dest,dest_port));
00035 }
00036 
00037 
00038 void MTIncomingAnalogMessageDispatcher::addAnalogMessage(AnalogDelayObject *src, analog_port_id_t src_port, SimObject *dest, string destfield)
00039 {
00040         const Field * dest_field = dest->findField(destfield);
00041     sources_positions_type::const_iterator pos_it;
00042     pair< AnalogDelayObject *, analog_port_id_t> src_pair(src, src_port);
00043     int position;
00044     if ((pos_it = field_sources_positions->find(src_pair)) != field_sources_positions->end() ) {
00045         position = pos_it->second;
00046     } else {
00047         position = field_msg_sources.size();
00048         field_sources_positions->insert(make_pair(src_pair, position));
00049         field_msg_destinations.push_back(vector< pair< void *, Field::ValueType > >());
00050         field_msg_sources.push_back(src_pair);
00051     }
00052     field_msg_destinations[position].push_back(make_pair(dest_field->getPtr(dest),dest_field->getType()));
00053 }
00054 
00055 void MTIncomingAnalogMessageDispatcher::dispatchIncomingAnalogMsgs(int step)
00056 {
00057     // dispatch port messages
00058     msg_sources_type::const_iterator port_src_it;
00059     port_msg_destinations_type::const_iterator port_dest_it = port_msg_destinations.begin();
00060     for (port_src_it = port_msg_sources.begin() ; port_src_it != port_msg_sources.end() ; ++port_src_it, ++port_dest_it) {
00061         vector< pair<SimObject *, analog_port_id_t > >::const_iterator port_dest_it_2;
00062         for (port_dest_it_2 = port_dest_it->begin(); port_dest_it_2 != port_dest_it->end() ; ++port_dest_it_2) {
00063 //              cerr << " new cycled dispatch value = " << port_src_it->first->getCycledAnalogOutput(port_src_it->second - step) << endl;
00064                     port_dest_it_2->first->setAnalogInput(
00065                         port_src_it->first->getCycledAnalogOutput(port_src_it->second - step), port_dest_it_2->second);
00066         }
00067     }
00068 
00069     //  dispatch field messages
00070     msg_sources_type::const_iterator field_src_it;
00071     field_msg_destinations_type::iterator field_dest_it = field_msg_destinations.begin();
00072     for (field_src_it = field_msg_sources.begin(); field_src_it != field_msg_sources.end(); ++field_src_it, ++field_dest_it) {
00073         vector< pair< void *, Field::ValueType > >::iterator field_dest_it_2;
00074         for (field_dest_it_2 = field_dest_it->begin() ; field_dest_it_2 != field_dest_it->end(); ++field_dest_it_2)
00075             Field::setValue(field_dest_it_2->first, field_dest_it_2->second, field_src_it->first->getCycledAnalogOutput(field_src_it->second - step) );
00076     }
00077 }
00078 
00079 
00080 void MTIncomingAnalogMessageDispatcher::initialize()
00081 {
00082     if (!initialized) {
00083         initialized = true;
00084         delete port_sources_positions;
00085         delete field_sources_positions;
00086     }
00087 }

Generated on Wed Jul 9 16:34:38 2008 for PCSIM by  doxygen 1.5.5