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
41 /// interpreted as inherently variable length, which may affect persistance.
42 /// This is a vector of ints (a shape) rather than an int (a length) to
43 /// accomodate nested data types, such as a vector of vectors of doubles or a
44 /// map of strings to ints. Use NULL as the shape for fixed length data types
45 /// such 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
63 /// datum.
64 const Vals& vals();
65
66 /// Returns a vector of all shapes (pointers to vectors of ints) that have
67 /// been added to this datum. The length of shapes must match the length of
68 /// vals.
69 const Shapes& shapes();
70
71 /// Returns a vector of all field names that have been added to this datum.
72 const Fields& fields();
73
74 static void* operator new(size_t size);
75 static void operator delete(void* rawMemory) throw();
76
77 private:
78 /// Datum objects should generally not be created using a constructor (i.e.
79 /// use the recorder interface).
80 Datum(Recorder* m, std::string title);
81 Datum* AddValBase(const char* field, boost::spirit::hold_any val,
82 std::vector<int>* shape = NULL);
83
84 Recorder* manager_;
85 std::string title_;
86 Vals vals_;
87 Shapes shapes_;
88 Fields fields_;
89};
90
91} // namespace cyclus
92
93#endif // CYCLUS_SRC_DATUM_H_
friend class Recorder
Definition datum.h:16
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
std::pair< const char *, boost::spirit::hold_any > Entry
Definition datum.h:19
virtual ~Datum()
Definition datum.cc:49
void Record()
Record this datum to its Recorder.
Definition datum.cc:34
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:51
const Vals & vals()
Returns a vector of all field-value pairs that have been added to this datum.
Definition datum.cc:55
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