GpgFrontend-Doxygen/docs/html/GpgFunctionObject_8h_source.html

252 lines
35 KiB
HTML
Raw Normal View History

2022-05-08 19:59:26 +00:00
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://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=11"/>
<meta name="generator" content="Doxygen 1.9.3"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>GpgFrontend Project: src/core/GpgFunctionObject.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="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.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 id="projectrow">
<td id="projectalign">
<div id="projectname">GpgFrontend Project
</div>
<div id="projectbrief">A Free, Powerful, Easy-to-Use, Compact, Cross-Platform, and Installation-Free OpenPGP(pgp) Crypto Tool.</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.3 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('GpgFunctionObject_8h_source.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- 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 class="header">
<div class="headertitle"><div class="title">GpgFunctionObject.h</div></div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno"> 1</span> </div>
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno"> 29</span><span class="preprocessor">#ifndef GPGFRONTEND_ZH_CN_TS_FUNCTIONOBJECT_H</span></div>
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno"> 30</span><span class="preprocessor">#define GPGFRONTEND_ZH_CN_TS_FUNCTIONOBJECT_H</span></div>
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno"> 31</span> </div>
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno"> 32</span><span class="preprocessor">#include &lt;map&gt;</span></div>
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno"> 33</span><span class="preprocessor">#include &lt;memory&gt;</span></div>
<div class="line"><a id="l00034" name="l00034"></a><span class="lineno"> 34</span><span class="preprocessor">#include &lt;mutex&gt;</span></div>
<div class="line"><a id="l00035" name="l00035"></a><span class="lineno"> 35</span><span class="preprocessor">#include &lt;shared_mutex&gt;</span></div>
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno"> 36</span><span class="preprocessor">#include &lt;stdexcept&gt;</span></div>
<div class="line"><a id="l00037" name="l00037"></a><span class="lineno"> 37</span><span class="preprocessor">#include &lt;string&gt;</span></div>
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno"> 38</span> </div>
<div class="line"><a id="l00039" name="l00039"></a><span class="lineno"> 39</span><span class="preprocessor">#include &quot;GpgConstants.h&quot;</span></div>
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno"> 40</span> </div>
<div class="line"><a id="l00041" name="l00041"></a><span class="lineno"> 41</span><span class="keyword">namespace </span><a class="code hl_namespace" href="namespaceGpgFrontend.html">GpgFrontend</a> {</div>
<div class="line"><a id="l00042" name="l00042"></a><span class="lineno"> 42</span> </div>
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno"> 48</span><span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div>
<div class="line"><a id="l00049" name="l00049"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html"> 49</a></span><span class="keyword">class </span><a class="code hl_class" href="classGpgFrontend_1_1SingletonFunctionObject.html">SingletonFunctionObject</a> {</div>
<div class="line"><a id="l00050" name="l00050"></a><span class="lineno"> 50</span> <span class="keyword">public</span>:</div>
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html#a8a378452876a685af879e04bfa456b6f"> 57</a></span> <span class="keyword">static</span> T&amp; <a class="code hl_function" href="classGpgFrontend_1_1SingletonFunctionObject.html#a8a378452876a685af879e04bfa456b6f">GetInstance</a>(</div>
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno"> 58</span> <span class="keywordtype">int</span> channel = GpgFrontend::GPGFRONTEND_DEFAULT_CHANNEL) {</div>
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno"> 59</span> <span class="keyword">static_assert</span>(std::is_base_of&lt;SingletonFunctionObject&lt;T&gt;, T&gt;::value,</div>
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno"> 60</span> <span class="stringliteral">&quot;T not derived from SingletonFunctionObject&lt;T&gt;&quot;</span>);</div>
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno"> 61</span> </div>
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno"> 62</span> <span class="keyword">auto</span> _p_pbj = <a class="code hl_function" href="classGpgFrontend_1_1SingletonFunctionObject.html#a7ad3a06b1a64d953f4861f6c9d360c8a">find_object_in_channel</a>(channel);</div>
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno"> 63</span> <span class="keywordflow">if</span> (_p_pbj == <span class="keyword">nullptr</span>)</div>
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno"> 64</span> <span class="keywordflow">return</span> *<a class="code hl_function" href="classGpgFrontend_1_1SingletonFunctionObject.html#a51f705fc4b4a60f07e924d0e5a027d2a">set_object_in_channel</a>(channel, std::make_unique&lt;T&gt;(channel));</div>
<div class="line"><a id="l00065" name="l00065"></a><span class="lineno"> 65</span> <span class="keywordflow">else</span></div>
<div class="line"><a id="l00066" name="l00066"></a><span class="lineno"> 66</span> <span class="keywordflow">return</span> *_p_pbj;</div>
<div class="line"><a id="l00067" name="l00067"></a><span class="lineno"> 67</span> }</div>
<div class="line"><a id="l00068" name="l00068"></a><span class="lineno"> 68</span> </div>
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html#a459af8206b25fed21b423aeb61c408fe"> 76</a></span> <span class="keyword">static</span> T&amp; <a class="code hl_function" href="classGpgFrontend_1_1SingletonFunctionObject.html#a459af8206b25fed21b423aeb61c408fe">CreateInstance</a>(<span class="keywordtype">int</span> channel,</div>
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno"> 77</span> std::function&lt;std::unique_ptr&lt;T&gt;(<span class="keywordtype">void</span>)&gt; factory) {</div>
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno"> 78</span> <span class="keyword">static_assert</span>(std::is_base_of&lt;SingletonFunctionObject&lt;T&gt;, T&gt;::value,</div>
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno"> 79</span> <span class="stringliteral">&quot;T not derived from SingletonFunctionObject&lt;T&gt;&quot;</span>);</div>
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno"> 80</span> </div>
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno"> 81</span> <span class="keyword">auto</span> _p_pbj = <a class="code hl_function" href="classGpgFrontend_1_1SingletonFunctionObject.html#a7ad3a06b1a64d953f4861f6c9d360c8a">find_object_in_channel</a>(channel);</div>
<div class="line"><a id="l00082" name="l00082"></a><span class="lineno"> 82</span> <span class="keywordflow">if</span> (_p_pbj == <span class="keyword">nullptr</span>)</div>
<div class="line"><a id="l00083" name="l00083"></a><span class="lineno"> 83</span> <span class="keywordflow">return</span> *<a class="code hl_function" href="classGpgFrontend_1_1SingletonFunctionObject.html#a51f705fc4b4a60f07e924d0e5a027d2a">set_object_in_channel</a>(channel, std::move(factory()));</div>
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno"> 84</span> <span class="keywordflow">else</span></div>
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno"> 85</span> <span class="keywordflow">return</span> *_p_pbj;</div>
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno"> 86</span> }</div>
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno"> 87</span> </div>
<div class="line"><a id="l00095" name="l00095"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html#a3116637b021c316ec3b615baaa5a77a1"> 95</a></span> <span class="keyword">static</span> T&amp; <a class="code hl_function" href="classGpgFrontend_1_1SingletonFunctionObject.html#a3116637b021c316ec3b615baaa5a77a1">CreateInstance</a>(<span class="keywordtype">int</span> channel, std::unique_ptr&lt;T&gt; p_obj = <span class="keyword">nullptr</span>) {</div>
<div class="line"><a id="l00096" name="l00096"></a><span class="lineno"> 96</span> <span class="keyword">static_assert</span>(std::is_base_of&lt;SingletonFunctionObject&lt;T&gt;, T&gt;::value,</div>
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno"> 97</span> <span class="stringliteral">&quot;T not derived from SingletonFunctionObject&lt;T&gt;&quot;</span>);</div>
<div class="line"><a id="l00098" name="l00098"></a><span class="lineno"> 98</span> </div>
<div class="line"><a id="l00099" name="l00099"></a><span class="lineno"> 99</span> <span class="keyword">auto</span> _p_pbj = <a class="code hl_function" href="classGpgFrontend_1_1SingletonFunctionObject.html#a7ad3a06b1a64d953f4861f6c9d360c8a">find_object_in_channel</a>(channel);</div>
<div class="line"><a id="l00100" name="l00100"></a><span class="lineno"> 100</span> <span class="keywordflow">if</span> (_p_pbj == <span class="keyword">nullptr</span>)</div>
<div class="line"><a id="l00101" name="l00101"></a><span class="lineno"> 101</span> <span class="keywordflow">return</span> *<a class="code hl_function" href="classGpgFrontend_1_1SingletonFunctionObject.html#a51f705fc4b4a60f07e924d0e5a027d2a">set_object_in_channel</a>(channel, std::move(p_obj));</div>
<div class="line"><a id="l00102" name="l00102"></a><span class="lineno"> 102</span> <span class="keywordflow">else</span></div>
<div class="line"><a id="l00103" name="l00103"></a><span class="lineno"> 103</span> <span class="keywordflow">return</span> *_p_pbj;</div>
<div class="line"><a id="l00104" name="l00104"></a><span class="lineno"> 104</span> }</div>
<div class="line"><a id="l00105" name="l00105"></a><span class="lineno"> 105</span> </div>
<div class="line"><a id="l00112" name="l00112"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html#abb1ea69c668223ee9da79e6c92d5a9fa"> 112</a></span> <span class="keyword">static</span> T&amp; <a class="code hl_function" href="classGpgFrontend_1_1SingletonFunctionObject.html#abb1ea69c668223ee9da79e6c92d5a9fa">ReleaseChannel</a>(<span class="keywordtype">int</span> channel) {</div>
<div class="line"><a id="l00113" name="l00113"></a><span class="lineno"> 113</span> <span class="keyword">decltype</span>(_instances_map.end()) _it;</div>
<div class="line"><a id="l00114" name="l00114"></a><span class="lineno"> 114</span> {</div>
<div class="line"><a id="l00115" name="l00115"></a><span class="lineno"> 115</span> std::shared_lock lock(_instances_mutex);</div>
<div class="line"><a id="l00116" name="l00116"></a><span class="lineno"> 116</span> _it = _instances_map.find(channel);</div>
<div class="line"><a id="l00117" name="l00117"></a><span class="lineno"> 117</span> }</div>
<div class="line"><a id="l00118" name="l00118"></a><span class="lineno"> 118</span> <span class="keywordflow">if</span> (_it != _instances_map.end()) _instances_map.erase(_it);</div>
<div class="line"><a id="l00119" name="l00119"></a><span class="lineno"> 119</span> DLOG(INFO) &lt;&lt; <span class="stringliteral">&quot;channel&quot;</span> &lt;&lt; channel &lt;&lt; <span class="stringliteral">&quot;released&quot;</span>;</div>
<div class="line"><a id="l00120" name="l00120"></a><span class="lineno"> 120</span> }</div>
<div class="line"><a id="l00121" name="l00121"></a><span class="lineno"> 121</span> </div>
<div class="line"><a id="l00127" name="l00127"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html#a50e2b3794d6553f4231eaec72d9d0a50"> 127</a></span> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code hl_function" href="classGpgFrontend_1_1SingletonFunctionObject.html#a50e2b3794d6553f4231eaec72d9d0a50">GetDefaultChannel</a>() { <span class="keywordflow">return</span> _default_channel; }</div>
<div class="line"><a id="l00128" name="l00128"></a><span class="lineno"> 128</span> </div>
<div class="line"><a id="l00134" name="l00134"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html#aa99440b9177f5d0c18840f08a40d64b7"> 134</a></span> [[nodiscard]] <span class="keywordtype">int</span> <a class="code hl_function" href="classGpgFrontend_1_1SingletonFunctionObject.html#aa99440b9177f5d0c18840f08a40d64b7">GetChannel</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> channel_; }</div>
<div class="line"><a id="l00135" name="l00135"></a><span class="lineno"> 135</span> </div>
<div class="line"><a id="l00140" name="l00140"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html#aabc5fe8e5a372ac276a265286457cb9a"> 140</a></span> <a class="code hl_function" href="classGpgFrontend_1_1SingletonFunctionObject.html#aabc5fe8e5a372ac276a265286457cb9a">SingletonFunctionObject</a>(T&amp;&amp;) = <span class="keyword">delete</span>;</div>
<div class="line"><a id="l00141" name="l00141"></a><span class="lineno"> 141</span> </div>
<div class="line"><a id="l00146" name="l00146"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html#a7090636bed6f4bad5b99f28f6872c645"> 146</a></span> <a class="code hl_function" href="classGpgFrontend_1_1SingletonFunctionObject.html#a7090636bed6f4bad5b99f28f6872c645">SingletonFunctionObject</a>(<span class="keyword">const</span> T&amp;) = <span class="keyword">delete</span>;</div>
<div class="line"><a id="l00147" name="l00147"></a><span class="lineno"> 147</span> </div>
<div class="line"><a id="l00152" name="l00152"></a><span class="lineno"> 152</span> <span class="keywordtype">void</span> operator=(<span class="keyword">const</span> T&amp;) = <span class="keyword">delete</span>;</div>
<div class="line"><a id="l00153" name="l00153"></a><span class="lineno"> 153</span> </div>
<div class="line"><a id="l00154" name="l00154"></a><span class="lineno"> 154</span> <span class="keyword">protected</span>:</div>
<div class="line"><a id="l00159" name="l00159"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html#a02e76b42ab51d77588b01c7508bed258"> 159</a></span> <a class="code hl_function" href="classGpgFrontend_1_1SingletonFunctionObject.html#a02e76b42ab51d77588b01c7508bed258">SingletonFunctionObject</a>() = <span class="keywordflow">default</span>;</div>
<div class="line"><a id="l00160" name="l00160"></a><span class="lineno"> 160</span> </div>
<div class="line"><a id="l00166" name="l00166"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html#a4aa7f1eb1d3281bb1fccfcbb1b416251"> 166</a></span> <span class="keyword">explicit</span> <a class="code hl_function" href="classGpgFrontend_1_1SingletonFunctionObject.html#a4aa7f1eb1d3281bb1fccfcbb1b416251">SingletonFunctionObject</a>(<span class="keywordtype">int</span> channel) : channel_(channel) {}</div>
<div class="line"><a id="l00167" name="l00167"></a><span class="lineno"> 167</span> </div>
<div class="line"><a id="l00172" name="l00172"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html#a8296be8c449f88175285186831b995bc"> 172</a></span> <span class="keyword">virtual</span> <a class="code hl_function" href="classGpgFrontend_1_1SingletonFunctionObject.html#a8296be8c449f88175285186831b995bc">~SingletonFunctionObject</a>() = <span class="keywordflow">default</span>;</div>
<div class="line"><a id="l00173" name="l00173"></a><span class="lineno"> 173</span> </div>
<div class="line"><a id="l00179" name="l00179"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html#a56ba12077251893e48f5ec360e8c7040"> 179</a></span> <span class="keywordtype">void</span> <a class="code hl_function" href="classGpgFrontend_1_1SingletonFunctionObject.html#a56ba12077251893e48f5ec360e8c7040">SetChannel</a>(<span class="keywordtype">int</span> channel) { this-&gt;channel_ = channel; }</div>
<div class="line"><a id="l00180" name="l00180"></a><span class="lineno"> 180</span> </div>
<div class="line"><a id="l00181" name="l00181"></a><span class="lineno"> 181</span> <span class="keyword">private</span>:</div>
<div class="line"><a id="l00182" name="l00182"></a><span class="lineno"> 182</span> <span class="keywordtype">int</span> channel_ = _default_channel; </div>
<div class="line"><a id="l00183" name="l00183"></a><span class="lineno"> 183</span> <span class="keyword">static</span> <span class="keywordtype">int</span> _default_channel; </div>
<div class="line"><a id="l00184" name="l00184"></a><span class="lineno"> 184</span> <span class="keyword">static</span> std::mutex _instance_mutex; </div>
<div class="line"><a id="l00185" name="l00185"></a><span class="lineno"> 185</span> <span class="keyword">static</span> std::shared_mutex _instances_mutex; </div>
<div class="line"><a id="l00186" name="l00186"></a><span class="lineno"> 186</span> <span class="keyword">static</span> std::unique_ptr&lt;T&gt; _instance; </div>
<div class="line"><a id="l00187" name="l00187"></a><span class="lineno"> 187</span> <span class="keyword">static</span> std::map&lt;int, std::unique_ptr&lt;T&gt;&gt; _instances_map; </div>
<div class="line"><a id="l00188" name="l00188"></a><span class="lineno"> 188</span> </div>
<div class="line"><a id="l00195" name="l00195"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html#a7ad3a06b1a64d953f4861f6c9d360c8a"> 195</a></span> <span class="keyword">static</span> T* <a class="code hl_function" href="classGpgFrontend_1_1SingletonFunctionObject.html#a7ad3a06b1a64d953f4861f6c9d360c8a">find_object_in_channel</a>(<span class="keywordtype">int</span> channel) {</div>
<div class="line"><a id="l00196" name="l00196"></a><span class="lineno"> 196</span> <span class="comment">// read _instances_map</span></div>
<div class="line"><a id="l00197" name="l00197"></a><span class="lineno"> 197</span> <span class="keyword">decltype</span>(_instances_map.end()) _it;</div>
<div class="line"><a id="l00198" name="l00198"></a><span class="lineno"> 198</span> {</div>
<div class="line"><a id="l00199" name="l00199"></a><span class="lineno"> 199</span> std::shared_lock lock(_instances_mutex);</div>
<div class="line"><a id="l00200" name="l00200"></a><span class="lineno"> 200</span> _it = _instances_map.find(channel);</div>
<div class="line"><a id="l00201" name="l00201"></a><span class="lineno"> 201</span> <span class="keywordflow">if</span> (_it == _instances_map.end())</div>
<div class="line"><a id="l00202" name="l00202"></a><span class="lineno"> 202</span> <span class="keywordflow">return</span> <span class="keyword">nullptr</span>;</div>
<div class="line"><a id="l00203" name="l00203"></a><span class="lineno"> 203</span> <span class="keywordflow">else</span></div>
<div class="line"><a id="l00204" name="l00204"></a><span class="lineno"> 204</span> <span class="keywordflow">return</span> _it-&gt;second.get();</div>
<div class="line"><a id="l00205" name="l00205"></a><span class="lineno"> 205</span> }</div>
<div class="line"><a id="l00206" name="l00206"></a><span class="lineno"> 206</span> }</div>
<div class="line"><a id="l00207" name="l00207"></a><span class="lineno"> 207</span> </div>
<div class="line"><a id="l00215" name="l00215"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html#a51f705fc4b4a60f07e924d0e5a027d2a"> 215</a></span> <span class="keyword">static</span> T* <a class="code hl_function" href="classGpgFrontend_1_1SingletonFunctionObject.html#a51f705fc4b4a60f07e924d0e5a027d2a">set_object_in_channel</a>(<span class="keywordtype">int</span> channel, std::unique_ptr&lt;T&gt; p_obj) {</div>
<div class="line"><a id="l00216" name="l00216"></a><span class="lineno"> 216</span> {</div>
<div class="line"><a id="l00217" name="l00217"></a><span class="lineno"> 217</span> <span class="keywordflow">if</span> (p_obj == <span class="keyword">nullptr</span>) p_obj = std::make_unique&lt;T&gt;();</div>
<div class="line"><a id="l00218" name="l00218"></a><span class="lineno"> 218</span> T* obj = p_obj.get();</div>
<div class="line"><a id="l00219" name="l00219"></a><span class="lineno"> 219</span> obj-&gt;SetChannel(channel);</div>
<div class="line"><a id="l00220" name="l00220"></a><span class="lineno"> 220</span> {</div>
<div class="line"><a id="l00221" name="l00221"></a><span class="lineno"> 221</span> std::unique_lock lock(_instances_mutex);</div>
<div class="line"><a id="l00222" name="l00222"></a><span class="lineno"> 222</span> _instances_map.insert({channel, std::move(p_obj)});</div>
<div class="line"><a id="l00223" name="l00223"></a><span class="lineno"> 223</span> }</div>
<div class="line"><a id="l00224" name="l00224"></a><span class="lineno"> 224</span> <span class="keywordflow">return</span> obj;</div>
<div class="line"><a id="l00225" name="l00225"></a><span class="lineno"> 225</span> }</div>
<div class="line"><a id="l00226" name="l00226"></a><span class="lineno"> 226</span> }</div>
<div class="line"><a id="l00227" name="l00227"></a><span class="lineno"> 227</span>};</div>
<div class="line"><a id="l00228" name="l00228"></a><span class="lineno"> 228</span> </div>
<div class="line"><a id="l00229" name="l00229"></a><span class="lineno"> 229</span><span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div>
<div class="line"><a id="l00230" name="l00230"></a><span class="lineno"> 230</span><span class="keywordtype">int</span> SingletonFunctionObject&lt;T&gt;::_default_channel =</div>
<div class="line"><a id="l00231" name="l00231"></a><span class="lineno"> 231</span> GpgFrontend::GPGFRONTEND_DEFAULT_CHANNEL;</div>
<div class="line"><a id="l00232" name="l00232"></a><span class="lineno"> 232</span> </div>
<div class="line"><a id="l00233" name="l00233"></a><span class="lineno"> 233</span><span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div>
<div class="line"><a id="l00234" name="l00234"></a><span class="lineno"> 234</span>std::mutex SingletonFunctionObject&lt;T&gt;::_instance_mutex;</div>
<div class="line"><a id="l00235" name="l00235"></a><span class="lineno"> 235</span> </div>
<div class="line"><a id="l00236" name="l00236"></a><span class="lineno"> 236</span><span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div>
<div class="line"><a id="l00237" name="l00237"></a><span class="lineno"> 237</span>std::shared_mutex SingletonFunctionObject&lt;T&gt;::_instances_mutex;</div>
<div class="line"><a id="l00238" name="l00238"></a><span class="lineno"> 238</span> </div>
<div class="line"><a id="l00239" name="l00239"></a><span class="lineno"> 239</span><span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div>
<div class="line"><a id="l00240" name="l00240"></a><span class="lineno"> 240</span>std::unique_ptr&lt;T&gt; SingletonFunctionObject&lt;T&gt;::_instance = <span class="keyword">nullptr</span>;</div>
<div class="line"><a id="l00241" name="l00241"></a><span class="lineno"> 241</span> </div>
<div class="line"><a id="l00242" name="l00242"></a><span class="lineno"> 242</span><span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div>
<div class="line"><a id="l00243" name="l00243"></a><span class="lineno"> 243</span>std::map&lt;int, std::unique_ptr&lt;T&gt;&gt; SingletonFunctionObject&lt;T&gt;::_instances_map;</div>
<div class="line"><a id="l00244" name="l00244"></a><span class="lineno"> 244</span> </div>
<div class="line"><a id="l00245" name="l00245"></a><span class="lineno"> 245</span>} <span class="comment">// namespace GpgFrontend</span></div>
<div class="line"><a id="l00246" name="l00246"></a><span class="lineno"> 246</span> </div>
<div class="line"><a id="l00247" name="l00247"></a><span class="lineno"> 247</span><span class="preprocessor">#endif </span><span class="comment">// GPGFRONTEND_ZH_CN_TS_FUNCTIONOBJECT_H</span></div>
<div class="ttc" id="aclassGpgFrontend_1_1SingletonFunctionObject_html"><div class="ttname"><a href="classGpgFrontend_1_1SingletonFunctionObject.html">GpgFrontend::SingletonFunctionObject</a></div><div class="ttdef"><b>Definition:</b> GpgFunctionObject.h:49</div></div>
<div class="ttc" id="aclassGpgFrontend_1_1SingletonFunctionObject_html_a02e76b42ab51d77588b01c7508bed258"><div class="ttname"><a href="classGpgFrontend_1_1SingletonFunctionObject.html#a02e76b42ab51d77588b01c7508bed258">GpgFrontend::SingletonFunctionObject::SingletonFunctionObject</a></div><div class="ttdeci">SingletonFunctionObject()=default</div><div class="ttdoc">Construct a new Singleton Function Object object.</div></div>
<div class="ttc" id="aclassGpgFrontend_1_1SingletonFunctionObject_html_a3116637b021c316ec3b615baaa5a77a1"><div class="ttname"><a href="classGpgFrontend_1_1SingletonFunctionObject.html#a3116637b021c316ec3b615baaa5a77a1">GpgFrontend::SingletonFunctionObject::CreateInstance</a></div><div class="ttdeci">static T &amp; CreateInstance(int channel, std::unique_ptr&lt; T &gt; p_obj=nullptr)</div><div class="ttdoc">Create a Instance object.</div><div class="ttdef"><b>Definition:</b> GpgFunctionObject.h:95</div></div>
<div class="ttc" id="aclassGpgFrontend_1_1SingletonFunctionObject_html_a459af8206b25fed21b423aeb61c408fe"><div class="ttname"><a href="classGpgFrontend_1_1SingletonFunctionObject.html#a459af8206b25fed21b423aeb61c408fe">GpgFrontend::SingletonFunctionObject::CreateInstance</a></div><div class="ttdeci">static T &amp; CreateInstance(int channel, std::function&lt; std::unique_ptr&lt; T &gt;(void)&gt; factory)</div><div class="ttdoc">Create a Instance object.</div><div class="ttdef"><b>Definition:</b> GpgFunctionObject.h:76</div></div>
<div class="ttc" id="aclassGpgFrontend_1_1SingletonFunctionObject_html_a4aa7f1eb1d3281bb1fccfcbb1b416251"><div class="ttname"><a href="classGpgFrontend_1_1SingletonFunctionObject.html#a4aa7f1eb1d3281bb1fccfcbb1b416251">GpgFrontend::SingletonFunctionObject::SingletonFunctionObject</a></div><div class="ttdeci">SingletonFunctionObject(int channel)</div><div class="ttdoc">Construct a new Singleton Function Object object.</div><div class="ttdef"><b>Definition:</b> GpgFunctionObject.h:166</div></div>
<div class="ttc" id="aclassGpgFrontend_1_1SingletonFunctionObject_html_a50e2b3794d6553f4231eaec72d9d0a50"><div class="ttname"><a href="classGpgFrontend_1_1SingletonFunctionObject.html#a50e2b3794d6553f4231eaec72d9d0a50">GpgFrontend::SingletonFunctionObject::GetDefaultChannel</a></div><div class="ttdeci">static int GetDefaultChannel()</div><div class="ttdoc">Get the Default Channel object.</div><div class="ttdef"><b>Definition:</b> GpgFunctionObject.h:127</div></div>
<div class="ttc" id="aclassGpgFrontend_1_1SingletonFunctionObject_html_a51f705fc4b4a60f07e924d0e5a027d2a"><div class="ttname"><a href="classGpgFrontend_1_1SingletonFunctionObject.html#a51f705fc4b4a60f07e924d0e5a027d2a">GpgFrontend::SingletonFunctionObject::set_object_in_channel</a></div><div class="ttdeci">static T * set_object_in_channel(int channel, std::unique_ptr&lt; T &gt; p_obj)</div><div class="ttdoc">Set the object in channel object.</div><div class="ttdef"><b>Definition:</b> GpgFunctionObject.h:215</div></div>
<div class="ttc" id="aclassGpgFrontend_1_1SingletonFunctionObject_html_a56ba12077251893e48f5ec360e8c7040"><div class="ttname"><a href="classGpgFrontend_1_1SingletonFunctionObject.html#a56ba12077251893e48f5ec360e8c7040">GpgFrontend::SingletonFunctionObject::SetChannel</a></div><div class="ttdeci">void SetChannel(int channel)</div><div class="ttdoc">Set the Channel object.</div><div class="ttdef"><b>Definition:</b> GpgFunctionObject.h:179</div></div>
<div class="ttc" id="aclassGpgFrontend_1_1SingletonFunctionObject_html_a7090636bed6f4bad5b99f28f6872c645"><div class="ttname"><a href="classGpgFrontend_1_1SingletonFunctionObject.html#a7090636bed6f4bad5b99f28f6872c645">GpgFrontend::SingletonFunctionObject::SingletonFunctionObject</a></div><div class="ttdeci">SingletonFunctionObject(const T &amp;)=delete</div><div class="ttdoc">Construct a new Singleton Function Object object.</div></div>
<div class="ttc" id="aclassGpgFrontend_1_1SingletonFunctionObject_html_a7ad3a06b1a64d953f4861f6c9d360c8a"><div class="ttname"><a href="classGpgFrontend_1_1SingletonFunctionObject.html#a7ad3a06b1a64d953f4861f6c9d360c8a">GpgFrontend::SingletonFunctionObject::find_object_in_channel</a></div><div class="ttdeci">static T * find_object_in_channel(int channel)</div><div class="ttdef"><b>Definition:</b> GpgFunctionObject.h:195</div></div>
<div class="ttc" id="aclassGpgFrontend_1_1SingletonFunctionObject_html_a8296be8c449f88175285186831b995bc"><div class="ttname"><a href="classGpgFrontend_1_1SingletonFunctionObject.html#a8296be8c449f88175285186831b995bc">GpgFrontend::SingletonFunctionObject::~SingletonFunctionObject</a></div><div class="ttdeci">virtual ~SingletonFunctionObject()=default</div><div class="ttdoc">Destroy the Singleton Function Object object.</div></div>
<div class="ttc" id="aclassGpgFrontend_1_1SingletonFunctionObject_html_a8a378452876a685af879e04bfa456b6f"><div class="ttname"><a href="classGpgFrontend_1_1SingletonFunctionObject.html#a8a378452876a685af879e04bfa456b6f">GpgFrontend::SingletonFunctionObject::GetInstance</a></div><div class="ttdeci">static T &amp; GetInstance(int channel=GpgFrontend::GPGFRONTEND_DEFAULT_CHANNEL)</div><div class="ttdoc">Get the Instance object.</div><div class="ttdef"><b>Definition:</b> GpgFunctionObject.h:57</div></div>
<div class="ttc" id="aclassGpgFrontend_1_1SingletonFunctionObject_html_aa99440b9177f5d0c18840f08a40d64b7"><div class="ttname"><a href="classGpgFrontend_1_1SingletonFunctionObject.html#aa99440b9177f5d0c18840f08a40d64b7">GpgFrontend::SingletonFunctionObject::GetChannel</a></div><div class="ttdeci">int GetChannel() const</div><div class="ttdoc">Get the Channel object.</div><div class="ttdef"><b>Definition:</b> GpgFunctionObject.h:134</div></div>
<div class="ttc" id="aclassGpgFrontend_1_1SingletonFunctionObject_html_aabc5fe8e5a372ac276a265286457cb9a"><div class="ttname"><a href="classGpgFrontend_1_1SingletonFunctionObject.html#aabc5fe8e5a372ac276a265286457cb9a">GpgFrontend::SingletonFunctionObject::SingletonFunctionObject</a></div><div class="ttdeci">SingletonFunctionObject(T &amp;&amp;)=delete</div><div class="ttdoc">Construct a new Singleton Function Object object.</div></div>
<div class="ttc" id="aclassGpgFrontend_1_1SingletonFunctionObject_html_abb1ea69c668223ee9da79e6c92d5a9fa"><div class="ttname"><a href="classGpgFrontend_1_1SingletonFunctionObject.html#abb1ea69c668223ee9da79e6c92d5a9fa">GpgFrontend::SingletonFunctionObject::ReleaseChannel</a></div><div class="ttdeci">static T &amp; ReleaseChannel(int channel)</div><div class="ttdef"><b>Definition:</b> GpgFunctionObject.h:112</div></div>
<div class="ttc" id="anamespaceGpgFrontend_html"><div class="ttname"><a href="namespaceGpgFrontend.html">GpgFrontend</a></div><div class="ttdef"><b>Definition:</b> CoreCommonUtil.cpp:29</div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><a class="el" href="dir_aebb8dcc11953d78e620bbef0b9e2183.html">core</a></li><li class="navelem"><b>GpgFunctionObject.h</b></li>
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.3 </li>
</ul>
</div>
</body>
</html>