summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/angle/src/libGLESv2/BinaryStream.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/angle/src/libGLESv2/BinaryStream.h')
-rw-r--r--src/3rdparty/angle/src/libGLESv2/BinaryStream.h118
1 files changed, 76 insertions, 42 deletions
diff --git a/src/3rdparty/angle/src/libGLESv2/BinaryStream.h b/src/3rdparty/angle/src/libGLESv2/BinaryStream.h
index 21c2f86ce8..1cbfc6751d 100644
--- a/src/3rdparty/angle/src/libGLESv2/BinaryStream.h
+++ b/src/3rdparty/angle/src/libGLESv2/BinaryStream.h
@@ -10,6 +10,7 @@
#define LIBGLESV2_BINARYSTREAM_H_
#include "common/angleutils.h"
+#include "common/mathutil.h"
namespace gl
{
@@ -25,42 +26,49 @@ class BinaryInputStream
mLength = length;
}
- template <typename T>
- void read(T *v, size_t num)
+ // readInt will generate an error for bool types
+ template <class IntT>
+ IntT readInt()
{
- union
- {
- T dummy; // Compilation error for non-trivial types
- } dummy;
- (void) dummy;
+ int value;
+ read(&value);
+ return static_cast<IntT>(value);
+ }
- if (mError)
- {
- return;
- }
+ template <class IntT>
+ void readInt(IntT *outValue)
+ {
+ *outValue = readInt<IntT>();
+ }
- size_t length = num * sizeof(T);
+ bool readBool()
+ {
+ int value;
+ read(&value);
+ return (value > 0);
+ }
- if (mOffset + length > mLength)
- {
- mError = true;
- return;
- }
+ void readBool(bool *outValue)
+ {
+ *outValue = readBool();
+ }
- memcpy(v, mData + mOffset, length);
- mOffset += length;
+ void readBytes(unsigned char outArray[], size_t count)
+ {
+ read<unsigned char>(outArray, count);
}
- template <typename T>
- void read(T * v)
+ std::string readString()
{
- read(v, 1);
+ std::string outString;
+ readString(&outString);
+ return outString;
}
- void read(std::string *v)
+ void readString(std::string *v)
{
size_t length;
- read(&length);
+ readInt(&length);
if (mError)
{
@@ -109,6 +117,30 @@ class BinaryInputStream
size_t mOffset;
const char *mData;
size_t mLength;
+
+ template <typename T>
+ void read(T *v, size_t num)
+ {
+ META_ASSERT(std::is_fundamental<T>::value);
+
+ size_t length = num * sizeof(T);
+
+ if (mOffset + length > mLength)
+ {
+ mError = true;
+ return;
+ }
+
+ memcpy(v, mData + mOffset, length);
+ mOffset += length;
+ }
+
+ template <typename T>
+ void read(T *v)
+ {
+ read(v, 1);
+ }
+
};
class BinaryOutputStream
@@ -118,31 +150,24 @@ class BinaryOutputStream
{
}
- template <typename T>
- void write(const T *v, size_t num)
+ // writeInt also handles bool types
+ template <class IntT>
+ void writeInt(IntT param)
{
- union
- {
- T dummy; // Compilation error for non-trivial types
- } dummy;
- (void) dummy;
-
- const char *asBytes = reinterpret_cast<const char*>(v);
- mData.insert(mData.end(), asBytes, asBytes + num * sizeof(T));
+ ASSERT(rx::IsIntegerCastSafe<int>(param));
+ int intValue = static_cast<int>(param);
+ write(&intValue, 1);
}
- template <typename T>
- void write(const T &v)
+ void writeString(const std::string &v)
{
- write(&v, 1);
+ writeInt(v.length());
+ write(v.c_str(), v.length());
}
- void write(const std::string &v)
+ void writeBytes(const unsigned char *bytes, size_t count)
{
- size_t length = v.length();
- write(length);
-
- write(v.c_str(), length);
+ write(bytes, count);
}
size_t length() const
@@ -158,6 +183,15 @@ class BinaryOutputStream
private:
DISALLOW_COPY_AND_ASSIGN(BinaryOutputStream);
std::vector<char> mData;
+
+ template <typename T>
+ void write(const T *v, size_t num)
+ {
+ META_ASSERT(std::is_fundamental<T>::value);
+ const char *asBytes = reinterpret_cast<const char*>(v);
+ mData.insert(mData.end(), asBytes, asBytes + num * sizeof(T));
+ }
+
};
}