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