00001 00011 #ifndef CONNECTIONDECISIONPREDICATESPECIALIZATION_H 00012 #define CONNECTIONDECISIONPREDICATESPECIALIZATION_H 00013 00014 #include "ConnectionDecisionPredicate.h" 00015 #include "PCSIMException.h" 00016 #include <typeinfo> 00017 using std::type_info; 00018 00019 #include <boost/format.hpp> 00020 #include <string> 00021 using std::string; 00022 00024 00027 template< typename S, typename D > 00028 class ConnectionDecisionPredicateSpecialization : public ConnectionDecisionPredicate { 00029 00030 public: 00031 00033 00037 virtual void init( SimObjectPopulation const& src, SimObjectPopulation const& dst, RandomEngine *rnd) { 00038 m_sourcePopulation = dynamic_cast< const S* >( &src ); 00039 if( m_sourcePopulation == NULL ) { 00040 throw( PCSIM::ConstructionException( boost::str( boost::format("ConnectionDecisionPredicateSpecialization<%1%>::init") % typeid(S).name() ), 00041 boost::str( boost::format("Source population must be a %1% or derived type (not %2%).") % typeid(S).name() % typeid(src).name() ) ) ); 00042 } 00043 m_destinationPopulation = dynamic_cast< const D* >( &dst ); 00044 if( m_destinationPopulation == NULL ) { 00045 throw( PCSIM::ConstructionException( boost::str( boost::format("ConnectionDecisionPredicateSpecialization<%1%>::init") % typeid(D).name() ), 00046 boost::str( boost::format("Destination population must be a %1% or derived type (not %2%).")% typeid(D).name() % typeid(dst).name() ) ) ); 00047 } 00048 }; 00049 00051 virtual bool decide( size_t src, size_t dst, RandomEngine *rnd ) { return false; }; 00052 00053 protected: 00054 const S* m_sourcePopulation; 00055 const D* m_destinationPopulation; 00056 }; 00057 00059 class PlainConnectionDecisionPredicate : public ConnectionDecisionPredicateSpecialization<SimObjectPopulation,SimObjectPopulation> { 00060 }; 00061 00062 #include "SpatialSimObjectPopulation.h" 00063 00065 class SpatialConnectionDecisionPredicate : public ConnectionDecisionPredicateSpecialization<SpatialSimObjectPopulation,SpatialSimObjectPopulation> { 00066 }; 00067 00068 #include "SpatialFamilyPopulation.h" 00069 00071 class FamilyIdConnectionDecisionPredicate : public ConnectionDecisionPredicateSpecialization<SpatialFamilyPopulation,SpatialFamilyPopulation> { 00072 }; 00073 00074 #include "AugmentedSpatialPopulation.h" 00075 00077 class AugmentedConnectionDecisionPredicate : 00078 public ConnectionDecisionPredicateSpecialization<AugmentedSpatialPopulation, AugmentedSpatialPopulation> { 00079 }; 00080 00081 #endif