PopObjectAttributeFactory.cpp

Go to the documentation of this file.
00001 
00012 #include "PopObjectAttributeFactory.h"
00013 /*
00014 #include <iostream>
00015 using std::cout;
00016 using std::cerr;
00017 using std::endl;
00018 */
00019 
00020 /*
00021 PopObjectAttributeFactory::PopObjectAttributeFactory(PopObjectAttributeFactory const& model)
00022     : PopObjectFactory(model)
00023     , m_attr_def(new SimObjectAttributesDefinition())
00024 {
00025 }
00026 */
00027 
00028 PopObjectAttributeFactory::PopObjectAttributeFactory(PopObjectFactory const& model)
00029     : PopObjectFactory(model)
00030     , m_attr_def(new SimObjectAttributesDefinition())
00031 {
00032 }
00033 
00034 
00035 PopObjectAttributeFactory::~PopObjectAttributeFactory()
00036 {
00037 }
00038 
00039 
00040 void PopObjectAttributeFactory::set(string const& attrname, RandomDistribution& rd)
00041 {
00042     if(CheckAndRemoveAttrName(attrname))
00043         m_attr_def->addDouble(attrname);
00044 
00045     m_attr_distributions[attrname] = rd.clone();
00046 }
00047 
00048 
00049 void PopObjectAttributeFactory::set(string const& attrname, string const& value)
00050 {
00051     throw( PCSIM::ConstructionException( "PopObjectAttributeFactory", "string attributes not implemented." ) );
00052 }
00053 
00054 
00055 void PopObjectAttributeFactory::set(string const& attrname, PopObjectValueGenerator& valgen)
00056 {
00057     if(CheckAndRemoveAttrName(attrname))
00058         m_attr_def->addDouble(attrname);
00059 
00060     m_attr_generators[attrname] = valgen.clone();
00061 }
00062 
00063 
00064 SimObject* PopObjectAttributeFactory::create(RandomEngine *eng)
00065 {
00066     return PopObjectFactory::create(eng);
00067 }
00068 
00069 
00070 SimObjectAttributes* PopObjectAttributeFactory::createAttributes(RandomEngine *eng)
00071 {
00072     SimObjectAttributes* attr= new SimObjectAttributes(m_attr_def);
00073 
00074     attr_distributions_t::const_iterator ad;
00075     attr_distributions_t::const_iterator ad_end = m_attr_distributions.end();
00076 
00077     for(ad = m_attr_distributions.begin(); ad != ad_end; ++ad ) {
00078         attr->set(ad->first, (*ad->second)(*eng));
00079     }
00080 
00081     attr_generators_t::const_iterator ag;
00082     attr_generators_t::const_iterator ag_end = m_attr_generators.end();
00083 
00084     for(ag = m_attr_generators.begin(); ag != ag_end; ++ag ) {
00085         attr->set(ag->first, ag->second->generate(eng));
00086     }
00087 
00088     return attr;
00089 }
00090 
00091 
00092 bool PopObjectAttributeFactory::CheckAndRemoveAttrName(string const& attrname)
00093 {
00094     bool isNew=true;
00095 
00096     if (m_attr_generators.find(attrname) != m_attr_generators.end() ) {
00097         delete m_attr_generators[attrname];
00098         isNew=false;
00099     }
00100 
00101     if (m_attr_distributions.find(attrname) != m_attr_distributions.end() ) {
00102         delete m_attr_distributions[attrname];
00103         isNew=false;
00104     }
00105 
00106     return isNew;
00107 }
00108 
00109 
00110 void PopObjectAttributeFactory::announce(SimObjectPopulation &pop, size_t idx)
00111 {
00112     PopObjectFactory::announce(pop, idx);
00113 
00114     attr_generators_t::const_iterator ag;
00115     attr_generators_t::const_iterator ag_end = m_attr_generators.end();
00116 
00117     for(ag = m_attr_generators.begin(); ag != ag_end; ++ag) {
00118         ag->second->prepare(pop, idx);
00119     }
00120 }

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