Files
entt/locator_8hpp_source.html
2022-04-18 19:54:29 +02:00

145 lines
17 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.9.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>EnTT: src/entt/locator/locator.hpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">EnTT
&#160;<span id="projectnumber">3.10.0</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<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','.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: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>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><a class="el" href="dir_66e9674e8206a335795995fa32a03c91.html">entt</a></li><li class="navelem"><a class="el" href="dir_b64489a1e8130d5ebf6d86d282f500f0.html">locator</a></li> </ul>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">locator.hpp</div> </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span>&#160;<span class="preprocessor">#ifndef ENTT_LOCATOR_LOCATOR_HPP</span></div>
<div class="line"><a name="l00002"></a><span class="lineno"> 2</span>&#160;<span class="preprocessor">#define ENTT_LOCATOR_LOCATOR_HPP</span></div>
<div class="line"><a name="l00003"></a><span class="lineno"> 3</span>&#160; </div>
<div class="line"><a name="l00004"></a><span class="lineno"> 4</span>&#160;<span class="preprocessor">#include &lt;memory&gt;</span></div>
<div class="line"><a name="l00005"></a><span class="lineno"> 5</span>&#160;<span class="preprocessor">#include &lt;utility&gt;</span></div>
<div class="line"><a name="l00006"></a><span class="lineno"> 6</span>&#160;<span class="preprocessor">#include &quot;../config/config.h&quot;</span></div>
<div class="line"><a name="l00007"></a><span class="lineno"> 7</span>&#160; </div>
<div class="line"><a name="l00008"></a><span class="lineno"> 8</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespaceentt.html">entt</a> {</div>
<div class="line"><a name="l00009"></a><span class="lineno"> 9</span>&#160; </div>
<div class="line"><a name="l00026"></a><span class="lineno"> 26</span>&#160;<span class="keyword">template</span>&lt;<span class="keyword">typename</span> Service&gt;</div>
<div class="line"><a name="l00027"></a><span class="lineno"><a class="line" href="structentt_1_1locator.html"> 27</a></span>&#160;<span class="keyword">struct </span><a class="code" href="structentt_1_1locator.html">locator</a> final {</div>
<div class="line"><a name="l00029"></a><span class="lineno"><a class="line" href="structentt_1_1locator.html#aa1b4b856f4d36f39bbbecfd79cb380ee"> 29</a></span>&#160; <span class="keyword">using</span> <a class="code" href="structentt_1_1locator.html#aa1b4b856f4d36f39bbbecfd79cb380ee">type</a> = Service;</div>
<div class="line"><a name="l00030"></a><span class="lineno"> 30</span>&#160; </div>
<div class="line"><a name="l00032"></a><span class="lineno"><a class="line" href="structentt_1_1locator.html#af0226a1ca179eba7e3b63ee47c1d668c"> 32</a></span>&#160; <a class="code" href="structentt_1_1locator.html#af0226a1ca179eba7e3b63ee47c1d668c">locator</a>() = <span class="keyword">delete</span>;</div>
<div class="line"><a name="l00034"></a><span class="lineno"><a class="line" href="structentt_1_1locator.html#a9f224d476bcb081004089f419a1ddde5"> 34</a></span>&#160; <a class="code" href="structentt_1_1locator.html#a9f224d476bcb081004089f419a1ddde5">~locator</a>() = <span class="keyword">delete</span>;</div>
<div class="line"><a name="l00035"></a><span class="lineno"> 35</span>&#160; </div>
<div class="line"><a name="l00040"></a><span class="lineno"><a class="line" href="structentt_1_1locator.html#a8beabd097ab7cb7edc9194b109bc25a2"> 40</a></span>&#160; [[nodiscard]] <span class="keyword">static</span> <span class="keywordtype">bool</span> <a class="code" href="structentt_1_1locator.html#a8beabd097ab7cb7edc9194b109bc25a2">has_value</a>() ENTT_NOEXCEPT {</div>
<div class="line"><a name="l00041"></a><span class="lineno"> 41</span>&#160; <span class="keywordflow">return</span> (service != <span class="keyword">nullptr</span>);</div>
<div class="line"><a name="l00042"></a><span class="lineno"> 42</span>&#160; }</div>
<div class="line"><a name="l00043"></a><span class="lineno"> 43</span>&#160; </div>
<div class="line"><a name="l00053"></a><span class="lineno"><a class="line" href="structentt_1_1locator.html#a22699e0d2a72b24d942e4937b001e0f8"> 53</a></span>&#160; [[nodiscard]] <span class="keyword">static</span> Service &amp;<a class="code" href="structentt_1_1locator.html#a22699e0d2a72b24d942e4937b001e0f8">value</a>() ENTT_NOEXCEPT {</div>
<div class="line"><a name="l00054"></a><span class="lineno"> 54</span>&#160; ENTT_ASSERT(<a class="code" href="structentt_1_1locator.html#a8beabd097ab7cb7edc9194b109bc25a2">has_value</a>(), <span class="stringliteral">&quot;Service not available&quot;</span>);</div>
<div class="line"><a name="l00055"></a><span class="lineno"> 55</span>&#160; <span class="keywordflow">return</span> *service;</div>
<div class="line"><a name="l00056"></a><span class="lineno"> 56</span>&#160; }</div>
<div class="line"><a name="l00057"></a><span class="lineno"> 57</span>&#160; </div>
<div class="line"><a name="l00069"></a><span class="lineno"> 69</span>&#160; <span class="keyword">template</span>&lt;<span class="keyword">typename</span> Impl = Service, <span class="keyword">typename</span>... Args&gt;</div>
<div class="line"><a name="l00070"></a><span class="lineno"><a class="line" href="structentt_1_1locator.html#a8948b6cc1b6f3446a26391c0025d1777"> 70</a></span>&#160; [[nodiscard]] <span class="keyword">static</span> Service &amp;<a class="code" href="structentt_1_1locator.html#a8948b6cc1b6f3446a26391c0025d1777">value_or</a>(Args &amp;&amp;...args) {</div>
<div class="line"><a name="l00071"></a><span class="lineno"> 71</span>&#160; <span class="keywordflow">return</span> service ? *service : emplace&lt;Impl&gt;(std::forward&lt;Args&gt;(args)...);</div>
<div class="line"><a name="l00072"></a><span class="lineno"> 72</span>&#160; }</div>
<div class="line"><a name="l00073"></a><span class="lineno"> 73</span>&#160; </div>
<div class="line"><a name="l00081"></a><span class="lineno"> 81</span>&#160; <span class="keyword">template</span>&lt;<span class="keyword">typename</span> Impl = Service, <span class="keyword">typename</span>... Args&gt;</div>
<div class="line"><a name="l00082"></a><span class="lineno"><a class="line" href="structentt_1_1locator.html#ab01151d77654a589cc94b302ced3c679"> 82</a></span>&#160; <span class="keyword">static</span> Service &amp;<a class="code" href="structentt_1_1locator.html#ab01151d77654a589cc94b302ced3c679">emplace</a>(Args &amp;&amp;...args) {</div>
<div class="line"><a name="l00083"></a><span class="lineno"> 83</span>&#160; service = std::make_shared&lt;Impl&gt;(std::forward&lt;Args&gt;(args)...);</div>
<div class="line"><a name="l00084"></a><span class="lineno"> 84</span>&#160; <span class="keywordflow">return</span> *service;</div>
<div class="line"><a name="l00085"></a><span class="lineno"> 85</span>&#160; }</div>
<div class="line"><a name="l00086"></a><span class="lineno"> 86</span>&#160; </div>
<div class="line"><a name="l00096"></a><span class="lineno"> 96</span>&#160; <span class="keyword">template</span>&lt;<span class="keyword">typename</span> Impl = Service, <span class="keyword">typename</span> Allocator, <span class="keyword">typename</span>... Args&gt;</div>
<div class="line"><a name="l00097"></a><span class="lineno"><a class="line" href="structentt_1_1locator.html#a9670f20018968edcf7677aa44ae036bf"> 97</a></span>&#160; <span class="keyword">static</span> Service &amp;<a class="code" href="structentt_1_1locator.html#a9670f20018968edcf7677aa44ae036bf">allocate_emplace</a>(Allocator alloc, Args &amp;&amp;...args) {</div>
<div class="line"><a name="l00098"></a><span class="lineno"> 98</span>&#160; service = std::allocate_shared&lt;Impl&gt;(alloc, std::forward&lt;Args&gt;(args)...);</div>
<div class="line"><a name="l00099"></a><span class="lineno"> 99</span>&#160; <span class="keywordflow">return</span> *service;</div>
<div class="line"><a name="l00100"></a><span class="lineno"> 100</span>&#160; }</div>
<div class="line"><a name="l00101"></a><span class="lineno"> 101</span>&#160; </div>
<div class="line"><a name="l00103"></a><span class="lineno"><a class="line" href="structentt_1_1locator.html#acf587655946b69f0c483c204a76ca84b"> 103</a></span>&#160; <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="structentt_1_1locator.html#acf587655946b69f0c483c204a76ca84b">reset</a>() ENTT_NOEXCEPT {</div>
<div class="line"><a name="l00104"></a><span class="lineno"> 104</span>&#160; service.reset();</div>
<div class="line"><a name="l00105"></a><span class="lineno"> 105</span>&#160; }</div>
<div class="line"><a name="l00106"></a><span class="lineno"> 106</span>&#160; </div>
<div class="line"><a name="l00107"></a><span class="lineno"> 107</span>&#160;<span class="keyword">private</span>:</div>
<div class="line"><a name="l00108"></a><span class="lineno"> 108</span>&#160; <span class="comment">// std::shared_ptr because of its type erased allocator which is pretty useful here</span></div>
<div class="line"><a name="l00109"></a><span class="lineno"> 109</span>&#160; <span class="keyword">inline</span> <span class="keyword">static</span> std::shared_ptr&lt;Service&gt; service = <span class="keyword">nullptr</span>;</div>
<div class="line"><a name="l00110"></a><span class="lineno"> 110</span>&#160;};</div>
<div class="line"><a name="l00111"></a><span class="lineno"> 111</span>&#160; </div>
<div class="line"><a name="l00112"></a><span class="lineno"> 112</span>&#160;} <span class="comment">// namespace entt</span></div>
<div class="line"><a name="l00113"></a><span class="lineno"> 113</span>&#160; </div>
<div class="line"><a name="l00114"></a><span class="lineno"> 114</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="ttc" id="anamespaceentt_html"><div class="ttname"><a href="namespaceentt.html">entt</a></div><div class="ttdoc">EnTT default namespace.</div><div class="ttdef"><b>Definition:</b> <a href="dense__map_8hpp_source.html#l00022">dense_map.hpp:22</a></div></div>
<div class="ttc" id="astructentt_1_1locator_html"><div class="ttname"><a href="structentt_1_1locator.html">entt::locator</a></div><div class="ttdoc">Service locator, nothing more.</div><div class="ttdef"><b>Definition:</b> <a href="locator_8hpp_source.html#l00027">locator.hpp:27</a></div></div>
<div class="ttc" id="astructentt_1_1locator_html_a22699e0d2a72b24d942e4937b001e0f8"><div class="ttname"><a href="structentt_1_1locator.html#a22699e0d2a72b24d942e4937b001e0f8">entt::locator::value</a></div><div class="ttdeci">static Service &amp; value()</div><div class="ttdoc">Returns a reference to a valid service, if any.</div><div class="ttdef"><b>Definition:</b> <a href="locator_8hpp_source.html#l00053">locator.hpp:53</a></div></div>
<div class="ttc" id="astructentt_1_1locator_html_a8948b6cc1b6f3446a26391c0025d1777"><div class="ttname"><a href="structentt_1_1locator.html#a8948b6cc1b6f3446a26391c0025d1777">entt::locator::value_or</a></div><div class="ttdeci">static Service &amp; value_or(Args &amp;&amp;...args)</div><div class="ttdoc">Returns a service if available or sets it from a fallback type.</div><div class="ttdef"><b>Definition:</b> <a href="locator_8hpp_source.html#l00070">locator.hpp:70</a></div></div>
<div class="ttc" id="astructentt_1_1locator_html_a8beabd097ab7cb7edc9194b109bc25a2"><div class="ttname"><a href="structentt_1_1locator.html#a8beabd097ab7cb7edc9194b109bc25a2">entt::locator::has_value</a></div><div class="ttdeci">static bool has_value()</div><div class="ttdoc">Checks whether a service locator contains a value.</div><div class="ttdef"><b>Definition:</b> <a href="locator_8hpp_source.html#l00040">locator.hpp:40</a></div></div>
<div class="ttc" id="astructentt_1_1locator_html_a9670f20018968edcf7677aa44ae036bf"><div class="ttname"><a href="structentt_1_1locator.html#a9670f20018968edcf7677aa44ae036bf">entt::locator::allocate_emplace</a></div><div class="ttdeci">static Service &amp; allocate_emplace(Allocator alloc, Args &amp;&amp;...args)</div><div class="ttdoc">Sets or replaces a service using a given allocator.</div><div class="ttdef"><b>Definition:</b> <a href="locator_8hpp_source.html#l00097">locator.hpp:97</a></div></div>
<div class="ttc" id="astructentt_1_1locator_html_a9f224d476bcb081004089f419a1ddde5"><div class="ttname"><a href="structentt_1_1locator.html#a9f224d476bcb081004089f419a1ddde5">entt::locator::~locator</a></div><div class="ttdeci">~locator()=delete</div><div class="ttdoc">Default destructor, deleted on purpose.</div></div>
<div class="ttc" id="astructentt_1_1locator_html_aa1b4b856f4d36f39bbbecfd79cb380ee"><div class="ttname"><a href="structentt_1_1locator.html#aa1b4b856f4d36f39bbbecfd79cb380ee">entt::locator::type</a></div><div class="ttdeci">Service type</div><div class="ttdoc">Service type.</div><div class="ttdef"><b>Definition:</b> <a href="locator_8hpp_source.html#l00029">locator.hpp:29</a></div></div>
<div class="ttc" id="astructentt_1_1locator_html_ab01151d77654a589cc94b302ced3c679"><div class="ttname"><a href="structentt_1_1locator.html#ab01151d77654a589cc94b302ced3c679">entt::locator::emplace</a></div><div class="ttdeci">static Service &amp; emplace(Args &amp;&amp;...args)</div><div class="ttdoc">Sets or replaces a service.</div><div class="ttdef"><b>Definition:</b> <a href="locator_8hpp_source.html#l00082">locator.hpp:82</a></div></div>
<div class="ttc" id="astructentt_1_1locator_html_acf587655946b69f0c483c204a76ca84b"><div class="ttname"><a href="structentt_1_1locator.html#acf587655946b69f0c483c204a76ca84b">entt::locator::reset</a></div><div class="ttdeci">static void reset()</div><div class="ttdoc">Resets a service.</div><div class="ttdef"><b>Definition:</b> <a href="locator_8hpp_source.html#l00103">locator.hpp:103</a></div></div>
<div class="ttc" id="astructentt_1_1locator_html_af0226a1ca179eba7e3b63ee47c1d668c"><div class="ttname"><a href="structentt_1_1locator.html#af0226a1ca179eba7e3b63ee47c1d668c">entt::locator::locator</a></div><div class="ttdeci">locator()=delete</div><div class="ttdoc">Default constructor, deleted on purpose.</div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1
</small></address>
</body>
</html>