diff options
Diffstat (limited to '')
-rw-r--r-- | src/stable/myriad.h | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/src/stable/myriad.h b/src/stable/myriad.h index 60c5a39..5accd1e 100644 --- a/src/stable/myriad.h +++ b/src/stable/myriad.h | |||
@@ -7,6 +7,8 @@ | |||
7 | #include "bu/array.h" | 7 | #include "bu/array.h" |
8 | #include "bu/hash.h" | 8 | #include "bu/hash.h" |
9 | 9 | ||
10 | #include "bu/bitstring.h" | ||
11 | |||
10 | namespace Bu | 12 | namespace Bu |
11 | { | 13 | { |
12 | class MyriadStream; | 14 | class MyriadStream; |
@@ -29,10 +31,20 @@ namespace Bu | |||
29 | }; | 31 | }; |
30 | subExceptionDeclEnd(); | 32 | subExceptionDeclEnd(); |
31 | 33 | ||
34 | /** | ||
35 | * Myriad Stream Multiplexer. This is a system that allows you to store | ||
36 | * many streams within a single backing stream. This is great for databases, | ||
37 | * caching, etc. It's fairly lightweight, and allows all streams to grow | ||
38 | * dynamically using a block-allocation scheme. This is used extensively | ||
39 | * by the caching system and MyriadFs as well as other systems within | ||
40 | * libbu++. | ||
41 | */ | ||
32 | class Myriad | 42 | class Myriad |
33 | { | 43 | { |
34 | public: | 44 | public: |
35 | typedef int32_t StreamId; | 45 | typedef int32_t StreamId; |
46 | typedef Bu::Array<StreamId> StreamIdArray; | ||
47 | typedef Bu::List<StreamId> StreamIdList; | ||
36 | enum Mode : int32_t { | 48 | enum Mode : int32_t { |
37 | None = 0x00, | 49 | None = 0x00, |
38 | 50 | ||
@@ -43,7 +55,7 @@ namespace Bu | |||
43 | Truncate = 0x08, ///< Truncate file if it does exist | 55 | Truncate = 0x08, ///< Truncate file if it does exist |
44 | Append = 0x10, ///< Start writing at end of file | 56 | Append = 0x10, ///< Start writing at end of file |
45 | //NonBlock = 0x20, ///< Open file in non-blocking mode | 57 | //NonBlock = 0x20, ///< Open file in non-blocking mode |
46 | Exclusive = 0x44, ///< Create file, if it exists then fail | 58 | Exclusive = 0x40, ///< Create file, if it exists then fail |
47 | 59 | ||
48 | // Helpful mixes | 60 | // Helpful mixes |
49 | ReadWrite = 0x03, ///< Open for reading and writing | 61 | ReadWrite = 0x03, ///< Open for reading and writing |
@@ -53,8 +65,9 @@ namespace Bu | |||
53 | 65 | ||
54 | public: | 66 | public: |
55 | /** | 67 | /** |
56 | * Open existing Myriad stream, or initialize a new one if it doesn't | 68 | * Open existing Myriad container, or initialize a new one if the |
57 | * exist. | 69 | * backing stream is empty. If other data is already in the provided |
70 | * backing stream an error is thrown. | ||
58 | * | 71 | * |
59 | * Myriad format V0 | 72 | * Myriad format V0 |
60 | * 0 - 3: Myriad_MAGIC_CODE (0ad3fa84) | 73 | * 0 - 3: Myriad_MAGIC_CODE (0ad3fa84) |
@@ -73,8 +86,32 @@ namespace Bu | |||
73 | int32_t iPreallocateBlocks=-1 ); | 86 | int32_t iPreallocateBlocks=-1 ); |
74 | virtual ~Myriad(); | 87 | virtual ~Myriad(); |
75 | 88 | ||
89 | /** | ||
90 | * Creates a new stream open in the specified eMode and, optionally, | ||
91 | * preallocates the specificed amount of space. The stream is zero | ||
92 | * bytes even if space is preallocated. The open stream is returned, | ||
93 | * ready for use. Use this if you don't care what the id is of the | ||
94 | * newly created stream. | ||
95 | */ | ||
76 | MyriadStream create( Mode eMode, int32_t iPreallocateBytes=-1 ); | 96 | MyriadStream create( Mode eMode, int32_t iPreallocateBytes=-1 ); |
97 | |||
98 | /** | ||
99 | * Open an existing stream or create a new stream with the specified | ||
100 | * id (iStream) with the specified eMode. This respects the normal file | ||
101 | * modes, see Bu::Myriad::Mode for details. | ||
102 | */ | ||
77 | MyriadStream open( StreamId iStream, Mode eMode ); | 103 | MyriadStream open( StreamId iStream, Mode eMode ); |
104 | |||
105 | /** | ||
106 | * Allocate a new stream but do not open it, just ensure it exists and | ||
107 | * return the id of the newly allocated stream. | ||
108 | */ | ||
109 | StreamId allocate(); | ||
110 | |||
111 | /** | ||
112 | * Erase the stream specified by iStream. This only can work when the | ||
113 | * stream is not open at the moment. | ||
114 | */ | ||
78 | void erase( StreamId iStream ); | 115 | void erase( StreamId iStream ); |
79 | void setSize( StreamId iStream, int32_t iNewSize ); | 116 | void setSize( StreamId iStream, int32_t iNewSize ); |
80 | int32_t getSize( StreamId iStream ) const; | 117 | int32_t getSize( StreamId iStream ) const; |
@@ -87,6 +124,16 @@ namespace Bu | |||
87 | int32_t getTotalStreams() const; | 124 | int32_t getTotalStreams() const; |
88 | int32_t getTotalUsedBytes() const; | 125 | int32_t getTotalUsedBytes() const; |
89 | int32_t getTotalUnusedBytes( int32_t iAssumeBlockSize=-1 ) const; | 126 | int32_t getTotalUnusedBytes( int32_t iAssumeBlockSize=-1 ) const; |
127 | Bu::BitString buildBlockUseMap() const; | ||
128 | StreamIdArray buildBlockMap() const; | ||
129 | |||
130 | /** | ||
131 | * Lists all stream ids that you are allowed to open. Technically there | ||
132 | * is always a zero stream, but it is used by Myriad for stream/block | ||
133 | * accounting. It works like a normal stream but you should not open | ||
134 | * it. | ||
135 | */ | ||
136 | StreamIdList getStreamList() const; | ||
90 | 137 | ||
91 | /** | 138 | /** |
92 | * Flush all caches to the backing stream, write all structural and | 139 | * Flush all caches to the backing stream, write all structural and |