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
5
6namespace cyclus {
7
8typedef boost::singleton_pool<Datum, sizeof(Datum)> DatumPool;
9
10// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
11Datum* Datum::AddValBase(const char* field, boost::spirit::hold_any val,
12 std::vector<int>* shape) {
13 vals_.push_back(std::pair<const char*, boost::spirit::hold_any>(field, val));
14 std::vector<int> s;
15 if (shape == NULL)
16 shapes_.push_back(s);
17 else
18 shapes_.push_back(*shape);
19 return this;
20}
21
23 std::vector<int>* shape) {
24 fields_.push_back(std::string(field));
25 return AddValBase(field, val, shape);
26}
27
29 std::vector<int>* shape) {
30 fields_.push_back(field);
31 return AddValBase(field.c_str(), val, shape);
32}
33
34// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
36 manager_->AddDatum(this);
37}
38
39// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
40Datum::Datum(Recorder* m, std::string title) : title_(title), manager_(m) {
41 // The (vect) size to reserve is chosen to be just bigger than most/all cyclus
42 // core tables. This prevents extra reallocations in the underlying
43 // vector as vals are added to the datum.
44 vals_.reserve(10);
45 shapes_.reserve(10);
46 fields_.reserve(10);
47}
48
49// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
51
52std::string Datum::title() {
53 return title_;
54}
55
57 return vals_;
58}
59
61 return shapes_;
62}
63
65 return fields_;
66}
67
68// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
69void* Datum::operator new(size_t size) {
70 if (size != sizeof(Datum)) {
71 return ::operator new(size);
72 }
73
74 while (true) {
75 void* ptr = DatumPool::malloc();
76 if (ptr != NULL) {
77 return ptr;
78 }
79
80 std::new_handler globalNewHandler = std::set_new_handler(0);
81 std::set_new_handler(globalNewHandler);
82
83 if (globalNewHandler) {
85 } else {
86 throw std::bad_alloc();
87 }
88 }
89}
90
91// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
92void Datum::operator delete(void* rawMemory) throw() {
93 if (rawMemory == 0) {
94 return;
95 }
96 DatumPool::free(rawMemory);
97}
98
99} // 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:22
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:64
const Shapes & shapes()
Returns a vector of all shapes (pointers to vectors of ints) that have been added to this datum.
Definition datum.cc:60
virtual ~Datum()
Definition datum.cc:50
void Record()
Record this datum to its Recorder.
Definition datum.cc:35
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:52
const Vals & vals()
Returns a vector of all field-value pairs that have been added to this datum.
Definition datum.cc:56
Collects and manages output data generation for the cyclus core and agents during a simulation.
Definition recorder.h:45
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:8
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters