CYCAMORE
src/manager_inst.cc
Go to the documentation of this file.
1 // Implements the ManagerInst class
2 #include "manager_inst.h"
3 
4 namespace cycamore {
5 
6 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7 ManagerInst::ManagerInst(cyclus::Context* ctx)
8  : cyclus::Institution(ctx),
9  latitude(0.0),
10  longitude(0.0),
12 
13 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
15 
16 void ManagerInst::BuildNotify(Agent* a) {
17  Register_(a);
18 }
19 
20 void ManagerInst::DecomNotify(Agent* a) {
21  Unregister_(a);
22 }
23 
25  cyclus::Institution::EnterNotify();
26  std::set<cyclus::Agent*>::iterator sit;
27  for (sit = cyclus::Agent::children().begin();
28  sit != cyclus::Agent::children().end();
29  ++sit) {
30  Agent* a = *sit;
31  Register_(a);
32  }
33 
34  using cyclus::toolkit::CommodityProducer;
35  std::vector<std::string>::iterator vit;
36  for (vit = prototypes.begin(); vit != prototypes.end(); ++vit) {
37  Agent* a = context()->CreateAgent<Agent>(*vit);
38  CommodityProducer* cp_cast = dynamic_cast<CommodityProducer*>(a);
39  if (cp_cast != NULL) {
40  LOG(cyclus::LEV_INFO3, "mani") << "Registering prototype "
41  << a->prototype() << a->id()
42  << " with the Builder interface.";
43  Builder::Register(cp_cast);
44  }
45  }
47 }
48 
49 void ManagerInst::Register_(Agent* a) {
50  using cyclus::toolkit::CommodityProducer;
51  using cyclus::toolkit::CommodityProducerManager;
52 
53  CommodityProducer* cp_cast = dynamic_cast<CommodityProducer*>(a);
54  if (cp_cast != NULL) {
55  LOG(cyclus::LEV_INFO3, "mani") << "Registering agent "
56  << a->prototype() << a->id()
57  << " as a commodity producer.";
58  CommodityProducerManager::Register(cp_cast);
59  }
60 }
61 
62 void ManagerInst::Unregister_(Agent* a) {
63  using cyclus::toolkit::CommodityProducer;
64  using cyclus::toolkit::CommodityProducerManager;
65 
66  CommodityProducer* cp_cast = dynamic_cast<CommodityProducer*>(a);
67  if (cp_cast != NULL)
68  CommodityProducerManager::Unregister(cp_cast);
69 }
70 
71 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
73  cyclus::toolkit::CommodityProducer* producer) {
74  using std::set;
75  set<cyclus::toolkit::Commodity,
76  cyclus::toolkit::CommodityCompare> commodities =
77  producer->ProducedCommodities();
78  set<cyclus::toolkit::Commodity, cyclus::toolkit::CommodityCompare>::
79  iterator it;
80 
81  LOG(cyclus::LEV_DEBUG3, "maninst") << " Clone produces " << commodities.size()
82  << " commodities.";
83  for (it = commodities.begin(); it != commodities.end(); it++) {
84  LOG(cyclus::LEV_DEBUG3, "maninst") << " Commodity produced: " << it->name();
85  LOG(cyclus::LEV_DEBUG3, "maninst") << " capacity: " <<
86  producer->Capacity(*it);
87  LOG(cyclus::LEV_DEBUG3, "maninst") << " cost: " <<
88  producer->Cost(*it);
89  }
90 }
91 
93  std::string specification = this->spec();
94  context()
95  ->NewDatum("AgentPosition")
96  ->AddVal("Spec", specification)
97  ->AddVal("Prototype", this->prototype())
98  ->AddVal("AgentId", id())
99  ->AddVal("Latitude", latitude)
100  ->AddVal("Longitude", longitude)
101  ->Record();
102 }
103 
104 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
105 extern "C" cyclus::Agent* ConstructManagerInst(cyclus::Context* ctx) {
106  return new ManagerInst(ctx);
107 }
108 
109 } // namespace cycamore
void WriteProducerInformation(cyclus::toolkit::CommodityProducer *producer)
write information about a commodity producer to a stream
cyclus::Agent * ConstructManagerInst(cyclus::Context *ctx)
virtual void BuildNotify(Agent *m)
register a new child
ManagerInst(cyclus::Context *ctx)
Default constructor.
double longitude
void Register_(cyclus::Agent *agent)
register a child
virtual void EnterNotify()
enter the simulation and register any children present
cycamore::GrowthRegion string
virtual ~ManagerInst()
Default destructor.
std::vector< std::string > prototypes
cyclus::toolkit::Position coordinates
virtual void DecomNotify(Agent *m)
unregister a child
void RecordPosition()
Records an agent&#39;s latitude and longitude to the output db.
void Unregister_(cyclus::Agent *agent)
unregister a child