6 #ifndef TURI_UNITY_VARIANT_HPP 7 #define TURI_UNITY_VARIANT_HPP 11 #include <boost/variant/variant.hpp> 12 #include <boost/variant/recursive_variant.hpp> 13 #include <boost/variant/get.hpp> 14 #include <core/data/flexible_type/flexible_type.hpp> 15 #include <core/storage/sframe_data/dataframe.hpp> 16 #include <core/storage/serialization/serialization_includes.hpp> 17 #include <model_server/lib/variant.hpp> 21 struct function_closure_info;
22 class unity_sframe_base;
23 class unity_sgraph_base;
24 class unity_sarray_base;
44 typedef typename boost::make_recursive_variant<
46 std::shared_ptr<unity_sgraph_base>,
48 std::shared_ptr<model_base>,
49 std::shared_ptr<unity_sframe_base>,
50 std::shared_ptr<unity_sarray_base>,
51 std::map<std::string, boost::recursive_variant_>,
52 std::vector<boost::recursive_variant_>,
53 boost::recursive_wrapper<function_closure_info> >::type
variant_type;
58 typedef std::map<std::string, variant_type> variant_map_type;
63 typedef std::vector<variant_type> variant_vector_type;
72 return "flexible_type";
97 namespace turi{
namespace archive_detail {
100 struct serialize_impl<oarchive, turi::
variant_type, false> {
105 struct deserialize_impl<iarchive, turi::
variant_type, false> {
115 template <
typename T>
118 std::string errormsg =
119 std::string(
"Variant type error: Expecting ") +
122 log_and_throw(errormsg);
130 template <
typename T>
133 return boost::get<T>(v);
135 _throw_variant_error<T>(v);
143 template <
typename T>
146 return boost::get<T>(v);
148 _throw_variant_error<T>(v);
157 template <
typename T>
165 inline bool variant_is<flexible_type>(
const variant_type& t) {
166 return t.which() == 0;
171 inline bool variant_is<flex_string>(
const variant_type& t) {
172 return variant_is<flexible_type>(t) && (variant_get_ref<flexible_type>(t).get_type() ==
flex_type_enum::STRING);
177 inline bool variant_is<flex_vec>(
const variant_type& t) {
178 return variant_is<flexible_type>(t) && (variant_get_ref<flexible_type>(t).get_type() ==
flex_type_enum::VECTOR);
183 inline bool variant_is<flex_int>(
const variant_type& t) {
184 return variant_is<flexible_type>(t) && (variant_get_ref<flexible_type>(t).get_type() ==
flex_type_enum::INTEGER);
189 inline bool variant_is<flex_float>(
const variant_type& t) {
190 return variant_is<flexible_type>(t) && (variant_get_ref<flexible_type>(t).get_type() ==
flex_type_enum::FLOAT);
195 inline bool variant_is<flex_list>(
const variant_type& t) {
196 return variant_is<flexible_type>(t) && (variant_get_ref<flexible_type>(t).get_type() ==
flex_type_enum::LIST);
201 inline bool variant_is<flex_dict>(
const variant_type& t) {
202 return variant_is<flexible_type>(t) && (variant_get_ref<flexible_type>(t).get_type() ==
flex_type_enum::DICT);
207 inline bool variant_is<flex_image>(
const variant_type& t) {
208 return variant_is<flexible_type>(t) && (variant_get_ref<flexible_type>(t).get_type() ==
flex_type_enum::IMAGE);
213 inline bool variant_is<flex_date_time>(
const variant_type& t) {
219 inline bool variant_is<flex_nd_vec>(
const variant_type& t) {
225 inline bool variant_is<flex_undefined>(
const variant_type& t) {
231 inline bool variant_is<std::shared_ptr<unity_sgraph_base> >(
const variant_type& t) {
232 return t.which() == 1;
237 inline bool variant_is<dataframe_t>(
const variant_type& t) {
238 return t.which() == 2;
243 inline bool variant_is<std::shared_ptr<model_base> >(
const variant_type& t) {
244 return t.which() == 3;
249 inline bool variant_is<std::shared_ptr<unity_sframe_base> >(
const variant_type& t) {
250 return t.which() == 4;
257 inline bool variant_is<gl_sframe>(
const variant_type& t) {
258 return t.which() == 4;
263 inline bool variant_is<std::shared_ptr<unity_sarray_base> >(
const variant_type& t) {
264 return t.which() == 5;
271 inline bool variant_is<gl_sarray>(
const variant_type& t) {
272 return t.which() == 5;
277 inline bool variant_is<variant_map_type>(
const variant_type& t) {
278 return t.which() == 6;
283 inline bool variant_is<boost::recursive_wrapper<function_closure_info> >(
const variant_type& t) {
284 return t.which() == 7;
290 #include <model_server/lib/variant_converter.hpp> 296 template <
typename T>
307 template <
typename T>
319 template <
typename T>
325 #include <model_server/lib/api/function_closure_info.hpp>
std::decay< T >::type variant_get_value(const variant_type &v)
static T & variant_get_ref(variant_type &v)
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
void variant_set_value(variant_type &v, const T &f)
#define GL_HOT_INLINE_FLATTEN
variant_type to_variant(const T &f)
#define GL_COLD_NOINLINE_ERROR
std::string get_variant_which_name(int i)