CYCLUS
product.h
Go to the documentation of this file.
1 #ifndef CYCLUS_SRC_PRODUCT_H_
2 #define CYCLUS_SRC_PRODUCT_H_
3 
4 #include <boost/shared_ptr.hpp>
5 
6 #include "context.h"
7 #include "resource.h"
8 #include "res_tracker.h"
9 
10 class SimInitTest;
11 
12 namespace cyclus {
13 
14 /// A Product is a general type of resource in the Cyclus simulation,
15 /// and is a catch-all for non-standard resources. It implements the Resource
16 /// class interface in a simple way usable for things such as: bananas,
17 /// man-hours, water, buying power, etc.
18 class Product : public Resource {
19  friend class SimInit;
20  friend class ::SimInitTest;
21 
22  public:
23  typedef
24  boost::shared_ptr<Product> Ptr;
25  static const ResourceType kType;
26 
27  /// Creates a new product that is "live" and tracked. creator is a
28  /// pointer to the agent creating the resource (usually will be the caller's
29  /// "this" pointer). All future output data recorded will be done using the
30  /// creator's context.
31  static Ptr Create(Agent* creator, double quantity, std::string quality);
32 
33  /// Creates a new product that does not actually exist as part of
34  /// the simulation and is untracked.
35  static Ptr CreateUntracked(double quantity, std::string quality);
36 
37  /// Returns 0 (for now).
38  virtual int qual_id() const {
39  return qualids_[quality_];
40  }
41 
42  /// Returns Product::kType.
43  virtual const ResourceType type() const {
44  return kType;
45  }
46 
47  virtual Resource::Ptr Clone() const;
48 
49  virtual void Record(Context* ctx) const {}
50 
51  virtual std::string units() const { return "NONE"; }
52 
53  virtual double quantity() const {
54  return quantity_;
55  }
56 
57  /// Returns the quality of this resource (e.g. bananas, human labor, water, etc.).
58  virtual const std::string& quality() const {
59  return quality_;
60  }
61 
62  virtual Resource::Ptr ExtractRes(double quantity);
63 
64  /// Extracts the specified mass from this resource and returns it as a
65  /// new product object with the same quality/type.
66  ///
67  /// @throws ValueError tried to extract more than exists.
68  Product::Ptr Extract(double quantity);
69 
70  /// Absorbs the contents of the given 'other' resource into this resource.
71  /// @throws ValueError 'other' resource is of different quality
72  void Absorb(Product::Ptr other);
73 
74  private:
75  /// @param ctx the simulation context
76  /// @param quantity is a double indicating the quantity
77  /// @param quality the resource quality
78  Product(Context* ctx, double quantity, std::string quality);
79 
80  // map<quality, quality_id>
81  static std::map<std::string, int> qualids_;
82  static int next_qualid_;
83 
84  Context* ctx_;
85  std::string quality_;
86  double quantity_;
87  ResTracker tracker_;
88 };
89 
90 } // namespace cyclus
91 
92 #endif // CYCLUS_SRC_PRODUCT_H_
virtual std::string units() const
Returns the units this resource is based in (e.g. "kg").
Definition: product.h:51
std::string ResourceType
Definition: resource.h:12
boost::shared_ptr< Product > Ptr
Definition: product.h:24
Tracks and records the state and parent-child relationships of resources as they are changed...
Definition: res_tracker.h:22
A Product is a general type of resource in the Cyclus simulation, and is a catch-all for non-standard...
Definition: product.h:18
virtual Resource::Ptr ExtractRes(double quantity)
Splits the resource and returns the extracted portion as a new resource object.
Definition: product.cc:71
virtual void Record(Context *ctx) const
Records the resource&#39;s state to the output database.
Definition: product.h:49
Resource defines an abstract interface implemented by types that are offered, requested, and transferred between simulation agents.
Definition: resource.h:19
void Absorb(Product::Ptr other)
Absorbs the contents of the given &#39;other&#39; resource into this resource.
Definition: product.cc:47
static Ptr Create(Agent *creator, double quantity, std::string quality)
Creates a new product that is "live" and tracked.
Definition: product.cc:14
virtual const std::string & quality() const
Returns the quality of this resource (e.g. bananas, human labor, water, etc.).
Definition: product.h:58
A simulation context provides access to necessary simulation-global functions and state...
Definition: context.h:130
boost::shared_ptr< Resource > Ptr
Definition: resource.h:24
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
virtual const ResourceType type() const
Returns Product::kType.
Definition: product.h:43
static const ResourceType kType
Definition: product.h:25
virtual Resource::Ptr Clone() const
Returns an untracked (not part of the simulation) copy of the resource.
Definition: product.cc:39
virtual double quantity() const
Returns the quantity of this resource with dimensions as specified by the return value of units()...
Definition: product.h:53
static Ptr CreateUntracked(double quantity, std::string quality)
Creates a new product that does not actually exist as part of the simulation and is untracked...
Definition: product.cc:31
Handles initialization of a simulation from the output database.
Definition: sim_init.h:24
virtual int qual_id() const
Returns 0 (for now).
Definition: product.h:38
Product::Ptr Extract(double quantity)
Extracts the specified mass from this resource and returns it as a new product object with the same q...
Definition: product.cc:58