6 #ifndef TURI_UNITY_MODEL_BASE_HPP 7 #define TURI_UNITY_MODEL_BASE_HPP 15 #include <core/export.hpp> 17 #include <core/system/cppipc/ipc_object_base.hpp> 18 #include <core/system/cppipc/magic_macros.hpp> 19 #include <core/storage/serialization/serialization_includes.hpp> 20 #include <model_server/lib/toolkit_class_macros.hpp> 21 #include <model_server/lib/variant.hpp> 45 class EXPORT
model_base:
public cppipc::ipc_object_base {
65 virtual const char* name() = 0;
75 virtual const std::string& uid() = 0;
78 oarc << get_version();
106 load_version(iarc, version);
117 void save_to_url(
const std::string& url,
const variant_map_type& side_data = {});
123 void save_model_to_data(std::ostream& out);
136 const std::map<std::string, std::vector<std::string> >& list_functions();
141 const std::vector<std::string>& list_get_properties();
146 const std::vector<std::string>& list_set_properties();
151 variant_type call_function(
const std::string&
function, variant_map_type argument);
162 variant_type set_property(
const std::string& property, variant_map_type argument);
167 const std::string& get_docstring(
const std::string& symbol);
173 virtual void perform_registration();
181 using impl_fn = std::function<variant_type(model_base*, variant_map_type)>;
190 bool is_registered()
const {
return m_registered; }
191 void set_registered() { m_registered =
true; }
196 void register_function(std::string fnname,
197 const std::vector<std::string>& arguments, impl_fn fn);
202 void register_defaults(
const std::string& fnname,
203 const variant_map_type& arguments);
208 void register_setter(
const std::string& propname, impl_fn setfn);
213 void register_getter(
const std::string& propname, impl_fn getfn);
218 void register_docstring(
219 const std::pair<std::string, std::string>& fnname_docstring);
223 bool m_registered =
false;
226 std::map<std::string, std::vector<std::string>> m_function_args;
229 std::map<std::string, variant_map_type> m_function_default_args;
231 std::map<std::string, impl_fn> m_function_list;
233 std::map<std::string, impl_fn> m_set_property_list;
234 mutable std::vector<std::string> m_set_property_cache;
237 std::map<std::string, impl_fn> m_get_property_list;
238 mutable std::vector<std::string> m_get_property_cache;
241 std::map<std::string, std::string> m_docstring;
244 inline void _check_registration();
246 template <
typename T>
248 const std::string& name,
const std::map<std::string, T>& m);
250 std::string _make_method_name(
const std::string&
function);
257 #ifndef DISABLE_TURI_CPPIPC_PROXY_GENERATION 267 bool auto_create =
true,
268 size_t object_id = (
size_t)(-1)):
269 proxy(comm, auto_create, object_id){ }
275 inline size_t __get_object_id()
const {
280 size_t objid; iarc >> objid;
285 std_log_and_throw(std::runtime_error,
"Calling Unreachable Function");
288 const std::string&
uid() {
289 std_log_and_throw(std::runtime_error,
"Calling Unreachable Function");
292 std_log_and_throw(std::runtime_error,
"Calling Unreachable Function");
300 std_log_and_throw(std::runtime_error,
"Calling Unreachable Function");
308 std_log_and_throw(std::runtime_error,
"Calling Unreachable Function");
311 BOOST_PP_SEQ_FOR_EACH(__GENERATE_PROXY_CALLS__,
model_base,
313 (
const char*, name, )
319 #endif // TURI_UNITY_MODEL_BASE_HPP
virtual size_t get_version() const
void load_version(iarchive &iarc, size_t version)
The serialization input archive object which, provided with a reference to an istream, will read from the istream, providing deserialization capabilities.
virtual void save_impl(oarchive &oarc) const
const std::string & uid()
void perform_registration()
boost::make_recursive_variant< flexible_type, std::shared_ptr< unity_sgraph_base >, dataframe_t, std::shared_ptr< model_base >, std::shared_ptr< unity_sframe_base >, std::shared_ptr< unity_sarray_base >, std::map< std::string, boost::recursive_variant_ >, std::vector< boost::recursive_variant_ >, boost::recursive_wrapper< function_closure_info > >::type variant_type
size_t get_object_id() const
#define REGISTRATION_BEGIN(name)
void set_object_id(size_t object_id)
The serialization output archive object which, provided with a reference to an ostream, will write to the ostream, providing serialization capabilities.
virtual void load_version(iarchive &iarc, size_t version)
#define GL_COLD_NOINLINE_ERROR
virtual size_t get_version() const
virtual void save_impl(oarchive &oarc) const