Intel® RealSense™ Cross Platform API
Intel Realsense Cross-platform API
options.h
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2015 Intel Corporation. All Rights Reserved.
3 #pragma once
4 
5 #include <map>
6 #include "../include/librealsense2/h/rs_option.h"
7 #include "extension.h"
8 #include "types.h"
9 
10 namespace librealsense
11 {
12  struct option_range
13  {
14  float min;
15  float max;
16  float step;
17  float def;
18  };
19 
20  class option : public recordable<option>
21  {
22  public:
23  virtual void set(float value) = 0;
24  virtual float query() const = 0;
25  virtual option_range get_range() const = 0;
26  virtual bool is_enabled() const = 0;
27  virtual bool is_read_only() const { return false; }
28  virtual const char* get_description() const = 0;
29  virtual const char* get_value_description(float) const { return nullptr; }
30  virtual void create_snapshot(std::shared_ptr<option>& snapshot) const override;
31 
32  virtual ~option() = default;
33  };
34 
35 
36  class options_interface : public recordable<options_interface>
37  {
38  public:
39  virtual option& get_option(rs2_option id) = 0;
40  virtual const option& get_option(rs2_option id) const = 0;
41  virtual bool supports_option(rs2_option id) const = 0;
42 
43  virtual ~options_interface() = default;
44  };
45 
47 
49  {
50  public:
51  bool supports_option(rs2_option id) const override
52  {
53  auto it = _options.find(id);
54  if (it == _options.end()) return false;
55  return it->second->is_enabled();
56  }
57 
59  {
60  return const_cast<option&>(const_cast<const options_container*>(this)->get_option(id));
61  }
62 
63  const option& get_option(rs2_option id) const override
64  {
65  auto it = _options.find(id);
66  if (it == _options.end())
67  {
69  << "Device does not support option "
70  << rs2_option_to_string(id) << "!");
71  }
72  return *it->second;
73  }
74 
75  void register_option(rs2_option id, std::shared_ptr<option> option)
76  {
77  _options[id] = option;
78  _recording_function(*this);
79  }
80 
82  {
83  _options.erase(id);
84  }
85 
86  void create_snapshot(std::shared_ptr<options_interface>& snapshot) const override
87  {
88  snapshot = std::make_shared<options_container>(*this);
89  }
90 
91  void enable_recording(std::function<void(const options_interface&)> record_action) override
92  {
93  _recording_function = record_action;
94  }
95 
96  void update(std::shared_ptr<extension_snapshot> ext) override
97  {
98  auto ctr = As<options_container>(ext);
99  if (!ctr) return;
100  for(auto&& opt : ctr->_options)
101  {
102  _options[opt.first] = opt.second;
103  }
104  }
105 
106  private:
107  std::map<rs2_option, std::shared_ptr<option>> _options;
108  std::function<void(const options_interface&)> _recording_function = [](const options_interface&) {};
109  };
110 }
Definition: options.h:48
virtual const char * get_description() const =0
virtual ~option()=default
Definition: backend.h:351
rs2_option
Defines general configuration controls. These can generally be mapped to camera UVC controls...
Definition: rs_option.h:22
float def
Definition: options.h:17
void enable_recording(std::function< void(const options_interface &)> record_action) override
Definition: options.h:91
Definition: options.h:20
const char * rs2_option_to_string(rs2_option option)
bool supports_option(rs2_option id) const override
Definition: options.h:51
float max
Definition: options.h:15
virtual option_range get_range() const =0
virtual void create_snapshot(std::shared_ptr< option > &snapshot) const override
option & get_option(rs2_option id) override
Definition: options.h:58
virtual float query() const =0
void unregister_option(rs2_option id)
Definition: options.h:81
void register_option(rs2_option id, std::shared_ptr< option > option)
Definition: options.h:75
Definition: algo.h:16
virtual bool is_read_only() const
Definition: options.h:27
virtual ~options_interface()=default
virtual const char * get_value_description(float) const
Definition: options.h:29
virtual bool is_enabled() const =0
Definition: rs_types.h:99
virtual option & get_option(rs2_option id)=0
void update(std::shared_ptr< extension_snapshot > ext) override
Definition: options.h:96
void create_snapshot(std::shared_ptr< options_interface > &snapshot) const override
Definition: options.h:86
Definition: options.h:36
Definition: options.h:12
const option & get_option(rs2_option id) const override
Definition: options.h:63
virtual bool supports_option(rs2_option id) const =0
Definition: types.h:54
Definition: extension.h:46
float min
Definition: options.h:14
Definition: extension.h:33
float step
Definition: options.h:16
MAP_EXTENSION(RS2_EXTENSION_POINTS, librealsense::points)