CYCLUS
datum.cc
Go to the documentation of this file.
1 #include "datum.h"
2 
3 #include <boost/pool/singleton_pool.hpp>
4 
5 #include "timer.h"
6 
7 namespace cyclus {
8 
9 typedef boost::singleton_pool<Datum, sizeof(Datum)> DatumPool;
10 
11 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
13  std::vector<int>* shape) {
14  vals_.push_back(std::pair<const char*, boost::spirit::hold_any>(field, val));
15  std::vector<int> s;
16  if (shape == NULL)
17  shapes_.push_back(s);
18  else
19  shapes_.push_back(*shape);
20  return this;
21 }
22 
23 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
24 void Datum::Record() {
25  manager_->AddDatum(this);
26 }
27 
28 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
29 Datum::Datum(Recorder* m, std::string title) : title_(title), manager_(m) {
30  // The (vect) size to reserve is chosen to be just bigger than most/all cyclus
31  // core tables. This prevents extra reallocations in the underlying
32  // vector as vals are added to the datum.
33  vals_.reserve(10);
34  shapes_.reserve(10);
35 }
36 
37 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
39 
40 std::string Datum::title() {
41  return title_;
42 }
43 
45  return vals_;
46 }
47 
49  return shapes_;
50 }
51 
52 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
53 void* Datum::operator new(size_t size) {
54  if (size != sizeof(Datum)) {
55  return ::operator new(size);
56  }
57 
58  while (true) {
59  void* ptr = DatumPool::malloc();
60  if (ptr != NULL) {
61  return ptr;
62  }
63 
64  std::new_handler globalNewHandler = std::set_new_handler(0);
65  std::set_new_handler(globalNewHandler);
66 
67  if (globalNewHandler) {
68  globalNewHandler();
69  } else {
70  throw std::bad_alloc();
71  }
72  }
73 }
74 
75 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
76 void Datum::operator delete(void* rawMemory) throw() {
77  if (rawMemory == 0) {
78  return;
79  }
80  DatumPool::free(rawMemory);
81 }
82 
83 } // namespace cyclus
const Vals & vals()
Returns a vector of all field-value pairs that have been added to this datum.
Definition: datum.cc:44
std::string title()
Returns the datum&#39;s title as specified during the datum&#39;s creation.
Definition: datum.cc:40
const Shapes & shapes()
Returns a vector of all shapes (pointers to vectors of ints) that have been added to this datum...
Definition: datum.cc:48
std::vector< Shape > Shapes
Definition: datum.h:22
Used to specify and send a collection of key-value pairs to the Recorder for recording.
Definition: datum.h:15
std::vector< Entry > Vals
Definition: datum.h:20
virtual ~Datum()
Definition: datum.cc:38
Datum * AddVal(const char *field, boost::spirit::hold_any val, std::vector< int > *shape=NULL)
Add an arbitrary field-value pair to the datum.
Definition: datum.cc:12
Collects and manages output data generation for the cyclus core and agents during a simulation...
Definition: recorder.h:45
boost::singleton_pool< Datum, sizeof(Datum)> DatumPool
Definition: datum.cc:9
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or.org/Osi/browser/trunk.
Definition: agent.cc:14
void Record()
Record this datum to its Recorder.
Definition: datum.cc:24