hobbes
a language, embedded compiler, and runtime for efficient dynamic expression evaluation, data storage and analysis
series.H
Go to the documentation of this file.
1 /*
2  * storage : handle abstract storage into structured log files
3  */
4 
5 #ifndef HOBBES_STORED_SERIES_H_INCLUDED
6 #define HOBBES_STORED_SERIES_H_INCLUDED
7 
8 #include <hobbes/hobbes.H>
9 #include <hobbes/db/file.H>
10 #include <hobbes/lang/tylift.H>
11 #include <hobbes/util/time.H>
12 #include <hobbes/util/perf.H>
13 
14 namespace hobbes {
15 
16 class StoredSeries {
17 public:
18  StoredSeries(cc*, writer*, const std::string&, const MonoTypePtr&, size_t);
19  ~StoredSeries();
20 
21  // what type will actually be recorded?
22  const MonoTypePtr& storageType() const;
23 
24  // record a value in this series
25  // (assumes that all such values are passed by reference)
26  void record(const void*, bool signal = true);
27 
28  // bind a function to record data into this series
29  // (assumes that this series will live at least as long as the bound function is usable)
30  void bindAs(cc*, const std::string&);
31 
32  // what is the head write position in this file?
33  // (this can be used to make a file reference to recorded values)
34  uint64_t writePosition() const;
35 private:
39 
40  size_t storageSize;
42  size_t batchSize;
43 
44  uint64_t batchDataRef;
45  void* batchData;
46  uint8_t* batchHead;
47  uint64_t batchNode;
48  uint64_t* headNodeRef;
49 
50  typedef void (*StoreFn)(writer*, const void*, void*);
52 
53  void consBatchNode(uint64_t nextPtr);
54  void restartFromBatchNode();
55 
56  static uint64_t allocBatchNode(writer*);
57  static uint64_t allocBatchNode(writer*,uint64_t,uint64_t);
58 };
59 
60 template <typename T>
61  class series {
62  public:
63  series(cc* c, writer* db, const std::string& sname, size_t bsize = 10000) : storage(c, db, sname, lift<T, true>::type(*c), bsize) {
64  }
65  void record(const T& x, bool signal = true) {
66  this->storage.record(&x, signal);
67  }
68  void operator()(const T& x, bool signal = true) {
69  this->storage.record(&x, signal);
70  }
71  private:
73  };
74 
75 inline MonoTypePtr filerefty(const MonoTypePtr& t) {
76  return tapp(primty("fileref"), list(t));
77 }
78 
79 }
80 
81 #endif
82 
void consBatchNode(uint64_t nextPtr)
Definition: series.C:213
void restartFromBatchNode()
Definition: series.C:227
Definition: series.H:16
uint8_t * batchHead
Definition: series.H:46
Definition: tylift.H:115
MonoTypePtr storedType
Definition: series.H:38
MonoTypePtr filerefty(const MonoTypePtr &t)
Definition: series.H:75
StoredSeries storage
Definition: series.H:72
Definition: series.H:61
MonoTypePtr primty(const char *x)
Definition: type.H:1008
void record(const T &x, bool signal=true)
Definition: series.H:65
series(cc *c, writer *db, const std::string &sname, size_t bsize=10000)
Definition: series.H:63
Definition: boot.H:7
void record(const void *, bool signal=true)
Definition: series.C:131
void(* StoreFn)(writer *, const void *, void *)
Definition: series.H:50
size_t batchSize
Definition: series.H:42
MonoTypePtr batchType
Definition: series.H:41
MonoType::ptr MonoTypePtr
Definition: type.H:71
writer * outputFile
Definition: series.H:36
const MonoTypePtr & storageType() const
Definition: series.C:123
MonoTypePtr recordType
Definition: series.H:37
Definition: file.H:225
void bindAs(cc *, const std::string &)
Definition: series.C:158
uint64_t * headNodeRef
Definition: series.H:48
void operator()(const T &x, bool signal=true)
Definition: series.H:68
std::vector< T > list()
Definition: array.H:25
uint64_t writePosition() const
Definition: series.C:127
Definition: cc.H:64
size_t storageSize
Definition: series.H:40
uint64_t batchNode
Definition: series.H:47
StoredSeries(cc *, writer *, const std::string &, const MonoTypePtr &, size_t)
Definition: series.C:102
static uint64_t allocBatchNode(writer *)
Definition: series.C:243
StoreFn storeFn
Definition: series.H:51
~StoredSeries()
Definition: series.C:120
uint64_t batchDataRef
Definition: series.H:44
MonoTypePtr tapp(const MonoTypePtr &f, const MonoTypes &args)
Definition: type.H:1133
void * batchData
Definition: series.H:45