MessageEncoder.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #pragma once
  2. //#include "BSTTree.hpp"
  3. namespace ECOM
  4. {
  5. namespace Utility
  6. {
  7. class BSTTree;
  8. }
  9. }
  10. #ifndef _ServiceBus_DLL
  11. #define _ServiceBus_API _declspec(dllimport)
  12. #else
  13. #define _ServiceBus_API _declspec(dllexport)
  14. #endif
  15. namespace ECOM
  16. {
  17. namespace ServiceBus
  18. {
  19. class _ServiceBus_API MessageEncoder
  20. {
  21. public:
  22. MessageEncoder ();
  23. virtual ~MessageEncoder ();
  24. void Set (LPCSTR Key, const DString & Value);
  25. void Set (LPCSTR Key, LPCSTR Value);
  26. void Set (LPCSTR Key, __int64 Value);
  27. void Set (LPCSTR Key, unsigned __int64 Value);
  28. void Set (LPCSTR Key, int Value);
  29. void Set (LPCSTR Key, unsigned int Value);
  30. void Set (LPCSTR Key, bool Value);
  31. void Set (LPCSTR Key, float Value);
  32. void Set (LPCSTR Key, double Value);
  33. // void Set (LPCSTR Key, MessageEncoder & Element); // 作为嵌入对象
  34. #if 0
  35. void Add (const DString & Value);
  36. void Add (LPCSTR Value);
  37. void Add (__int64 Value);
  38. void Add (unsigned __int64 Value);
  39. void Add (int Value);
  40. void Add (unsigned int Value);
  41. void Add (bool Value);
  42. void Add (float Value);
  43. void Add (double Value);
  44. void Add (MessageEncoder & Element); // 作为嵌入对象
  45. #endif
  46. bool Recode (LPCSTR String);
  47. DString ToString () const;
  48. operator DString () const { return ToString (); }
  49. // 我没有拷贝构造函数
  50. private:
  51. MessageEncoder (const MessageEncoder &);
  52. MessageEncoder & operator = (MessageEncoder & Value);
  53. protected:
  54. // Json::Value * m_JsonRoot;
  55. ECOM::Utility::BSTTree * m_JsonRoot;
  56. protected:
  57. class Proxy
  58. {
  59. public:
  60. inline Proxy (MessageEncoder & Encoder, LPCSTR Key) :
  61. m_Encoder (Encoder),
  62. m_Key (Key)
  63. {
  64. }
  65. inline Proxy & operator = (const DString & Value)
  66. {
  67. m_Encoder.Set (m_Key, Value);
  68. return (*this);
  69. }
  70. inline Proxy & operator = (LPCSTR Value)
  71. {
  72. m_Encoder.Set (m_Key, Value);
  73. return (*this);
  74. }
  75. inline Proxy & operator = (__int64 Value)
  76. {
  77. m_Encoder.Set (m_Key, Value);
  78. return (*this);
  79. }
  80. inline Proxy & operator = (unsigned __int64 Value)
  81. {
  82. m_Encoder.Set (m_Key, Value);
  83. return (*this);
  84. }
  85. inline Proxy & operator = (int Value)
  86. {
  87. m_Encoder.Set (m_Key, Value);
  88. return (*this);
  89. }
  90. inline Proxy & operator = (unsigned int Value)
  91. {
  92. m_Encoder.Set (m_Key, Value);
  93. return (*this);
  94. }
  95. inline Proxy & operator = (bool Value)
  96. {
  97. m_Encoder.Set (m_Key, Value);
  98. return (*this);
  99. }
  100. inline Proxy & operator = (float Value)
  101. {
  102. m_Encoder.Set (m_Key, Value);
  103. return (*this);
  104. }
  105. inline Proxy & operator = (double Value)
  106. {
  107. m_Encoder.Set (m_Key, Value);
  108. return (*this);
  109. }
  110. inline Proxy & operator = (MessageEncoder & Value)
  111. {
  112. m_Encoder.Set (m_Key, Value);
  113. return (*this);
  114. }
  115. protected:
  116. LPCSTR m_Key;
  117. MessageEncoder & m_Encoder;
  118. };
  119. public:
  120. Proxy operator [] (LPCSTR Key)
  121. {
  122. return Proxy (*this, Key);
  123. }
  124. Proxy operator () (LPCSTR Key)
  125. {
  126. return Proxy (*this, Key);
  127. }
  128. };
  129. };
  130. };