rs2_type_traits.h
Go to the documentation of this file.
1 #pragma once
2 #include "librealsense2/rs.hpp"
4 #include <type_traits>
5 
6 // extra checks to help specialization priority resoultion
8 // || std::is_base_of<rs2::options, T>::value
10 
11 // C API
12 
13 // rs_types.hpp
14 
15 // rs_frame.hpp
16 template<typename T> struct MatlabParamParser::type_traits<T, typename std::enable_if<std::is_base_of<rs2::stream_profile, T>::value>::type> {
19  static T from_internal(rs2_internal_t * ptr) { return T(rs2::stream_profile(*ptr)); }
20 };
21 template<typename T> struct MatlabParamParser::type_traits<T, typename std::enable_if<std::is_base_of<rs2::frame, T>::value>::type> { using rs2_internal_t = rs2_frame * ; };
22 
23 // rs_sensor.hpp
24 template<> struct MatlabParamParser::type_traits<rs2::options> {
25  // since it is impossible to create an rs2::options object (you must cast from a deriving type)
26  // The carrier's job is to help jump bridge that gap. Each type that derives directly from rs2::options
27  // must be added to the carrier's logic
28  struct carrier {
29  void * ptr;
31  carrier(void *ptr_, types t) : ptr(ptr_), type(t) {}
32  ~carrier(); // implemented at the bottom with an explanation as to why
33  };
34  using rs2_internal_t = carrier;
35  static rs2::options from_internal(rs2_internal_t * ptr);
36 };
37 template<typename T> struct MatlabParamParser::type_traits<T, typename std::enable_if<std::is_base_of<rs2::sensor, T>::value>::type>
38  : MatlabParamParser::type_traits<rs2::options> {
39  using carrier_t = std::shared_ptr<rs2_sensor>;
40  using carrier_enum = std::integral_constant<rs2_internal_t::types, rs2_internal_t::types::rs2_sensor>;
41  static T from_internal(rs2_internal_t * ptr) {
42  if (ptr->type == carrier_enum::value) return T(rs2::sensor(*reinterpret_cast<carrier_t*>(ptr->ptr)));
43  mexErrMsgTxt("Error parsing argument, object is not a sensor");
44  }
45  static rs2_internal_t* to_internal(T&& var) { mexLock(); return new rs2_internal_t(new carrier_t(var), carrier_enum::value); }
46 };
47 
48 // rs_device.hpp
49 template<> struct MatlabParamParser::type_traits<rs2::device> { using rs2_internal_t = std::shared_ptr<rs2_device>; };
50 template<> struct MatlabParamParser::type_traits<rs2::device_list> {
51  using rs2_internal_t = std::shared_ptr<rs2_device_list>;
53 };
54 
55 // rs_record_playback.hpp
56 template<> struct MatlabParamParser::type_traits<rs2::playback> : MatlabParamParser::type_traits<rs2::device> {
57  static rs2::playback from_internal(rs2_internal_t * ptr) { return traits_trampoline::from_internal<rs2::device>(ptr); }
58 };
60  static rs2::recorder from_internal(rs2_internal_t * ptr) { return traits_trampoline::from_internal<rs2::device>(ptr); }
61 };
62 
63 // rs_processing.hpp
64 template <typename T> struct over_wrapper {
65  using rs2_internal_t = std::shared_ptr<T>;
66  static T from_internal(rs2_internal_t * ptr) { return T(**ptr); }
67  static rs2_internal_t* to_internal(T&& val) { mexLock(); return new rs2_internal_t(new T(val)); }
68 };
69 template<typename T> struct MatlabParamParser::type_traits<T, typename std::enable_if<std::is_base_of<rs2::processing_block, T>::value>::type>
70  : MatlabParamParser::type_traits<rs2::options> {
71  using carrier_t = std::shared_ptr<rs2::processing_block>;
72  using carrier_enum = std::integral_constant<rs2_internal_t::types, rs2_internal_t::types::rs2_processing_block>;
73  static T from_internal(rs2_internal_t * ptr) {
74  if (ptr->type == carrier_enum::value) return *std::dynamic_pointer_cast<T>(*static_cast<carrier_t*>(ptr->ptr));
75  mexErrMsgTxt("Error parsing argument, object is not a processing block");
76  }
77  static rs2_internal_t* to_internal(T&& var) { mexLock(); return new rs2_internal_t(new carrier_t(new T(var)), carrier_enum::value); }
78 };
79 template<> struct MatlabParamParser::type_traits<rs2::syncer> : over_wrapper<rs2::syncer> {};
80 template<> struct MatlabParamParser::type_traits<rs2::frame_queue> : over_wrapper<rs2::frame_queue> {};
81 
82 // rs_context.hpp
83 // rs2::event_information [?]
84 template<> struct MatlabParamParser::type_traits<rs2::context> { using rs2_internal_t = std::shared_ptr<rs2_context>; };
85 template<> struct MatlabParamParser::type_traits<rs2::device_hub> { using rs2_internal_t = std::shared_ptr<rs2_device_hub>; };
86 
87 // rs_pipeline.hpp
88 template<> struct MatlabParamParser::type_traits<rs2::pipeline> { using rs2_internal_t = std::shared_ptr<rs2_pipeline>; };
89 template<> struct MatlabParamParser::type_traits<rs2::config> { using rs2_internal_t = std::shared_ptr<rs2_config>; };
90 template<> struct MatlabParamParser::type_traits<rs2::pipeline_profile> { using rs2_internal_t = std::shared_ptr<rs2_pipeline_profile>; };
91 
92 // rs_advanced_mode.hpp
93 template <> struct MatlabParamParser::type_traits<rs400::advanced_mode> : MatlabParamParser::type_traits<rs2::device> {
94  static rs400::advanced_mode from_internal(rs2_internal_t * ptr) { return traits_trampoline::from_internal<rs2::device>(ptr); }
95 };
96 
97 // This needs to go at the bottom so that all the relevant type_traits specializations will have already occured.
99  switch (type) {
100  case types::rs2_sensor: delete reinterpret_cast<type_traits<rs2::sensor>::carrier_t*>(ptr); break;
101  case types::rs2_processing_block: delete reinterpret_cast<type_traits<rs2::processing_block>::carrier_t*>(ptr); break;
102  }
103 }
104 
106  switch (ptr->type) {
107  case carrier::types::rs2_sensor: return traits_trampoline::from_internal<rs2::sensor>(ptr).as<rs2::options>();
108  // TODO: Fix
109  case carrier::types::rs2_processing_block: return *std::shared_ptr<rs2::options>(*static_cast<type_traits<rs2::processing_block>::carrier_t*>(ptr->ptr));
110  default: mexErrMsgTxt("Error parsing argument of type rs2::options: unrecognized carrier type");
111  }
112 
113 }
static rs2_internal_t * to_internal(T &&val)
std::shared_ptr< rs2_device_hub > rs2_internal_t
std::shared_ptr< rs2_context > rs2_internal_t
GLfloat value
static rs2::playback from_internal(rs2_internal_t *ptr)
Definition: cah-model.h:10
static rs2::recorder from_internal(rs2_internal_t *ptr)
struct rs2_sensor rs2_sensor
Definition: rs_types.h:282
std::shared_ptr< rs2_device_list > rs2_internal_t
GLdouble t
GLuint GLfloat * val
std::shared_ptr< rs2_pipeline > rs2_internal_t
std::integral_constant< rs2_internal_t::types, rs2_internal_t::types::rs2_processing_block > carrier_enum
integral_constant< bool, B > bool_constant
std::shared_ptr< rs2_pipeline_profile > rs2_internal_t
std::shared_ptr< rs2_device > rs2_internal_t
static rs400::advanced_mode from_internal(rs2_internal_t *ptr)
std::bool_constant< std::is_base_of< rs2::frame, T >::value||std::is_base_of< rs2::stream_profile, T >::value > extra_checks
static T from_internal(rs2_internal_t *ptr)
struct rs2_processing_block rs2_processing_block
Definition: rs_types.h:275
GLenum type
std::integral_constant< rs2_internal_t::types, rs2_internal_t::types::rs2_sensor > carrier_enum
std::shared_ptr< rs2::frame_queue > rs2_internal_t
std::shared_ptr< rs2_config > rs2_internal_t
integral_constant< bool, true > true_type
auto device
Definition: pyrs_net.cpp:17
struct rs2_frame rs2_frame
Definition: rs_types.h:261


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:40