#pragma once //#include "BSTTree.hpp" namespace ECOM { namespace Utility { class BSTTree; } } #ifndef _ServiceBus_DLL #define _ServiceBus_API _declspec(dllimport) #else #define _ServiceBus_API _declspec(dllexport) #endif namespace ECOM { namespace ServiceBus { class _ServiceBus_API MessageEncoder { public: MessageEncoder (); virtual ~MessageEncoder (); void Set (LPCSTR Key, const DString & Value); void Set (LPCSTR Key, LPCSTR Value); void Set (LPCSTR Key, __int64 Value); void Set (LPCSTR Key, unsigned __int64 Value); void Set (LPCSTR Key, int Value); void Set (LPCSTR Key, unsigned int Value); void Set (LPCSTR Key, bool Value); void Set (LPCSTR Key, float Value); void Set (LPCSTR Key, double Value); // void Set (LPCSTR Key, MessageEncoder & Element); // 作为嵌入对象 #if 0 void Add (const DString & Value); void Add (LPCSTR Value); void Add (__int64 Value); void Add (unsigned __int64 Value); void Add (int Value); void Add (unsigned int Value); void Add (bool Value); void Add (float Value); void Add (double Value); void Add (MessageEncoder & Element); // 作为嵌入对象 #endif bool Recode (LPCSTR String); DString ToString () const; operator DString () const { return ToString (); } // 我没有拷贝构造函数 private: MessageEncoder (const MessageEncoder &); MessageEncoder & operator = (MessageEncoder & Value); protected: // Json::Value * m_JsonRoot; ECOM::Utility::BSTTree * m_JsonRoot; protected: class Proxy { public: inline Proxy (MessageEncoder & Encoder, LPCSTR Key) : m_Encoder (Encoder), m_Key (Key) { } inline Proxy & operator = (const DString & Value) { m_Encoder.Set (m_Key, Value); return (*this); } inline Proxy & operator = (LPCSTR Value) { m_Encoder.Set (m_Key, Value); return (*this); } inline Proxy & operator = (__int64 Value) { m_Encoder.Set (m_Key, Value); return (*this); } inline Proxy & operator = (unsigned __int64 Value) { m_Encoder.Set (m_Key, Value); return (*this); } inline Proxy & operator = (int Value) { m_Encoder.Set (m_Key, Value); return (*this); } inline Proxy & operator = (unsigned int Value) { m_Encoder.Set (m_Key, Value); return (*this); } inline Proxy & operator = (bool Value) { m_Encoder.Set (m_Key, Value); return (*this); } inline Proxy & operator = (float Value) { m_Encoder.Set (m_Key, Value); return (*this); } inline Proxy & operator = (double Value) { m_Encoder.Set (m_Key, Value); return (*this); } inline Proxy & operator = (MessageEncoder & Value) { m_Encoder.Set (m_Key, Value); return (*this); } protected: LPCSTR m_Key; MessageEncoder & m_Encoder; }; public: Proxy operator [] (LPCSTR Key) { return Proxy (*this, Key); } Proxy operator () (LPCSTR Key) { return Proxy (*this, Key); } }; }; };