rs-config.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 
6 #include <map>
7 #include <string>
8 #include <sstream>
9 #include <functional>
10 
11 namespace rs2
12 {
14  {
15  public:
16  template<class T>
17  operator T()
18  {
19  std::stringstream ss;
20  ss.str(_val);
21  T res;
22  ss >> res;
23  return res;
24  }
25 
26  // When converting config_value to string, we can't use >> operator since it reads until first whitespace rather than the whole string;
27  // Therefore we use a different overload for strings
28  operator std::string()
29  {
30  return _val;
31  }
32 
34 
35  private:
37  };
38 
40  {
41  public:
42  config_file();
44 
45  void set_default(const char* key, const char* calculate);
46 
47  template<class T>
48  void set_default(const char* key, T val)
49  {
50  std::stringstream ss;
51  ss << val;
52  set_default(key, ss.str().c_str());
53  }
54 
55  bool operator==(const config_file& other) const;
56 
57  config_file& operator=(const config_file& other);
58 
59  void set(const char* key, const char* value);
60  std::string get(const char* key, const char* def) const;
61 
62  config_value get(const char* key) const;
63 
64  template<class T>
65  T get_or_default(const char* key, T def) const
66  {
67  if (contains(key)) return get(key);
68  return def;
69  }
70 
71  template<class T>
72  void set(const char* key, T val)
73  {
74  std::stringstream ss;
75  ss << val;
76  set(key, ss.str().c_str());
77  }
78 
79  bool contains(const char* key) const;
80 
81  void save(const char* filename);
82 
83  void reset();
84 
85  static config_file& instance();
86 
87  private:
88  std::string get_default(const char* key, const char* def) const;
89 
90  void save();
91 
92  std::map<std::string, std::string> _values;
93  std::map<std::string, std::string> _defaults;
95  };
96 }
bool operator==(const plane &lhs, const plane &rhs)
Definition: rendering.h:134
GLboolean reset
GLfloat value
void set_default(const char *key, T val)
Definition: rs-config.h:48
Definition: cah-model.h:10
GLsizei const GLchar *const * string
GLuint GLfloat * val
GLuint64 key
Definition: glext.h:8966
T get_or_default(const char *key, T def) const
Definition: rs-config.h:65
bool contains(const std::shared_ptr< librealsense::device_info > &first, const std::shared_ptr< librealsense::device_info > &second)
Definition: context.cpp:49
std::map< std::string, std::string > _defaults
Definition: rs-config.h:93
typename::boost::move_detail::remove_reference< T >::type && move(T &&t) BOOST_NOEXCEPT
std::map< std::string, std::string > _values
Definition: rs-config.h:92
std::string _val
Definition: rs-config.h:36
std::string _filename
Definition: rs-config.h:94
GLuint res
Definition: glext.h:8856
config_value(std::string val)
Definition: rs-config.h:33


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