Merge pull request #37 from libAthena/atdna-atvec

Implement atVec*d for atdna
This commit is contained in:
Phillip 2015-10-15 15:44:58 -07:00
commit 25de226e65
4 changed files with 548 additions and 20 deletions

View File

@ -1,4 +1,5 @@
#include <stdio.h> #include <stdio.h>
#include <iostream>
#include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTConsumer.h"
#include "clang/AST/RecursiveASTVisitor.h" #include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/CompilerInstance.h"
@ -218,15 +219,31 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor>
if (vType->isVectorType()) if (vType->isVectorType())
{ {
const clang::BuiltinType* eType = (clang::BuiltinType*)vType->getElementType().getTypePtr(); const clang::BuiltinType* eType = (clang::BuiltinType*)vType->getElementType().getTypePtr();
const uint64_t width = context.getTypeInfo(eType).Width;
if (!eType->isBuiltinType() || !eType->isFloatingPoint() || if (!eType->isBuiltinType() || !eType->isFloatingPoint() ||
context.getTypeInfo(eType).Width != 32) (width != 32 && width != 64))
continue; continue;
if (vType->getNumElements() == 2) if (vType->getNumElements() == 2)
{
if (width == 32)
return ATHENA_DNA_WRITER ".writeVec2f" + funcPrefix + "(" + fieldName + ");"; return ATHENA_DNA_WRITER ".writeVec2f" + funcPrefix + "(" + fieldName + ");";
else if (width == 64)
return ATHENA_DNA_WRITER ".writeVec2d" + funcPrefix + "(" + fieldName + ");";
}
else if (vType->getNumElements() == 3) else if (vType->getNumElements() == 3)
{
if (width == 32)
return ATHENA_DNA_WRITER ".writeVec3f" + funcPrefix + "(" + fieldName + ");"; return ATHENA_DNA_WRITER ".writeVec3f" + funcPrefix + "(" + fieldName + ");";
else if (width == 64)
return ATHENA_DNA_WRITER ".writeVec3d" + funcPrefix + "(" + fieldName + ");";
}
else if (vType->getNumElements() == 4) else if (vType->getNumElements() == 4)
{
if (width == 32)
return ATHENA_DNA_WRITER ".writeVec4f" + funcPrefix + "(" + fieldName + ");"; return ATHENA_DNA_WRITER ".writeVec4f" + funcPrefix + "(" + fieldName + ");";
else if (width == 64)
return ATHENA_DNA_WRITER ".writeVec4d" + funcPrefix + "(" + fieldName + ");";
}
} }
} }
} }
@ -323,15 +340,31 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor>
if (vType->isVectorType()) if (vType->isVectorType())
{ {
const clang::BuiltinType* eType = (clang::BuiltinType*)vType->getElementType().getTypePtr(); const clang::BuiltinType* eType = (clang::BuiltinType*)vType->getElementType().getTypePtr();
const uint64_t width = context.getTypeInfo(eType).Width;
if (!eType->isBuiltinType() || !eType->isFloatingPoint() || if (!eType->isBuiltinType() || !eType->isFloatingPoint() ||
context.getTypeInfo(eType).Width != 32) (width != 32 && width != 64))
continue; continue;
if (vType->getNumElements() == 2) if (vType->getNumElements() == 2)
{
if (width == 32)
return ATHENA_DNA_READER ".readVec2f" + funcPrefix + "()"; return ATHENA_DNA_READER ".readVec2f" + funcPrefix + "()";
else if (width == 64)
return ATHENA_DNA_READER ".readVec2d" + funcPrefix + "()";
}
else if (vType->getNumElements() == 3) else if (vType->getNumElements() == 3)
{
if (width == 32)
return ATHENA_DNA_READER ".readVec3f" + funcPrefix + "()"; return ATHENA_DNA_READER ".readVec3f" + funcPrefix + "()";
else if (width == 64)
return ATHENA_DNA_READER ".readVec3d" + funcPrefix + "()";
}
else if (vType->getNumElements() == 4) else if (vType->getNumElements() == 4)
{
if (width == 32)
return ATHENA_DNA_READER ".readVec4f" + funcPrefix + "()"; return ATHENA_DNA_READER ".readVec4f" + funcPrefix + "()";
else if (width == 64)
return ATHENA_DNA_READER ".readVec4d" + funcPrefix + "()";
}
} }
} }
} }
@ -436,15 +469,31 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor>
if (vType->isVectorType()) if (vType->isVectorType())
{ {
const clang::BuiltinType* eType = (clang::BuiltinType*)vType->getElementType().getTypePtr(); const clang::BuiltinType* eType = (clang::BuiltinType*)vType->getElementType().getTypePtr();
const uint64_t width = context.getTypeInfo(eType).Width;
if (!eType->isBuiltinType() || !eType->isFloatingPoint() || if (!eType->isBuiltinType() || !eType->isFloatingPoint() ||
context.getTypeInfo(eType).Width != 32) (width != 32 && width != 64))
continue; continue;
if (vType->getNumElements() == 2) if (vType->getNumElements() == 2)
{
if (width == 32)
return ATHENA_YAML_WRITER ".writeVec2f(\"" + bareFieldName + "\", " + fieldName + ");"; return ATHENA_YAML_WRITER ".writeVec2f(\"" + bareFieldName + "\", " + fieldName + ");";
else if (width == 64)
return ATHENA_YAML_WRITER ".writeVec2d(\"" + bareFieldName + "\", " + fieldName + ");";
}
else if (vType->getNumElements() == 3) else if (vType->getNumElements() == 3)
{
if (width == 32)
return ATHENA_YAML_WRITER ".writeVec3f(\"" + bareFieldName + "\", " + fieldName + ");"; return ATHENA_YAML_WRITER ".writeVec3f(\"" + bareFieldName + "\", " + fieldName + ");";
else if (width == 64)
return ATHENA_YAML_WRITER ".writeVec3d(\"" + bareFieldName + "\", " + fieldName + ");";
}
else if (vType->getNumElements() == 4) else if (vType->getNumElements() == 4)
{
if (width == 32)
return ATHENA_YAML_WRITER ".writeVec4f(\"" + bareFieldName + "\", " + fieldName + ");"; return ATHENA_YAML_WRITER ".writeVec4f(\"" + bareFieldName + "\", " + fieldName + ");";
else if (width == 64)
return ATHENA_YAML_WRITER ".writeVec4d(\"" + bareFieldName + "\", " + fieldName + ");";
}
} }
} }
} }
@ -541,15 +590,31 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor>
if (vType->isVectorType()) if (vType->isVectorType())
{ {
const clang::BuiltinType* eType = (clang::BuiltinType*)vType->getElementType().getTypePtr(); const clang::BuiltinType* eType = (clang::BuiltinType*)vType->getElementType().getTypePtr();
const uint64_t width = context.getTypeInfo(eType).Width;
if (!eType->isBuiltinType() || !eType->isFloatingPoint() || if (!eType->isBuiltinType() || !eType->isFloatingPoint() ||
context.getTypeInfo(eType).Width != 32) (width != 32 && width != 64))
continue; continue;
if (vType->getNumElements() == 2) if (vType->getNumElements() == 2)
{
if (width == 32)
return ATHENA_YAML_READER ".readVec2f(\"" + bareFieldName + "\")"; return ATHENA_YAML_READER ".readVec2f(\"" + bareFieldName + "\")";
else if (width == 64)
return ATHENA_YAML_READER ".readVec2d(\"" + bareFieldName + "\")";
}
else if (vType->getNumElements() == 3) else if (vType->getNumElements() == 3)
{
if (width == 32)
return ATHENA_YAML_READER ".readVec3f(\"" + bareFieldName + "\")"; return ATHENA_YAML_READER ".readVec3f(\"" + bareFieldName + "\")";
else if (width == 64)
return ATHENA_YAML_READER ".readVec3d(\"" + bareFieldName + "\")";
}
else if (vType->getNumElements() == 4) else if (vType->getNumElements() == 4)
{
if (width == 32)
return ATHENA_YAML_READER ".readVec4f(\"" + bareFieldName + "\")"; return ATHENA_YAML_READER ".readVec4f(\"" + bareFieldName + "\")";
else if (width == 64)
return ATHENA_YAML_READER ".readVec4d(\"" + bareFieldName + "\")";
}
} }
} }
} }

View File

@ -263,7 +263,14 @@ inline RETURNTYPE NodeToVec(const YAMLNode* node)
{ {
YAMLNode* snode = it->get(); YAMLNode* snode = it->get();
if (snode->m_type == YAML_SCALAR_NODE) if (snode->m_type == YAML_SCALAR_NODE)
{
if (std::is_same<RETURNTYPE, atVec2d>::value ||
std::is_same<RETURNTYPE, atVec3d>::value ||
std::is_same<RETURNTYPE, atVec4d>::value)
retval.vec[i] = NodeToVal<double>(snode);
else
retval.vec[i] = NodeToVal<float>(snode); retval.vec[i] = NodeToVal<float>(snode);
}
else else
retval.vec[i] = 0.0; retval.vec[i] = 0.0;
} }
@ -336,6 +343,72 @@ inline std::unique_ptr<YAMLNode> ValToNode(const atVec4f& val)
return std::unique_ptr<YAMLNode>(ret); return std::unique_ptr<YAMLNode>(ret);
} }
template <>
inline atVec2d NodeToVal(const YAMLNode* node)
{
return NodeToVec<atVec2d>(node);
}
template <>
inline std::unique_ptr<YAMLNode> ValToNode(const atVec2d& val)
{
YAMLNode* ret = new YAMLNode(YAML_SEQUENCE_NODE);
ret->m_seqChildren.reserve(2);
for (size_t i=0 ; i<2 ; ++i)
{
char str[64];
snprintf(str, 64, "%f", val.vec[i]);
YAMLNode* comp = new YAMLNode(YAML_SCALAR_NODE);
comp->m_scalarString = str;
ret->m_seqChildren.emplace_back(comp);
}
return std::unique_ptr<YAMLNode>(ret);
}
template <>
inline atVec3d NodeToVal(const YAMLNode* node)
{
return NodeToVec<atVec3d>(node);
}
template <>
inline std::unique_ptr<YAMLNode> ValToNode(const atVec3d& val)
{
YAMLNode* ret = new YAMLNode(YAML_SEQUENCE_NODE);
ret->m_seqChildren.reserve(3);
for (size_t i=0 ; i<3 ; ++i)
{
char str[64];
snprintf(str, 64, "%f", val.vec[i]);
YAMLNode* comp = new YAMLNode(YAML_SCALAR_NODE);
comp->m_scalarString = str;
ret->m_seqChildren.emplace_back(comp);
}
return std::unique_ptr<YAMLNode>(ret);
}
template <>
inline atVec4d NodeToVal(const YAMLNode* node)
{
return NodeToVec<atVec4d>(node);
}
template <>
inline std::unique_ptr<YAMLNode> ValToNode(const atVec4d& val)
{
YAMLNode* ret = new YAMLNode(YAML_SEQUENCE_NODE);
ret->m_seqChildren.reserve(4);
for (size_t i=0 ; i<4 ; ++i)
{
char str[64];
snprintf(str, 64, "%f", val.vec[i]);
YAMLNode* comp = new YAMLNode(YAML_SCALAR_NODE);
comp->m_scalarString = str;
ret->m_seqChildren.emplace_back(comp);
}
return std::unique_ptr<YAMLNode>(ret);
}
template <> template <>
inline std::unique_ptr<atUint8[]> NodeToVal(const YAMLNode* node) inline std::unique_ptr<atUint8[]> NodeToVal(const YAMLNode* node)
{ {
@ -643,12 +716,26 @@ public:
{ {
return readVal<atVec3f>(name); return readVal<atVec3f>(name);
} }
inline atVec4f readVec4f(const char* name) inline atVec4f readVec4f(const char* name)
{ {
return readVal<atVec4f>(name); return readVal<atVec4f>(name);
} }
inline atVec2d readVec2d(const char* name)
{
return readVal<atVec2d>(name);
}
inline atVec3d readVec3d(const char* name)
{
return readVal<atVec3d>(name);
}
inline atVec4d readVec4d(const char* name)
{
return readVal<atVec4d>(name);
}
inline std::unique_ptr<atUint8[]> readUBytes(const char* name) inline std::unique_ptr<atUint8[]> readUBytes(const char* name)
{ {
return readVal<std::unique_ptr<atUint8[]>>(name); return readVal<std::unique_ptr<atUint8[]>>(name);
@ -751,7 +838,10 @@ public:
typename std::enable_if<!std::is_arithmetic<T>::value && typename std::enable_if<!std::is_arithmetic<T>::value &&
!std::is_same<T, atVec2f>::value && !std::is_same<T, atVec2f>::value &&
!std::is_same<T, atVec3f>::value && !std::is_same<T, atVec3f>::value &&
!std::is_same<T, atVec4f>::value>::type* = 0) !std::is_same<T, atVec4f>::value &&
!std::is_same<T, atVec2d>::value &&
!std::is_same<T, atVec3d>::value &&
!std::is_same<T, atVec4d>::value>::type* = 0)
{ {
enterSubVector(name); enterSubVector(name);
for (const T& item : vector) for (const T& item : vector)
@ -768,7 +858,10 @@ public:
typename std::enable_if<std::is_arithmetic<T>::value || typename std::enable_if<std::is_arithmetic<T>::value ||
std::is_same<T, atVec2f>::value || std::is_same<T, atVec2f>::value ||
std::is_same<T, atVec3f>::value || std::is_same<T, atVec3f>::value ||
std::is_same<T, atVec4f>::value>::type* = 0) std::is_same<T, atVec4f>::value ||
std::is_same<T, atVec2d>::value ||
std::is_same<T, atVec3d>::value ||
std::is_same<T, atVec4d>::value>::type* = 0)
{ {
enterSubVector(name); enterSubVector(name);
for (T item : vector) for (T item : vector)
@ -898,6 +991,21 @@ public:
writeVal<atVec4f>(name, val); writeVal<atVec4f>(name, val);
} }
inline void writeVec2d(const char* name, const atVec2d& val)
{
writeVal<atVec2d>(name, val);
}
inline void writeVec3d(const char* name, const atVec3d& val)
{
writeVal<atVec3d>(name, val);
}
inline void writeVec4d(const char* name, const atVec4d& val)
{
writeVal<atVec4d>(name, val);
}
inline void writeUBytes(const char* name, const std::unique_ptr<atUint8[]>& val, size_t byteCount) inline void writeUBytes(const char* name, const std::unique_ptr<atUint8[]>& val, size_t byteCount)
{ {
writeVal<const std::unique_ptr<atUint8[]>&>(name, val, byteCount); writeVal<const std::unique_ptr<atUint8[]>&>(name, val, byteCount);

View File

@ -686,6 +686,195 @@ public:
inline atVec4f readValBig(typename std::enable_if<std::is_same<T, atVec4f>::value>::type* = 0) inline atVec4f readValBig(typename std::enable_if<std::is_same<T, atVec4f>::value>::type* = 0)
{return readVec4fBig();} {return readVec4fBig();}
/** @brief Reads an atVec2d (16 bytes), swaps to endianness specified by setEndian depending on platform
* and advances the current position
*
* @return The value at the current address
*/
inline atVec2d readVec2d()
{
atVec2d val;
readUBytesToBuf(&val, 16);
if (m_endian == BigEndian)
{
utility::BigDouble(val.vec[0]);
utility::BigDouble(val.vec[1]);
}
else
{
utility::LittleDouble(val.vec[0]);
utility::LittleDouble(val.vec[1]);
}
return val;
}
template <class T>
inline atVec2d readVal(typename std::enable_if<std::is_same<T, atVec2d>::value>::type* = 0)
{return readVec2d();}
/** @brief Reads an atVec2d (16 bytes), swaps against little endianness depending on platform
* and advances the current position
*
* @return The value at the current address
*/
inline atVec2d readVec2dLittle()
{
atVec2d val;
readUBytesToBuf(&val, 16);
utility::LittleDouble(val.vec[0]);
utility::LittleDouble(val.vec[1]);
return val;
}
template <class T>
inline atVec2d readValLittle(typename std::enable_if<std::is_same<T, atVec2d>::value>::type* = 0)
{return readVec2dLittle();}
/** @brief Reads an atVec2d (16 bytes), swaps against big endianness depending on platform
* and advances the current position
*
* @return The value at the current address
*/
inline atVec2d readVec2dBig()
{
atVec2d val;
readUBytesToBuf(&val, 16);
utility::BigDouble(val.vec[0]);
utility::BigDouble(val.vec[1]);
return val;
}
template <class T>
inline atVec2d readValBig(typename std::enable_if<std::is_same<T, atVec2d>::value>::type* = 0)
{return readVec2dBig();}
/** @brief Reads an atVec3d (24 bytes), swaps to endianness specified by setEndian depending on platform
* and advances the current position
*
* @return The value at the current address
*/
inline atVec3d readVec3d()
{
atVec3d val;
readUBytesToBuf(&val, 24);
if (m_endian == BigEndian)
{
utility::BigDouble(val.vec[0]);
utility::BigDouble(val.vec[1]);
utility::BigDouble(val.vec[2]);
}
else
{
utility::LittleDouble(val.vec[0]);
utility::LittleDouble(val.vec[1]);
utility::LittleDouble(val.vec[2]);
}
return val;
}
template <class T>
inline atVec3d readVal(typename std::enable_if<std::is_same<T, atVec3d>::value>::type* = 0)
{return readVec3d();}
/** @brief Reads an atVec3d (24 bytes), swaps against little endianness depending on platform
* and advances the current position
*
* @return The value at the current address
*/
inline atVec3d readVec3dLittle()
{
atVec3d val;
readUBytesToBuf(&val, 24);
utility::LittleDouble(val.vec[0]);
utility::LittleDouble(val.vec[1]);
utility::LittleDouble(val.vec[2]);
return val;
}
template <class T>
inline atVec3d readValLittle(typename std::enable_if<std::is_same<T, atVec3d>::value>::type* = 0)
{return readVec3dLittle();}
/** @brief Reads an atVec3d (24 bytes), swaps against big endianness depending on platform
* and advances the current position
*
* @return The value at the current address
*/
inline atVec3d readVec3dBig()
{
atVec3d val;
readUBytesToBuf(&val, 24);
utility::BigDouble(val.vec[0]);
utility::BigDouble(val.vec[1]);
utility::BigDouble(val.vec[2]);
return val;
}
template <class T>
inline atVec3d readValBig(typename std::enable_if<std::is_same<T, atVec3d>::value>::type* = 0)
{return readVec3dBig();}
/** @brief Reads an atVec4d (32 bytes), swaps to endianness specified by setEndian depending on platform
* and advances the current position
*
* @return The value at the current address
*/
inline atVec4d readVec4d()
{
atVec4d val;
readUBytesToBuf(&val, 32);
if (m_endian == BigEndian)
{
utility::BigDouble(val.vec[0]);
utility::BigDouble(val.vec[1]);
utility::BigDouble(val.vec[2]);
utility::BigDouble(val.vec[3]);
}
else
{
utility::LittleDouble(val.vec[0]);
utility::LittleDouble(val.vec[1]);
utility::LittleDouble(val.vec[2]);
utility::LittleDouble(val.vec[3]);
}
return val;
}
template <class T>
inline atVec4d readVal(typename std::enable_if<std::is_same<T, atVec4d>::value>::type* = 0)
{return readVec4d();}
/** @brief Reads an atVec4d (32 bytes), swaps against little endianness depending on platform
* and advances the current position
*
* @return The value at the current address
*/
inline atVec4d readVec4dLittle()
{
atVec4d val;
readUBytesToBuf(&val, 32);
utility::LittleDouble(val.vec[0]);
utility::LittleDouble(val.vec[1]);
utility::LittleDouble(val.vec[2]);
utility::LittleDouble(val.vec[3]);
return val;
}
template <class T>
inline atVec4d readValLittle(typename std::enable_if<std::is_same<T, atVec4d>::value>::type* = 0)
{return readVec4dLittle();}
/** @brief Reads an atVec4d (32 bytes), swaps against big endianness depending on platform
* and advances the current position
*
* @return The value at the current address
*/
inline atVec4d readVec4dBig()
{
atVec4d val;
readUBytesToBuf(&val, 32);
utility::BigDouble(val.vec[0]);
utility::BigDouble(val.vec[1]);
utility::BigDouble(val.vec[2]);
utility::BigDouble(val.vec[3]);
return val;
}
template <class T>
inline atVec4d readValBig(typename std::enable_if<std::is_same<T, atVec4d>::value>::type* = 0)
{return readVec4dBig();}
/** @brief Reads a wide-char string (using endianness from setEndian), /** @brief Reads a wide-char string (using endianness from setEndian),
* converts to UTF8 and advances the position in the file * converts to UTF8 and advances the position in the file
* *
@ -1025,6 +1214,12 @@ public:
protected: protected:
Endian m_endian; Endian m_endian;
}; };
template <typename T>
IStreamReader& operator>>(IStreamReader& lhs, T& rhs)
{
rhs = lhs.readVal<T>(rhs);
return lhs;
}
} }
} }
#endif // ISTREAMREADER #endif // ISTREAMREADER

View File

@ -531,6 +531,159 @@ public:
} }
inline void writeValBig(atVec4f val) {writeVec4fBig(val);} inline void writeValBig(atVec4f val) {writeVec4fBig(val);}
/** @brief Writes an atVec2d (16 bytes) to the buffer and advances the buffer.
* It also swaps the bytes depending on the platform and Stream settings.
*
* @param vec The value to write to the buffer
*/
inline void writeVec2d(atVec2d vec)
{
if (m_endian == BigEndian)
{
utility::BigDouble(vec.vec[0]);
utility::BigDouble(vec.vec[1]);
}
else
{
utility::LittleDouble(vec.vec[0]);
utility::LittleDouble(vec.vec[1]);
}
writeUBytes((atUint8*)&vec, 16);
}
inline void writeVal(atVec2d val) {writeVec2d(val);}
/** @brief Writes an atVec2d (16 bytes) to the buffer and advances the buffer.
* It also swaps the bytes against little depending on the platform.
*
* @param vec The value to write to the buffer
*/
inline void writeVec2dLittle(atVec2d vec)
{
utility::LittleDouble(vec.vec[0]);
utility::LittleDouble(vec.vec[1]);
writeUBytes((atUint8*)&vec, 16);
}
inline void writeValLittle(atVec2d val) {writeVec2dLittle(val);}
/** @brief Writes an atVec2d (16 bytes) to the buffer and advances the buffer.
* It also swaps the bytes against big depending on the platform.
*
* @param vec The value to write to the buffer
*/
inline void writeVec2dBig(atVec2d vec)
{
utility::BigDouble(vec.vec[0]);
utility::BigDouble(vec.vec[1]);
writeUBytes((atUint8*)&vec, 16);
}
inline void writeValBig(atVec2d val) {writeVec2dBig(val);}
/** @brief Writes an atVec3d (24 bytes) to the buffer and advances the buffer.
* It also swaps the bytes depending on the platform and Stream settings.
*
* @param vec The value to write to the buffer
*/
inline void writeVec3d(atVec3d vec)
{
if (m_endian == BigEndian)
{
utility::BigDouble(vec.vec[0]);
utility::BigDouble(vec.vec[1]);
utility::BigDouble(vec.vec[2]);
}
else
{
utility::LittleDouble(vec.vec[0]);
utility::LittleDouble(vec.vec[1]);
utility::LittleDouble(vec.vec[2]);
}
writeUBytes((atUint8*)&vec, 24);
}
inline void writeVal(atVec3d val) {writeVec3d(val);}
/** @brief Writes an atVec3d (24 bytes) to the buffer and advances the buffer.
* It also swaps the bytes against little depending on the platform.
*
* @param vec The value to write to the buffer
*/
inline void writeVec3dLittle(atVec3d vec)
{
utility::LittleDouble(vec.vec[0]);
utility::LittleDouble(vec.vec[1]);
utility::LittleDouble(vec.vec[2]);
writeUBytes((atUint8*)&vec, 24);
}
inline void writeValLittle(atVec3d val) {writeVec3dLittle(val);}
/** @brief Writes an atVec3d (24 bytes) to the buffer and advances the buffer.
* It also swaps the bytes against big depending on the platform.
*
* @param vec The value to write to the buffer
*/
inline void writeVec3dBig(atVec3d vec)
{
utility::BigDouble(vec.vec[0]);
utility::BigDouble(vec.vec[1]);
utility::BigDouble(vec.vec[2]);
writeUBytes((atUint8*)&vec, 24);
}
inline void writeValBig(atVec3d val) {writeVec3dBig(val);}
/** @brief Writes an atVec4d (32 bytes) to the buffer and advances the buffer.
* It also swaps the bytes depending on the platform and Stream settings.
*
* @param vec The value to write to the buffer
*/
inline void writeVec4d(atVec4d vec)
{
if (m_endian == BigEndian)
{
utility::BigDouble(vec.vec[0]);
utility::BigDouble(vec.vec[1]);
utility::BigDouble(vec.vec[2]);
utility::BigDouble(vec.vec[3]);
}
else
{
utility::LittleDouble(vec.vec[0]);
utility::LittleDouble(vec.vec[1]);
utility::LittleDouble(vec.vec[2]);
utility::LittleDouble(vec.vec[3]);
}
writeUBytes((atUint8*)&vec, 32);
}
inline void writeVal(atVec4d val) {writeVec4d(val);}
/** @brief Writes an atVec4d (32 bytes) to the buffer and advances the buffer.
* It also swaps the bytes against little depending on the platform.
*
* @param vec The value to write to the buffer
*/
inline void writeVec4dLittle(atVec4d vec)
{
utility::LittleDouble(vec.vec[0]);
utility::LittleDouble(vec.vec[1]);
utility::LittleDouble(vec.vec[2]);
utility::LittleDouble(vec.vec[3]);
writeUBytes((atUint8*)&vec, 32);
}
inline void writeValLittle(atVec4d val) {writeVec4dLittle(val);}
/** @brief Writes an atVec4d (32 bytes) to the buffer and advances the buffer.
* It also swaps the bytes against big depending on the platform.
*
* @param vec The value to write to the buffer
*/
inline void writeVec4dBig(atVec4d vec)
{
utility::BigDouble(vec.vec[0]);
utility::BigDouble(vec.vec[1]);
utility::BigDouble(vec.vec[2]);
utility::BigDouble(vec.vec[3]);
writeUBytes((atUint8*)&vec, 32);
}
inline void writeValBig(atVec4d val) {writeVec4dBig(val);}
/** @brief Converts a UTF8 string to a wide-char string in the buffer and advances the buffer. /** @brief Converts a UTF8 string to a wide-char string in the buffer and advances the buffer.
* It also swaps the bytes depending on the platform and Stream settings. * It also swaps the bytes depending on the platform and Stream settings.
* *
@ -911,6 +1064,13 @@ public:
protected: protected:
Endian m_endian; Endian m_endian;
}; };
template <typename T>
IStreamWriter& operator<<(IStreamWriter& lhs, const T& rhs)
{
lhs.writeVal<T>(rhs);
return lhs;
}
} }
} }
#endif // STREAMWRITER_HPP #endif // STREAMWRITER_HPP