ConnObjectValueGenerator.h

Go to the documentation of this file.
00001 
00012 #ifndef CONNOBJECTVALUEGENERATOR_H_
00013 #define CONNOBJECTVALUEGENERATOR_H_
00014 
00015 #include "SimObjectPopulation.h"
00016 #include "RandomDistribution.h"
00017 
00019 class ConnObjectValueGenerator
00020 {
00021 public:
00022     ConnObjectValueGenerator();
00023 
00024     virtual ~ConnObjectValueGenerator();
00025 
00027 
00031     virtual void init(const SimObjectPopulation &src_pop,
00032                       const SimObjectPopulation &dst_pop,
00033                       RandomEngine *rnd=NULL) = 0;
00034 
00036 
00042     virtual double generate(size_t src_idx, size_t dst_idx, RandomEngine *rnd) = 0;
00043 
00044     virtual ConnObjectValueGenerator* clone(void) const = 0;
00045 
00046 };
00047 
00049 
00055 /*
00056 class PyConnObjectValueGenerator
00057 {
00058 public:
00059     PyConnObjectValueGenerator();
00060 
00061     virtual ~PyConnObjectValueGenerator();
00062 
00063     virtual void init( SimObjectPopulation &src_pop, SimObjectPopulation &dst_pop, RandomEngine *rnd=NULL )
00064     {
00065         //NOOP
00066     };
00067 
00068     virtual double generate( size_t src_idx, size_t dst_idx, RandomEngine *rnd )
00069     {
00070         return 0.0;
00071     };
00072 };
00073 */
00075 template< typename S, typename D >
00076 class ConnObjectValueGeneratorSpecialization : public ConnObjectValueGenerator
00077 {
00078 public:
00079     ConnObjectValueGeneratorSpecialization()
00080         : m_sourcePopulation(NULL), m_destinationPopulation(NULL), rnd_eng(NULL)
00081     {}
00082 
00084 
00088     virtual void init( SimObjectPopulation const& src, SimObjectPopulation const& dst, RandomEngine *rnd=NULL )
00089     {
00090         m_sourcePopulation = dynamic_cast< const S* >( &src );
00091         if( m_sourcePopulation == NULL ) {
00092             throw( PCSIM::ConstructionException( boost::str( boost::format("ConnObjectValueGeneratorSpecialization<%1%>::init") % typeid(S).name() ),
00093                                                  boost::str( boost::format("Source population must be a %1% or derived type (not %2%).") % typeid(S).name() % typeid(src).name() ) ) );
00094         }
00095         m_destinationPopulation = dynamic_cast< const D* >( &dst );
00096         if( m_destinationPopulation == NULL ) {
00097             throw( PCSIM::ConstructionException( boost::str( boost::format("ConnObjectValueGeneratorSpecialization<%1%>::init") % typeid(D).name()  ),
00098                                                  boost::str( boost::format("Destination population must be a %1% or derived type (not %2%).")% typeid(D).name() % typeid(dst).name() ) ) );
00099         }
00100 
00101         rnd_eng=rnd;
00102     };
00103 
00105     virtual double generate( size_t src_idx, size_t dst_idx, RandomEngine *rnd )
00106     {
00107         return 0.0;
00108     };
00109 
00110 protected:
00111     const S* m_sourcePopulation;
00112     const D* m_destinationPopulation;
00113     RandomEngine *rnd_eng;
00114 };
00115 
00117 class PlainConnObjectValueGenerator
00118     : public ConnObjectValueGeneratorSpecialization<SimObjectPopulation, SimObjectPopulation>
00119 {
00120 };
00121 
00122 #include "SpatialSimObjectPopulation.h"
00123 
00125 class SpatialConnObjectValueGenerator
00126     : public ConnObjectValueGeneratorSpecialization<SpatialSimObjectPopulation, SpatialSimObjectPopulation>
00127 {
00128 };
00129 
00130 #include "SpatialFamilyPopulation.h"
00131 
00133 class FamilyConnObjectValueGenerator
00134     : public ConnObjectValueGeneratorSpecialization<SpatialFamilyPopulation, SpatialFamilyPopulation>
00135 {
00136 };
00137 
00138 #include "AugmentedSpatialPopulation.h"
00139 
00141 class AttributeConnObjectValueGenerator 
00142     : public ConnObjectValueGeneratorSpecialization<AugmentedSpatialPopulation, AugmentedSpatialPopulation>
00143 {
00144 };
00145 
00146 #endif /*CONNOBJECTVALUEGENERATOR_H_*/

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