OneToOneWiringMethod.cpp

Go to the documentation of this file.
00001 
00011 #include "OneToOneWiringMethod.h"
00012 
00013 #include "SimNetwork.h"
00014 
00015 #include <utility>
00016 
00017 using std::make_pair;
00018 #include <iostream>
00019 using std::cerr;
00020 using std::endl;
00021 
00022 SimObject::ID::Vector OneToOneWiringMethod::connect(const SimObjectPopulation &srcPopulation, const SimObjectPopulation &destPopulation,
00023                                                     const SimObjectFactory &connector, ConnectionIterator &, bool collectIDs, bool collectPairs,
00024                                                     WiringMethod::ConnectPairsVector connectPairs)
00025 {
00026     if (srcPopulation.size() != destPopulation.size())
00027         throw PCSIM::ConstructionException("OneToOneWiringMethod::connect", "Cannot connect populations with different size with one-to-one method" );
00028     unsigned cnt = 0;
00029     SimObject::ID id;
00030     SimObject::ID::Vector collids(new vector<SimObject::ID::Packed>);
00031     for (unsigned i = 0; i < srcPopulation.size(); ++i) {
00032         net->connect(srcPopulation(i), destPopulation(i), connector, id);
00033         if (collectPairs)
00034             connectPairs->push_back(make_pair(srcPopulation(i), destPopulation(i) ) );
00035         if (collectIDs)
00036             collids->push_back(id.packed() );
00037     }
00038     if ( !collectIDs) // store number of created objects
00039         collids->push_back( (SimObject::ID::Packed)cnt );
00040     return collids;
00041 }
00042 
00043 SimObject::ID::Vector OneToOneWiringMethod::connect(const SimObjectPopulation &srcPopulation, const SimObjectPopulation &destPopulation,
00044                                                     ConnObjectFactory &connector, ConnectionIterator &, bool collectIDs, bool collectPairs,
00045                                                     WiringMethod::ConnectPairsVector connectPairs)
00046 {
00047     if (srcPopulation.size() != destPopulation.size())
00048         throw PCSIM::ConstructionException("OneToOneWiringMethod::connect", "Cannot connect populations with different size with one-to-one method" );
00049     unsigned cnt = 0;
00050     SimObject::ID id;
00051     SimObject::ID::Vector collids(new vector<SimObject::ID::Packed>);
00052     for (unsigned i = 0; i < srcPopulation.size(); ++i) {
00053         connector.init(srcPopulation, (size_t)i, destPopulation, (size_t)i);
00054         net->connect(srcPopulation(i), destPopulation(i), connector, id);
00055 
00056         if (collectPairs)
00057             connectPairs->push_back(make_pair(srcPopulation(i), destPopulation(i) ) );
00058         if (collectIDs)
00059             collids->push_back(id.packed() );
00060     }
00061     if ( !collectIDs) // store number of created objects
00062         collids->push_back( (SimObject::ID::Packed)cnt );
00063     return collids;
00064 }
00065 
00066 unsigned OneToOneWiringMethod::connect(const SimObjectPopulation &srcPopulation, const SimObjectPopulation &destPopulation, ConnectionIterator &,
00067                                        bool collectPairs, WiringMethod::ConnectPairsVector connectPairs)
00068 {
00069     if (srcPopulation.size() != destPopulation.size())
00070         throw PCSIM::ConstructionException("OneToOneWiringMethod::connect", "Cannot connect populations with different size with one-to-one method" );
00071     
00072    // cerr << "OneToOneWiringMethod::connect( srcpop, dstpop, decider, collectQ, pairs );" << endl;
00073 
00074     unsigned cnt = 0;
00075     for (unsigned i = 0; i < srcPopulation.size(); ++i) {
00076         net->connect(srcPopulation[i], destPopulation[i]);
00077         if (collectPairs) {
00078             connectPairs->push_back(make_pair(srcPopulation(i), destPopulation(i)));
00079         }
00080         cnt++;
00081     }
00082     return cnt;
00083 }
00084 
00085 unsigned OneToOneWiringMethod::connect(const SimObjectPopulation &srcPopulation, const SimObjectPopulation &destPopulation, const Time &delay,
00086                                        bool collectPairs, WiringMethod::ConnectPairsVector connectPairs)
00087 {
00088     if (srcPopulation.size() != destPopulation.size())
00089         throw PCSIM::ConstructionException("OneToOneWiringMethod::connect", "Cannot connect populations with different size with one-to-one method" );
00090 
00091     //cerr << "OneToOneWiringMethod::connect( srcpop, dstpop, delay, collectQ, pairs );" << endl;
00092     
00093     unsigned cnt = 0;
00094     for (unsigned i = 0; i < srcPopulation.size(); ++i) {
00095         net->connect( srcPopulation[i], destPopulation[i], delay );
00096         if (collectPairs) {
00097             connectPairs->push_back( make_pair(srcPopulation(i), destPopulation(i) ) );
00098             //cerr << "from " << srcPopulation[i] << " to " << destPopulation[i] << endl;
00099         }
00100         cnt++;
00101     }
00102     return cnt;
00103 }
00104 

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