output_buffer operates like a smart c style array with a checking option. * Meant to be written to through [] with AUTO index or write(). * Size (current) counter increases when written to. Can be constructed with * zero length buffer but be sure to allocate before first use. * Don't use add write for a couple bytes, use [] instead, way less overhead. * * Not using vector because need che
| 137 | * write to the buffer bulk wise and retain correct size |
| 138 | */ |
| 139 | class output_buffer : public NoCheck { |
| 140 | uint current_; // current offset and elements in buffer |
| 141 | byte* buffer_; // storage for buffer |
| 142 | byte* end_; // end of storage marker |
| 143 | public: |
| 144 | // default |
| 145 | output_buffer(); |
| 146 | |
| 147 | // with allocate |
| 148 | explicit output_buffer(uint s); |
| 149 | |
| 150 | // with assign |
| 151 | output_buffer(uint s, const byte* t, uint len); |
| 152 | |
| 153 | ~output_buffer(); |
| 154 | |
| 155 | uint get_size() const; |
| 156 | |
| 157 | uint get_capacity() const; |
| 158 | |
| 159 | void set_current(uint c); |
| 160 | |
| 161 | // users can pass defualt zero length buffer and then allocate |
| 162 | void allocate(uint s); |
| 163 | |
| 164 | // for passing to reading functions when finished |
| 165 | const byte* get_buffer() const; |
| 166 | |
| 167 | // allow write access through [], update current |
| 168 | // user passes in AUTO as index for ease of use |
| 169 | byte& operator[](uint i); |
| 170 | |
| 171 | // end of output test |
| 172 | bool eof(); |
| 173 | |
| 174 | void write(const byte* t, uint s); |
| 175 | |
| 176 | private: |
| 177 | output_buffer(const output_buffer&); // hide copy |
| 178 | output_buffer& operator=(const output_buffer&); // and assign |
| 179 | }; |
| 180 | |
| 181 | |
| 182 |