ConnObjectFactory.cpp

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

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