Mercurial > hg > octave-jordi
view libinterp/corefcn/json-util.h @ 21052:b702efa70fb5 draft default tip shane
Adding --json-sock option; publishes octave_link events to a UNIX socket.
author | Shane F. Carr <shane.carr@wustl.edu> |
---|---|
date | Mon, 04 Jan 2016 08:51:31 +0000 |
parents | |
children |
line wrap: on
line source
#ifndef json_util_h #define json_util_h #include <json-c/json.h> #include <map> #include <list> #include "workspace-element.h" #include "octave-link.h" class string_vector; // All of the code interacting with the external JSON library should be in // the json-util.h and json-util.cc files. This way, if we want to change // the external JSON library, we can do it all in one place. #define JSON_OBJECT_T json_object* #define JSON_MAP_T std::map<std::string, JSON_OBJECT_T> class json_util { public: static JSON_OBJECT_T from_string(const std::string& str); static JSON_OBJECT_T from_int(int i); static JSON_OBJECT_T from_float(float flt); static JSON_OBJECT_T from_boolean(bool b); static JSON_OBJECT_T empty(); static JSON_OBJECT_T from_string_list(const std::list<std::string>& list); static JSON_OBJECT_T from_string_vector(const string_vector& list); static JSON_OBJECT_T from_int_list(const std::list<int>& list); static JSON_OBJECT_T from_float_list(const std::list<float>& list); static JSON_OBJECT_T from_workspace_list(const std::list<workspace_element>& list); static JSON_OBJECT_T from_filter_list(const octave_link::filter_list& list); static JSON_OBJECT_T from_value_string(const std::string str); static JSON_OBJECT_T from_workspace_element(workspace_element element); static JSON_OBJECT_T from_pair(std::pair<std::string, std::string> pair); static JSON_OBJECT_T from_map(JSON_MAP_T m); static std::string to_message(const std::string& name, JSON_OBJECT_T jobj); static std::string to_string(JSON_OBJECT_T jobj); static std::pair<std::list<int>, int> to_int_list_int_pair(JSON_OBJECT_T jobj); static std::list<std::string> to_string_list(JSON_OBJECT_T jobj); static int to_int(JSON_OBJECT_T jobj); static bool to_boolean(JSON_OBJECT_T jobj); static void read_stream(int sockfd, void (*cb)(std::string, JSON_OBJECT_T, void*), void* arg); private: static void process_message(JSON_OBJECT_T jobj, void (*cb)(std::string, JSON_OBJECT_T, void*), void* arg); }; #endif