CYCAMORE
Loading...
Searching...
No Matches
src/manager_inst.cc
Go to the documentation of this file.
1// Implements the ManagerInst class
2#include "manager_inst.h"
3
4namespace cycamore {
5
6// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7ManagerInst::ManagerInst(cyclus::Context* ctx)
8 : cyclus::Institution(ctx) {}
9
10// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
11ManagerInst::~ManagerInst() {}
12
13void ManagerInst::BuildNotify(Agent* a) {
14 Register_(a);
15}
16
17void ManagerInst::DecomNotify(Agent* a) {
18 Unregister_(a);
19}
20
21void ManagerInst::EnterNotify() {
22 cyclus::Institution::EnterNotify();
23 std::set<cyclus::Agent*>::iterator sit;
24 for (sit = cyclus::Agent::children().begin();
25 sit != cyclus::Agent::children().end();
26 ++sit) {
27 Agent* a = *sit;
28 Register_(a);
29 }
30
31 using cyclus::toolkit::CommodityProducer;
32 std::vector<std::string>::iterator vit;
33 for (vit = prototypes.begin(); vit != prototypes.end(); ++vit) {
34 Agent* a = context()->CreateAgent<Agent>(*vit);
35 CommodityProducer* cp_cast = dynamic_cast<CommodityProducer*>(a);
36 if (cp_cast != NULL) {
37 LOG(cyclus::LEV_INFO3, "mani") << "Registering prototype "
38 << a->prototype() << a->id()
39 << " with the Builder interface.";
40 Builder::Register(cp_cast);
41 }
42 }
43
44 InitializePosition();
45}
46
47void ManagerInst::Register_(Agent* a) {
48 using cyclus::toolkit::CommodityProducer;
49 using cyclus::toolkit::CommodityProducerManager;
50
51 CommodityProducer* cp_cast = dynamic_cast<CommodityProducer*>(a);
52 if (cp_cast != NULL) {
53 LOG(cyclus::LEV_INFO3, "mani") << "Registering agent "
54 << a->prototype() << a->id()
55 << " as a commodity producer.";
56 CommodityProducerManager::Register(cp_cast);
57 }
58}
59
60void ManagerInst::Unregister_(Agent* a) {
61 using cyclus::toolkit::CommodityProducer;
62 using cyclus::toolkit::CommodityProducerManager;
63
64 CommodityProducer* cp_cast = dynamic_cast<CommodityProducer*>(a);
65 if (cp_cast != NULL)
66 CommodityProducerManager::Unregister(cp_cast);
67}
68
69// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
70void ManagerInst::WriteProducerInformation(
71 cyclus::toolkit::CommodityProducer* producer) {
72 using std::set;
73 set<cyclus::toolkit::Commodity,
74 cyclus::toolkit::CommodityCompare> commodities =
75 producer->ProducedCommodities();
76 set<cyclus::toolkit::Commodity, cyclus::toolkit::CommodityCompare>::
77 iterator it;
78
79 LOG(cyclus::LEV_DEBUG3, "maninst") << " Clone produces " << commodities.size()
80 << " commodities.";
81 for (it = commodities.begin(); it != commodities.end(); it++) {
82 LOG(cyclus::LEV_DEBUG3, "maninst") << " Commodity produced: " << it->name();
83 LOG(cyclus::LEV_DEBUG3, "maninst") << " capacity: " <<
84 producer->Capacity(*it);
85 LOG(cyclus::LEV_DEBUG3, "maninst") << " cost: " <<
86 producer->Cost(*it);
87 }
88}
89
90// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
91extern "C" cyclus::Agent* ConstructManagerInst(cyclus::Context* ctx) {
92 return new ManagerInst(ctx);
93}
94
95} // namespace cycamore
ManagerInst(cyclus::Context *ctx)
Default constructor.
cyclus::Agent * ConstructManagerInst(cyclus::Context *ctx)
void Unregister_(cyclus::Agent *agent)
unregister a child
void Register_(cyclus::Agent *agent)
register a child