aboutsummaryrefslogtreecommitdiff
path: root/src/stable/myriad.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/stable/myriad.h')
-rw-r--r--src/stable/myriad.h49
1 files changed, 46 insertions, 3 deletions
diff --git a/src/stable/myriad.h b/src/stable/myriad.h
index 6168aa2..5accd1e 100644
--- a/src/stable/myriad.h
+++ b/src/stable/myriad.h
@@ -31,10 +31,20 @@ namespace Bu
31 }; 31 };
32 subExceptionDeclEnd(); 32 subExceptionDeclEnd();
33 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 */
34 class Myriad 42 class Myriad
35 { 43 {
36 public: 44 public:
37 typedef int32_t StreamId; 45 typedef int32_t StreamId;
46 typedef Bu::Array<StreamId> StreamIdArray;
47 typedef Bu::List<StreamId> StreamIdList;
38 enum Mode : int32_t { 48 enum Mode : int32_t {
39 None = 0x00, 49 None = 0x00,
40 50
@@ -55,8 +65,9 @@ namespace Bu
55 65
56 public: 66 public:
57 /** 67 /**
58 * 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
59 * exist. 69 * backing stream is empty. If other data is already in the provided
70 * backing stream an error is thrown.
60 * 71 *
61 * Myriad format V0 72 * Myriad format V0
62 * 0 - 3: Myriad_MAGIC_CODE (0ad3fa84) 73 * 0 - 3: Myriad_MAGIC_CODE (0ad3fa84)
@@ -75,8 +86,32 @@ namespace Bu
75 int32_t iPreallocateBlocks=-1 ); 86 int32_t iPreallocateBlocks=-1 );
76 virtual ~Myriad(); 87 virtual ~Myriad();
77 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 */
78 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 */
79 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 */
80 void erase( StreamId iStream ); 115 void erase( StreamId iStream );
81 void setSize( StreamId iStream, int32_t iNewSize ); 116 void setSize( StreamId iStream, int32_t iNewSize );
82 int32_t getSize( StreamId iStream ) const; 117 int32_t getSize( StreamId iStream ) const;
@@ -90,7 +125,15 @@ namespace Bu
90 int32_t getTotalUsedBytes() const; 125 int32_t getTotalUsedBytes() const;
91 int32_t getTotalUnusedBytes( int32_t iAssumeBlockSize=-1 ) const; 126 int32_t getTotalUnusedBytes( int32_t iAssumeBlockSize=-1 ) const;
92 Bu::BitString buildBlockUseMap() const; 127 Bu::BitString buildBlockUseMap() const;
93 Bu::Array<int32_t> buildBlockMap() 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;
94 137
95 /** 138 /**
96 * Flush all caches to the backing stream, write all structural and 139 * Flush all caches to the backing stream, write all structural and