PopObjectFactory.cpp

Go to the documentation of this file.
00001 
00012 #include "PopObjectFactory.h"
00013 
00014 #include <iostream>
00015 using std::cout;
00016 using std::cerr;
00017 using std::endl;
00018 
00019 PopObjectFactory::PopObjectFactory(SimObjectVariationFactory const& model)
00020     : SimObjectVariationFactory(model)
00021 {
00022         
00023 }
00024 
00025 
00026 PopObjectFactory::PopObjectFactory(SimObjectFactory const& model)
00027     : SimObjectVariationFactory(model)
00028 {
00029 
00030 }
00031 
00032 
00033 PopObjectFactory::~PopObjectFactory()
00034 {
00035     for(value_generators_t::const_iterator f = m_value_generators.begin(); f != m_value_generators.end(); ++f)
00036     {
00037         delete f->second->gen;
00038         delete f->second;
00039     }
00040 }
00041 
00042 
00043 void PopObjectFactory::set(string const& fieldname, RandomDistribution const& rd )
00044 {
00045     SimObjectVariationFactory::set(fieldname, rd);
00046 }
00047 
00048 
00049 void PopObjectFactory::set(string const& fieldname, PopObjectValueGenerator const& rd )
00050 {
00051 //    cout << "PopObjectFactory::set("<< fieldname << ")" << endl;
00052 
00053     Field const* f = m_base->findField( fieldname );
00054 
00055     if (m_value_generators.find( fieldname ) != m_value_generators.end() )
00056     {
00057         delete m_value_generators[fieldname]->gen;
00058         delete m_value_generators[fieldname];
00059     }
00060 
00061     PopObjectValueGenerator *pGen = rd.clone();
00062 //    if (pGen == NULL)
00063 //        pGen=&rd;
00064 
00065     m_value_generators[fieldname] = new FieldGeneratorPair(f, pGen);    
00066 }
00067 
00068 
00069 void PopObjectFactory::announce(SimObjectPopulation &pop, size_t idx)
00070 {
00071 //    cout << "PopObjectFactory::announce("<< idx << ")" << endl;
00072 
00073     value_generators_t::const_iterator f;
00074     value_generators_t::const_iterator f_end = m_value_generators.end();
00075 
00076     for(f = m_value_generators.begin(); f != f_end; ++f) {
00077         (*(f->second->gen)).prepare(pop, idx, rnd_eng);
00078     }
00079 }
00080 
00081 
00082 SimObject* PopObjectFactory::create(RandomEngine *eng) const
00083 {
00084     SimObject* obj = SimObjectVariationFactory::create(eng);
00085 //    cout << "PopObjectFactory::create() done" << endl;
00086 
00087     value_generators_t::const_iterator f;
00088     value_generators_t::const_iterator f_end = m_value_generators.end();
00089 
00090     for( f = m_value_generators.begin(); f != f_end; ++f ) {
00091         obj->setScalarField(f->second->field, (*(f->second->gen)).generate(eng));
00092 //        cout << "obj->setScalarField() done" << endl;
00093     }
00094 
00095     return obj;
00096 }
00097 
00098 
00099 
00100 SimObject* PopObjectFactory::create(void) const
00101 {
00102     return PopObjectFactory::create(rnd_eng);
00103 }
00104 
00105 
00106 
00107 

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