1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (c) 2019, Nefelus Inc
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:
9 //
10 // * Redistributions of source code must retain the above copyright notice, this
11 //   list of conditions and the following disclaimer.
12 //
13 // * Redistributions in binary form must reproduce the above copyright notice,
14 //   this list of conditions and the following disclaimer in the documentation
15 //   and/or other materials provided with the distribution.
16 //
17 // * Neither the name of the copyright holder nor the names of its
18 //   contributors may be used to endorse or promote products derived from
19 //   this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 // POSSIBILITY OF SUCH DAMAGE.
32 
33 #pragma once
34 
35 #include "dbPagedVector.h"
36 #include "odb.h"
37 
38 namespace odb {
39 
40 class dbIStream;
41 class dbOStream;
42 
43 class dbJournalLog
44 {
45   dbPagedVector<unsigned char> _data;
46   int _idx;
47   int _debug;
48 
next()49   unsigned char next() { return _data[_idx++]; }
50 
51  public:
52   dbJournalLog();
53   ~dbJournalLog();
54 
clear()55   void clear()
56   {
57     _data.clear();
58     _idx = 0;
59   }
60 
empty()61   bool empty() { return _data.size() == 0; }
62 
idx()63   uint idx() { return _idx; }
size()64   uint size() { return _data.size(); }
65   void push(bool value);
66   void push(char value);
67   void push(unsigned char value);
68   void push(int value);
69   void push(unsigned int value);
70   void push(float value);
71   void push(double value);
72   void push(const char* value);
73 
begin()74   void begin() { _idx = 0; }
end()75   bool end() { return _idx == (int) _data.size(); }
set(uint idx)76   void set(uint idx) { _idx = idx; }
77 
78   void pop(bool& value);
79   void pop(char& value);
80   void pop(unsigned char& value);
81   void pop(int& value);
82   void pop(unsigned int& value);
83   void pop(float& value);
84   void pop(double& value);
85   void pop(char*& value);
86   void pop(std::string& value);
87   friend dbIStream& operator>>(dbIStream& stream, dbJournalLog& log);
88   friend dbOStream& operator<<(dbOStream& stream, const dbJournalLog& log);
89 };
90 
91 }  // namespace odb
92