CYCLUS
res_tracker.h
Go to the documentation of this file.
1 #ifndef CYCLUS_SRC_RES_TRACKER_H_
2 #define CYCLUS_SRC_RES_TRACKER_H_
3 
4 #include <string>
5 #include <vector>
6 #include <boost/shared_ptr.hpp>
7 
8 #include "context.h"
9 #include "resource.h"
10 
11 namespace cyclus {
12 
13 /// Tracks and records the state and parent-child relationships of resources as
14 /// they are changed. Resource implementations embed this as a member variable
15 /// and invoke its methods appropriately to have their state changes tracked in
16 /// the canonical core resource table.
17 ///
18 /// Invocations to Create, Extract, Absorb, and Modify result in one or more
19 /// entries in the output db Resource table and also call the Record method of
20 /// the tracker's tracked resource. A zero parent id indicates a resource id
21 /// has no parent; if both are zeros the resource was newly created.
22 class ResTracker {
23  public:
24  /// Create a new tracker following r.
25  ResTracker(Context* ctx, Resource* r);
26 
27  /// Prevent a resource's heritage from being tracked and recorded.
28  void DontTrack();
29 
30  /// Should be called when a resource instance is newly created.
31  void Create(Agent* creator);
32 
33  /// Should be called when a resource has some quantity removed from it (e.g.
34  /// resource is split).
35  /// @param removed the tracker of the extracted/removed resource.
36  void Extract(ResTracker* removed);
37 
38  /// Should be called when a resource is combined with another.
39  /// @param absorbed the tracker of the resource being absorbed.
40  void Absorb(ResTracker* absorbed);
41 
42  /// Should be called when the state of a resource changes (e.g. radioactive
43  /// decay).
44  void Modify();
45 
46  private:
47  void Record();
48 
49  int parent1_;
50  int parent2_;
51  bool tracked_;
52  Resource* res_;
53  Context* ctx_;
54 };
55 
56 } // namespace cyclus
57 
58 #endif // CYCLUS_SRC_RES_TRACKER_H_
void Absorb(ResTracker *absorbed)
Should be called when a resource is combined with another.
Definition: res_tracker.cc:57
void Create(Agent *creator)
Should be called when a resource instance is newly created.
Definition: res_tracker.cc:18
Tracks and records the state and parent-child relationships of resources as they are changed...
Definition: res_tracker.h:22
Resource defines an abstract interface implemented by types that are offered, requested, and transferred between simulation agents.
Definition: resource.h:19
void DontTrack()
Prevent a resource&#39;s heritage from being tracked and recorded.
Definition: res_tracker.cc:14
void Modify()
Should be called when the state of a resource changes (e.g.
Definition: res_tracker.cc:32
void Extract(ResTracker *removed)
Should be called when a resource has some quantity removed from it (e.g.
Definition: res_tracker.cc:42
A simulation context provides access to necessary simulation-global functions and state...
Definition: context.h:128
The abstract base class used by all types of agents that live and interact in a simulation.
Definition: agent.h:51
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or.org/Osi/browser/trunk.
Definition: agent.cc:14
ResTracker(Context *ctx, Resource *r)
Create a new tracker following r.
Definition: res_tracker.cc:7