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) : cyclus::Institution(ctx) { }
8 
9 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
11 
12 void ManagerInst::BuildNotify(Agent* a) {
13  Register_(a);
14 }
15 
16 void ManagerInst::DecomNotify(Agent* a) {
17  Unregister_(a);
18 }
19 
21  cyclus::Institution::EnterNotify();
22  std::set<cyclus::Agent*>::iterator sit;
23  for (sit = cyclus::Agent::children().begin();
24  sit != cyclus::Agent::children().end();
25  ++sit) {
26  Agent* a = *sit;
27  Register_(a);
28  }
29 
30  using cyclus::toolkit::CommodityProducer;
31  std::vector<std::string>::iterator vit;
32  for (vit = prototypes.begin(); vit != prototypes.end(); ++vit) {
33  Agent* a = context()->CreateAgent<Agent>(*vit);
34  CommodityProducer* cp_cast = dynamic_cast<CommodityProducer*>(a);
35  if (cp_cast != NULL) {
36  LOG(cyclus::LEV_INFO3, "mani") << "Registering prototype "
37  << a->prototype() << a->id()
38  << " with the Builder interface.";
39  Builder::Register(cp_cast);
40  }
41  }
42 }
43 
44 void ManagerInst::Register_(Agent* a) {
45  using cyclus::toolkit::CommodityProducer;
46  using cyclus::toolkit::CommodityProducerManager;
47 
48  CommodityProducer* cp_cast = dynamic_cast<CommodityProducer*>(a);
49  if (cp_cast != NULL) {
50  LOG(cyclus::LEV_INFO3, "mani") << "Registering agent "
51  << a->prototype() << a->id()
52  << " as a commodity producer.";
53  CommodityProducerManager::Register(cp_cast);
54  }
55 }
56 
57 void ManagerInst::Unregister_(Agent* a) {
58  using cyclus::toolkit::CommodityProducer;
59  using cyclus::toolkit::CommodityProducerManager;
60 
61  CommodityProducer* cp_cast = dynamic_cast<CommodityProducer*>(a);
62  if (cp_cast != NULL)
63  CommodityProducerManager::Unregister(cp_cast);
64 }
65 
66 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
68  cyclus::toolkit::CommodityProducer* producer) {
69  using std::set;
70  set<cyclus::toolkit::Commodity,
71  cyclus::toolkit::CommodityCompare> commodities =
72  producer->ProducedCommodities();
73  set<cyclus::toolkit::Commodity, cyclus::toolkit::CommodityCompare>::
74  iterator it;
75 
76  LOG(cyclus::LEV_DEBUG3, "maninst") << " Clone produces " << commodities.size()
77  << " commodities.";
78  for (it = commodities.begin(); it != commodities.end(); it++) {
79  LOG(cyclus::LEV_DEBUG3, "maninst") << " Commodity produced: " << it->name();
80  LOG(cyclus::LEV_DEBUG3, "maninst") << " capacity: " <<
81  producer->Capacity(*it);
82  LOG(cyclus::LEV_DEBUG3, "maninst") << " cost: " <<
83  producer->Cost(*it);
84  }
85 }
86 
87 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
88 extern "C" cyclus::Agent* ConstructManagerInst(cyclus::Context* ctx) {
89  return new ManagerInst(ctx);
90 }
91 
92 } // 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.
void Register_(cyclus::Agent *agent)
register a child
virtual void EnterNotify()
enter the simulation and register any children present
virtual ~ManagerInst()
Default destructor.
std::vector< std::string > prototypes
virtual void DecomNotify(Agent *m)
unregister a child
void Unregister_(cyclus::Agent *agent)
unregister a child