SimObjectVariationFactory.cpp

Go to the documentation of this file.
00001 
00011 #include "SimObjectVariationFactory.h"
00012 #include "SimObject.h"
00013 
00014 #include "ThreadSpecificRandomDistribution.h"
00015 
00016 /*
00017 #include <iostream>
00018 using std::cerr;
00019 using std::endl;
00020 
00021 #include <typeinfo>
00022 */
00023 
00028 SimObjectVariationFactory::SimObjectVariationFactory( SimObjectFactory const& sof )
00029 {
00030     m_base = sof.create();
00031     theThreadSpecificRandomEngine.init();
00032     rnd_eng =theThreadSpecificRandomEngine.get();
00033 }
00034 
00035 SimObjectVariationFactory::SimObjectVariationFactory( SimObjectVariationFactory const& sovf )
00036 {
00037     m_base = sovf.m_base->create();
00038     theThreadSpecificRandomEngine.init();
00039     rnd_eng = theThreadSpecificRandomEngine.get();
00040     
00041     // TODO copy the m_var_fields!!!!
00042     for( var_fields_t::const_iterator f = sovf.m_var_fields.begin(); f != sovf.m_var_fields.end(); ++f ) {
00043         Field const* field = m_base->findField(f->first);
00044         m_var_fields[f->first] = new FieldRngPair(field, f->second->rng->clone());
00045     }
00046 }
00047 
00048 SimObjectVariationFactory::~SimObjectVariationFactory()
00049 {
00050     for( var_fields_t::const_iterator f = m_var_fields.begin(); f != m_var_fields.end(); ++f ) {
00051         delete f->second;
00052     }
00053     delete m_base;
00054 }
00055 
00056 void SimObjectVariationFactory::unsetRandomEngine( void )
00057 {
00058     theThreadSpecificRandomEngine.init();
00059     rnd_eng =theThreadSpecificRandomEngine.get();
00060 }
00061 
00065 void SimObjectVariationFactory::set( string  const& fieldname, RandomDistribution const& rd )
00066 {
00067     Field const* f = m_base->findField( fieldname );
00068     if (  m_var_fields.find( fieldname ) != m_var_fields.end() ) {
00069         delete m_var_fields[fieldname]->rng;
00070         delete m_var_fields[fieldname];
00071     }
00072     m_var_fields[fieldname] = new FieldRngPair( f, rd.clone() );
00073 }
00074 
00075 SimObject* SimObjectVariationFactory::create( RandomEngine *eng ) const
00076 {
00077     SimObject *obj = m_base->create();
00078     var_fields_t::const_iterator f;
00079     var_fields_t::const_iterator f_end = m_var_fields.end();
00080     for( f = m_var_fields.begin(); f != f_end; ++f ) {
00081         obj->setScalarField( f->second->field, (*(f->second->rng))( *eng ) );
00082     }
00083     return obj;
00084 }
00085 
00086 SimObject* SimObjectVariationFactory::create(void) const
00087 {
00088     return SimObjectVariationFactory::create( rnd_eng );
00089 }
00090 
00091 object_type_t SimObjectVariationFactory::getObjectTypeID() const
00092 {
00093     return m_base->getObjectTypeID();
00094 }

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