CYCLUS
Loading...
Searching...
No Matches
datum.h
Go to the documentation of this file.
1#ifndef CYCLUS_SRC_DATUM_H_
2#define CYCLUS_SRC_DATUM_H_
3
4#include <list>
5#include <string>
6#include <vector>
7
8#include "any.hpp"
9#include "recorder.h"
10
11namespace cyclus {
12
13/// Used to specify and send a collection of key-value pairs to the
14/// Recorder for recording.
15class Datum {
16 friend class Recorder;
17
18 public:
19 typedef std::pair<const char*, boost::spirit::hold_any> Entry;
20 typedef std::vector<Entry> Vals;
21 typedef std::vector<int> Shape;
22 typedef std::vector<Shape> Shapes;
23 typedef std::vector<std::string> Fields;
24
25 virtual ~Datum();
26
27 /// Add an arbitrary field-value pair to the datum.
28 ///
29 /// @param field a label or key for a value. Loosely analogous to a column
30 /// label.
31 ///
32 /// @param val a value of any type (int, bool, string, vector) supported by
33 /// the backends being used.
34 ///
35 /// @param shape a pointer to a vector of ints that represents the maximum
36 /// shape for this field. This is only useful for variable length data types
37 /// such as string and blob. If a shape is provided, this field and value
38 /// is interpreted as having a fixed length (of the value given). If the
39
40 /// pointer is NULL or the entry is less than one (<1), the field is interpreted
41 /// as inherently variable length, which may affect persistance. This is a
42 /// vector of ints (a shape) rather than an int (a length) to accomodate
43 /// nested data types, such as a vector of vectors of doubles or a map of
44 /// strings to ints. Use NULL as the shape for fixed length data types such
45 /// as int, float, double, etc.
46 ///
47 /// @warning for the val argument - what variable types are supported
48 /// depends on what the backend(s) in use are designed to handle.
49 Datum* AddVal(const char* field, boost::spirit::hold_any val,
50 std::vector<int>* shape = NULL);
51 Datum* AddVal(std::string field, boost::spirit::hold_any val,
52 std::vector<int>* shape = NULL);
53
54 /// Record this datum to its Recorder. Recorded Datum objects of the same
55 /// title (e.g. same table) must not contain any fields that were not
56 /// present in the first datum recorded of that title.
57 void Record();
58
59 /// Returns the datum's title as specified during the datum's creation.
60 std::string title();
61
62 /// Returns a vector of all field-value pairs that have been added to this datum.
63 const Vals& vals();
64
65 /// Returns a vector of all shapes (pointers to vectors of ints) that have been
66 /// added to this datum. The length of shapes must match the length of vals.
67 const Shapes& shapes();
68
69 /// Returns a vector of all field names that have been added to this datum.
70 const Fields& fields();
71
72 static void* operator new(size_t size);
73 static void operator delete(void* rawMemory) throw();
74
75 private:
76 /// Datum objects should generally not be created using a constructor (i.e.
77 /// use the recorder interface).
78 Datum(Recorder* m, std::string title);
79 Datum* AddValBase(const char* field, boost::spirit::hold_any val,
80 std::vector<int>* shape = NULL);
81
82 Recorder* manager_;
83 std::string title_;
84 Vals vals_;
85 Shapes shapes_;
86 Fields fields_;
87};
88
89} // namespace cyclus
90
91#endif // CYCLUS_SRC_DATUM_H_
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
std::pair< const char *, boost::spirit::hold_any > Entry
Definition datum.h:19
virtual ~Datum()
Definition datum.cc:50
void Record()
Record this datum to its Recorder.
Definition datum.cc:35
std::vector< int > Shape
Definition datum.h:21
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
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters