00001 #ifndef DV_UTIL_CHARRAYSTREAM_H
00002 #define DV_UTIL_CHARRAYSTREAM_H
00003
00004
00005 #include <iostream>
00006
00007 namespace Dv {
00008 namespace Util {
00009
00010
00011
00012
00013
00014
00015 class charraystreambuf: public std::streambuf {
00016 public:
00017 explicit charraystreambuf(const char* begin, size_t size) {
00018 setg(const_cast<char*>(begin), const_cast<char*>(begin),
00019 const_cast<char*>(begin+size));
00020 setp(0,0);
00021 }
00022 virtual ~charraystreambuf() {}
00023 };
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 class charraystream: public std::istream {
00039 public:
00040
00041
00042
00043
00044 charraystream(const char* begin, size_t size): std::istream(&buf), buf(begin,size) {
00045 std::istream::rdbuf(&buf);
00046 }
00047
00048
00049
00050 std::streambuf* rdbuf() const { return const_cast<charraystreambuf*>(&buf); }
00051 private:
00052 charraystreambuf buf;
00053 };
00054 }
00055 }
00056 #endif