#include #include class EasyJSONEncoder { using LPCTSTR = const char *; public: EasyJSONEncoder (); EasyJSONEncoder (const EasyJSONEncoder & Encoder); virtual ~EasyJSONEncoder (); void Set (std::string Key, LPCTSTR Value); void Set (std::string Key, const std::string & Value); void Set (std::string Key, int64_t Value); void Set (std::string Key, uintptr_t Value); void Set (std::string Key, uint32_t Value); void Set (std::string Key, int Value); void Set (std::string Key, bool Value); void Set (std::string Key, float Value); void Set (std::string Key, double Value); void Set (std::string Key, const std::vector & arValue); void Set (std::string Key, const std::vector & arValue); void Set (std::string Key, const std::vector & arValue); bool Recode (std::string String); std::string ToString () const; std::string ToStringOfElement () const; operator std::string () const { return ToString (); } void operator = (const EasyJSONEncoder & Encoder); void CopyTo (EasyJSONEncoder & toEncoder) const; void Empty (); template EasyJSONEncoder & Encode (LPCTSTR Key, T value) { Set (Key, value); return (*this); } protected: std::vector m_arMessage; protected: class Proxy { public: inline Proxy (EasyJSONEncoder & Encoder, LPCTSTR Key) : m_Encoder (Encoder), m_Key (Key) { } inline Proxy & operator = (LPCTSTR Value) { m_Encoder.Set (m_Key, Value); return (*this); } inline Proxy & operator = (const std::string & Value) { m_Encoder.Set (m_Key, Value); return (*this); } inline Proxy & operator = (int64_t Value) { m_Encoder.Set (m_Key, Value); return (*this); } inline Proxy & operator = (uintptr_t Value) { m_Encoder.Set (m_Key, Value); return (*this); } inline Proxy & operator = (uint32_t 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 = (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 = (std::vector & arValue) { m_Encoder.Set (m_Key, arValue); return (*this); } inline Proxy & operator = (std::vector & arValue) { m_Encoder.Set (m_Key, arValue); return (*this); } inline Proxy & operator = (std::vector & arValue) { m_Encoder.Set (m_Key, arValue); return (*this); } protected: LPCTSTR m_Key; EasyJSONEncoder & m_Encoder; }; public: Proxy operator [] (LPCTSTR Key) { return Proxy (*this, Key); } Proxy operator () (LPCTSTR Key) { return Proxy (*this, Key); } }; /*// #define JSON EasyJSONEncoder () arg->SetAck (JSON .Encode ("A", "a") .Encode ("B", 22) .Encode ("C", true) .ToString ()); *///