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