diff --git a/doomsday/libdeng2/include/de/data/reader.h b/doomsday/libdeng2/include/de/data/reader.h index 124e8537f3..0ee140f2d8 100644 --- a/doomsday/libdeng2/include/de/data/reader.h +++ b/doomsday/libdeng2/include/de/data/reader.h @@ -24,6 +24,8 @@ #include "../IByteArray" #include "../ByteOrder" +#include + namespace de { class Block; @@ -46,6 +48,13 @@ class DENG2_PUBLIC Reader DENG2_ERROR(SeekError); public: + /** + * Copy constructor. + * + * @param other Reader. + */ + Reader(Reader const &other); + /** * Constructs a new reader. * @@ -165,6 +174,10 @@ class DENG2_PUBLIC Reader */ ByteOrder const &byteOrder() const; + inline void swap(Reader &other) { + std::swap(d, other.d); + } + private: struct Instance; Instance *d; diff --git a/doomsday/libdeng2/include/de/data/writer.h b/doomsday/libdeng2/include/de/data/writer.h index e9909cdf01..6aeea53167 100644 --- a/doomsday/libdeng2/include/de/data/writer.h +++ b/doomsday/libdeng2/include/de/data/writer.h @@ -24,6 +24,8 @@ #include "../IByteArray" #include "../ByteOrder" +#include // std::swap + namespace de { class IWritable; @@ -83,14 +85,21 @@ class DENG2_PUBLIC Writer Writer(ByteArrayFile &destination, ByteOrder const &byteOrder = littleEndianByteOrder, IByteArray::Offset offset = 0); + /** + * Copy constructor. + * + * @param other Writer. + */ + Writer(Writer const &other); + /** * Constructs a new writer that uses the current offset of @a other as its * zero offset. * * @param other Writer. - * @param byteOrder Byte order. Defaults to little-endian. + * @param byteOrder Byte order. */ - Writer(Writer const &other, ByteOrder const &byteOrder = littleEndianByteOrder); + Writer(Writer const &other, ByteOrder const &byteOrder); virtual ~Writer(); @@ -169,6 +178,10 @@ class DENG2_PUBLIC Writer */ void seek(dint count); + inline void swap(Writer &other) { + std::swap(d, other.d); + } + private: struct Instance; Instance *d; diff --git a/doomsday/libdeng2/include/de/vector.h b/doomsday/libdeng2/include/de/vector.h index 3b1db2a26e..d62c1554ee 100644 --- a/doomsday/libdeng2/include/de/vector.h +++ b/doomsday/libdeng2/include/de/vector.h @@ -29,338 +29,400 @@ #include #include -namespace de +namespace de { + +/** + * Template class for 2D vectors (points). The members are public for + * convenient access. The used value type must be serializable. + * + * Does not directly implement ISerializable to keep the size of the class + * at sizeof(Type) * 2 for array usage. + * + * @ingroup math + */ +template +class Vector2 { - /** - * Template class for 2D vectors (points). The members are public for - * convenient access. The used value type must be serializable. - * - * @ingroup math - */ - template - class Vector2 : public ISerializable - { - public: - typedef Type ValueType; - - public: - Vector2(Type a = 0, Type b = 0) : x(a), y(b) {} - Vector2(Type const *ab) : x(ab[0]), y(ab[1]) {} - - /// Conversion operator to a float vector. - operator Vector2 () const { - return Vector2(dfloat(x), dfloat(y)); - } - /// Conversion operator to a double vector. - operator Vector2 () const { - return Vector2(ddouble(x), ddouble(y)); - } - Vector2 operator + (Vector2 const &other) const { - return Vector2(x + other.x, y + other.y); - } - Vector2 operator - (Vector2 const &other) const { - return Vector2(x - other.x, y - other.y); - } - Vector2 operator - () const { - return Vector2(-x, -y); - } - Vector2 operator * (ddouble scalar) const { - return Vector2(Type(x * scalar), Type(y * scalar)); - } - Vector2 operator * (Vector2 const &other) const { - return Vector2(x * other.x, y * other.y); - } - Vector2 &operator += (Vector2 const &other) { - x += other.x; - y += other.y; - return *this; - } - Vector2 &operator -= (Vector2 const &other) { - x -= other.x; - y -= other.y; - return *this; - } - bool operator > (Vector2 const &other) const { - return x > other.x && y > other.y; - } - bool operator < (Vector2 const &other) const { - return x < other.x && y < other.y; - } - bool operator >= (Vector2 const &other) const { - return x >= other.x && y >= other.y; - } - bool operator <= (Vector2 const &other) const { - return x <= other.x && y <= other.y; - } - ddouble length() const { - return std::sqrt(ddouble(x*x + y*y)); - } - String asText() const { - String str; - QTextStream s(&str); - s << *this; - return str; - } - Vector2 min(Vector2 const &other) const { - return Vector2(de::min(x, other.x), de::min(y, other.y)); - } - Vector2 max(Vector2 const &other) const { - return Vector2(de::max(x, other.x), de::max(y, other.y)); - } - Type min() const { - return de::min(x, y); - } - Type max() const { - return de::max(x, y); - } - // Implements ISerializable. - void operator >> (Writer &to) const { - to << x << y; - } - void operator << (Reader &from) { - from >> x >> y; - } - - public: - Type x; - Type y; - }; - - template - QTextStream &operator << (QTextStream &os, Vector2 const &vec2) - { - os << "(" << vec2.x << ", " << vec2.y << ")"; - return os; - } - - /** - * Template class for 3D vectors (points). - * The members are public for convenient access. - * - * @ingroup math - */ - template - class Vector3 : public Vector2 - { - public: - Vector3(Type a = 0, Type b = 0, Type c = 0) : Vector2(a, b), z(c) {} - Vector3(Vector2 const &v2) : Vector2(v2), z(0) {} - Vector3(Type const *abc) : Vector2(abc), z(abc[2]) {} - - /// Conversion operator to a float vector. - operator Vector3 () const { - return Vector3(Vector2::x, Vector2::y, z); - } - /// Conversion operator to a double vector. - operator Vector3 () const { - return Vector3(Vector2::x, Vector2::y, z); - } - Vector3 operator + (Vector3 const &other) const { - return Vector3(Vector2::x + other.x, Vector2::y + other.y, z + other.z); - } - Vector3 operator - (Vector3 const &other) const { - return Vector3(Vector2::x - other.x, Vector2::y - other.y, z - other.z); - } - Vector3 operator - () const { - return Vector3(-Vector2::x, -Vector2::y, -z); - } - Vector3 operator * (ddouble scalar) const { - return Vector3(Type(Vector2::x * scalar), Type(Vector2::y * scalar), - Type(z * scalar)); - } - Vector3 operator * (Vector3 const &other) const { - return Vector3(Vector2::x * other.x, Vector2::y * other.y, z * other.z); - } - Vector3 &operator += (Vector3 const &other) { - Vector2::x += other.x; - Vector2::y += other.y; - z += other.z; - return *this; - } - Vector3 &operator -= (Vector3 const &other) { - Vector2::x -= other.x; - Vector2::y -= other.y; - z -= other.z; - return *this; - } - bool operator > (Vector3 const &other) const { - return Vector2::operator > (other) && z > other.z; - } - bool operator < (Vector3 const &other) const { - return Vector2::operator < (other) && z < other.z; - } - bool operator >= (Vector3 const &other) const { - return Vector2::operator >= (other) && z >= other.z; - } - bool operator <= (Vector3 const &other) const { - return Vector2::operator <= (other) && z <= other.z; - } - ddouble length() const { return std::sqrt(Vector2::x*Vector2::x + - Vector2::y*Vector2::y + z*z); } - String asText() const { - String str; - QTextStream os(&str); - os << *this; - return str; - } - Vector3 min(Vector3 const &other) const { - return Vector3(de::min(Vector2::x, other.x), de::min(Vector2::y, other.y), - de::min(z, other.z)); - } - Vector3 max(Vector3 const &other) const { - return Vector3(de::max(Vector2::x, other.x), de::max(Vector2::y, other.y), - de::max(z, other.z)); - } - Type min() const { - return de::min(z, Vector2::min()); - } - Type max() const { - return de::max(z, Vector2::max()); - } - // Implements ISerializable. - void operator >> (Writer &to) const { - Vector2::operator >> (to); - to << z; - } - void operator << (Reader &from) { - Vector2::operator << (from); - from >> z; - } - - public: - Type z; - }; - - template - QTextStream &operator << (QTextStream &os, Vector3 const &vec3) - { - os << "(" << vec3.x << ", " << vec3.y << ", " << vec3.z << ")"; - return os; - } - - /** - * Template class for 4D vectors. - * The members are public for convenient access. - * - * @ingroup math - */ - template - class Vector4 : public Vector3 - { - public: - Vector4(Type a = 0, Type b = 0, Type c = 0, Type d = 0) : Vector3(a, b, c), w(d) {} - Vector4(Vector3 const &v3) : Vector3(v3), w(0) {} - Vector4(Type const *abcd) : Vector3(abcd), w(abcd[3]) {} - - /// Conversion operator to a float vector. - operator Vector4 () const { - return Vector4(Vector3::x, Vector3::y, Vector3::z, w); - } - /// Conversion operator to a double vector. - operator Vector4 () const { - return Vector4(Vector3::x, Vector3::y, Vector3::z, w); - } - Vector4 operator + (Vector4 const &other) const { - return Vector4(Vector3::x + other.x, Vector3::y + other.y, - Vector3::z + other.z, w + other.w); - } - Vector4 operator - (Vector4 const &other) const { - return Vector4(Vector3::x - other.x, Vector3::y - other.y, - Vector3::z - other.z, w - other.w); - } - Vector4 operator - () const { - return Vector4(-Vector3::x, -Vector3::y, -Vector3::z, -w); - } - Vector4 operator * (ddouble scalar) const { - return Vector4(Type(Vector3::x * scalar), Type(Vector3::y * scalar), - Type(Vector3::z * scalar), Type(w * scalar)); - } - Vector4 operator * (Vector4 const &other) const { - return Vector4(Vector3::x * other.x, Vector3::y * other.y, - Vector3::z * other.z, w * other.w); - } - Vector4 &operator += (Vector4 const &other) { - Vector3::x += other.x; - Vector3::y += other.y; - Vector3::z += other.z; - w += other.w; - return *this; - } - Vector4 &operator -= (Vector4 const &other) { - Vector3::x -= other.x; - Vector3::y -= other.y; - Vector3::z -= other.z; - w -= other.w; - return *this; - } - bool operator > (Vector4 const &other) const { - return Vector3::operator > (other) && w > other.w; - } - bool operator < (Vector4 const &other) const { - return Vector3::operator < (other) && w < other.w; - } - bool operator >= (Vector4 const &other) const { - return Vector3::operator >= (other) && w >= other.w; - } - bool operator <= (Vector4 const &other) const { - return Vector3::operator <= (other) && w <= other.w; - } - String asText() const { - String str; - QTextStream os(&str); - os << *this; - return str; - } - Vector4 min(Vector4 const &other) const { - return Vector4(de::min(Vector3::x, other.x), de::min(Vector3::y, other.y), - de::min(Vector3::z, other.z), de::min(w, other.w)); - } - Vector4 max(Vector4 const &other) const { - return Vector4(de::max(Vector3::x, other.x), de::max(Vector3::y, other.y), - de::max(Vector3::z, other.z), de::max(w, other.w)); - } - Type min() const { - return de::min(w, Vector3::min()); - } - Type max() const { - return de::max(w, Vector3::max()); - } - // Implements ISerializable. - void operator >> (Writer &to) const { - Vector3::operator >> (to); - to << w; - } - void operator << (Reader &from) { - Vector3::operator << (from); - from >> w; - } - - public: - Type w; - }; - - template - QTextStream &operator << (QTextStream &os, Vector4 const &vec4) - { - os << "(" << vec4.x << ", " << vec4.y << ", " << vec4.z << ", " << vec4.w << ")"; - return os; - } - - //@{ - /// @ingroup types - typedef Vector2 Vector2i; ///< 2-component vector of integer values. - typedef Vector2 Vector2ui; ///< 2-component vector of unsigned integer values. - typedef Vector2 Vector2f; ///< 2-component vector of floating point values. - typedef Vector2 Vector2d; ///< 2-component vector of high-precision floating point values. - typedef Vector3 Vector3i; ///< 3-component vector of integer values. - typedef Vector3 Vector3ui; ///< 3-component vector of unsigned integer values. - typedef Vector3 Vector3f; ///< 3-component vector of floating point values. - typedef Vector3 Vector3d; ///< 3-component vector of high-precision floating point values. - typedef Vector4 Vector4i; ///< 4-component vector of integer values. - typedef Vector4 Vector4ui; ///< 4-component vector of unsigned integer values. - typedef Vector4 Vector4f; ///< 4-component vector of floating point values. - typedef Vector4 Vector4d; ///< 4-component vector of high-precision floating point values. - //@} +public: + typedef Type ValueType; + +public: + Vector2(Type a = 0, Type b = 0) : x(a), y(b) {} + Vector2(Type const *ab) : x(ab[0]), y(ab[1]) {} + + /// Conversion operator to a float vector. + operator Vector2 () const { + return Vector2(dfloat(x), dfloat(y)); + } + /// Conversion operator to a double vector. + operator Vector2 () const { + return Vector2(ddouble(x), ddouble(y)); + } + Vector2 operator + (Vector2 const &other) const { + return Vector2(x + other.x, y + other.y); + } + Vector2 operator - (Vector2 const &other) const { + return Vector2(x - other.x, y - other.y); + } + Vector2 operator - () const { + return Vector2(-x, -y); + } + Vector2 operator * (ddouble scalar) const { + return Vector2(Type(x * scalar), Type(y * scalar)); + } + Vector2 operator * (Vector2 const &other) const { + return Vector2(x * other.x, y * other.y); + } + Vector2 &operator += (Vector2 const &other) { + x += other.x; + y += other.y; + return *this; + } + Vector2 &operator -= (Vector2 const &other) { + x -= other.x; + y -= other.y; + return *this; + } + bool operator > (Vector2 const &other) const { + return x > other.x && y > other.y; + } + bool operator < (Vector2 const &other) const { + return x < other.x && y < other.y; + } + bool operator >= (Vector2 const &other) const { + return x >= other.x && y >= other.y; + } + bool operator <= (Vector2 const &other) const { + return x <= other.x && y <= other.y; + } + ddouble length() const { + return std::sqrt(ddouble(x*x + y*y)); + } + String asText() const { + String str; + QTextStream s(&str); + s << *this; + return str; + } + Vector2 min(Vector2 const &other) const { + return Vector2(de::min(x, other.x), de::min(y, other.y)); + } + Vector2 max(Vector2 const &other) const { + return Vector2(de::max(x, other.x), de::max(y, other.y)); + } + Type min() const { + return de::min(x, y); + } + Type max() const { + return de::max(x, y); + } + +public: + Type x; + Type y; +}; + +// Serialization of Vector2. +template +inline Writer &operator << (Writer &to, Vector2 const &vec2) { + to << vec2.x << vec2.y; + return to; } +template +inline void operator << (Writer const &to, Vector2 const &vec2) { + Writer w(to); + w << vec2.x << vec2.y; +} + +template +inline Reader &operator >> (Reader &from, Vector2 &vec2) { + from >> vec2.x >> vec2.y; + return from; +} + +template +inline void operator >> (Reader const &from, Vector2 &vec2) { + Reader r(from); + r >> vec2.x >> vec2.y; +} + +template +inline QTextStream &operator << (QTextStream &os, Vector2 const &vec2) { + os << "(" << vec2.x << ", " << vec2.y << ")"; + return os; +} + +/** + * Template class for 3D vectors (points). + * The members are public for convenient access. + * + * @ingroup math + */ +template +class Vector3 : public Vector2 +{ +public: + Vector3(Type a = 0, Type b = 0, Type c = 0) : Vector2(a, b), z(c) {} + Vector3(Vector2 const &v2) : Vector2(v2), z(0) {} + Vector3(Type const *abc) : Vector2(abc), z(abc[2]) {} + + /// Conversion operator to a float vector. + operator Vector3 () const { + return Vector3(Vector2::x, Vector2::y, z); + } + /// Conversion operator to a double vector. + operator Vector3 () const { + return Vector3(Vector2::x, Vector2::y, z); + } + Vector3 operator + (Vector3 const &other) const { + return Vector3(Vector2::x + other.x, Vector2::y + other.y, z + other.z); + } + Vector3 operator - (Vector3 const &other) const { + return Vector3(Vector2::x - other.x, Vector2::y - other.y, z - other.z); + } + Vector3 operator - () const { + return Vector3(-Vector2::x, -Vector2::y, -z); + } + Vector3 operator * (ddouble scalar) const { + return Vector3(Type(Vector2::x * scalar), Type(Vector2::y * scalar), + Type(z * scalar)); + } + Vector3 operator * (Vector3 const &other) const { + return Vector3(Vector2::x * other.x, Vector2::y * other.y, z * other.z); + } + Vector3 &operator += (Vector3 const &other) { + Vector2::x += other.x; + Vector2::y += other.y; + z += other.z; + return *this; + } + Vector3 &operator -= (Vector3 const &other) { + Vector2::x -= other.x; + Vector2::y -= other.y; + z -= other.z; + return *this; + } + bool operator > (Vector3 const &other) const { + return Vector2::operator > (other) && z > other.z; + } + bool operator < (Vector3 const &other) const { + return Vector2::operator < (other) && z < other.z; + } + bool operator >= (Vector3 const &other) const { + return Vector2::operator >= (other) && z >= other.z; + } + bool operator <= (Vector3 const &other) const { + return Vector2::operator <= (other) && z <= other.z; + } + ddouble length() const { return std::sqrt(Vector2::x*Vector2::x + + Vector2::y*Vector2::y + z*z); } + String asText() const { + String str; + QTextStream os(&str); + os << *this; + return str; + } + Vector3 min(Vector3 const &other) const { + return Vector3(de::min(Vector2::x, other.x), de::min(Vector2::y, other.y), + de::min(z, other.z)); + } + Vector3 max(Vector3 const &other) const { + return Vector3(de::max(Vector2::x, other.x), de::max(Vector2::y, other.y), + de::max(z, other.z)); + } + Type min() const { + return de::min(z, Vector2::min()); + } + Type max() const { + return de::max(z, Vector2::max()); + } + +public: + Type z; +}; + +// Serialization of Vector3. +template +inline Writer &operator << (Writer &to, Vector3 const &vec3) { + to << vec3.x << vec3.y << vec3.z; + return to; +} + +template +inline void operator << (Writer const &to, Vector3 const &vec3) { + Writer w(to); + w << vec3.x << vec3.y << vec3.z; +} + +template +inline Reader &operator >> (Reader &from, Vector3 &vec3) { + from >> vec3.x >> vec3.y >> vec3.z; + return from; +} + +template +inline void operator >> (Reader const &from, Vector3 &vec3) { + Reader r(from); + r >> vec3.x >> vec3.y >> vec3.z; +} + +template +QTextStream &operator << (QTextStream &os, Vector3 const &vec3) +{ + os << "(" << vec3.x << ", " << vec3.y << ", " << vec3.z << ")"; + return os; +} + +/** + * Template class for 4D vectors. + * The members are public for convenient access. + * + * @ingroup math + */ +template +class Vector4 : public Vector3 +{ +public: + Vector4(Type a = 0, Type b = 0, Type c = 0, Type d = 0) : Vector3(a, b, c), w(d) {} + Vector4(Vector3 const &v3) : Vector3(v3), w(0) {} + Vector4(Type const *abcd) : Vector3(abcd), w(abcd[3]) {} + + /// Conversion operator to a float vector. + operator Vector4 () const { + return Vector4(Vector3::x, Vector3::y, Vector3::z, w); + } + /// Conversion operator to a double vector. + operator Vector4 () const { + return Vector4(Vector3::x, Vector3::y, Vector3::z, w); + } + Vector4 operator + (Vector4 const &other) const { + return Vector4(Vector3::x + other.x, Vector3::y + other.y, + Vector3::z + other.z, w + other.w); + } + Vector4 operator - (Vector4 const &other) const { + return Vector4(Vector3::x - other.x, Vector3::y - other.y, + Vector3::z - other.z, w - other.w); + } + Vector4 operator - () const { + return Vector4(-Vector3::x, -Vector3::y, -Vector3::z, -w); + } + Vector4 operator * (ddouble scalar) const { + return Vector4(Type(Vector3::x * scalar), Type(Vector3::y * scalar), + Type(Vector3::z * scalar), Type(w * scalar)); + } + Vector4 operator * (Vector4 const &other) const { + return Vector4(Vector3::x * other.x, Vector3::y * other.y, + Vector3::z * other.z, w * other.w); + } + Vector4 &operator += (Vector4 const &other) { + Vector3::x += other.x; + Vector3::y += other.y; + Vector3::z += other.z; + w += other.w; + return *this; + } + Vector4 &operator -= (Vector4 const &other) { + Vector3::x -= other.x; + Vector3::y -= other.y; + Vector3::z -= other.z; + w -= other.w; + return *this; + } + bool operator > (Vector4 const &other) const { + return Vector3::operator > (other) && w > other.w; + } + bool operator < (Vector4 const &other) const { + return Vector3::operator < (other) && w < other.w; + } + bool operator >= (Vector4 const &other) const { + return Vector3::operator >= (other) && w >= other.w; + } + bool operator <= (Vector4 const &other) const { + return Vector3::operator <= (other) && w <= other.w; + } + String asText() const { + String str; + QTextStream os(&str); + os << *this; + return str; + } + Vector4 min(Vector4 const &other) const { + return Vector4(de::min(Vector3::x, other.x), de::min(Vector3::y, other.y), + de::min(Vector3::z, other.z), de::min(w, other.w)); + } + Vector4 max(Vector4 const &other) const { + return Vector4(de::max(Vector3::x, other.x), de::max(Vector3::y, other.y), + de::max(Vector3::z, other.z), de::max(w, other.w)); + } + Type min() const { + return de::min(w, Vector3::min()); + } + Type max() const { + return de::max(w, Vector3::max()); + } + // Implements ISerializable. + void operator >> (Writer &to) const { + Vector3::operator >> (to); + to << w; + } + void operator << (Reader &from) { + Vector3::operator << (from); + from >> w; + } + +public: + Type w; +}; + +// Serialization of Vector4. +template +inline Writer &operator << (Writer &to, Vector4 const &vec4) { + to << vec4.x << vec4.y << vec4.z << vec4.w; + return to; +} + +template +inline void operator << (Writer const &to, Vector4 const &vec4) { + Writer w(to); + w << vec4.x << vec4.y << vec4.z << vec4.w; +} + +template +inline Reader &operator >> (Reader &from, Vector4 &vec4) { + from >> vec4.x >> vec4.y >> vec4.z >> vec4.w; + return from; +} + +template +inline void operator >> (Reader const &from, Vector4 &vec4) { + Reader r(from); + r >> vec4.x >> vec4.y >> vec4.z >> vec4.w; +} + +template +QTextStream &operator << (QTextStream &os, Vector4 const &vec4) +{ + os << "(" << vec4.x << ", " << vec4.y << ", " << vec4.z << ", " << vec4.w << ")"; + return os; +} + +//@{ +/// @ingroup types +typedef Vector2 Vector2i; ///< 2-component vector of integer values. +typedef Vector2 Vector2ui; ///< 2-component vector of unsigned integer values. +typedef Vector2 Vector2f; ///< 2-component vector of floating point values. +typedef Vector2 Vector2d; ///< 2-component vector of high-precision floating point values. +typedef Vector3 Vector3i; ///< 3-component vector of integer values. +typedef Vector3 Vector3ui; ///< 3-component vector of unsigned integer values. +typedef Vector3 Vector3f; ///< 3-component vector of floating point values. +typedef Vector3 Vector3d; ///< 3-component vector of high-precision floating point values. +typedef Vector4 Vector4i; ///< 4-component vector of integer values. +typedef Vector4 Vector4ui; ///< 4-component vector of unsigned integer values. +typedef Vector4 Vector4f; ///< 4-component vector of floating point values. +typedef Vector4 Vector4d; ///< 4-component vector of high-precision floating point values. +//@} + +} // namespace de + #endif /* LIBDENG2_VECTOR_H */ diff --git a/doomsday/libdeng2/src/data/reader.cpp b/doomsday/libdeng2/src/data/reader.cpp index be56902acf..4961423edd 100644 --- a/doomsday/libdeng2/src/data/reader.cpp +++ b/doomsday/libdeng2/src/data/reader.cpp @@ -151,6 +151,9 @@ struct Reader::Instance } }; +Reader::Reader(const Reader &other) : d(new Instance(*other.d)) +{} + Reader::Reader(IByteArray const &source, ByteOrder const &byteOrder, IByteArray::Offset offset) : d(new Instance(byteOrder, &source, offset)) {} diff --git a/doomsday/libdeng2/src/data/writer.cpp b/doomsday/libdeng2/src/data/writer.cpp index 4250d568cc..0cb0c04c58 100644 --- a/doomsday/libdeng2/src/data/writer.cpp +++ b/doomsday/libdeng2/src/data/writer.cpp @@ -92,6 +92,10 @@ Writer::Writer(ByteArrayFile &destination, ByteOrder const &byteOrder, IByteArra : d(new Instance(byteOrder, static_cast(&destination), offset)) {} +Writer::Writer(Writer const &other) + : d(new Instance(*other.d, other.d->convert)) +{} + Writer::Writer(Writer const &other, ByteOrder const &byteOrder) : d(new Instance(*other.d, byteOrder)) {} diff --git a/doomsday/tests/vectors/main.cpp b/doomsday/tests/vectors/main.cpp index b2245bc19c..e5c33112f2 100644 --- a/doomsday/tests/vectors/main.cpp +++ b/doomsday/tests/vectors/main.cpp @@ -18,6 +18,9 @@ */ #include +#include +#include +#include #include using namespace de; @@ -74,6 +77,24 @@ int main(int, char **) qDebug() << "t > s: " << (t > s); qDebug() << "s < t: " << (s < t) << " <- first operand causes conversion to Vector2"; qDebug() << "t < s: " << (t < s); + + Vector2d u(3.1415926535, 3.33333333333333333333333); + qDebug() << "u:" << u.asText(); + Block block, block2; + //Writer writer(block); writer << u; + Writer(block) << u; + + Writer writer(block2); + writer << u; + + Vector2d w; + Reader(block) >> w; + + Vector2d y; + Reader reader(block2); + reader >> y; + qDebug() << "w:" << w.asText(); + qDebug() << "y:" << w.asText(); } catch(Error const &err) {