GpgFrontend-Doxygen/docs/html/GpgFunctionObject_8h_source.html
2022-05-08 22:01:23 +00:00

252 lines
32 KiB
HTML

<!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=9"/>
<meta name="generator" content="Doxygen 1.8.17"/>
<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 style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<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.8.17 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @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:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(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:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(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 name="l00001"></a><span class="lineno"> 1</span>&#160; </div>
<div class="line"><a name="l00029"></a><span class="lineno"> 29</span>&#160;<span class="preprocessor">#ifndef GPGFRONTEND_ZH_CN_TS_FUNCTIONOBJECT_H</span></div>
<div class="line"><a name="l00030"></a><span class="lineno"> 30</span>&#160;<span class="preprocessor">#define GPGFRONTEND_ZH_CN_TS_FUNCTIONOBJECT_H</span></div>
<div class="line"><a name="l00031"></a><span class="lineno"> 31</span>&#160; </div>
<div class="line"><a name="l00032"></a><span class="lineno"> 32</span>&#160;<span class="preprocessor">#include &lt;map&gt;</span></div>
<div class="line"><a name="l00033"></a><span class="lineno"> 33</span>&#160;<span class="preprocessor">#include &lt;memory&gt;</span></div>
<div class="line"><a name="l00034"></a><span class="lineno"> 34</span>&#160;<span class="preprocessor">#include &lt;mutex&gt;</span></div>
<div class="line"><a name="l00035"></a><span class="lineno"> 35</span>&#160;<span class="preprocessor">#include &lt;shared_mutex&gt;</span></div>
<div class="line"><a name="l00036"></a><span class="lineno"> 36</span>&#160;<span class="preprocessor">#include &lt;stdexcept&gt;</span></div>
<div class="line"><a name="l00037"></a><span class="lineno"> 37</span>&#160;<span class="preprocessor">#include &lt;string&gt;</span></div>
<div class="line"><a name="l00038"></a><span class="lineno"> 38</span>&#160; </div>
<div class="line"><a name="l00039"></a><span class="lineno"> 39</span>&#160;<span class="preprocessor">#include &quot;GpgConstants.h&quot;</span></div>
<div class="line"><a name="l00040"></a><span class="lineno"> 40</span>&#160; </div>
<div class="line"><a name="l00041"></a><span class="lineno"> 41</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespaceGpgFrontend.html">GpgFrontend</a> {</div>
<div class="line"><a name="l00042"></a><span class="lineno"> 42</span>&#160; </div>
<div class="line"><a name="l00048"></a><span class="lineno"> 48</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div>
<div class="line"><a name="l00049"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html"> 49</a></span>&#160;<span class="keyword">class </span><a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html">SingletonFunctionObject</a> {</div>
<div class="line"><a name="l00050"></a><span class="lineno"> 50</span>&#160; <span class="keyword">public</span>:</div>
<div class="line"><a name="l00057"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html#a70484d7cfe9f9dcbcd5f8bb749250f36"> 57</a></span>&#160; <span class="keyword">static</span> T&amp; <a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html#a70484d7cfe9f9dcbcd5f8bb749250f36">GetInstance</a>(</div>
<div class="line"><a name="l00058"></a><span class="lineno"> 58</span>&#160; <span class="keywordtype">int</span> channel = GpgFrontend::GPGFRONTEND_DEFAULT_CHANNEL) {</div>
<div class="line"><a name="l00059"></a><span class="lineno"> 59</span>&#160; static_assert(std::is_base_of&lt;<a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html">SingletonFunctionObject&lt;T&gt;</a>, T&gt;::value,</div>
<div class="line"><a name="l00060"></a><span class="lineno"> 60</span>&#160; <span class="stringliteral">&quot;T not derived from SingletonFunctionObject&lt;T&gt;&quot;</span>);</div>
<div class="line"><a name="l00061"></a><span class="lineno"> 61</span>&#160; </div>
<div class="line"><a name="l00062"></a><span class="lineno"> 62</span>&#160; <span class="keyword">auto</span> _p_pbj = <a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html#a6c6c54060c4f4926adb1ee4a71ee8c89">find_object_in_channel</a>(channel);</div>
<div class="line"><a name="l00063"></a><span class="lineno"> 63</span>&#160; <span class="keywordflow">if</span> (_p_pbj == <span class="keyword">nullptr</span>)</div>
<div class="line"><a name="l00064"></a><span class="lineno"> 64</span>&#160; <span class="keywordflow">return</span> *<a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html#a7377f8bddac073dbf9aa631726d8c021">set_object_in_channel</a>(channel, std::make_unique&lt;T&gt;(channel));</div>
<div class="line"><a name="l00065"></a><span class="lineno"> 65</span>&#160; <span class="keywordflow">else</span></div>
<div class="line"><a name="l00066"></a><span class="lineno"> 66</span>&#160; <span class="keywordflow">return</span> *_p_pbj;</div>
<div class="line"><a name="l00067"></a><span class="lineno"> 67</span>&#160; }</div>
<div class="line"><a name="l00068"></a><span class="lineno"> 68</span>&#160; </div>
<div class="line"><a name="l00076"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html#a43b21fa20b4102b826e3527f7bbdf218"> 76</a></span>&#160; <span class="keyword">static</span> T&amp; <a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html#a43b21fa20b4102b826e3527f7bbdf218">CreateInstance</a>(<span class="keywordtype">int</span> channel,</div>
<div class="line"><a name="l00077"></a><span class="lineno"> 77</span>&#160; std::function&lt;std::unique_ptr&lt;T&gt;(<span class="keywordtype">void</span>)&gt; factory) {</div>
<div class="line"><a name="l00078"></a><span class="lineno"> 78</span>&#160; static_assert(std::is_base_of&lt;<a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html">SingletonFunctionObject&lt;T&gt;</a>, T&gt;::value,</div>
<div class="line"><a name="l00079"></a><span class="lineno"> 79</span>&#160; <span class="stringliteral">&quot;T not derived from SingletonFunctionObject&lt;T&gt;&quot;</span>);</div>
<div class="line"><a name="l00080"></a><span class="lineno"> 80</span>&#160; </div>
<div class="line"><a name="l00081"></a><span class="lineno"> 81</span>&#160; <span class="keyword">auto</span> _p_pbj = <a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html#a6c6c54060c4f4926adb1ee4a71ee8c89">find_object_in_channel</a>(channel);</div>
<div class="line"><a name="l00082"></a><span class="lineno"> 82</span>&#160; <span class="keywordflow">if</span> (_p_pbj == <span class="keyword">nullptr</span>)</div>
<div class="line"><a name="l00083"></a><span class="lineno"> 83</span>&#160; <span class="keywordflow">return</span> *<a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html#a7377f8bddac073dbf9aa631726d8c021">set_object_in_channel</a>(channel, std::move(factory()));</div>
<div class="line"><a name="l00084"></a><span class="lineno"> 84</span>&#160; <span class="keywordflow">else</span></div>
<div class="line"><a name="l00085"></a><span class="lineno"> 85</span>&#160; <span class="keywordflow">return</span> *_p_pbj;</div>
<div class="line"><a name="l00086"></a><span class="lineno"> 86</span>&#160; }</div>
<div class="line"><a name="l00087"></a><span class="lineno"> 87</span>&#160; </div>
<div class="line"><a name="l00095"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html#a3d40217b6536ffafff8e58078d8e6b95"> 95</a></span>&#160; <span class="keyword">static</span> T&amp; <a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html#a3d40217b6536ffafff8e58078d8e6b95">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 name="l00096"></a><span class="lineno"> 96</span>&#160; static_assert(std::is_base_of&lt;<a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html">SingletonFunctionObject&lt;T&gt;</a>, T&gt;::value,</div>
<div class="line"><a name="l00097"></a><span class="lineno"> 97</span>&#160; <span class="stringliteral">&quot;T not derived from SingletonFunctionObject&lt;T&gt;&quot;</span>);</div>
<div class="line"><a name="l00098"></a><span class="lineno"> 98</span>&#160; </div>
<div class="line"><a name="l00099"></a><span class="lineno"> 99</span>&#160; <span class="keyword">auto</span> _p_pbj = <a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html#a6c6c54060c4f4926adb1ee4a71ee8c89">find_object_in_channel</a>(channel);</div>
<div class="line"><a name="l00100"></a><span class="lineno"> 100</span>&#160; <span class="keywordflow">if</span> (_p_pbj == <span class="keyword">nullptr</span>)</div>
<div class="line"><a name="l00101"></a><span class="lineno"> 101</span>&#160; <span class="keywordflow">return</span> *<a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html#a7377f8bddac073dbf9aa631726d8c021">set_object_in_channel</a>(channel, std::move(p_obj));</div>
<div class="line"><a name="l00102"></a><span class="lineno"> 102</span>&#160; <span class="keywordflow">else</span></div>
<div class="line"><a name="l00103"></a><span class="lineno"> 103</span>&#160; <span class="keywordflow">return</span> *_p_pbj;</div>
<div class="line"><a name="l00104"></a><span class="lineno"> 104</span>&#160; }</div>
<div class="line"><a name="l00105"></a><span class="lineno"> 105</span>&#160; </div>
<div class="line"><a name="l00112"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html#aadb8743cd8943395f5cbb631667da363"> 112</a></span>&#160; <span class="keyword">static</span> T&amp; <a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html#aadb8743cd8943395f5cbb631667da363">ReleaseChannel</a>(<span class="keywordtype">int</span> channel) {</div>
<div class="line"><a name="l00113"></a><span class="lineno"> 113</span>&#160; decltype(_instances_map.end()) _it;</div>
<div class="line"><a name="l00114"></a><span class="lineno"> 114</span>&#160; {</div>
<div class="line"><a name="l00115"></a><span class="lineno"> 115</span>&#160; std::shared_lock lock(_instances_mutex);</div>
<div class="line"><a name="l00116"></a><span class="lineno"> 116</span>&#160; _it = _instances_map.find(channel);</div>
<div class="line"><a name="l00117"></a><span class="lineno"> 117</span>&#160; }</div>
<div class="line"><a name="l00118"></a><span class="lineno"> 118</span>&#160; <span class="keywordflow">if</span> (_it != _instances_map.end()) _instances_map.erase(_it);</div>
<div class="line"><a name="l00119"></a><span class="lineno"> 119</span>&#160; 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 name="l00120"></a><span class="lineno"> 120</span>&#160; }</div>
<div class="line"><a name="l00121"></a><span class="lineno"> 121</span>&#160; </div>
<div class="line"><a name="l00127"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html#a50e2b3794d6553f4231eaec72d9d0a50"> 127</a></span>&#160; <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html#a50e2b3794d6553f4231eaec72d9d0a50">GetDefaultChannel</a>() { <span class="keywordflow">return</span> _default_channel; }</div>
<div class="line"><a name="l00128"></a><span class="lineno"> 128</span>&#160; </div>
<div class="line"><a name="l00134"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html#aa99440b9177f5d0c18840f08a40d64b7"> 134</a></span>&#160; [[nodiscard]] <span class="keywordtype">int</span> <a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html#aa99440b9177f5d0c18840f08a40d64b7">GetChannel</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> channel_; }</div>
<div class="line"><a name="l00135"></a><span class="lineno"> 135</span>&#160; </div>
<div class="line"><a name="l00140"></a><span class="lineno"> 140</span>&#160; <a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html#a02e76b42ab51d77588b01c7508bed258">SingletonFunctionObject</a>(T&amp;&amp;) = <span class="keyword">delete</span>;</div>
<div class="line"><a name="l00141"></a><span class="lineno"> 141</span>&#160; </div>
<div class="line"><a name="l00146"></a><span class="lineno"> 146</span>&#160; <a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html#a02e76b42ab51d77588b01c7508bed258">SingletonFunctionObject</a>(<span class="keyword">const</span> T&amp;) = <span class="keyword">delete</span>;</div>
<div class="line"><a name="l00147"></a><span class="lineno"> 147</span>&#160; </div>
<div class="line"><a name="l00152"></a><span class="lineno"> 152</span>&#160; <span class="keywordtype">void</span> operator=(<span class="keyword">const</span> T&amp;) = <span class="keyword">delete</span>;</div>
<div class="line"><a name="l00153"></a><span class="lineno"> 153</span>&#160; </div>
<div class="line"><a name="l00154"></a><span class="lineno"> 154</span>&#160; <span class="keyword">protected</span>:</div>
<div class="line"><a name="l00159"></a><span class="lineno"> 159</span>&#160; <a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html#a02e76b42ab51d77588b01c7508bed258">SingletonFunctionObject</a>() = <span class="keywordflow">default</span>;</div>
<div class="line"><a name="l00160"></a><span class="lineno"> 160</span>&#160; </div>
<div class="line"><a name="l00166"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html#a4aa7f1eb1d3281bb1fccfcbb1b416251"> 166</a></span>&#160; <span class="keyword">explicit</span> <a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html#a4aa7f1eb1d3281bb1fccfcbb1b416251">SingletonFunctionObject</a>(<span class="keywordtype">int</span> channel) : channel_(channel) {}</div>
<div class="line"><a name="l00167"></a><span class="lineno"> 167</span>&#160; </div>
<div class="line"><a name="l00172"></a><span class="lineno"> 172</span>&#160; <span class="keyword">virtual</span> <a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html#a8296be8c449f88175285186831b995bc">~SingletonFunctionObject</a>() = <span class="keywordflow">default</span>;</div>
<div class="line"><a name="l00173"></a><span class="lineno"> 173</span>&#160; </div>
<div class="line"><a name="l00179"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html#a56ba12077251893e48f5ec360e8c7040"> 179</a></span>&#160; <span class="keywordtype">void</span> <a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html#a56ba12077251893e48f5ec360e8c7040">SetChannel</a>(<span class="keywordtype">int</span> channel) { this-&gt;channel_ = channel; }</div>
<div class="line"><a name="l00180"></a><span class="lineno"> 180</span>&#160; </div>
<div class="line"><a name="l00181"></a><span class="lineno"> 181</span>&#160; <span class="keyword">private</span>:</div>
<div class="line"><a name="l00182"></a><span class="lineno"> 182</span>&#160; <span class="keywordtype">int</span> channel_ = _default_channel; </div>
<div class="line"><a name="l00183"></a><span class="lineno"> 183</span>&#160; <span class="keyword">static</span> <span class="keywordtype">int</span> _default_channel; </div>
<div class="line"><a name="l00184"></a><span class="lineno"> 184</span>&#160; <span class="keyword">static</span> std::mutex _instance_mutex; </div>
<div class="line"><a name="l00185"></a><span class="lineno"> 185</span>&#160; <span class="keyword">static</span> std::shared_mutex _instances_mutex; </div>
<div class="line"><a name="l00186"></a><span class="lineno"> 186</span>&#160; <span class="keyword">static</span> std::unique_ptr&lt;T&gt; _instance; </div>
<div class="line"><a name="l00187"></a><span class="lineno"> 187</span>&#160; <span class="keyword">static</span> std::map&lt;int, std::unique_ptr&lt;T&gt;&gt; _instances_map; </div>
<div class="line"><a name="l00188"></a><span class="lineno"> 188</span>&#160; </div>
<div class="line"><a name="l00195"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html#a6c6c54060c4f4926adb1ee4a71ee8c89"> 195</a></span>&#160; <span class="keyword">static</span> T* <a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html#a6c6c54060c4f4926adb1ee4a71ee8c89">find_object_in_channel</a>(<span class="keywordtype">int</span> channel) {</div>
<div class="line"><a name="l00196"></a><span class="lineno"> 196</span>&#160; <span class="comment">// read _instances_map</span></div>
<div class="line"><a name="l00197"></a><span class="lineno"> 197</span>&#160; decltype(_instances_map.end()) _it;</div>
<div class="line"><a name="l00198"></a><span class="lineno"> 198</span>&#160; {</div>
<div class="line"><a name="l00199"></a><span class="lineno"> 199</span>&#160; std::shared_lock lock(_instances_mutex);</div>
<div class="line"><a name="l00200"></a><span class="lineno"> 200</span>&#160; _it = _instances_map.find(channel);</div>
<div class="line"><a name="l00201"></a><span class="lineno"> 201</span>&#160; <span class="keywordflow">if</span> (_it == _instances_map.end())</div>
<div class="line"><a name="l00202"></a><span class="lineno"> 202</span>&#160; <span class="keywordflow">return</span> <span class="keyword">nullptr</span>;</div>
<div class="line"><a name="l00203"></a><span class="lineno"> 203</span>&#160; <span class="keywordflow">else</span></div>
<div class="line"><a name="l00204"></a><span class="lineno"> 204</span>&#160; <span class="keywordflow">return</span> _it-&gt;second.get();</div>
<div class="line"><a name="l00205"></a><span class="lineno"> 205</span>&#160; }</div>
<div class="line"><a name="l00206"></a><span class="lineno"> 206</span>&#160; }</div>
<div class="line"><a name="l00207"></a><span class="lineno"> 207</span>&#160; </div>
<div class="line"><a name="l00215"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html#a7377f8bddac073dbf9aa631726d8c021"> 215</a></span>&#160; <span class="keyword">static</span> T* <a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html#a7377f8bddac073dbf9aa631726d8c021">set_object_in_channel</a>(<span class="keywordtype">int</span> channel, std::unique_ptr&lt;T&gt; p_obj) {</div>
<div class="line"><a name="l00216"></a><span class="lineno"> 216</span>&#160; {</div>
<div class="line"><a name="l00217"></a><span class="lineno"> 217</span>&#160; <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 name="l00218"></a><span class="lineno"> 218</span>&#160; T* obj = p_obj.get();</div>
<div class="line"><a name="l00219"></a><span class="lineno"> 219</span>&#160; obj-&gt;SetChannel(channel);</div>
<div class="line"><a name="l00220"></a><span class="lineno"> 220</span>&#160; {</div>
<div class="line"><a name="l00221"></a><span class="lineno"> 221</span>&#160; std::unique_lock lock(_instances_mutex);</div>
<div class="line"><a name="l00222"></a><span class="lineno"> 222</span>&#160; _instances_map.insert({channel, std::move(p_obj)});</div>
<div class="line"><a name="l00223"></a><span class="lineno"> 223</span>&#160; }</div>
<div class="line"><a name="l00224"></a><span class="lineno"> 224</span>&#160; <span class="keywordflow">return</span> obj;</div>
<div class="line"><a name="l00225"></a><span class="lineno"> 225</span>&#160; }</div>
<div class="line"><a name="l00226"></a><span class="lineno"> 226</span>&#160; }</div>
<div class="line"><a name="l00227"></a><span class="lineno"> 227</span>&#160;};</div>
<div class="line"><a name="l00228"></a><span class="lineno"> 228</span>&#160; </div>
<div class="line"><a name="l00229"></a><span class="lineno"> 229</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div>
<div class="line"><a name="l00230"></a><span class="lineno"> 230</span>&#160;<span class="keywordtype">int</span> SingletonFunctionObject&lt;T&gt;::_default_channel =</div>
<div class="line"><a name="l00231"></a><span class="lineno"> 231</span>&#160; GpgFrontend::GPGFRONTEND_DEFAULT_CHANNEL;</div>
<div class="line"><a name="l00232"></a><span class="lineno"> 232</span>&#160; </div>
<div class="line"><a name="l00233"></a><span class="lineno"> 233</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div>
<div class="line"><a name="l00234"></a><span class="lineno"> 234</span>&#160;std::mutex SingletonFunctionObject&lt;T&gt;::_instance_mutex;</div>
<div class="line"><a name="l00235"></a><span class="lineno"> 235</span>&#160; </div>
<div class="line"><a name="l00236"></a><span class="lineno"> 236</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div>
<div class="line"><a name="l00237"></a><span class="lineno"> 237</span>&#160;std::shared_mutex SingletonFunctionObject&lt;T&gt;::_instances_mutex;</div>
<div class="line"><a name="l00238"></a><span class="lineno"> 238</span>&#160; </div>
<div class="line"><a name="l00239"></a><span class="lineno"> 239</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div>
<div class="line"><a name="l00240"></a><span class="lineno"> 240</span>&#160;std::unique_ptr&lt;T&gt; SingletonFunctionObject&lt;T&gt;::_instance = <span class="keyword">nullptr</span>;</div>
<div class="line"><a name="l00241"></a><span class="lineno"> 241</span>&#160; </div>
<div class="line"><a name="l00242"></a><span class="lineno"> 242</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div>
<div class="line"><a name="l00243"></a><span class="lineno"> 243</span>&#160;std::map&lt;int, std::unique_ptr&lt;T&gt;&gt; SingletonFunctionObject&lt;T&gt;::_instances_map;</div>
<div class="line"><a name="l00244"></a><span class="lineno"> 244</span>&#160; </div>
<div class="line"><a name="l00245"></a><span class="lineno"> 245</span>&#160;} <span class="comment">// namespace GpgFrontend</span></div>
<div class="line"><a name="l00246"></a><span class="lineno"> 246</span>&#160; </div>
<div class="line"><a name="l00247"></a><span class="lineno"> 247</span>&#160;<span class="preprocessor">#endif // GPGFRONTEND_ZH_CN_TS_FUNCTIONOBJECT_H</span></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<div class="ttc" id="aclassGpgFrontend_1_1SingletonFunctionObject_html_aadb8743cd8943395f5cbb631667da363"><div class="ttname"><a href="classGpgFrontend_1_1SingletonFunctionObject.html#aadb8743cd8943395f5cbb631667da363">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="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_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="anamespaceGpgFrontend_html"><div class="ttname"><a href="namespaceGpgFrontend.html">GpgFrontend</a></div><div class="ttdef"><b>Definition:</b> CoreCommonUtil.cpp:29</div></div>
<div class="ttc" id="aclassGpgFrontend_1_1SingletonFunctionObject_html_a70484d7cfe9f9dcbcd5f8bb749250f36"><div class="ttname"><a href="classGpgFrontend_1_1SingletonFunctionObject.html#a70484d7cfe9f9dcbcd5f8bb749250f36">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_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_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_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_a3d40217b6536ffafff8e58078d8e6b95"><div class="ttname"><a href="classGpgFrontend_1_1SingletonFunctionObject.html#a3d40217b6536ffafff8e58078d8e6b95">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_a7377f8bddac073dbf9aa631726d8c021"><div class="ttname"><a href="classGpgFrontend_1_1SingletonFunctionObject.html#a7377f8bddac073dbf9aa631726d8c021">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_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_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_a6c6c54060c4f4926adb1ee4a71ee8c89"><div class="ttname"><a href="classGpgFrontend_1_1SingletonFunctionObject.html#a6c6c54060c4f4926adb1ee4a71ee8c89">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_a43b21fa20b4102b826e3527f7bbdf218"><div class="ttname"><a href="classGpgFrontend_1_1SingletonFunctionObject.html#a43b21fa20b4102b826e3527f7bbdf218">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>
<!-- 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="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.17 </li>
</ul>
</div>
</body>
</html>