-
-
Save rightfold/f9f6bd70d00034c59528 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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