Zero  0.1.0
handler.h
Go to the documentation of this file.
1 #ifndef __HANDLER_H
2 #define __HANDLER_H
3 
4 #include "logrec.h"
5 
6 #include <fstream>
7 #include <sstream>
8 #include <unordered_set>
9 #include <algorithm>
10 
11 class Handler {
12 public:
13  Handler() :
14  hout(std::cout) {}
15 
16  virtual ~Handler() {};
17 
18  virtual void initialize() {};
19 
20  virtual void invoke(logrec_t &r) = 0;
21 
22  virtual void finalize() {};
23 
24  virtual void newFile(const char* /* fname */) {};
25 
26  Handler(const Handler&) = delete;
27 
28  Handler& operator=(const Handler&) = delete;
29 
30  void setFileOutput(string fpath) {
31  fileOutput.reset(new ofstream(fpath));
32  hout = *fileOutput;
33  }
34 
35 protected:
36  ostream& out() {
37  return hout.get();
38  }
39 
40 private:
41  reference_wrapper<ostream> hout;
42 
43  unique_ptr<ofstream> fileOutput;
44 };
45 
46 class PageHandler {
47 public:
48  virtual void finalize() {};
49 
50  virtual void handle(const generic_page& page) = 0;
51 };
52 
53 class StoreHandler {
54 public:
55  virtual void finalize() {};
56 
57  virtual void handle(const StoreID&) = 0;
58 };
59 
60 #endif // __HANDLER_H
unique_ptr< ofstream > fileOutput
Definition: handler.h:43
STL namespace.
virtual void finalize()
Definition: handler.h:22
uint32_t StoreID
Definition: basics.h:47
A generic page view: any Zero page can be viewed as being of this type but it only exposes fields sha...
Definition: generic_page.h:121
reference_wrapper< ostream > hout
Definition: handler.h:41
virtual void finalize()
Definition: handler.h:55
Represents a transactional log record.
Definition: logrec.h:143
Handler()
Definition: handler.h:13
Definition: handler.h:46
Definition: handler.h:53
virtual ~Handler()
Definition: handler.h:16
void setFileOutput(string fpath)
Definition: handler.h:30
virtual void newFile(const char *)
Definition: handler.h:24
Definition: handler.h:11
virtual void finalize()
Definition: handler.h:48
virtual void initialize()
Definition: handler.h:18
Handler & operator=(const Handler &)=delete
virtual void invoke(logrec_t &r)=0
ostream & out()
Definition: handler.h:36