Skip to content

Instantly share code, notes, and snippets.

@rightfold
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rightfold/f9f6bd70d00034c59528 to your computer and use it in GitHub Desktop.
Save rightfold/f9f6bd70d00034c59528 to your computer and use it in GitHub Desktop.
#pragma once
#include <cstddef>
#include <vector>
namespace baka {
namespace io {
class memory_stream {
public:
memory_stream() : offset(0) { }
char const* write(char const* begin, char const* end) {
while (begin != end) {
if (data.size() - 1 == offset) {
data.push_back(*begin);
} else {
data[offset] = *begin;
}
++offset;
++begin;
}
return end;
}
char* read(char* begin, char* end) {
while (begin != end) {
if (data.size() - 1 == offset) {
return begin;
}
*begin = data[offset];
++offset;
++begin;
}
return end;
}
private:
std::vector<char> data;
std::size_t offset;
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment