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 {
13  {
14  float min;
15  float max;
16  float step;
17  float def;
18  };
19 
20  class LRS_EXTENSION_API 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;
31 
32  virtual ~option() = default;
33  };
34 
35  class options_interface : public recordable<options_interface>
36  {
37  public:
38  virtual option& get_option(rs2_option id) = 0;
39  virtual const option& get_option(rs2_option id) const = 0;
40  virtual bool supports_option(rs2_option id) const = 0;
41  virtual std::vector<rs2_option> get_supported_options() const = 0;
42  virtual const char* get_option_name(rs2_option) const = 0;
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  << get_option_name(id) << "!");
71  }
72  return *it->second;
73  }
74 
75  std::shared_ptr<option> get_option_handler(rs2_option id)
76  {
77  return (const_cast<const options_container*>(this)->get_option_handler(id));
78  }
79 
80  std::shared_ptr<option> get_option_handler(rs2_option id) const
81  {
82  auto it = _options.find(id);
83  return (it == _options.end() ? std::shared_ptr<option>(nullptr) : it->second);
84  }
85 
86  void register_option(rs2_option id, std::shared_ptr<option> option)
87  {
88  _options[id] = option;
89  _recording_function(*this);
90  }
91 
93  {
94  _options.erase(id);
95  }
96 
97  void create_snapshot(std::shared_ptr<options_interface>& snapshot) const override
98  {
99  snapshot = std::make_shared<options_container>(*this);
100  }
101 
102  void enable_recording(std::function<void(const options_interface&)> record_action) override
103  {
104  _recording_function = record_action;
105  }
106 
107  void update(std::shared_ptr<extension_snapshot> ext) override
108  {
109  auto ctr = As<options_container>(ext);
110  if (!ctr) return;
111  for(auto&& opt : ctr->_options)
112  {
113  _options[opt.first] = opt.second;
114  }
115  }
116 
117  std::vector<rs2_option> get_supported_options() const override;
118 
119  virtual const char* get_option_name(rs2_option option) const override
120  {
121  return get_string(option);
122  }
123 
124  protected:
125  std::map<rs2_option, std::shared_ptr<option>> _options;
126  std::function<void(const options_interface&)> _recording_function = [](const options_interface&) {};
127  };
128 }
std::shared_ptr< option > get_option_handler(rs2_option id) const
Definition: options.h:80
const char * get_string(rs2_rs400_visual_preset value)
rs2_option
Defines general configuration controls. These can generally be mapped to camera UVC controls...
Definition: rs_option.h:22
void enable_recording(std::function< void(const options_interface &)> record_action) override
Definition: options.h:102
GLfloat value
std::shared_ptr< option > get_option_handler(rs2_option id)
Definition: options.h:75
bool supports_option(rs2_option id) const override
Definition: options.h:51
std::map< rs2_option, std::shared_ptr< option > > _options
Definition: options.h:125
#define LRS_EXTENSION_API
Definition: src/types.h:20
option & get_option(rs2_option id) override
Definition: options.h:58
GLenum GLuint id
void unregister_option(rs2_option id)
Definition: options.h:92
void register_option(rs2_option id, std::shared_ptr< option > option)
Definition: options.h:86
GLuint GLenum option
Definition: glext.h:5923
virtual const char * get_value_description(float) const
Definition: options.h:29
void update(std::shared_ptr< extension_snapshot > ext) override
Definition: options.h:107
void create_snapshot(std::shared_ptr< options_interface > &snapshot) const override
Definition: options.h:97
const option & get_option(rs2_option id) const override
Definition: options.h:63
GLenum query
static auto it
virtual bool is_read_only() const
Definition: options.h:27
virtual const char * get_option_name(rs2_option option) const override
Definition: options.h:119
MAP_EXTENSION(RS2_EXTENSION_POINTS, librealsense::points)
std::string to_string(T value)


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