Advertisement
Guest User

AutoMessage.h

a guest
Nov 25th, 2012
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.24 KB | None | 0 0
  1. #ifndef _AUTOMESSAGE_H_
  2. #define DISABLE_ASSERTS
  3. #define _AUTOMESSAGE_H_
  4.  
  5. #include "LTClient.h"
  6. #include "iltmessage.h"
  7. #include <Windows.h>
  8. #define DISABLE_ASSERTS
  9. #include <d3d9.h>
  10.  
  11. class ILTMessage_Write;
  12. class ILTMessage_Read;
  13.  
  14. //extern CCommonLT* g_CommonLT;
  15.  
  16. static class CCommonLT* g_CommonLT;
  17.  
  18. class CAutoMessage
  19. {
  20. public:
  21.     CAutoMessage() : m_pMsg(NULL)
  22.     {
  23.         Init();
  24.     }
  25.     ~CAutoMessage()
  26.     {
  27.         Term();
  28.     }
  29.     CAutoMessage(const ILTMessage_Read &cMsg) : m_pMsg(NULL)
  30.     {
  31.         Init();
  32.         CLTMsgRef_Read cReadMsg(cMsg.Clone());
  33.         WriteMessage(cReadMsg);
  34.     }
  35.     CAutoMessage(const char *pStr) : m_pMsg(NULL)
  36.     {
  37.         Init();
  38.         WriteString(pStr);
  39.     }
  40.     CAutoMessage(const wchar_t *pStr) : m_pMsg(NULL)
  41.     {
  42.         Init();
  43.         WriteWString(pStr);
  44.     }
  45.     template <class T>
  46.     CAutoMessage(const T &tValue) : m_pMsg(NULL)
  47.     {
  48.         Init();
  49.         WriteType(tValue);
  50.     }
  51.  
  52.     void Reset() { Init(); }
  53.     bool IsValid() { return m_pMsg != NULL ; }
  54.  
  55.     inline operator ILTMessage_Write*() { return m_pMsg; }
  56.     inline operator const ILTMessage_Write*() const { return m_pMsg; }
  57.     inline operator ILTMessage_Write&() { return *m_pMsg; }
  58.     inline operator const ILTMessage_Write&() const { return *m_pMsg; }
  59.  
  60.     inline CLTMsgRef_Read Read() { return CLTMsgRef_Read(m_pMsg->Read()); }
  61.     inline uint32 Size() const { return m_pMsg->Size(); }
  62.     inline void WriteBits(uint32 nValue, uint32 nSize) { m_pMsg->WriteBits(nValue, nSize); }
  63.     inline void WriteBits64(uint64 nValue, uint32 nSize) { m_pMsg->WriteBits64(nValue, nSize); }
  64.     inline void WriteData(const void *pData, uint32 nSize) { m_pMsg->WriteData(pData, nSize); }
  65.     inline void WriteMessage(ILTMessage_Read *pMsg) { m_pMsg->WriteMessage(pMsg); }
  66.     inline void WriteMessageRaw(ILTMessage_Read *pMsg) { m_pMsg->WriteMessageRaw(pMsg); }
  67.     inline void WriteString(const char *pString) { m_pMsg->WriteString(pString); }
  68.     inline void WriteWString(const wchar_t *pString) { m_pMsg->WriteWString(pString); }
  69.     inline void WriteCompLTVector(const LTVector &vVec) { m_pMsg->WriteCompLTVector(vVec); }
  70.     inline void WriteCompPos(const LTVector &vPos) { m_pMsg->WriteCompPos(vPos); }
  71.     inline void WriteCompLTRotation(const LTRotation &cRotation) { m_pMsg->WriteCompLTRotation(cRotation); }
  72.     inline void WriteObject(HOBJECT hObj) { m_pMsg->WriteObject(hObj); }
  73.     inline void WriteYRotation(const LTRotation &cRotation) { m_pMsg->WriteYRotation(cRotation); }
  74.     inline void WriteDatabaseRecord( IDatabaseMgr *pDatabase, HRECORD hRecord ) { m_pMsg->WriteDatabaseRecord( pDatabase, hRecord ); }
  75.     inline void Writebool(bool bValue) { WriteBits(bValue ? 1 : 0, 1); }
  76.     inline void Writeuint8(uint8 nValue) { WriteBits(nValue, 8); }
  77.     inline void Writeuint16(uint16 nValue) { WriteBits(nValue, 16); }
  78.     inline void Writeuint32(uint32 nValue) { WriteBits(nValue, 32); }
  79.     inline void Writeuint64(uint64 nValue) { WriteBits64(nValue, 64); }
  80.     inline void Writeint8(int8 nValue) { WriteBits((uint32)nValue, 8); }
  81.     inline void Writeint16(int16 nValue) { WriteBits((uint32)nValue, 16); }
  82.     inline void Writeint32(int32 nValue) { WriteBits((uint32)nValue, 32); }
  83.     inline void Writeint64(int32 nValue) { WriteBits64((uint64)nValue, 32); }
  84.     inline void Writefloat(float fValue) { WriteBits(reinterpret_cast<const uint32&>(fValue), 32); }
  85.     inline void Writedouble(double fValue) { WriteBits64(reinterpret_cast<const uint64&>(fValue), 64); }
  86.     inline void WriteLTVector(const LTVector &vValue) { WriteType(vValue); }
  87.     inline void WriteLTRotation(const LTRotation &cValue) { WriteType(cValue); }
  88.     inline void WriteLTRigidTransform(const LTRigidTransform &tfValue) { WriteType( tfValue ); }
  89.     inline void WriteLTTransform(const LTTransform &tfValue) { WriteType( tfValue ); }
  90.     inline void WriteLTPolarCoord(const LTPolarCoord &polarCoord) { m_pMsg->WriteLTPolarCoord( polarCoord ); }
  91.     inline void WriteCompLTPolarCoord(const LTPolarCoord &polarCoord) { m_pMsg->WriteCompLTPolarCoord( polarCoord ); }
  92.     template <class T>
  93.     inline void WriteType(const T &tValue) { m_pMsg->WriteType(tValue); }
  94. private:
  95.     inline void Init()
  96.     {
  97.         Term();
  98.         m_pMsg = NULL;
  99.         ILTMessage_Write *pMsg;
  100.         LTRESULT nResult = g_CommonLT->CreateMessage(pMsg);
  101.         if (nResult == LT_OK)
  102.             m_pMsg = pMsg;
  103.         ASSERT(nResult == LT_OK);
  104.     }
  105.     inline void Term()
  106.     {
  107.         m_pMsg = NULL;
  108.     }
  109.     CLTMsgRef_Write m_pMsg;
  110. };
  111.  
  112. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement