_resource_list_8h_source.html
68.4 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>hueplusplus: include/hueplusplus/ResourceList.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">hueplusplus
 <span id="projectnumber">1.0.0</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="dir_e05b4b7707bd5f9fd045e8be02b17d0a.html">hueplusplus</a></li> </ul>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">ResourceList.h</div> </div>
</div><!--header-->
<div class="contents">
<a href="_resource_list_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> </div><div class="line"><a name="l00022"></a><span class="lineno"> 22</span> <span class="preprocessor">#ifndef INCLUDE_HUEPLUSPLUS_RESOURCE_LIST_H</span></div><div class="line"><a name="l00023"></a><span class="lineno"> 23</span> <span class="preprocessor">#define INCLUDE_HUEPLUSPLUS_RESOURCE_LIST_H</span></div><div class="line"><a name="l00024"></a><span class="lineno"> 24</span> </div><div class="line"><a name="l00025"></a><span class="lineno"> 25</span> <span class="preprocessor">#include <functional></span></div><div class="line"><a name="l00026"></a><span class="lineno"> 26</span> <span class="preprocessor">#include <map></span></div><div class="line"><a name="l00027"></a><span class="lineno"> 27</span> <span class="preprocessor">#include <string></span></div><div class="line"><a name="l00028"></a><span class="lineno"> 28</span> <span class="preprocessor">#include <vector></span></div><div class="line"><a name="l00029"></a><span class="lineno"> 29</span> </div><div class="line"><a name="l00030"></a><span class="lineno"> 30</span> <span class="preprocessor">#include "<a class="code" href="_a_p_i_cache_8h.html">APICache.h</a>"</span></div><div class="line"><a name="l00031"></a><span class="lineno"> 31</span> <span class="preprocessor">#include "<a class="code" href="_hue_exception_8h.html">HueException.h</a>"</span></div><div class="line"><a name="l00032"></a><span class="lineno"> 32</span> <span class="preprocessor">#include "<a class="code" href="_new_device_list_8h.html">NewDeviceList.h</a>"</span></div><div class="line"><a name="l00033"></a><span class="lineno"> 33</span> <span class="preprocessor">#include "<a class="code" href="_utils_8h.html">Utils.h</a>"</span></div><div class="line"><a name="l00034"></a><span class="lineno"> 34</span> </div><div class="line"><a name="l00035"></a><span class="lineno"> 35</span> <span class="keyword">namespace </span><a class="code" href="namespacehueplusplus.html">hueplusplus</a></div><div class="line"><a name="l00036"></a><span class="lineno"> 36</span> {</div><div class="line"><a name="l00045"></a><span class="lineno"> 45</span> <span class="keyword">template</span> <<span class="keyword">typename</span> Resource, <span class="keyword">typename</span> IdT></div><div class="line"><a name="l00046"></a><span class="lineno"><a class="line" href="classhueplusplus_1_1_resource_list.html"> 46</a></span> <span class="keyword">class </span><a class="code" href="classhueplusplus_1_1_resource_list.html">ResourceList</a></div><div class="line"><a name="l00047"></a><span class="lineno"> 47</span> {</div><div class="line"><a name="l00048"></a><span class="lineno"> 48</span> <span class="keyword">public</span>:</div><div class="line"><a name="l00049"></a><span class="lineno"><a class="line" href="classhueplusplus_1_1_resource_list.html#a177194d18e9f0f37228a262d6dd6a73c"> 49</a></span>  <span class="keyword">using</span> <a class="code" href="classhueplusplus_1_1_resource_list.html#a177194d18e9f0f37228a262d6dd6a73c">ResourceType</a> = Resource;</div><div class="line"><a name="l00050"></a><span class="lineno"><a class="line" href="classhueplusplus_1_1_resource_list.html#ab122d90e1fcfde172b21670c74b33f89"> 50</a></span>  <span class="keyword">using</span> <a class="code" href="classhueplusplus_1_1_resource_list.html#ab122d90e1fcfde172b21670c74b33f89">IdType</a> = IdT;</div><div class="line"><a name="l00051"></a><span class="lineno"> 51</span>  static_assert(std::is_integral<IdType>::value || std::is_same<std::string, IdType>::value,</div><div class="line"><a name="l00052"></a><span class="lineno"> 52</span>  <span class="stringliteral">"IdType must be integral or string"</span>);</div><div class="line"><a name="l00053"></a><span class="lineno"> 53</span> </div><div class="line"><a name="l00061"></a><span class="lineno"><a class="line" href="classhueplusplus_1_1_resource_list.html#a92d644c4440523ba31d36da291ce499a"> 61</a></span>  <a class="code" href="classhueplusplus_1_1_resource_list.html#a92d644c4440523ba31d36da291ce499a">ResourceList</a>(std::shared_ptr<APICache> baseCache, <span class="keyword">const</span> std::string& cacheEntry,</div><div class="line"><a name="l00062"></a><span class="lineno"> 62</span>  std::chrono::steady_clock::duration refreshDuration, <span class="keywordtype">bool</span> <a class="code" href="classhueplusplus_1_1_resource_list.html#abc08e43ff0bd00145331db6a39fd1708">sharedState</a> = <span class="keyword">false</span>,</div><div class="line"><a name="l00063"></a><span class="lineno"> 63</span>  <span class="keyword">const</span> std::function<Resource(<a class="code" href="classhueplusplus_1_1_resource_list.html#ab122d90e1fcfde172b21670c74b33f89">IdType</a>, <span class="keyword">const</span> nlohmann::json&, <span class="keyword">const</span> std::shared_ptr<APICache>&)>& <a class="code" href="classhueplusplus_1_1_resource_list.html#ac5777102379d55049380d777e779f56f">factory</a></div><div class="line"><a name="l00064"></a><span class="lineno"> 64</span>  = <span class="keyword">nullptr</span>)</div><div class="line"><a name="l00065"></a><span class="lineno"> 65</span>  : <a class="code" href="classhueplusplus_1_1_resource_list.html#abc77b3be3e5e8da4c7b6cfe86637f048">stateCache</a>(std::make_shared<<a class="code" href="classhueplusplus_1_1_a_p_i_cache.html">APICache</a>>(baseCache, cacheEntry, refreshDuration)),</div><div class="line"><a name="l00066"></a><span class="lineno"> 66</span>  <a class="code" href="classhueplusplus_1_1_resource_list.html#ac5777102379d55049380d777e779f56f">factory</a>(<a class="code" href="classhueplusplus_1_1_resource_list.html#ac5777102379d55049380d777e779f56f">factory</a>),</div><div class="line"><a name="l00067"></a><span class="lineno"> 67</span>  <a class="code" href="classhueplusplus_1_1_resource_list.html#ac3490f9e6b165f3a71c13337887a1a88">path</a>(<a class="code" href="classhueplusplus_1_1_resource_list.html#abc77b3be3e5e8da4c7b6cfe86637f048">stateCache</a>->getRequestPath() + <span class="stringliteral">'/'</span>),</div><div class="line"><a name="l00068"></a><span class="lineno"> 68</span>  <a class="code" href="classhueplusplus_1_1_resource_list.html#abc08e43ff0bd00145331db6a39fd1708">sharedState</a>(<a class="code" href="classhueplusplus_1_1_resource_list.html#abc08e43ff0bd00145331db6a39fd1708">sharedState</a>)</div><div class="line"><a name="l00069"></a><span class="lineno"> 69</span>  { }</div><div class="line"><a name="l00076"></a><span class="lineno"><a class="line" href="classhueplusplus_1_1_resource_list.html#a3ad0fc473c4b3ac35210da9f2909e034"> 76</a></span>  <a class="code" href="classhueplusplus_1_1_resource_list.html#a3ad0fc473c4b3ac35210da9f2909e034">ResourceList</a>(<span class="keyword">const</span> <a class="code" href="classhueplusplus_1_1_hue_command_a_p_i.html">HueCommandAPI</a>& commands, <span class="keyword">const</span> std::string& <a class="code" href="classhueplusplus_1_1_resource_list.html#ac3490f9e6b165f3a71c13337887a1a88">path</a>,</div><div class="line"><a name="l00077"></a><span class="lineno"> 77</span>  std::chrono::steady_clock::duration refreshDuration,</div><div class="line"><a name="l00078"></a><span class="lineno"> 78</span>  <span class="keyword">const</span> std::function<Resource(<a class="code" href="classhueplusplus_1_1_resource_list.html#ab122d90e1fcfde172b21670c74b33f89">IdType</a>, <span class="keyword">const</span> nlohmann::json&, <span class="keyword">const</span> std::shared_ptr<APICache>&)>& <a class="code" href="classhueplusplus_1_1_resource_list.html#ac5777102379d55049380d777e779f56f">factory</a></div><div class="line"><a name="l00079"></a><span class="lineno"> 79</span>  = <span class="keyword">nullptr</span>)</div><div class="line"><a name="l00080"></a><span class="lineno"> 80</span>  : <a class="code" href="classhueplusplus_1_1_resource_list.html#abc77b3be3e5e8da4c7b6cfe86637f048">stateCache</a>(std::make_shared<<a class="code" href="classhueplusplus_1_1_a_p_i_cache.html">APICache</a>>(path, commands, refreshDuration, nullptr)),</div><div class="line"><a name="l00081"></a><span class="lineno"> 81</span>  <a class="code" href="classhueplusplus_1_1_resource_list.html#ac5777102379d55049380d777e779f56f">factory</a>(<a class="code" href="classhueplusplus_1_1_resource_list.html#ac5777102379d55049380d777e779f56f">factory</a>),</div><div class="line"><a name="l00082"></a><span class="lineno"> 82</span>  path(path + <span class="stringliteral">'/'</span>),</div><div class="line"><a name="l00083"></a><span class="lineno"> 83</span>  <a class="code" href="classhueplusplus_1_1_resource_list.html#abc08e43ff0bd00145331db6a39fd1708">sharedState</a>(false)</div><div class="line"><a name="l00084"></a><span class="lineno"> 84</span>  { }</div><div class="line"><a name="l00085"></a><span class="lineno"> 85</span> </div><div class="line"><a name="l00087"></a><span class="lineno"> 87</span>  <a class="code" href="classhueplusplus_1_1_resource_list.html#a92d644c4440523ba31d36da291ce499a">ResourceList</a>(<span class="keyword">const</span> <a class="code" href="classhueplusplus_1_1_resource_list.html">ResourceList</a>&) = <span class="keyword">delete</span>;</div><div class="line"><a name="l00089"></a><span class="lineno"> 89</span>  <a class="code" href="classhueplusplus_1_1_resource_list.html">ResourceList</a>& <a class="code" href="classhueplusplus_1_1_resource_list.html#aa75121b18d67faf84ff6b894d0c45b0b">operator=</a>(<span class="keyword">const</span> <a class="code" href="classhueplusplus_1_1_resource_list.html">ResourceList</a>&) = <span class="keyword">delete</span>;</div><div class="line"><a name="l00090"></a><span class="lineno"> 90</span> </div><div class="line"><a name="l00092"></a><span class="lineno"><a class="line" href="classhueplusplus_1_1_resource_list.html#a6fe81cf76931d2bcf9dda56ea63524bd"> 92</a></span>  <span class="keywordtype">void</span> <a class="code" href="classhueplusplus_1_1_resource_list.html#a6fe81cf76931d2bcf9dda56ea63524bd">refresh</a>() { <a class="code" href="classhueplusplus_1_1_resource_list.html#abc77b3be3e5e8da4c7b6cfe86637f048">stateCache</a>->refresh(); }</div><div class="line"><a name="l00093"></a><span class="lineno"> 93</span> </div><div class="line"><a name="l00096"></a><span class="lineno"><a class="line" href="classhueplusplus_1_1_resource_list.html#aa165e446439defcae7d1bf05b4576739"> 96</a></span>  <span class="keywordtype">void</span> <a class="code" href="classhueplusplus_1_1_resource_list.html#aa165e446439defcae7d1bf05b4576739">setRefreshDuration</a>(std::chrono::steady_clock::duration refreshDuration)</div><div class="line"><a name="l00097"></a><span class="lineno"> 97</span>  {</div><div class="line"><a name="l00098"></a><span class="lineno"> 98</span>  <a class="code" href="classhueplusplus_1_1_resource_list.html#abc77b3be3e5e8da4c7b6cfe86637f048">stateCache</a>->setRefreshDuration(refreshDuration);</div><div class="line"><a name="l00099"></a><span class="lineno"> 99</span>  }</div><div class="line"><a name="l00100"></a><span class="lineno"> 100</span> </div><div class="line"><a name="l00107"></a><span class="lineno"><a class="line" href="classhueplusplus_1_1_resource_list.html#ad7b3bef47b0c09764377cbad327545df"> 107</a></span>  std::vector<Resource> <a class="code" href="classhueplusplus_1_1_resource_list.html#ad7b3bef47b0c09764377cbad327545df">getAll</a>()</div><div class="line"><a name="l00108"></a><span class="lineno"> 108</span>  {</div><div class="line"><a name="l00109"></a><span class="lineno"> 109</span>  nlohmann::json& state = <a class="code" href="classhueplusplus_1_1_resource_list.html#abc77b3be3e5e8da4c7b6cfe86637f048">stateCache</a>->getValue();</div><div class="line"><a name="l00110"></a><span class="lineno"> 110</span>  std::vector<Resource> result;</div><div class="line"><a name="l00111"></a><span class="lineno"> 111</span>  result.reserve(state.size());</div><div class="line"><a name="l00112"></a><span class="lineno"> 112</span>  <span class="keywordflow">for</span> (<span class="keyword">auto</span> it = state.begin(); it != state.end(); ++it)</div><div class="line"><a name="l00113"></a><span class="lineno"> 113</span>  {</div><div class="line"><a name="l00114"></a><span class="lineno"> 114</span>  result.emplace_back(<a class="code" href="classhueplusplus_1_1_resource_list.html#ab98434ae91b0868dcf9cb95dfa168c95">construct</a>(<a class="code" href="classhueplusplus_1_1_resource_list.html#ab98e351ff57e1674cc5aa25f150a4471">maybeStoi</a>(it.key()), it.value()));</div><div class="line"><a name="l00115"></a><span class="lineno"> 115</span>  }</div><div class="line"><a name="l00116"></a><span class="lineno"> 116</span>  <span class="keywordflow">return</span> result;</div><div class="line"><a name="l00117"></a><span class="lineno"> 117</span>  }</div><div class="line"><a name="l00118"></a><span class="lineno"> 118</span> </div><div class="line"><a name="l00126"></a><span class="lineno"><a class="line" href="classhueplusplus_1_1_resource_list.html#a7bcf2ed48e70e9f11a4b6bdc24e0e611"> 126</a></span>  Resource <span class="keyword">get</span>(<span class="keyword">const</span> <a class="code" href="classhueplusplus_1_1_resource_list.html#ab122d90e1fcfde172b21670c74b33f89">IdType</a>& id)</div><div class="line"><a name="l00127"></a><span class="lineno"> 127</span>  {</div><div class="line"><a name="l00128"></a><span class="lineno"> 128</span>  <span class="keyword">const</span> nlohmann::json& state = <a class="code" href="classhueplusplus_1_1_resource_list.html#abc77b3be3e5e8da4c7b6cfe86637f048">stateCache</a>->getValue();</div><div class="line"><a name="l00129"></a><span class="lineno"> 129</span>  std::string key = <a class="code" href="classhueplusplus_1_1_resource_list.html#ae26bacb486e03c961d992da82d63fdd6">maybeToString</a>(<span class="keywordtype">id</span>);</div><div class="line"><a name="l00130"></a><span class="lineno"> 130</span>  <span class="keywordflow">if</span> (!state.count(key))</div><div class="line"><a name="l00131"></a><span class="lineno"> 131</span>  {</div><div class="line"><a name="l00132"></a><span class="lineno"> 132</span>  <span class="keywordflow">throw</span> <a class="code" href="classhueplusplus_1_1_hue_exception.html">HueException</a>(<a class="code" href="structhueplusplus_1_1_file_info.html">FileInfo</a> {__FILE__, __LINE__, __func__}, <span class="stringliteral">"Resource id is not valid"</span>);</div><div class="line"><a name="l00133"></a><span class="lineno"> 133</span>  }</div><div class="line"><a name="l00134"></a><span class="lineno"> 134</span>  <span class="keywordflow">return</span> <a class="code" href="classhueplusplus_1_1_resource_list.html#ab98434ae91b0868dcf9cb95dfa168c95">construct</a>(<span class="keywordtype">id</span>, state[key]);</div><div class="line"><a name="l00135"></a><span class="lineno"> 135</span>  }</div><div class="line"><a name="l00136"></a><span class="lineno"> 136</span> </div><div class="line"><a name="l00144"></a><span class="lineno"><a class="line" href="classhueplusplus_1_1_resource_list.html#af5e884eefde0a45d53f029a9f30a6ab7"> 144</a></span>  <span class="keywordtype">bool</span> <a class="code" href="classhueplusplus_1_1_resource_list.html#af5e884eefde0a45d53f029a9f30a6ab7">exists</a>(<span class="keyword">const</span> <a class="code" href="classhueplusplus_1_1_resource_list.html#ab122d90e1fcfde172b21670c74b33f89">IdType</a>& <span class="keywordtype">id</span>) { <span class="keywordflow">return</span> <a class="code" href="classhueplusplus_1_1_resource_list.html#abc77b3be3e5e8da4c7b6cfe86637f048">stateCache</a>->getValue().count(<a class="code" href="classhueplusplus_1_1_resource_list.html#ae26bacb486e03c961d992da82d63fdd6">maybeToString</a>(<span class="keywordtype">id</span>)) != 0; }</div><div class="line"><a name="l00145"></a><span class="lineno"> 145</span> </div><div class="line"><a name="l00151"></a><span class="lineno"><a class="line" href="classhueplusplus_1_1_resource_list.html#a8c0219d853d551394020b7b482518070"> 151</a></span>  <span class="keywordtype">bool</span> <a class="code" href="classhueplusplus_1_1_resource_list.html#a8c0219d853d551394020b7b482518070">exists</a>(<span class="keyword">const</span> <a class="code" href="classhueplusplus_1_1_resource_list.html#ab122d90e1fcfde172b21670c74b33f89">IdType</a>& <span class="keywordtype">id</span>)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="classhueplusplus_1_1_resource_list.html#abc77b3be3e5e8da4c7b6cfe86637f048">stateCache</a>->getValue().count(<a class="code" href="classhueplusplus_1_1_resource_list.html#ae26bacb486e03c961d992da82d63fdd6">maybeToString</a>(<span class="keywordtype">id</span>)) != 0; }</div><div class="line"><a name="l00152"></a><span class="lineno"> 152</span> </div><div class="line"><a name="l00162"></a><span class="lineno"><a class="line" href="classhueplusplus_1_1_resource_list.html#ac65ac738c8cf0eaac35634ccffa455f5"> 162</a></span>  <span class="keywordtype">bool</span> <span class="keyword">remove</span>(<span class="keyword">const</span> <a class="code" href="classhueplusplus_1_1_resource_list.html#ab122d90e1fcfde172b21670c74b33f89">IdType</a>& id)</div><div class="line"><a name="l00163"></a><span class="lineno"> 163</span>  {</div><div class="line"><a name="l00164"></a><span class="lineno"> 164</span>  std::string requestPath = path + <a class="code" href="classhueplusplus_1_1_resource_list.html#ae26bacb486e03c961d992da82d63fdd6">maybeToString</a>(<span class="keywordtype">id</span>);</div><div class="line"><a name="l00165"></a><span class="lineno"> 165</span>  nlohmann::json result = <a class="code" href="classhueplusplus_1_1_resource_list.html#abc77b3be3e5e8da4c7b6cfe86637f048">stateCache</a>->getCommandAPI().DELETERequest(</div><div class="line"><a name="l00166"></a><span class="lineno"> 166</span>  requestPath, nlohmann::json::object(), <a class="code" href="structhueplusplus_1_1_file_info.html">FileInfo</a> {__FILE__, __LINE__, __func__});</div><div class="line"><a name="l00167"></a><span class="lineno"> 167</span>  <span class="keywordtype">bool</span> success = <a class="code" href="namespacehueplusplus_1_1utils.html#ae6268e7923eee8d5300471820c3d8094">utils::safeGetMember</a>(result, 0, <span class="stringliteral">"success"</span>) == requestPath + <span class="stringliteral">" deleted"</span>;</div><div class="line"><a name="l00168"></a><span class="lineno"> 168</span>  <span class="keywordflow">return</span> success;</div><div class="line"><a name="l00169"></a><span class="lineno"> 169</span>  }</div><div class="line"><a name="l00170"></a><span class="lineno"> 170</span> </div><div class="line"><a name="l00171"></a><span class="lineno"> 171</span> <span class="keyword">protected</span>:</div><div class="line"><a name="l00173"></a><span class="lineno"><a class="line" href="classhueplusplus_1_1_resource_list.html#ab98e351ff57e1674cc5aa25f150a4471"> 173</a></span>  <span class="keyword">static</span> <a class="code" href="classhueplusplus_1_1_resource_list.html#ab122d90e1fcfde172b21670c74b33f89">IdType</a> <a class="code" href="classhueplusplus_1_1_resource_list.html#ab98e351ff57e1674cc5aa25f150a4471">maybeStoi</a>(<span class="keyword">const</span> std::string& key) { <span class="keywordflow">return</span> <a class="code" href="classhueplusplus_1_1_resource_list.html#ab98e351ff57e1674cc5aa25f150a4471">maybeStoi</a>(key, std::is_integral<IdType> {}); }</div><div class="line"><a name="l00174"></a><span class="lineno"> 174</span> </div><div class="line"><a name="l00176"></a><span class="lineno"><a class="line" href="classhueplusplus_1_1_resource_list.html#ae26bacb486e03c961d992da82d63fdd6"> 176</a></span>  <span class="keyword">static</span> std::string <a class="code" href="classhueplusplus_1_1_resource_list.html#ae26bacb486e03c961d992da82d63fdd6">maybeToString</a>(<span class="keyword">const</span> <a class="code" href="classhueplusplus_1_1_resource_list.html#ab122d90e1fcfde172b21670c74b33f89">IdType</a>& <span class="keywordtype">id</span>) { <span class="keywordflow">return</span> <a class="code" href="classhueplusplus_1_1_resource_list.html#ae26bacb486e03c961d992da82d63fdd6">maybeToString</a>(<span class="keywordtype">id</span>, std::is_integral<IdType> {}); }</div><div class="line"><a name="l00177"></a><span class="lineno"> 177</span> </div><div class="line"><a name="l00180"></a><span class="lineno"><a class="line" href="classhueplusplus_1_1_resource_list.html#ab98434ae91b0868dcf9cb95dfa168c95"> 180</a></span>  Resource <a class="code" href="classhueplusplus_1_1_resource_list.html#ab98434ae91b0868dcf9cb95dfa168c95">construct</a>(<span class="keyword">const</span> <a class="code" href="classhueplusplus_1_1_resource_list.html#ab122d90e1fcfde172b21670c74b33f89">IdType</a>& <span class="keywordtype">id</span>, <span class="keyword">const</span> nlohmann::json& state)</div><div class="line"><a name="l00181"></a><span class="lineno"> 181</span>  {</div><div class="line"><a name="l00182"></a><span class="lineno"> 182</span>  <span class="keywordflow">return</span> <a class="code" href="classhueplusplus_1_1_resource_list.html#ab98434ae91b0868dcf9cb95dfa168c95">construct</a>(<span class="keywordtype">id</span>, state,</div><div class="line"><a name="l00183"></a><span class="lineno"> 183</span>  std::is_constructible<Resource, <a class="code" href="classhueplusplus_1_1_resource_list.html#ab122d90e1fcfde172b21670c74b33f89">IdType</a>, <a class="code" href="classhueplusplus_1_1_hue_command_a_p_i.html">HueCommandAPI</a>, std::chrono::steady_clock::duration,</div><div class="line"><a name="l00184"></a><span class="lineno"> 184</span>  <span class="keyword">const</span> nlohmann::json&> {});</div><div class="line"><a name="l00185"></a><span class="lineno"> 185</span>  }</div><div class="line"><a name="l00186"></a><span class="lineno"> 186</span> </div><div class="line"><a name="l00188"></a><span class="lineno"> 188</span>  <a class="code" href="classhueplusplus_1_1_resource_list.html#a92d644c4440523ba31d36da291ce499a">ResourceList</a>(<a class="code" href="classhueplusplus_1_1_resource_list.html">ResourceList</a>&&) = <span class="keywordflow">default</span>;</div><div class="line"><a name="l00190"></a><span class="lineno"> 190</span>  <a class="code" href="classhueplusplus_1_1_resource_list.html">ResourceList</a>& <a class="code" href="classhueplusplus_1_1_resource_list.html#aa75121b18d67faf84ff6b894d0c45b0b">operator=</a>(<a class="code" href="classhueplusplus_1_1_resource_list.html">ResourceList</a>&&) = <span class="keywordflow">default</span>;</div><div class="line"><a name="l00191"></a><span class="lineno"> 191</span> </div><div class="line"><a name="l00192"></a><span class="lineno"> 192</span> <span class="keyword">private</span>:</div><div class="line"><a name="l00193"></a><span class="lineno"> 193</span>  <span class="comment">// Resource is constructible</span></div><div class="line"><a name="l00194"></a><span class="lineno"> 194</span>  Resource <a class="code" href="classhueplusplus_1_1_resource_list.html#ab98434ae91b0868dcf9cb95dfa168c95">construct</a>(<span class="keyword">const</span> <a class="code" href="classhueplusplus_1_1_resource_list.html#ab122d90e1fcfde172b21670c74b33f89">IdType</a>& <span class="keywordtype">id</span>, <span class="keyword">const</span> nlohmann::json& state, std::true_type)</div><div class="line"><a name="l00195"></a><span class="lineno"> 195</span>  {</div><div class="line"><a name="l00196"></a><span class="lineno"> 196</span>  <span class="keywordflow">if</span> (<a class="code" href="classhueplusplus_1_1_resource_list.html#ac5777102379d55049380d777e779f56f">factory</a>)</div><div class="line"><a name="l00197"></a><span class="lineno"> 197</span>  {</div><div class="line"><a name="l00198"></a><span class="lineno"> 198</span>  <span class="keywordflow">return</span> <a class="code" href="classhueplusplus_1_1_resource_list.html#ac5777102379d55049380d777e779f56f">factory</a>(<span class="keywordtype">id</span>, state, <a class="code" href="classhueplusplus_1_1_resource_list.html#abc08e43ff0bd00145331db6a39fd1708">sharedState</a> ? <a class="code" href="classhueplusplus_1_1_resource_list.html#abc77b3be3e5e8da4c7b6cfe86637f048">stateCache</a> : std::shared_ptr<APICache>());</div><div class="line"><a name="l00199"></a><span class="lineno"> 199</span>  }</div><div class="line"><a name="l00200"></a><span class="lineno"> 200</span>  <span class="keywordflow">else</span></div><div class="line"><a name="l00201"></a><span class="lineno"> 201</span>  {</div><div class="line"><a name="l00202"></a><span class="lineno"> 202</span>  <span class="keywordflow">if</span> (<a class="code" href="classhueplusplus_1_1_resource_list.html#abc08e43ff0bd00145331db6a39fd1708">sharedState</a>)</div><div class="line"><a name="l00203"></a><span class="lineno"> 203</span>  {</div><div class="line"><a name="l00204"></a><span class="lineno"> 204</span>  <span class="keywordflow">return</span> Resource(<span class="keywordtype">id</span>, <a class="code" href="classhueplusplus_1_1_resource_list.html#abc77b3be3e5e8da4c7b6cfe86637f048">stateCache</a>);</div><div class="line"><a name="l00205"></a><span class="lineno"> 205</span>  }</div><div class="line"><a name="l00206"></a><span class="lineno"> 206</span>  <span class="keywordflow">else</span></div><div class="line"><a name="l00207"></a><span class="lineno"> 207</span>  {</div><div class="line"><a name="l00208"></a><span class="lineno"> 208</span>  <span class="keywordflow">return</span> Resource(<span class="keywordtype">id</span>, <a class="code" href="classhueplusplus_1_1_resource_list.html#abc77b3be3e5e8da4c7b6cfe86637f048">stateCache</a>->getCommandAPI(), <a class="code" href="classhueplusplus_1_1_resource_list.html#abc77b3be3e5e8da4c7b6cfe86637f048">stateCache</a>->getRefreshDuration(), state);</div><div class="line"><a name="l00209"></a><span class="lineno"> 209</span>  }</div><div class="line"><a name="l00210"></a><span class="lineno"> 210</span>  }</div><div class="line"><a name="l00211"></a><span class="lineno"> 211</span>  }</div><div class="line"><a name="l00212"></a><span class="lineno"> 212</span>  <span class="comment">// Resource is not constructible</span></div><div class="line"><a name="l00213"></a><span class="lineno"> 213</span>  Resource <a class="code" href="classhueplusplus_1_1_resource_list.html#ab98434ae91b0868dcf9cb95dfa168c95">construct</a>(<span class="keyword">const</span> <a class="code" href="classhueplusplus_1_1_resource_list.html#ab122d90e1fcfde172b21670c74b33f89">IdType</a>& <span class="keywordtype">id</span>, <span class="keyword">const</span> nlohmann::json& state, std::false_type)</div><div class="line"><a name="l00214"></a><span class="lineno"> 214</span>  {</div><div class="line"><a name="l00215"></a><span class="lineno"> 215</span>  <span class="keywordflow">if</span> (!<a class="code" href="classhueplusplus_1_1_resource_list.html#ac5777102379d55049380d777e779f56f">factory</a>)</div><div class="line"><a name="l00216"></a><span class="lineno"> 216</span>  {</div><div class="line"><a name="l00217"></a><span class="lineno"> 217</span>  <span class="keywordflow">throw</span> <a class="code" href="classhueplusplus_1_1_hue_exception.html">HueException</a>(<a class="code" href="structhueplusplus_1_1_file_info.html">FileInfo</a> {__FILE__, __LINE__, __func__},</div><div class="line"><a name="l00218"></a><span class="lineno"> 218</span>  <span class="stringliteral">"Resource is not constructable with default parameters, but no factory given"</span>);</div><div class="line"><a name="l00219"></a><span class="lineno"> 219</span>  }</div><div class="line"><a name="l00220"></a><span class="lineno"> 220</span>  <span class="keywordflow">return</span> <a class="code" href="classhueplusplus_1_1_resource_list.html#ac5777102379d55049380d777e779f56f">factory</a>(<span class="keywordtype">id</span>, state, <a class="code" href="classhueplusplus_1_1_resource_list.html#abc08e43ff0bd00145331db6a39fd1708">sharedState</a> ? <a class="code" href="classhueplusplus_1_1_resource_list.html#abc77b3be3e5e8da4c7b6cfe86637f048">stateCache</a> : std::shared_ptr<APICache>());</div><div class="line"><a name="l00221"></a><span class="lineno"> 221</span>  }</div><div class="line"><a name="l00222"></a><span class="lineno"> 222</span> </div><div class="line"><a name="l00223"></a><span class="lineno"> 223</span> <span class="keyword">private</span>:</div><div class="line"><a name="l00224"></a><span class="lineno"> 224</span>  <span class="keyword">static</span> <a class="code" href="classhueplusplus_1_1_resource_list.html#ab122d90e1fcfde172b21670c74b33f89">IdType</a> <a class="code" href="classhueplusplus_1_1_resource_list.html#ab98e351ff57e1674cc5aa25f150a4471">maybeStoi</a>(<span class="keyword">const</span> std::string& key, std::true_type) { <span class="keywordflow">return</span> std::stoi(key); }</div><div class="line"><a name="l00225"></a><span class="lineno"> 225</span>  <span class="keyword">static</span> <a class="code" href="classhueplusplus_1_1_resource_list.html#ab122d90e1fcfde172b21670c74b33f89">IdType</a> <a class="code" href="classhueplusplus_1_1_resource_list.html#ab98e351ff57e1674cc5aa25f150a4471">maybeStoi</a>(<span class="keyword">const</span> std::string& key, std::false_type) { <span class="keywordflow">return</span> key; }</div><div class="line"><a name="l00226"></a><span class="lineno"> 226</span>  <span class="keyword">static</span> std::string <a class="code" href="classhueplusplus_1_1_resource_list.html#ae26bacb486e03c961d992da82d63fdd6">maybeToString</a>(<a class="code" href="classhueplusplus_1_1_resource_list.html#ab122d90e1fcfde172b21670c74b33f89">IdType</a> <span class="keywordtype">id</span>, std::true_type) { <span class="keywordflow">return</span> std::to_string(<span class="keywordtype">id</span>); }</div><div class="line"><a name="l00227"></a><span class="lineno"> 227</span>  <span class="keyword">static</span> std::string <a class="code" href="classhueplusplus_1_1_resource_list.html#ae26bacb486e03c961d992da82d63fdd6">maybeToString</a>(<span class="keyword">const</span> <a class="code" href="classhueplusplus_1_1_resource_list.html#ab122d90e1fcfde172b21670c74b33f89">IdType</a>& <span class="keywordtype">id</span>, std::false_type) { <span class="keywordflow">return</span> id; }</div><div class="line"><a name="l00228"></a><span class="lineno"> 228</span> </div><div class="line"><a name="l00229"></a><span class="lineno"> 229</span> <span class="keyword">protected</span>:</div><div class="line"><a name="l00230"></a><span class="lineno"><a class="line" href="classhueplusplus_1_1_resource_list.html#abc77b3be3e5e8da4c7b6cfe86637f048"> 230</a></span>  std::shared_ptr<APICache> <a class="code" href="classhueplusplus_1_1_resource_list.html#abc77b3be3e5e8da4c7b6cfe86637f048">stateCache</a>;</div><div class="line"><a name="l00231"></a><span class="lineno"><a class="line" href="classhueplusplus_1_1_resource_list.html#ac5777102379d55049380d777e779f56f"> 231</a></span>  std::function<Resource(IdType, const nlohmann::json&, const std::shared_ptr<APICache>&)> <a class="code" href="classhueplusplus_1_1_resource_list.html#ac5777102379d55049380d777e779f56f">factory</a>;</div><div class="line"><a name="l00232"></a><span class="lineno"><a class="line" href="classhueplusplus_1_1_resource_list.html#ac3490f9e6b165f3a71c13337887a1a88"> 232</a></span>  std::string <a class="code" href="classhueplusplus_1_1_resource_list.html#ac3490f9e6b165f3a71c13337887a1a88">path</a>;</div><div class="line"><a name="l00233"></a><span class="lineno"><a class="line" href="classhueplusplus_1_1_resource_list.html#abc08e43ff0bd00145331db6a39fd1708"> 233</a></span>  <span class="keywordtype">bool</span> <a class="code" href="classhueplusplus_1_1_resource_list.html#abc08e43ff0bd00145331db6a39fd1708">sharedState</a>;</div><div class="line"><a name="l00234"></a><span class="lineno"> 234</span> };</div><div class="line"><a name="l00235"></a><span class="lineno"> 235</span> </div><div class="line"><a name="l00238"></a><span class="lineno"> 238</span> <span class="keyword">template</span> <<span class="keyword">typename</span> Resource></div><div class="line"><a name="l00239"></a><span class="lineno"><a class="line" href="classhueplusplus_1_1_searchable_resource_list.html"> 239</a></span> <span class="keyword">class </span><a class="code" href="classhueplusplus_1_1_searchable_resource_list.html">SearchableResourceList</a> : <span class="keyword">public</span> <a class="code" href="classhueplusplus_1_1_resource_list.html">ResourceList</a><Resource, int></div><div class="line"><a name="l00240"></a><span class="lineno"> 240</span> {</div><div class="line"><a name="l00241"></a><span class="lineno"> 241</span> <span class="keyword">public</span>:</div><div class="line"><a name="l00242"></a><span class="lineno"> 242</span>  <span class="keyword">using</span> <a class="code" href="classhueplusplus_1_1_resource_list.html">ResourceList<Resource, int>::ResourceList</a>;</div><div class="line"><a name="l00243"></a><span class="lineno"> 243</span> </div><div class="line"><a name="l00248"></a><span class="lineno"><a class="line" href="classhueplusplus_1_1_searchable_resource_list.html#aa67cf6cc3bde30b1c8a79d98d270ae32"> 248</a></span>  <span class="keywordtype">void</span> <a class="code" href="classhueplusplus_1_1_searchable_resource_list.html#aa67cf6cc3bde30b1c8a79d98d270ae32">search</a>(<span class="keyword">const</span> std::vector<std::string>& deviceIds = {})</div><div class="line"><a name="l00249"></a><span class="lineno"> 249</span>  {</div><div class="line"><a name="l00250"></a><span class="lineno"> 250</span>  std::string requestPath = this-><a class="code" href="classhueplusplus_1_1_resource_list.html#ac3490f9e6b165f3a71c13337887a1a88">path</a>;</div><div class="line"><a name="l00251"></a><span class="lineno"> 251</span>  <span class="comment">// Remove trailing slash</span></div><div class="line"><a name="l00252"></a><span class="lineno"> 252</span>  requestPath.pop_back();</div><div class="line"><a name="l00253"></a><span class="lineno"> 253</span>  <span class="keywordflow">if</span> (deviceIds.empty())</div><div class="line"><a name="l00254"></a><span class="lineno"> 254</span>  {</div><div class="line"><a name="l00255"></a><span class="lineno"> 255</span>  this-><a class="code" href="classhueplusplus_1_1_resource_list.html#abc77b3be3e5e8da4c7b6cfe86637f048">stateCache</a>->getCommandAPI().POSTRequest(</div><div class="line"><a name="l00256"></a><span class="lineno"> 256</span>  requestPath, nlohmann::json::object(), <a class="code" href="structhueplusplus_1_1_file_info.html">FileInfo</a> {__FILE__, __LINE__, __func__});</div><div class="line"><a name="l00257"></a><span class="lineno"> 257</span>  }</div><div class="line"><a name="l00258"></a><span class="lineno"> 258</span>  <span class="keywordflow">else</span></div><div class="line"><a name="l00259"></a><span class="lineno"> 259</span>  {</div><div class="line"><a name="l00260"></a><span class="lineno"> 260</span>  this-><a class="code" href="classhueplusplus_1_1_resource_list.html#abc77b3be3e5e8da4c7b6cfe86637f048">stateCache</a>->getCommandAPI().POSTRequest(</div><div class="line"><a name="l00261"></a><span class="lineno"> 261</span>  requestPath, nlohmann::json {{<span class="stringliteral">"deviceid"</span>, deviceIds}}, <a class="code" href="structhueplusplus_1_1_file_info.html">FileInfo</a> {__FILE__, __LINE__, __func__});</div><div class="line"><a name="l00262"></a><span class="lineno"> 262</span>  }</div><div class="line"><a name="l00263"></a><span class="lineno"> 263</span>  }</div><div class="line"><a name="l00264"></a><span class="lineno"> 264</span> </div><div class="line"><a name="l00266"></a><span class="lineno"><a class="line" href="classhueplusplus_1_1_searchable_resource_list.html#a07bc6249721ec996a38091ee7c46ef3d"> 266</a></span>  <a class="code" href="classhueplusplus_1_1_new_device_list.html">NewDeviceList</a> <a class="code" href="classhueplusplus_1_1_searchable_resource_list.html#a07bc6249721ec996a38091ee7c46ef3d">getNewDevices</a>()<span class="keyword"> const</span></div><div class="line"><a name="l00267"></a><span class="lineno"> 267</span> <span class="keyword"> </span>{</div><div class="line"><a name="l00268"></a><span class="lineno"> 268</span>  nlohmann::json response = this-><a class="code" href="classhueplusplus_1_1_resource_list.html#abc77b3be3e5e8da4c7b6cfe86637f048">stateCache</a>->getCommandAPI().GETRequest(</div><div class="line"><a name="l00269"></a><span class="lineno"> 269</span>  this-><a class="code" href="classhueplusplus_1_1_resource_list.html#ac3490f9e6b165f3a71c13337887a1a88">path</a> + <span class="stringliteral">"new"</span>, nlohmann::json::object(), <a class="code" href="structhueplusplus_1_1_file_info.html">FileInfo</a> {__FILE__, __LINE__, __func__});</div><div class="line"><a name="l00270"></a><span class="lineno"> 270</span>  <span class="keywordflow">return</span> <a class="code" href="classhueplusplus_1_1_new_device_list.html#a5b529a5a874e4acc4c00d9ad3a34e650">NewDeviceList::parse</a>(response);</div><div class="line"><a name="l00271"></a><span class="lineno"> 271</span>  }</div><div class="line"><a name="l00272"></a><span class="lineno"> 272</span> </div><div class="line"><a name="l00273"></a><span class="lineno"> 273</span> <span class="keyword">protected</span>:</div><div class="line"><a name="l00275"></a><span class="lineno"> 275</span>  <a class="code" href="classhueplusplus_1_1_searchable_resource_list.html">SearchableResourceList</a>(<a class="code" href="classhueplusplus_1_1_searchable_resource_list.html">SearchableResourceList</a>&&) = <span class="keywordflow">default</span>;</div><div class="line"><a name="l00277"></a><span class="lineno"> 277</span>  <a class="code" href="classhueplusplus_1_1_searchable_resource_list.html">SearchableResourceList</a>& <a class="code" href="classhueplusplus_1_1_resource_list.html#aa75121b18d67faf84ff6b894d0c45b0b">operator=</a>(<a class="code" href="classhueplusplus_1_1_searchable_resource_list.html">SearchableResourceList</a>&&) = <span class="keywordflow">default</span>;</div><div class="line"><a name="l00278"></a><span class="lineno"> 278</span> };</div><div class="line"><a name="l00279"></a><span class="lineno"> 279</span> </div><div class="line"><a name="l00284"></a><span class="lineno"> 284</span> <span class="keyword">template</span> <<span class="keyword">typename</span> BaseResourceList, <span class="keyword">typename</span> CreateType></div><div class="line"><a name="l00285"></a><span class="lineno"><a class="line" href="classhueplusplus_1_1_createable_resource_list.html"> 285</a></span> <span class="keyword">class </span><a class="code" href="classhueplusplus_1_1_createable_resource_list.html">CreateableResourceList</a> : <span class="keyword">public</span> BaseResourceList</div><div class="line"><a name="l00286"></a><span class="lineno"> 286</span> {</div><div class="line"><a name="l00287"></a><span class="lineno"> 287</span> <span class="keyword">public</span>:</div><div class="line"><a name="l00288"></a><span class="lineno"> 288</span>  <span class="keyword">using</span> BaseResourceList::BaseResourceList;</div><div class="line"><a name="l00289"></a><span class="lineno"> 289</span> </div><div class="line"><a name="l00298"></a><span class="lineno"><a class="line" href="classhueplusplus_1_1_createable_resource_list.html#abf886bbd80f86e00a66c7ad61bd773c9"> 298</a></span>  <span class="keyword">typename</span> BaseResourceList::IdType <a class="code" href="classhueplusplus_1_1_createable_resource_list.html#abf886bbd80f86e00a66c7ad61bd773c9">create</a>(<span class="keyword">const</span> CreateType& params)</div><div class="line"><a name="l00299"></a><span class="lineno"> 299</span>  {</div><div class="line"><a name="l00300"></a><span class="lineno"> 300</span>  std::string requestPath = this-><a class="code" href="classhueplusplus_1_1_resource_list.html#ac3490f9e6b165f3a71c13337887a1a88">path</a>;</div><div class="line"><a name="l00301"></a><span class="lineno"> 301</span>  <span class="comment">// Remove slash</span></div><div class="line"><a name="l00302"></a><span class="lineno"> 302</span>  requestPath.pop_back();</div><div class="line"><a name="l00303"></a><span class="lineno"> 303</span>  nlohmann::json response = this-><a class="code" href="classhueplusplus_1_1_resource_list.html#abc77b3be3e5e8da4c7b6cfe86637f048">stateCache</a>->getCommandAPI().POSTRequest(</div><div class="line"><a name="l00304"></a><span class="lineno"> 304</span>  requestPath, params.getRequest(), <a class="code" href="structhueplusplus_1_1_file_info.html">FileInfo</a> {__FILE__, __LINE__, __func__});</div><div class="line"><a name="l00305"></a><span class="lineno"> 305</span>  nlohmann::json <span class="keywordtype">id</span> = <a class="code" href="namespacehueplusplus_1_1utils.html#ae6268e7923eee8d5300471820c3d8094">utils::safeGetMember</a>(response, 0, <span class="stringliteral">"success"</span>, <span class="stringliteral">"id"</span>);</div><div class="line"><a name="l00306"></a><span class="lineno"> 306</span>  <span class="keywordflow">if</span> (<span class="keywordtype">id</span>.is_string())</div><div class="line"><a name="l00307"></a><span class="lineno"> 307</span>  {</div><div class="line"><a name="l00308"></a><span class="lineno"> 308</span>  std::string idStr = <span class="keywordtype">id</span>.get<std::string>();</div><div class="line"><a name="l00309"></a><span class="lineno"> 309</span>  <span class="keywordflow">if</span> (idStr.find(this->path) == 0)</div><div class="line"><a name="l00310"></a><span class="lineno"> 310</span>  {</div><div class="line"><a name="l00311"></a><span class="lineno"> 311</span>  idStr.erase(0, this-><a class="code" href="classhueplusplus_1_1_resource_list.html#ac3490f9e6b165f3a71c13337887a1a88">path</a>.size());</div><div class="line"><a name="l00312"></a><span class="lineno"> 312</span>  }</div><div class="line"><a name="l00313"></a><span class="lineno"> 313</span>  this-><a class="code" href="classhueplusplus_1_1_resource_list.html#abc77b3be3e5e8da4c7b6cfe86637f048">stateCache</a>->refresh();</div><div class="line"><a name="l00314"></a><span class="lineno"> 314</span>  <span class="keywordflow">return</span> this-><a class="code" href="classhueplusplus_1_1_resource_list.html#ab98e351ff57e1674cc5aa25f150a4471">maybeStoi</a>(idStr);</div><div class="line"><a name="l00315"></a><span class="lineno"> 315</span>  }</div><div class="line"><a name="l00316"></a><span class="lineno"> 316</span>  <span class="keywordflow">return</span> <span class="keyword">typename</span> BaseResourceList::IdType {};</div><div class="line"><a name="l00317"></a><span class="lineno"> 317</span>  }</div><div class="line"><a name="l00318"></a><span class="lineno"> 318</span> </div><div class="line"><a name="l00319"></a><span class="lineno"> 319</span> <span class="keyword">protected</span>:</div><div class="line"><a name="l00321"></a><span class="lineno"> 321</span>  <a class="code" href="classhueplusplus_1_1_createable_resource_list.html">CreateableResourceList</a>(<a class="code" href="classhueplusplus_1_1_createable_resource_list.html">CreateableResourceList</a>&&) = <span class="keywordflow">default</span>;</div><div class="line"><a name="l00323"></a><span class="lineno"> 323</span>  <a class="code" href="classhueplusplus_1_1_createable_resource_list.html">CreateableResourceList</a>& <a class="code" href="classhueplusplus_1_1_resource_list.html#aa75121b18d67faf84ff6b894d0c45b0b">operator=</a>(<a class="code" href="classhueplusplus_1_1_createable_resource_list.html">CreateableResourceList</a>&&) = <span class="keywordflow">default</span>;</div><div class="line"><a name="l00324"></a><span class="lineno"> 324</span> };</div><div class="line"><a name="l00325"></a><span class="lineno"> 325</span> </div><div class="line"><a name="l00330"></a><span class="lineno"> 330</span> <span class="keyword">template</span> <<span class="keyword">typename</span> Resource, <span class="keyword">typename</span> CreateType></div><div class="line"><a name="l00331"></a><span class="lineno"><a class="line" href="classhueplusplus_1_1_group_resource_list.html"> 331</a></span> <span class="keyword">class </span><a class="code" href="classhueplusplus_1_1_group_resource_list.html">GroupResourceList</a> : <span class="keyword">public</span> <a class="code" href="classhueplusplus_1_1_createable_resource_list.html">CreateableResourceList</a><ResourceList<Resource, int>, CreateType></div><div class="line"><a name="l00332"></a><span class="lineno"> 332</span> {</div><div class="line"><a name="l00333"></a><span class="lineno"> 333</span>  <span class="keyword">using</span> <a class="code" href="classhueplusplus_1_1_createable_resource_list.html">Base</a> = <a class="code" href="classhueplusplus_1_1_createable_resource_list.html">CreateableResourceList<ResourceList<Resource, int></a>, CreateType>;</div><div class="line"><a name="l00334"></a><span class="lineno"> 334</span> </div><div class="line"><a name="l00335"></a><span class="lineno"> 335</span> <span class="keyword">public</span>:</div><div class="line"><a name="l00336"></a><span class="lineno"> 336</span>  <span class="keyword">using</span> Base::Base;</div><div class="line"><a name="l00339"></a><span class="lineno"><a class="line" href="classhueplusplus_1_1_group_resource_list.html#a06bda9ca6016b48eb6a4a5f86a67c76d"> 339</a></span>  Resource <span class="keyword">get</span>(<span class="keyword">const</span> <span class="keywordtype">int</span>& id)</div><div class="line"><a name="l00340"></a><span class="lineno"> 340</span>  {</div><div class="line"><a name="l00341"></a><span class="lineno"> 341</span>  <span class="keyword">const</span> nlohmann::json& state = this-><a class="code" href="classhueplusplus_1_1_resource_list.html#abc77b3be3e5e8da4c7b6cfe86637f048">stateCache</a>->getValue();</div><div class="line"><a name="l00342"></a><span class="lineno"> 342</span>  std::string key = this-><a class="code" href="classhueplusplus_1_1_resource_list.html#ae26bacb486e03c961d992da82d63fdd6">maybeToString</a>(<span class="keywordtype">id</span>);</div><div class="line"><a name="l00343"></a><span class="lineno"> 343</span>  <span class="keywordflow">if</span> (!state.count(key) && <span class="keywordtype">id</span> != 0)</div><div class="line"><a name="l00344"></a><span class="lineno"> 344</span>  {</div><div class="line"><a name="l00345"></a><span class="lineno"> 345</span>  <span class="keywordflow">throw</span> <a class="code" href="classhueplusplus_1_1_hue_exception.html">HueException</a>(<a class="code" href="structhueplusplus_1_1_file_info.html">FileInfo</a> {__FILE__, __LINE__, __func__}, <span class="stringliteral">"Resource id is not valid"</span>);</div><div class="line"><a name="l00346"></a><span class="lineno"> 346</span>  }</div><div class="line"><a name="l00347"></a><span class="lineno"> 347</span>  <span class="keywordflow">return</span> this-><a class="code" href="classhueplusplus_1_1_resource_list.html#ab98434ae91b0868dcf9cb95dfa168c95">construct</a>(<span class="keywordtype">id</span>, <span class="keywordtype">id</span> == 0 ? nlohmann::json {<span class="keyword">nullptr</span>} : state[key]);</div><div class="line"><a name="l00348"></a><span class="lineno"> 348</span>  }</div><div class="line"><a name="l00351"></a><span class="lineno"><a class="line" href="classhueplusplus_1_1_group_resource_list.html#ac9fca6bd61117170325efd7c903dc95d"> 351</a></span>  <span class="keywordtype">bool</span> <a class="code" href="classhueplusplus_1_1_group_resource_list.html#ac9fca6bd61117170325efd7c903dc95d">exists</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <span class="keywordtype">id</span> == 0 || Base::exists(<span class="keywordtype">id</span>); }</div><div class="line"><a name="l00352"></a><span class="lineno"> 352</span> </div><div class="line"><a name="l00353"></a><span class="lineno"> 353</span> <span class="keyword">protected</span>:</div><div class="line"><a name="l00355"></a><span class="lineno"> 355</span>  <a class="code" href="classhueplusplus_1_1_group_resource_list.html">GroupResourceList</a>(<a class="code" href="classhueplusplus_1_1_group_resource_list.html">GroupResourceList</a>&&) = <span class="keywordflow">default</span>;</div><div class="line"><a name="l00357"></a><span class="lineno"> 357</span>  <a class="code" href="classhueplusplus_1_1_group_resource_list.html">GroupResourceList</a>& <a class="code" href="classhueplusplus_1_1_resource_list.html#aa75121b18d67faf84ff6b894d0c45b0b">operator=</a>(<a class="code" href="classhueplusplus_1_1_group_resource_list.html">GroupResourceList</a>&&) = <span class="keywordflow">default</span>;</div><div class="line"><a name="l00358"></a><span class="lineno"> 358</span> };</div><div class="line"><a name="l00359"></a><span class="lineno"> 359</span> } <span class="comment">// namespace hueplusplus</span></div><div class="line"><a name="l00360"></a><span class="lineno"> 360</span> </div><div class="line"><a name="l00361"></a><span class="lineno"> 361</span> <span class="preprocessor">#endif</span></div><div class="ttc" id="classhueplusplus_1_1_group_resource_list_html_ac9fca6bd61117170325efd7c903dc95d"><div class="ttname"><a href="classhueplusplus_1_1_group_resource_list.html#ac9fca6bd61117170325efd7c903dc95d">hueplusplus::GroupResourceList::exists</a></div><div class="ttdeci">bool exists(int id) const</div><div class="ttdoc">Get group, specially handles group 0. </div><div class="ttdef"><b>Definition:</b> ResourceList.h:351</div></div>
<div class="ttc" id="classhueplusplus_1_1_searchable_resource_list_html_aa67cf6cc3bde30b1c8a79d98d270ae32"><div class="ttname"><a href="classhueplusplus_1_1_searchable_resource_list.html#aa67cf6cc3bde30b1c8a79d98d270ae32">hueplusplus::SearchableResourceList::search</a></div><div class="ttdeci">void search(const std::vector< std::string > &deviceIds={})</div><div class="ttdoc">Start search for new devices. </div><div class="ttdef"><b>Definition:</b> ResourceList.h:248</div></div>
<div class="ttc" id="classhueplusplus_1_1_resource_list_html_a6fe81cf76931d2bcf9dda56ea63524bd"><div class="ttname"><a href="classhueplusplus_1_1_resource_list.html#a6fe81cf76931d2bcf9dda56ea63524bd">hueplusplus::ResourceList::refresh</a></div><div class="ttdeci">void refresh()</div><div class="ttdoc">Refreshes internal state now. </div><div class="ttdef"><b>Definition:</b> ResourceList.h:92</div></div>
<div class="ttc" id="classhueplusplus_1_1_hue_command_a_p_i_html"><div class="ttname"><a href="classhueplusplus_1_1_hue_command_a_p_i.html">hueplusplus::HueCommandAPI</a></div><div class="ttdef"><b>Definition:</b> HueCommandAPI.h:37</div></div>
<div class="ttc" id="classhueplusplus_1_1_hue_exception_html"><div class="ttname"><a href="classhueplusplus_1_1_hue_exception.html">hueplusplus::HueException</a></div><div class="ttdoc">Exception class with file information. Base class of all custom exception classes. </div><div class="ttdef"><b>Definition:</b> HueException.h:49</div></div>
<div class="ttc" id="classhueplusplus_1_1_createable_resource_list_html"><div class="ttname"><a href="classhueplusplus_1_1_createable_resource_list.html">hueplusplus::CreateableResourceList</a></div><div class="ttdoc">Handles a ResourceList where Resources can be added by the user. </div><div class="ttdef"><b>Definition:</b> ResourceList.h:285</div></div>
<div class="ttc" id="classhueplusplus_1_1_new_device_list_html_a5b529a5a874e4acc4c00d9ad3a34e650"><div class="ttname"><a href="classhueplusplus_1_1_new_device_list.html#a5b529a5a874e4acc4c00d9ad3a34e650">hueplusplus::NewDeviceList::parse</a></div><div class="ttdeci">static NewDeviceList parse(const nlohmann::json &json)</div><div class="ttdoc">Parse from json response. </div><div class="ttdef"><b>Definition:</b> NewDeviceList.cpp:45</div></div>
<div class="ttc" id="classhueplusplus_1_1_resource_list_html_abc77b3be3e5e8da4c7b6cfe86637f048"><div class="ttname"><a href="classhueplusplus_1_1_resource_list.html#abc77b3be3e5e8da4c7b6cfe86637f048">hueplusplus::ResourceList::stateCache</a></div><div class="ttdeci">std::shared_ptr< APICache > stateCache</div><div class="ttdef"><b>Definition:</b> ResourceList.h:230</div></div>
<div class="ttc" id="classhueplusplus_1_1_resource_list_html_aa75121b18d67faf84ff6b894d0c45b0b"><div class="ttname"><a href="classhueplusplus_1_1_resource_list.html#aa75121b18d67faf84ff6b894d0c45b0b">hueplusplus::ResourceList::operator=</a></div><div class="ttdeci">ResourceList & operator=(const ResourceList &)=delete</div><div class="ttdoc">Deleted copy assignment. </div></div>
<div class="ttc" id="classhueplusplus_1_1_resource_list_html_a8c0219d853d551394020b7b482518070"><div class="ttname"><a href="classhueplusplus_1_1_resource_list.html#a8c0219d853d551394020b7b482518070">hueplusplus::ResourceList::exists</a></div><div class="ttdeci">bool exists(const IdType &id) const</div><div class="ttdoc">Checks whether resource with id exists. </div><div class="ttdef"><b>Definition:</b> ResourceList.h:151</div></div>
<div class="ttc" id="namespacehueplusplus_html"><div class="ttname"><a href="namespacehueplusplus.html">hueplusplus</a></div><div class="ttdoc">Namespace for the hueplusplus library. </div><div class="ttdef"><b>Definition:</b> Action.h:27</div></div>
<div class="ttc" id="classhueplusplus_1_1_resource_list_html_a92d644c4440523ba31d36da291ce499a"><div class="ttname"><a href="classhueplusplus_1_1_resource_list.html#a92d644c4440523ba31d36da291ce499a">hueplusplus::ResourceList::ResourceList</a></div><div class="ttdeci">ResourceList(std::shared_ptr< APICache > baseCache, const std::string &cacheEntry, std::chrono::steady_clock::duration refreshDuration, bool sharedState=false, const std::function< Resource(IdType, const nlohmann::json &, const std::shared_ptr< APICache > &)> &factory=nullptr)</div><div class="ttdoc">Construct ResourceList using a base cache and optional factory function. </div><div class="ttdef"><b>Definition:</b> ResourceList.h:61</div></div>
<div class="ttc" id="classhueplusplus_1_1_a_p_i_cache_html"><div class="ttname"><a href="classhueplusplus_1_1_a_p_i_cache.html">hueplusplus::APICache</a></div><div class="ttdoc">Caches API GET requests and refreshes regularly. </div><div class="ttdef"><b>Definition:</b> APICache.h:37</div></div>
<div class="ttc" id="classhueplusplus_1_1_new_device_list_html"><div class="ttname"><a href="classhueplusplus_1_1_new_device_list.html">hueplusplus::NewDeviceList</a></div><div class="ttdoc">List of new devices found during the last scan. </div><div class="ttdef"><b>Definition:</b> NewDeviceList.h:35</div></div>
<div class="ttc" id="classhueplusplus_1_1_resource_list_html_ad7b3bef47b0c09764377cbad327545df"><div class="ttname"><a href="classhueplusplus_1_1_resource_list.html#ad7b3bef47b0c09764377cbad327545df">hueplusplus::ResourceList::getAll</a></div><div class="ttdeci">std::vector< Resource > getAll()</div><div class="ttdoc">Get all resources that exist. </div><div class="ttdef"><b>Definition:</b> ResourceList.h:107</div></div>
<div class="ttc" id="classhueplusplus_1_1_group_resource_list_html"><div class="ttname"><a href="classhueplusplus_1_1_group_resource_list.html">hueplusplus::GroupResourceList</a></div><div class="ttdoc">Handles a group list with the special group 0. </div><div class="ttdef"><b>Definition:</b> ResourceList.h:331</div></div>
<div class="ttc" id="classhueplusplus_1_1_resource_list_html"><div class="ttname"><a href="classhueplusplus_1_1_resource_list.html">hueplusplus::ResourceList</a></div><div class="ttdoc">Handles a list of a certain API resource. </div><div class="ttdef"><b>Definition:</b> ResourceList.h:46</div></div>
<div class="ttc" id="_utils_8h_html"><div class="ttname"><a href="_utils_8h.html">Utils.h</a></div></div>
<div class="ttc" id="_hue_exception_8h_html"><div class="ttname"><a href="_hue_exception_8h.html">HueException.h</a></div></div>
<div class="ttc" id="structhueplusplus_1_1_file_info_html"><div class="ttname"><a href="structhueplusplus_1_1_file_info.html">hueplusplus::FileInfo</a></div><div class="ttdoc">Contains information about error location, use CURRENT_FILE_INFO to create. </div><div class="ttdef"><b>Definition:</b> HueException.h:34</div></div>
<div class="ttc" id="classhueplusplus_1_1_resource_list_html_ac3490f9e6b165f3a71c13337887a1a88"><div class="ttname"><a href="classhueplusplus_1_1_resource_list.html#ac3490f9e6b165f3a71c13337887a1a88">hueplusplus::ResourceList::path</a></div><div class="ttdeci">std::string path</div><div class="ttdef"><b>Definition:</b> ResourceList.h:232</div></div>
<div class="ttc" id="classhueplusplus_1_1_resource_list_html_ac5777102379d55049380d777e779f56f"><div class="ttname"><a href="classhueplusplus_1_1_resource_list.html#ac5777102379d55049380d777e779f56f">hueplusplus::ResourceList::factory</a></div><div class="ttdeci">std::function< Resource(IdType, const nlohmann::json &, const std::shared_ptr< APICache > &)> factory</div><div class="ttdef"><b>Definition:</b> ResourceList.h:231</div></div>
<div class="ttc" id="classhueplusplus_1_1_searchable_resource_list_html_a07bc6249721ec996a38091ee7c46ef3d"><div class="ttname"><a href="classhueplusplus_1_1_searchable_resource_list.html#a07bc6249721ec996a38091ee7c46ef3d">hueplusplus::SearchableResourceList::getNewDevices</a></div><div class="ttdeci">NewDeviceList getNewDevices() const</div><div class="ttdoc">Get devices found in last search. </div><div class="ttdef"><b>Definition:</b> ResourceList.h:266</div></div>
<div class="ttc" id="classhueplusplus_1_1_resource_list_html_aa165e446439defcae7d1bf05b4576739"><div class="ttname"><a href="classhueplusplus_1_1_resource_list.html#aa165e446439defcae7d1bf05b4576739">hueplusplus::ResourceList::setRefreshDuration</a></div><div class="ttdeci">void setRefreshDuration(std::chrono::steady_clock::duration refreshDuration)</div><div class="ttdoc">Sets custom refresh interval for this list and all resources created. </div><div class="ttdef"><b>Definition:</b> ResourceList.h:96</div></div>
<div class="ttc" id="classhueplusplus_1_1_resource_list_html_af5e884eefde0a45d53f029a9f30a6ab7"><div class="ttname"><a href="classhueplusplus_1_1_resource_list.html#af5e884eefde0a45d53f029a9f30a6ab7">hueplusplus::ResourceList::exists</a></div><div class="ttdeci">bool exists(const IdType &id)</div><div class="ttdoc">Checks whether resource with id exists. </div><div class="ttdef"><b>Definition:</b> ResourceList.h:144</div></div>
<div class="ttc" id="classhueplusplus_1_1_createable_resource_list_html_abf886bbd80f86e00a66c7ad61bd773c9"><div class="ttname"><a href="classhueplusplus_1_1_createable_resource_list.html#abf886bbd80f86e00a66c7ad61bd773c9">hueplusplus::CreateableResourceList::create</a></div><div class="ttdeci">BaseResourceList::IdType create(const CreateType &params)</div><div class="ttdoc">Create a new resource. </div><div class="ttdef"><b>Definition:</b> ResourceList.h:298</div></div>
<div class="ttc" id="classhueplusplus_1_1_resource_list_html_a177194d18e9f0f37228a262d6dd6a73c"><div class="ttname"><a href="classhueplusplus_1_1_resource_list.html#a177194d18e9f0f37228a262d6dd6a73c">hueplusplus::ResourceList< Resource, int >::ResourceType</a></div><div class="ttdeci">Resource ResourceType</div><div class="ttdef"><b>Definition:</b> ResourceList.h:49</div></div>
<div class="ttc" id="classhueplusplus_1_1_resource_list_html_ab122d90e1fcfde172b21670c74b33f89"><div class="ttname"><a href="classhueplusplus_1_1_resource_list.html#ab122d90e1fcfde172b21670c74b33f89">hueplusplus::ResourceList< Resource, int >::IdType</a></div><div class="ttdeci">int IdType</div><div class="ttdef"><b>Definition:</b> ResourceList.h:50</div></div>
<div class="ttc" id="namespacehueplusplus_1_1utils_html_ae6268e7923eee8d5300471820c3d8094"><div class="ttname"><a href="namespacehueplusplus_1_1utils.html#ae6268e7923eee8d5300471820c3d8094">hueplusplus::utils::safeGetMember</a></div><div class="ttdeci">nlohmann::json safeGetMember(const nlohmann::json &json, Paths &&... paths)</div><div class="ttdoc">Returns the object/array member or null if it does not exist. </div><div class="ttdef"><b>Definition:</b> Utils.h:92</div></div>
<div class="ttc" id="classhueplusplus_1_1_resource_list_html_ab98e351ff57e1674cc5aa25f150a4471"><div class="ttname"><a href="classhueplusplus_1_1_resource_list.html#ab98e351ff57e1674cc5aa25f150a4471">hueplusplus::ResourceList::maybeStoi</a></div><div class="ttdeci">static IdType maybeStoi(const std::string &key)</div><div class="ttdoc">Calls std::stoi if IdType is int. </div><div class="ttdef"><b>Definition:</b> ResourceList.h:173</div></div>
<div class="ttc" id="_a_p_i_cache_8h_html"><div class="ttname"><a href="_a_p_i_cache_8h.html">APICache.h</a></div></div>
<div class="ttc" id="classhueplusplus_1_1_resource_list_html_ab98434ae91b0868dcf9cb95dfa168c95"><div class="ttname"><a href="classhueplusplus_1_1_resource_list.html#ab98434ae91b0868dcf9cb95dfa168c95">hueplusplus::ResourceList::construct</a></div><div class="ttdeci">Resource construct(const IdType &id, const nlohmann::json &state)</div><div class="ttdoc">Constructs resource using factory or constructor, if available. </div><div class="ttdef"><b>Definition:</b> ResourceList.h:180</div></div>
<div class="ttc" id="classhueplusplus_1_1_resource_list_html_abc08e43ff0bd00145331db6a39fd1708"><div class="ttname"><a href="classhueplusplus_1_1_resource_list.html#abc08e43ff0bd00145331db6a39fd1708">hueplusplus::ResourceList::sharedState</a></div><div class="ttdeci">bool sharedState</div><div class="ttdef"><b>Definition:</b> ResourceList.h:233</div></div>
<div class="ttc" id="classhueplusplus_1_1_resource_list_html_a3ad0fc473c4b3ac35210da9f2909e034"><div class="ttname"><a href="classhueplusplus_1_1_resource_list.html#a3ad0fc473c4b3ac35210da9f2909e034">hueplusplus::ResourceList::ResourceList</a></div><div class="ttdeci">ResourceList(const HueCommandAPI &commands, const std::string &path, std::chrono::steady_clock::duration refreshDuration, const std::function< Resource(IdType, const nlohmann::json &, const std::shared_ptr< APICache > &)> &factory=nullptr)</div><div class="ttdoc">Construct ResourceList with a separate cache and optional factory function. </div><div class="ttdef"><b>Definition:</b> ResourceList.h:76</div></div>
<div class="ttc" id="classhueplusplus_1_1_resource_list_html_ae26bacb486e03c961d992da82d63fdd6"><div class="ttname"><a href="classhueplusplus_1_1_resource_list.html#ae26bacb486e03c961d992da82d63fdd6">hueplusplus::ResourceList::maybeToString</a></div><div class="ttdeci">static std::string maybeToString(const IdType &id)</div><div class="ttdoc">Calls std::to_string if IdType is int. </div><div class="ttdef"><b>Definition:</b> ResourceList.h:176</div></div>
<div class="ttc" id="_new_device_list_8h_html"><div class="ttname"><a href="_new_device_list_8h.html">NewDeviceList.h</a></div></div>
<div class="ttc" id="classhueplusplus_1_1_searchable_resource_list_html"><div class="ttname"><a href="classhueplusplus_1_1_searchable_resource_list.html">hueplusplus::SearchableResourceList</a></div><div class="ttdoc">Handles a ResourceList of physical devices which can be searched for. </div><div class="ttdef"><b>Definition:</b> ResourceList.h:239</div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by  <a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>