extension.h
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2017 Intel Corporation. All Rights Reserved.
3 
4 #pragma once
5 #include "../../include/librealsense2/h/rs_types.h"
6 #include <memory>
7 #include <functional>
8 
10 #define MAP_EXTENSION(E, T) \
11  template<> struct ExtensionToType<E> { \
12  using type = T; \
13  static constexpr const char* to_string() { return #T; }; \
14  }; \
15  template<> struct TypeToExtension<T> { \
16  static constexpr rs2_extension value = E; \
17  static constexpr const char* to_string() { return #T; }; \
18  } \
19 
20 namespace librealsense
21 {
23  {
24  public:
25  virtual bool extend_to(rs2_extension extension_type, void** ptr) = 0;
26  virtual ~extendable_interface() = default;
27  };
28 
34  {
35  public:
36  virtual void update(std::shared_ptr<extension_snapshot> ext) = 0;
37  virtual ~extension_snapshot() = default;
38  };
39 
45  template <typename T>
46  class recordable
47  {
48  public:
53  virtual void create_snapshot(std::shared_ptr<T>& snapshot) const = 0;
54 
59  virtual void enable_recording(std::function<void(const T&)> recording_function) = 0;
60 
61  virtual ~recordable() = default;
62 
63  };
64 
65  /*
66  * Helper functions
67  *
68  */
69 
70  template <typename To>
71  inline bool try_extend(std::shared_ptr<extension_snapshot> from, void** ext)
72  {
73  if (from == nullptr)
74  {
75  return false;
76  }
77 
78  auto casted = std::dynamic_pointer_cast<To>(from);
79  if (casted == nullptr)
80  {
81  return false;
82  }
83  *ext = casted.get();
84  return true;
85  }
86 
87  template<typename T, typename P>
88  inline std::shared_ptr<T> As(std::shared_ptr<P> ptr)
89  {
90  return std::dynamic_pointer_cast<T>(ptr);
91  }
92 
93  template<typename T, typename P>
94  inline T* As(P* ptr)
95  {
96  return dynamic_cast<T*>(ptr);
97  }
98 
99  template<typename T, typename P>
100  inline bool Is(std::shared_ptr<P> ptr)
101  {
102  return As<T>(ptr) != nullptr;
103  }
104 
105  template<typename T, typename P>
106  inline bool Is(P* ptr)
107  {
108  return As<T>(ptr) != nullptr;
109  }
110  //Creating Helper functions to map rs2_extension enums to actual interface
111  template<rs2_extension> struct ExtensionToType;
112  template<typename T> struct TypeToExtension;
113 }
bool try_extend(std::shared_ptr< extension_snapshot > from, void **ext)
Definition: extension.h:71
std::shared_ptr< T > As(std::shared_ptr< P > ptr)
Definition: extension.h:88
bool Is(std::shared_ptr< P > ptr)
Definition: extension.h:100
virtual ~extendable_interface()=default
void update(rs2::update_device fwu_dev, std::vector< uint8_t > fw_image)
virtual bool extend_to(rs2_extension extension_type, void **ptr)=0
rs2_extension
Specifies advanced interfaces (capabilities) objects may implement.
Definition: rs_types.h:166


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