CYCLUS
Public Member Functions | List of all members
cyclus::toolkit::ResBuf< T > Class Template Reference

Detailed Description

template<class T>
class cyclus::toolkit::ResBuf< T >

ResBuf is a helper class that provides semi-automated management of a collection of resources (e.g.

agent stocks and inventories). Constructed buffers have infinite capacity unless explicitly changed. Resource popping occurs in the order the resources were pushed (i.e. oldest resources are popped first), unless explicitly specified otherwise.

Typically, a ResBuf will be a member variable on an agent/archetype class. Resources can be added and retrieved from it as needed, and the buffer can be queried in various ways as done in the example below:

class MyAgent : public cyclus::Facility {
public:
Tick() {
double batch_size = 2703;
if (outventory_.space() < batch_size) {
return;
} else if (inventory_.quantity() < batch_size) {
return;
}
outventory_.Push(inventory_.Pop(batch_size));
}
... // resource exchange to fill up inventory_ buffer
private:
...
};

In this example, if there is sufficient material in inventory_, 2703 kg is removed as a single object that is then placed in another buffer (outventory_) each time step.

Definition at line 62 of file res_buf.h.

#include <res_buf.h>

Public Member Functions

double capacity () const
 
void capacity (double cap)
 
int count () const
 
bool empty () const
 
T::Ptr Peek ()
 
T::Ptr Pop (double qty)
 
T::Ptr Pop (double qty, double eps)
 
T::Ptr Pop ()
 
T::Ptr PopBack ()
 
std::vector< typename T::Ptr > PopN (int n)
 
ResVec PopNRes (int n)
 
void Push (Resource::Ptr r)
 
template<class B >
void Push (std::vector< B > rs)
 
double quantity () const
 
 ResBuf ()
 
double space () const
 
virtual ~ResBuf ()
 

Constructor & Destructor Documentation

template<class T>
cyclus::toolkit::ResBuf< T >::ResBuf ( )
inline

Definition at line 64 of file res_buf.h.

template<class T>
virtual cyclus::toolkit::ResBuf< T >::~ResBuf ( )
inlinevirtual

Definition at line 66 of file res_buf.h.

Member Function Documentation

template<class T>
double cyclus::toolkit::ResBuf< T >::capacity ( ) const
inline

Returns the maximum resource quantity this buffer can hold (units based on constituent resource objects' units).

Never throws.

Definition at line 71 of file res_buf.h.

template<class T>
void cyclus::toolkit::ResBuf< T >::capacity ( double  cap)
inline

Sets the maximum quantity this buffer can hold (units based on constituent resource objects' units).

Exceptions
ValueErrorthe new capacity is lower (by eps_rsrc()) than the quantity of resources that exist in the buffer.

Definition at line 78 of file res_buf.h.

template<class T>
int cyclus::toolkit::ResBuf< T >::count ( ) const
inline

Returns the total number of constituent resource objects in the buffer.

Never throws.

Definition at line 90 of file res_buf.h.

template<class T>
bool cyclus::toolkit::ResBuf< T >::empty ( ) const
inline

Returns true if there are no resources in the buffer.

Definition at line 102 of file res_buf.h.

template<class T>
T::Ptr cyclus::toolkit::ResBuf< T >::Peek ( )
inline

Returns the next resource in line to be popped from the buffer without actually removing it from the buffer.

Definition at line 197 of file res_buf.h.

template<class T>
T::Ptr cyclus::toolkit::ResBuf< T >::Pop ( double  qty)
inline

Pops and returns the specified quantity from the buffer as a single resource object.

Resources are split if necessary in order to pop the exact quantity requested (within eps_rsrc()). Resources are retrieved in the order they were pushed (i.e. oldest first) and are squashed into a single object when returned.

Exceptions
ValueErrorthe specified pop quantity is larger than the buffer's current inventory.

Definition at line 113 of file res_buf.h.

template<class T>
T::Ptr cyclus::toolkit::ResBuf< T >::Pop ( double  qty,
double  eps 
)
inline

Same behavior as Pop(double) except a non-zero eps may be specified.

eps is used only in cases where qty might be slightly larger than the buffer's current inventory quantity.

Definition at line 152 of file res_buf.h.

template<class T>
T::Ptr cyclus::toolkit::ResBuf< T >::Pop ( )
inline

Pops one resource object from the buffer.

Resources are not split and are retrieved in the order they were pushed (i.e. oldest first).

Exceptions
ValueErrorthe buffer is empty.

Definition at line 209 of file res_buf.h.

template<class T>
T::Ptr cyclus::toolkit::ResBuf< T >::PopBack ( )
inline

Same as Pop, except it returns the most recently added resource.

Definition at line 223 of file res_buf.h.

template<class T>
std::vector<typename T::Ptr> cyclus::toolkit::ResBuf< T >::PopN ( int  n)
inline

Pops the specified number of resource objects from the buffer.

Resources are not split and are retrieved in the order they were pushed (i.e. oldest first).

Exceptions
ValueErrorthe specified n is larger than the buffer's current resource count or the specified number is negative.

Definition at line 172 of file res_buf.h.

template<class T>
ResVec cyclus::toolkit::ResBuf< T >::PopNRes ( int  n)
inline

Same as PopN except returns the Resource-typed objects.

Definition at line 193 of file res_buf.h.

template<class T>
void cyclus::toolkit::ResBuf< T >::Push ( Resource::Ptr  r)
inline

Pushes a single resource object to the buffer.

Resource objects are never combined in the buffer; they are stored as unique objects. The resource object is only pushed to the buffer if it does not cause the buffer to exceed its capacity.

Exceptions
ValueErrorthe pushing of the given resource object would cause the buffer to exceed its capacity.
KeyErrorthe resource object to be pushed is already present in the buffer.

Definition at line 246 of file res_buf.h.

template<class T>
template<class B >
void cyclus::toolkit::ResBuf< T >::Push ( std::vector< B >  rs)
inline

Pushes one or more resource objects (as a std::vector) to the buffer.

Resource objects are never squashed in the buffer; they are stored as unique objects. The resource objects are only pushed to the buffer if they do not cause the buffer to exceed its capacity; otherwise none of the given resource objects are added to the buffer.

Exceptions
ValueErroradding the given resource objects would cause the buffer to exceed its capacity.
KeyErrorone or more of the resource objects to be added are already present in the buffer.

Definition at line 277 of file res_buf.h.

template<class T>
double cyclus::toolkit::ResBuf< T >::quantity ( ) const
inline

Returns the total resource quantity of constituent resource objects in the buffer.

Never throws.

Definition at line 94 of file res_buf.h.

template<class T>
double cyclus::toolkit::ResBuf< T >::space ( ) const
inline

Returns the quantity of space remaining in this buffer.

This is effectively the difference between the capacity and the quantity and is never negative. Never throws.

Definition at line 99 of file res_buf.h.


The documentation for this class was generated from the following file: