diff options
author | Florian Diebold <flodiebold@gmail.com> | 2011-11-18 22:38:12 +0100 |
---|---|---|
committer | Florian Diebold <flodiebold@gmail.com> | 2011-12-08 22:52:58 +0100 |
commit | 5500a343a383e824ef46d208386ab956cd18b92a (patch) | |
tree | f13775191b765b0bacae405e614aba68baf3dcb4 /crawl-ref/source/tileweb.h | |
parent | 18444e85adfd61bdde0bcea2b8b8261425bbf345 (diff) | |
download | crawl-ref-5500a343a383e824ef46d208386ab956cd18b92a.tar.gz crawl-ref-5500a343a383e824ef46d208386ab956cd18b92a.zip |
A bunch of helper functions for writing JSON for Webtiles.
Diffstat (limited to 'crawl-ref/source/tileweb.h')
-rw-r--r-- | crawl-ref/source/tileweb.h | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/crawl-ref/source/tileweb.h b/crawl-ref/source/tileweb.h index 630fd59e0e..54b0174f52 100644 --- a/crawl-ref/source/tileweb.h +++ b/crawl-ref/source/tileweb.h @@ -61,7 +61,7 @@ public: void write_message(const char *format, ...); void finish_message(); - void send_message(const char *format, ...); + void send_message(const char *format = "", ...); /* Webtiles can receive input both via stdin, and on the socket. Also, while waiting for input, it should be @@ -87,10 +87,23 @@ public: data is sent until pop_prefix is called. The suffix passed to pop_prefix will only be sent if the prefix was sent. */ - void push_prefix(std::string prefix); - void pop_prefix(std::string suffix); + void push_prefix(const std::string& prefix); + void pop_prefix(const std::string& suffix); bool prefix_popped(); + // Helper functions for writing JSON + void write_message_escaped(const std::string& s); + void json_open_object(const std::string& name = ""); + void json_close_object(); + void json_open_array(const std::string& name = ""); + void json_close_array(); + void json_write_comma(); + void json_write_name(const std::string& name); + void json_write_int(int value); + void json_write_int(const std::string& name, int value); + void json_write_string(const std::string& value); + void json_write_string(const std::string& name, const std::string& value); + std::string m_sock_name; bool m_await_connection; @@ -108,6 +121,8 @@ protected: wint_t _receive_control_message(); std::vector<std::string> m_prefixes; + int json_object_level; + bool need_comma; enum LayerID { |