123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- #include <vector>
- #include <string>
- 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 <std::string> & arValue);
- void Set (std::string Key, const std::vector <int> & arValue);
- void Set (std::string Key, const std::vector <EasyJSONEncoder> & 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 <typename T>
- EasyJSONEncoder & Encode (LPCTSTR Key, T value)
- {
- Set (Key, value);
- return (*this);
- }
- protected:
- std::vector <std::string> 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 <std::string> & arValue)
- {
- m_Encoder.Set (m_Key, arValue);
- return (*this);
- }
- inline Proxy & operator = (std::vector <int> & arValue)
- {
- m_Encoder.Set (m_Key, arValue);
- return (*this);
- }
- inline Proxy & operator = (std::vector <EasyJSONEncoder> & 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 ());
- *///
|