cat3d
A tiny OpenGL 3D engine library written in and for C++.
opts.hpp
1 #pragma once
2 
3 #include <any>
4 #include <stdexcept>
5 #include <unordered_map>
6 
7 namespace cat3d {
8 
9 enum opt {
10  WIDTH,
11  HEIGHT,
12  TITLE,
13  CLEAR_COLOR,
14  ANTIALIASING
15 
16 };
17 
22 class opts {
23 public:
24  typedef std::unordered_map<opt, std::any> opt_map;
25 
31  opts(opt_map opt);
32 
40  template <typename T>
41  T get(opt key) const {
42  return std::any_cast<T>(m_config.at(key));
43  }
44 
53  template <typename T>
54  T get(opt key, T fallback) const {
55  try {
56  return std::any_cast<T>(m_config.at(key));
57  } catch (const std::out_of_range& e) {
58  return fallback;
59  }
60  }
61 
62 private:
64  opt_map m_config;
65 };
66 
67 }
cat3d::opts::get
T get(opt key, T fallback) const
Retrieve the value at the given key.
Definition: opts.hpp:54
cat3d::opts::get
T get(opt key) const
Retrieve the value at the given key.
Definition: opts.hpp:41
cat3d::opts
cat3d main configuration options class
Definition: opts.hpp:22
cat3d::opts::opts
opts(opt_map opt)
initialize the options object