-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBlock.h
74 lines (61 loc) · 1.58 KB
/
Block.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* File: Block.h
* Author: Tobias Fleig <tobifleig@gmail.com>
*
* Created on August 16, 2015, 3:54 PM
*/
#ifndef SDI4FS_BLOCK_H
#define SDI4FS_BLOCK_H
#include <iostream>
#include <cstdint>
#include "StreamSelectorHeader.inc"
namespace SDI4FS {
/**
* Represents a single Block on disk.
* Superclass for all other Blocks, holds common values (id, last write time).
*/
class Block {
public:
/**
* Creates a block by reading contents from the stream.
* Will read up to SDI4FS_BLOCK_SIZE bytes from the stream.
* The caller must call seekg beforehand.
* @param input the stream to read from
*/
Block(STREAM &input);
/**
* Creates a new Block with the given id.
* @param id new unique id for this block
*/
Block(uint32_t id);
virtual ~Block();
/**
* Returns the unique id of this block.
* @return the id of this block
*/
uint32_t getId();
/**
* Returns the last write time of this block.
* @return UNIX-timestamp, last write time of this block
*/
uint32_t getLastWriteTime();
/**
* Writes disk block to disk.
* Writes up to SDI4FS_BLOCK_SIZE bytes.
* Caller must call seekp beforehand.
* Subclasses should override this, but still call Superclass::save().
* @param output the stream to write into
*/
virtual void save(STREAM &output);
private:
/**
* Unique id of this block.
*/
uint32_t id;
/**
* UNIX-timestamp, last time this block was written.
*/
uint32_t lastWriteTime;
};
} // SDI4FS
#endif // SDI4FS_BLOCK_H