forked from alandefreitas/matplotplusplus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfigure_registry.cpp
More file actions
88 lines (75 loc) 路 2.58 KB
/
Copy pathfigure_registry.cpp
File metadata and controls
88 lines (75 loc) 路 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//
// Created by Alan Freitas on 03/09/20.
//
#include <map>
#include <matplot/core/figure_registry.h>
namespace matplot {
namespace detail {
/// Map with all figure handles there are
std::map<size_t, figure_handle> &global_figure_handles() {
static std::map<size_t, figure_handle> registry;
return registry;
}
/// Global handle to the figure considered the current figure
figure_handle ¤t_figure_handle() {
static figure_handle cfh;
return cfh;
}
void set_current_figure_handle(figure_handle &h) {
current_figure_handle() = h;
}
/// Register a figure handler with a given index
void register_figure_handle(size_t figure_index,
const figure_handle &h) {
global_figure_handles()[figure_index] = h;
}
/// Find an index for a new handler and register it there
void register_figure_handle(const figure_handle &h) {
size_t index_candidate = 1;
for (const auto &[index, figure_handle] : global_figure_handles()) {
if (index_candidate != index) {
break;
}
++index_candidate;
}
register_figure_handle(index_candidate, h);
}
figure_handle register_figure_handle(bool quiet_mode) {
size_t index_candidate = 1;
for (const auto &[index, figure_handle] : global_figure_handles()) {
if (index_candidate != index) {
break;
}
++index_candidate;
}
figure_handle h = std::make_shared<class figure_type>(
index_candidate, quiet_mode);
register_figure_handle(index_candidate, h);
return h;
}
} // namespace detail
figure_handle figure_no_backend(bool quiet_mode) {
figure_handle h = detail::register_figure_handle(quiet_mode);
detail::set_current_figure_handle(h);
return h;
}
figure_handle figure(figure_handle h) {
detail::set_current_figure_handle(h);
return h;
}
figure_handle figure(class figure_type *h) {
return figure(figure_handle{h});
}
figure_handle gcf() {
figure_handle h = detail::current_figure_handle();
if (!h) {
h = figure();
}
return h;
}
figure_handle gcf(bool quiet) {
figure_handle h = gcf();
h->quiet_mode(quiet);
return h;
}
} // namespace matplot