16 #ifndef INC_StdMeshLoaderDataStream
17 #define INC_StdMeshLoaderDataStream
25 const char *begin, *cursor, *end;
30 end = cursor + length;
37 bool AtEof()
const {
return cursor == end; }
40 void Seek(ptrdiff_t offset)
43 throw InsufficientData();
44 if (cursor - begin < -offset)
45 throw InsufficientData();
51 typename std::enable_if<std::is_pod<T>::value && !std::is_pointer<T>::value, T>
::type
55 throw InsufficientData();
57 std::memcpy(
reinterpret_cast<char*
>(&temp), cursor,
sizeof(T));
62 template<
class T>
typename std::enable_if<!std::is_pod<T>::value, T>
::type
71 void Peek(
void *dest,
size_t size)
const
74 throw InsufficientData();
75 std::memcpy(dest, cursor, size);
77 void Read(
void *dest,
size_t size)
84 template<>
inline bool DataStream::Peek<bool>()
const
87 throw InsufficientData();
88 return *cursor !=
'\0';
91 template<>
inline std::string DataStream::Peek<std::string>()
const
94 const char *terminator =
static_cast<const char*
>(std::memchr(cursor,
'\n', GetRemainingBytes()));
96 throw InsufficientData(
"Unterminated string");
97 return std::string(cursor, terminator);
100 template<>
inline std::string DataStream::Read<std::string>()
102 std::string temp = Peek<std::string>();
103 Seek(temp.size() + 1);
std::enable_if<!std::is_pod< T >::value, T >::type Peek() const
DataStream(const DataStream &)=delete
size_t GetRemainingBytes() const
void Read(void *dest, size_t size)
void Seek(ptrdiff_t offset)
DataStream & operator=(const DataStream &)=delete
DataStream(const char *src, size_t length)
void Peek(void *dest, size_t size) const
std::enable_if< std::is_pod< T >::value &&!std::is_pointer< T >::value, T >::type Peek() const