252 lines
32 KiB
HTML
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&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&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&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>  </div>
|
|
<div class="line"><a name="l00029"></a><span class="lineno"> 29</span> <span class="preprocessor">#ifndef GPGFRONTEND_ZH_CN_TS_FUNCTIONOBJECT_H</span></div>
|
|
<div class="line"><a name="l00030"></a><span class="lineno"> 30</span> <span class="preprocessor">#define GPGFRONTEND_ZH_CN_TS_FUNCTIONOBJECT_H</span></div>
|
|
<div class="line"><a name="l00031"></a><span class="lineno"> 31</span>  </div>
|
|
<div class="line"><a name="l00032"></a><span class="lineno"> 32</span> <span class="preprocessor">#include <map></span></div>
|
|
<div class="line"><a name="l00033"></a><span class="lineno"> 33</span> <span class="preprocessor">#include <memory></span></div>
|
|
<div class="line"><a name="l00034"></a><span class="lineno"> 34</span> <span class="preprocessor">#include <mutex></span></div>
|
|
<div class="line"><a name="l00035"></a><span class="lineno"> 35</span> <span class="preprocessor">#include <shared_mutex></span></div>
|
|
<div class="line"><a name="l00036"></a><span class="lineno"> 36</span> <span class="preprocessor">#include <stdexcept></span></div>
|
|
<div class="line"><a name="l00037"></a><span class="lineno"> 37</span> <span class="preprocessor">#include <string></span></div>
|
|
<div class="line"><a name="l00038"></a><span class="lineno"> 38</span>  </div>
|
|
<div class="line"><a name="l00039"></a><span class="lineno"> 39</span> <span class="preprocessor">#include "GpgConstants.h"</span></div>
|
|
<div class="line"><a name="l00040"></a><span class="lineno"> 40</span>  </div>
|
|
<div class="line"><a name="l00041"></a><span class="lineno"> 41</span> <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>  </div>
|
|
<div class="line"><a name="l00048"></a><span class="lineno"> 48</span> <span class="keyword">template</span> <<span class="keyword">typename</span> T></div>
|
|
<div class="line"><a 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" href="classGpgFrontend_1_1SingletonFunctionObject.html">SingletonFunctionObject</a> {</div>
|
|
<div class="line"><a name="l00050"></a><span class="lineno"> 50</span>  <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>  <span class="keyword">static</span> T& <a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html#a70484d7cfe9f9dcbcd5f8bb749250f36">GetInstance</a>(</div>
|
|
<div class="line"><a name="l00058"></a><span class="lineno"> 58</span>  <span class="keywordtype">int</span> channel = GpgFrontend::GPGFRONTEND_DEFAULT_CHANNEL) {</div>
|
|
<div class="line"><a name="l00059"></a><span class="lineno"> 59</span>  static_assert(std::is_base_of<<a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html">SingletonFunctionObject<T></a>, T>::value,</div>
|
|
<div class="line"><a name="l00060"></a><span class="lineno"> 60</span>  <span class="stringliteral">"T not derived from SingletonFunctionObject<T>"</span>);</div>
|
|
<div class="line"><a name="l00061"></a><span class="lineno"> 61</span>  </div>
|
|
<div class="line"><a name="l00062"></a><span class="lineno"> 62</span>  <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>  <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>  <span class="keywordflow">return</span> *<a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html#a7377f8bddac073dbf9aa631726d8c021">set_object_in_channel</a>(channel, std::make_unique<T>(channel));</div>
|
|
<div class="line"><a name="l00065"></a><span class="lineno"> 65</span>  <span class="keywordflow">else</span></div>
|
|
<div class="line"><a name="l00066"></a><span class="lineno"> 66</span>  <span class="keywordflow">return</span> *_p_pbj;</div>
|
|
<div class="line"><a name="l00067"></a><span class="lineno"> 67</span>  }</div>
|
|
<div class="line"><a name="l00068"></a><span class="lineno"> 68</span>  </div>
|
|
<div class="line"><a name="l00076"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html#a43b21fa20b4102b826e3527f7bbdf218"> 76</a></span>  <span class="keyword">static</span> T& <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>  std::function<std::unique_ptr<T>(<span class="keywordtype">void</span>)> factory) {</div>
|
|
<div class="line"><a name="l00078"></a><span class="lineno"> 78</span>  static_assert(std::is_base_of<<a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html">SingletonFunctionObject<T></a>, T>::value,</div>
|
|
<div class="line"><a name="l00079"></a><span class="lineno"> 79</span>  <span class="stringliteral">"T not derived from SingletonFunctionObject<T>"</span>);</div>
|
|
<div class="line"><a name="l00080"></a><span class="lineno"> 80</span>  </div>
|
|
<div class="line"><a name="l00081"></a><span class="lineno"> 81</span>  <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>  <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>  <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>  <span class="keywordflow">else</span></div>
|
|
<div class="line"><a name="l00085"></a><span class="lineno"> 85</span>  <span class="keywordflow">return</span> *_p_pbj;</div>
|
|
<div class="line"><a name="l00086"></a><span class="lineno"> 86</span>  }</div>
|
|
<div class="line"><a name="l00087"></a><span class="lineno"> 87</span>  </div>
|
|
<div class="line"><a name="l00095"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html#a3d40217b6536ffafff8e58078d8e6b95"> 95</a></span>  <span class="keyword">static</span> T& <a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html#a3d40217b6536ffafff8e58078d8e6b95">CreateInstance</a>(<span class="keywordtype">int</span> channel, std::unique_ptr<T> p_obj = <span class="keyword">nullptr</span>) {</div>
|
|
<div class="line"><a name="l00096"></a><span class="lineno"> 96</span>  static_assert(std::is_base_of<<a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html">SingletonFunctionObject<T></a>, T>::value,</div>
|
|
<div class="line"><a name="l00097"></a><span class="lineno"> 97</span>  <span class="stringliteral">"T not derived from SingletonFunctionObject<T>"</span>);</div>
|
|
<div class="line"><a name="l00098"></a><span class="lineno"> 98</span>  </div>
|
|
<div class="line"><a name="l00099"></a><span class="lineno"> 99</span>  <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>  <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>  <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>  <span class="keywordflow">else</span></div>
|
|
<div class="line"><a name="l00103"></a><span class="lineno"> 103</span>  <span class="keywordflow">return</span> *_p_pbj;</div>
|
|
<div class="line"><a name="l00104"></a><span class="lineno"> 104</span>  }</div>
|
|
<div class="line"><a name="l00105"></a><span class="lineno"> 105</span>  </div>
|
|
<div class="line"><a name="l00112"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html#aadb8743cd8943395f5cbb631667da363"> 112</a></span>  <span class="keyword">static</span> T& <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>  decltype(_instances_map.end()) _it;</div>
|
|
<div class="line"><a name="l00114"></a><span class="lineno"> 114</span>  {</div>
|
|
<div class="line"><a name="l00115"></a><span class="lineno"> 115</span>  std::shared_lock lock(_instances_mutex);</div>
|
|
<div class="line"><a name="l00116"></a><span class="lineno"> 116</span>  _it = _instances_map.find(channel);</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>  <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>  DLOG(INFO) << <span class="stringliteral">"channel"</span> << channel << <span class="stringliteral">"released"</span>;</div>
|
|
<div class="line"><a name="l00120"></a><span class="lineno"> 120</span>  }</div>
|
|
<div class="line"><a name="l00121"></a><span class="lineno"> 121</span>  </div>
|
|
<div class="line"><a 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" 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>  </div>
|
|
<div class="line"><a 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" 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>  </div>
|
|
<div class="line"><a name="l00140"></a><span class="lineno"> 140</span>  <a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html#a02e76b42ab51d77588b01c7508bed258">SingletonFunctionObject</a>(T&&) = <span class="keyword">delete</span>;</div>
|
|
<div class="line"><a name="l00141"></a><span class="lineno"> 141</span>  </div>
|
|
<div class="line"><a name="l00146"></a><span class="lineno"> 146</span>  <a class="code" href="classGpgFrontend_1_1SingletonFunctionObject.html#a02e76b42ab51d77588b01c7508bed258">SingletonFunctionObject</a>(<span class="keyword">const</span> T&) = <span class="keyword">delete</span>;</div>
|
|
<div class="line"><a name="l00147"></a><span class="lineno"> 147</span>  </div>
|
|
<div class="line"><a name="l00152"></a><span class="lineno"> 152</span>  <span class="keywordtype">void</span> operator=(<span class="keyword">const</span> T&) = <span class="keyword">delete</span>;</div>
|
|
<div class="line"><a name="l00153"></a><span class="lineno"> 153</span>  </div>
|
|
<div class="line"><a name="l00154"></a><span class="lineno"> 154</span>  <span class="keyword">protected</span>:</div>
|
|
<div class="line"><a name="l00159"></a><span class="lineno"> 159</span>  <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>  </div>
|
|
<div class="line"><a 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" 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>  </div>
|
|
<div class="line"><a name="l00172"></a><span class="lineno"> 172</span>  <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>  </div>
|
|
<div class="line"><a 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" href="classGpgFrontend_1_1SingletonFunctionObject.html#a56ba12077251893e48f5ec360e8c7040">SetChannel</a>(<span class="keywordtype">int</span> channel) { this->channel_ = channel; }</div>
|
|
<div class="line"><a name="l00180"></a><span class="lineno"> 180</span>  </div>
|
|
<div class="line"><a name="l00181"></a><span class="lineno"> 181</span>  <span class="keyword">private</span>:</div>
|
|
<div class="line"><a name="l00182"></a><span class="lineno"> 182</span>  <span class="keywordtype">int</span> channel_ = _default_channel; </div>
|
|
<div class="line"><a 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 name="l00184"></a><span class="lineno"> 184</span>  <span class="keyword">static</span> std::mutex _instance_mutex; </div>
|
|
<div class="line"><a name="l00185"></a><span class="lineno"> 185</span>  <span class="keyword">static</span> std::shared_mutex _instances_mutex; </div>
|
|
<div class="line"><a name="l00186"></a><span class="lineno"> 186</span>  <span class="keyword">static</span> std::unique_ptr<T> _instance; </div>
|
|
<div class="line"><a name="l00187"></a><span class="lineno"> 187</span>  <span class="keyword">static</span> std::map<int, std::unique_ptr<T>> _instances_map; </div>
|
|
<div class="line"><a name="l00188"></a><span class="lineno"> 188</span>  </div>
|
|
<div class="line"><a name="l00195"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html#a6c6c54060c4f4926adb1ee4a71ee8c89"> 195</a></span>  <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>  <span class="comment">// read _instances_map</span></div>
|
|
<div class="line"><a name="l00197"></a><span class="lineno"> 197</span>  decltype(_instances_map.end()) _it;</div>
|
|
<div class="line"><a name="l00198"></a><span class="lineno"> 198</span>  {</div>
|
|
<div class="line"><a name="l00199"></a><span class="lineno"> 199</span>  std::shared_lock lock(_instances_mutex);</div>
|
|
<div class="line"><a name="l00200"></a><span class="lineno"> 200</span>  _it = _instances_map.find(channel);</div>
|
|
<div class="line"><a name="l00201"></a><span class="lineno"> 201</span>  <span class="keywordflow">if</span> (_it == _instances_map.end())</div>
|
|
<div class="line"><a name="l00202"></a><span class="lineno"> 202</span>  <span class="keywordflow">return</span> <span class="keyword">nullptr</span>;</div>
|
|
<div class="line"><a name="l00203"></a><span class="lineno"> 203</span>  <span class="keywordflow">else</span></div>
|
|
<div class="line"><a name="l00204"></a><span class="lineno"> 204</span>  <span class="keywordflow">return</span> _it->second.get();</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>  }</div>
|
|
<div class="line"><a name="l00207"></a><span class="lineno"> 207</span>  </div>
|
|
<div class="line"><a name="l00215"></a><span class="lineno"><a class="line" href="classGpgFrontend_1_1SingletonFunctionObject.html#a7377f8bddac073dbf9aa631726d8c021"> 215</a></span>  <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<T> p_obj) {</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">if</span> (p_obj == <span class="keyword">nullptr</span>) p_obj = std::make_unique<T>();</div>
|
|
<div class="line"><a name="l00218"></a><span class="lineno"> 218</span>  T* obj = p_obj.get();</div>
|
|
<div class="line"><a name="l00219"></a><span class="lineno"> 219</span>  obj->SetChannel(channel);</div>
|
|
<div class="line"><a name="l00220"></a><span class="lineno"> 220</span>  {</div>
|
|
<div class="line"><a name="l00221"></a><span class="lineno"> 221</span>  std::unique_lock lock(_instances_mutex);</div>
|
|
<div class="line"><a name="l00222"></a><span class="lineno"> 222</span>  _instances_map.insert({channel, std::move(p_obj)});</div>
|
|
<div class="line"><a name="l00223"></a><span class="lineno"> 223</span>  }</div>
|
|
<div class="line"><a name="l00224"></a><span class="lineno"> 224</span>  <span class="keywordflow">return</span> obj;</div>
|
|
<div class="line"><a name="l00225"></a><span class="lineno"> 225</span>  }</div>
|
|
<div class="line"><a name="l00226"></a><span class="lineno"> 226</span>  }</div>
|
|
<div class="line"><a name="l00227"></a><span class="lineno"> 227</span> };</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">template</span> <<span class="keyword">typename</span> T></div>
|
|
<div class="line"><a name="l00230"></a><span class="lineno"> 230</span> <span class="keywordtype">int</span> SingletonFunctionObject<T>::_default_channel =</div>
|
|
<div class="line"><a name="l00231"></a><span class="lineno"> 231</span>  GpgFrontend::GPGFRONTEND_DEFAULT_CHANNEL;</div>
|
|
<div class="line"><a name="l00232"></a><span class="lineno"> 232</span>  </div>
|
|
<div class="line"><a name="l00233"></a><span class="lineno"> 233</span> <span class="keyword">template</span> <<span class="keyword">typename</span> T></div>
|
|
<div class="line"><a name="l00234"></a><span class="lineno"> 234</span> std::mutex SingletonFunctionObject<T>::_instance_mutex;</div>
|
|
<div class="line"><a name="l00235"></a><span class="lineno"> 235</span>  </div>
|
|
<div class="line"><a name="l00236"></a><span class="lineno"> 236</span> <span class="keyword">template</span> <<span class="keyword">typename</span> T></div>
|
|
<div class="line"><a name="l00237"></a><span class="lineno"> 237</span> std::shared_mutex SingletonFunctionObject<T>::_instances_mutex;</div>
|
|
<div class="line"><a name="l00238"></a><span class="lineno"> 238</span>  </div>
|
|
<div class="line"><a name="l00239"></a><span class="lineno"> 239</span> <span class="keyword">template</span> <<span class="keyword">typename</span> T></div>
|
|
<div class="line"><a name="l00240"></a><span class="lineno"> 240</span> std::unique_ptr<T> SingletonFunctionObject<T>::_instance = <span class="keyword">nullptr</span>;</div>
|
|
<div class="line"><a name="l00241"></a><span class="lineno"> 241</span>  </div>
|
|
<div class="line"><a name="l00242"></a><span class="lineno"> 242</span> <span class="keyword">template</span> <<span class="keyword">typename</span> T></div>
|
|
<div class="line"><a name="l00243"></a><span class="lineno"> 243</span> std::map<int, std::unique_ptr<T>> SingletonFunctionObject<T>::_instances_map;</div>
|
|
<div class="line"><a name="l00244"></a><span class="lineno"> 244</span>  </div>
|
|
<div class="line"><a name="l00245"></a><span class="lineno"> 245</span> } <span class="comment">// namespace GpgFrontend</span></div>
|
|
<div class="line"><a name="l00246"></a><span class="lineno"> 246</span>  </div>
|
|
<div class="line"><a name="l00247"></a><span class="lineno"> 247</span> <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 & 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 & 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 & CreateInstance(int channel, std::unique_ptr< T > 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< T > 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 & CreateInstance(int channel, std::function< std::unique_ptr< T >(void)> 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>
|