blob: 179b098d76c8d71c479e959a4f77635cbb6626a0 (
plain) (
tree)
|
|
<!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>winapi_common: include/winapi/handle.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">winapi_common
</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&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&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_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="dir_f1714771db42b7b5a0cd2ebe6e9736ed.html">winapi</a></li> </ul>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">handle.hpp</div> </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> <span class="comment">// Copyright (c) 2020 Egor Tensin <Egor.Tensin@gmail.com></span></div>
<div class="line"><a name="l00002"></a><span class="lineno"> 2</span> <span class="comment">// This file is part of the "winapi-common" project.</span></div>
<div class="line"><a name="l00003"></a><span class="lineno"> 3</span> <span class="comment">// For details, see https://github.com/egor-tensin/winapi-common.</span></div>
<div class="line"><a name="l00004"></a><span class="lineno"> 4</span> <span class="comment">// Distributed under the MIT License.</span></div>
<div class="line"><a name="l00005"></a><span class="lineno"> 5</span>  </div>
<div class="line"><a name="l00006"></a><span class="lineno"> 6</span> <span class="preprocessor">#pragma once</span></div>
<div class="line"><a name="l00007"></a><span class="lineno"> 7</span>  </div>
<div class="line"><a name="l00008"></a><span class="lineno"> 8</span> <span class="preprocessor">#include "buffer.hpp"</span></div>
<div class="line"><a name="l00009"></a><span class="lineno"> 9</span>  </div>
<div class="line"><a name="l00010"></a><span class="lineno"> 10</span> <span class="preprocessor">#include <windows.h></span></div>
<div class="line"><a name="l00011"></a><span class="lineno"> 11</span>  </div>
<div class="line"><a name="l00012"></a><span class="lineno"> 12</span> <span class="preprocessor">#include <cstddef></span></div>
<div class="line"><a name="l00013"></a><span class="lineno"> 13</span> <span class="preprocessor">#include <memory></span></div>
<div class="line"><a name="l00014"></a><span class="lineno"> 14</span> <span class="preprocessor">#include <string></span></div>
<div class="line"><a name="l00015"></a><span class="lineno"> 15</span> <span class="preprocessor">#include <utility></span></div>
<div class="line"><a name="l00016"></a><span class="lineno"> 16</span>  </div>
<div class="line"><a name="l00017"></a><span class="lineno"> 17</span> <span class="keyword">namespace </span>winapi {</div>
<div class="line"><a name="l00018"></a><span class="lineno"> 18</span>  </div>
<div class="line"><a name="l00025"></a><span class="lineno"><a class="line" href="classwinapi_1_1Handle.html"> 25</a></span> <span class="keyword">class </span><a class="code" href="classwinapi_1_1Handle.html">Handle</a> {</div>
<div class="line"><a name="l00026"></a><span class="lineno"> 26</span> <span class="keyword">public</span>:</div>
<div class="line"><a name="l00027"></a><span class="lineno"> 27</span>  <a class="code" href="classwinapi_1_1Handle.html">Handle</a>() = <span class="keywordflow">default</span>;</div>
<div class="line"><a name="l00028"></a><span class="lineno"> 28</span>  <span class="keyword">explicit</span> <a class="code" href="classwinapi_1_1Handle.html">Handle</a>(HANDLE);</div>
<div class="line"><a name="l00029"></a><span class="lineno"> 29</span>  </div>
<div class="line"><a name="l00030"></a><span class="lineno"> 30</span>  HANDLE get()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> m_impl.get(); }</div>
<div class="line"><a name="l00031"></a><span class="lineno"> 31</span>  HANDLE ptr()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> get(); }</div>
<div class="line"><a name="l00032"></a><span class="lineno"> 32</span>  </div>
<div class="line"><a name="l00033"></a><span class="lineno"> 33</span>  <span class="keyword">explicit</span> <span class="keyword">operator</span> HANDLE()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> ptr(); }</div>
<div class="line"><a name="l00034"></a><span class="lineno"> 34</span>  </div>
<div class="line"><a name="l00035"></a><span class="lineno"> 35</span>  <span class="keywordtype">bool</span> is_valid() <span class="keyword">const</span>;</div>
<div class="line"><a name="l00036"></a><span class="lineno"> 36</span>  <span class="keyword">static</span> <span class="keywordtype">bool</span> is_valid(HANDLE);</div>
<div class="line"><a name="l00037"></a><span class="lineno"> 37</span>  </div>
<div class="line"><a name="l00039"></a><span class="lineno"> 39</span>  <span class="keywordtype">void</span> <a class="code" href="classwinapi_1_1Handle.html#a6f28cc73ae2e3e447251cef0160e3555">close</a>();</div>
<div class="line"><a name="l00040"></a><span class="lineno"> 40</span>  </div>
<div class="line"><a name="l00042"></a><span class="lineno"> 42</span>  <span class="keywordtype">bool</span> <a class="code" href="classwinapi_1_1Handle.html#acc001a0f466d9c92cf7f2ef62896afc5">is_std</a>() <span class="keyword">const</span>;</div>
<div class="line"><a name="l00044"></a><span class="lineno"> 44</span>  <span class="keyword">static</span> <a class="code" href="classwinapi_1_1Handle.html">Handle</a> <a class="code" href="classwinapi_1_1Handle.html#a1817fdf127291cf5f47d6429d8f468cd">std_in</a>();</div>
<div class="line"><a name="l00046"></a><span class="lineno"> 46</span>  <span class="keyword">static</span> <a class="code" href="classwinapi_1_1Handle.html">Handle</a> <a class="code" href="classwinapi_1_1Handle.html#a76e96327afd0b943d996c90289f2883e">std_out</a>();</div>
<div class="line"><a name="l00048"></a><span class="lineno"> 48</span>  <span class="keyword">static</span> <a class="code" href="classwinapi_1_1Handle.html">Handle</a> <a class="code" href="classwinapi_1_1Handle.html#a894d880e1241c9516889a7a63a0c1750">std_err</a>();</div>
<div class="line"><a name="l00049"></a><span class="lineno"> 49</span>  </div>
<div class="line"><a name="l00051"></a><span class="lineno"> 51</span>  <a class="code" href="classwinapi_1_1Buffer.html">Buffer</a> <a class="code" href="classwinapi_1_1Handle.html#ae340b095569654f8b709614f23577f2e">read</a>() <span class="keyword">const</span>;</div>
<div class="line"><a name="l00052"></a><span class="lineno"> 52</span>  </div>
<div class="line"><a name="l00053"></a><span class="lineno"> 53</span>  <span class="keyword">static</span> constexpr std::size_t max_chunk_size = 16 * 1024;</div>
<div class="line"><a name="l00059"></a><span class="lineno"> 59</span>  <span class="keywordtype">bool</span> <a class="code" href="classwinapi_1_1Handle.html#a31c8440493e29cdd9b6fc40ffe8c06f1">read_chunk</a>(<a class="code" href="classwinapi_1_1Buffer.html">Buffer</a>& <a class="code" href="classwinapi_1_1Handle.html#a31c8440493e29cdd9b6fc40ffe8c06f1">read_chunk</a>) <span class="keyword">const</span>;</div>
<div class="line"><a name="l00060"></a><span class="lineno"> 60</span>  </div>
<div class="line"><a name="l00066"></a><span class="lineno"> 66</span>  <span class="keywordtype">void</span> <a class="code" href="classwinapi_1_1Handle.html#afbfe1b7de229eb5656504e05acf9bbcc">write</a>(<span class="keyword">const</span> <span class="keywordtype">void</span>* data, std::size_t nb) <span class="keyword">const</span>;</div>
<div class="line"><a name="l00071"></a><span class="lineno"> 71</span>  <span class="keywordtype">void</span> <a class="code" href="classwinapi_1_1Handle.html#afbfe1b7de229eb5656504e05acf9bbcc">write</a>(<span class="keyword">const</span> <a class="code" href="classwinapi_1_1Buffer.html">Buffer</a>& buffer) <span class="keyword">const</span>;</div>
<div class="line"><a name="l00072"></a><span class="lineno"> 72</span>  </div>
<div class="line"><a name="l00077"></a><span class="lineno"> 77</span>  <span class="keyword">template</span> <<span class="keyword">typename</span> CharT></div>
<div class="line"><a name="l00078"></a><span class="lineno"><a class="line" href="classwinapi_1_1Handle.html#ab78fab4796ef5ec3f9576f19b54cfd04"> 78</a></span>  <span class="keywordtype">void</span> <a class="code" href="classwinapi_1_1Handle.html#ab78fab4796ef5ec3f9576f19b54cfd04">write</a>(<span class="keyword">const</span> std::basic_string<CharT>& src)<span class="keyword"> const </span>{</div>
<div class="line"><a name="l00079"></a><span class="lineno"> 79</span>  <a class="code" href="classwinapi_1_1Handle.html#afbfe1b7de229eb5656504e05acf9bbcc">write</a>(src.c_str(), src.size() * <span class="keyword">sizeof</span>(CharT));</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>  </div>
<div class="line"><a name="l00082"></a><span class="lineno"> 82</span>  <span class="keywordtype">void</span> inherit(<span class="keywordtype">bool</span> yes = <span class="keyword">true</span>) <span class="keyword">const</span>;</div>
<div class="line"><a name="l00083"></a><span class="lineno"> 83</span>  <span class="keywordtype">void</span> dont_inherit()<span class="keyword"> const </span>{ inherit(<span class="keyword">false</span>); }</div>
<div class="line"><a name="l00084"></a><span class="lineno"> 84</span>  </div>
<div class="line"><a name="l00085"></a><span class="lineno"> 85</span> <span class="keyword">private</span>:</div>
<div class="line"><a name="l00086"></a><span class="lineno"> 86</span>  <span class="keyword">struct </span>Close {</div>
<div class="line"><a name="l00087"></a><span class="lineno"> 87</span>  <span class="keywordtype">void</span> operator()(HANDLE) <span class="keyword">const</span>;</div>
<div class="line"><a name="l00088"></a><span class="lineno"> 88</span>  };</div>
<div class="line"><a name="l00089"></a><span class="lineno"> 89</span>  </div>
<div class="line"><a name="l00090"></a><span class="lineno"> 90</span>  std::unique_ptr<void, Close> m_impl;</div>
<div class="line"><a name="l00091"></a><span class="lineno"> 91</span> };</div>
<div class="line"><a name="l00092"></a><span class="lineno"> 92</span>  </div>
<div class="line"><a name="l00093"></a><span class="lineno"> 93</span> } <span class="comment">// namespace winapi</span></div>
<div class="ttc" id="aclasswinapi_1_1Buffer_html"><div class="ttname"><a href="classwinapi_1_1Buffer.html">winapi::Buffer</a></div><div class="ttdoc">Binary data container.</div><div class="ttdef"><b>Definition:</b> <a href="buffer_8hpp_source.html#l00024">buffer.hpp:24</a></div></div>
<div class="ttc" id="aclasswinapi_1_1Handle_html"><div class="ttname"><a href="classwinapi_1_1Handle.html">winapi::Handle</a></div><div class="ttdoc">HANDLE wrapper.</div><div class="ttdef"><b>Definition:</b> <a href="handle_8hpp_source.html#l00025">handle.hpp:25</a></div></div>
<div class="ttc" id="aclasswinapi_1_1Handle_html_a1817fdf127291cf5f47d6429d8f468cd"><div class="ttname"><a href="classwinapi_1_1Handle.html#a1817fdf127291cf5f47d6429d8f468cd">winapi::Handle::std_in</a></div><div class="ttdeci">static Handle std_in()</div><div class="ttdef"><b>Definition:</b> <a href="handle_8cpp_source.html#l00055">handle.cpp:55</a></div></div>
<div class="ttc" id="aclasswinapi_1_1Handle_html_a31c8440493e29cdd9b6fc40ffe8c06f1"><div class="ttname"><a href="classwinapi_1_1Handle.html#a31c8440493e29cdd9b6fc40ffe8c06f1">winapi::Handle::read_chunk</a></div><div class="ttdeci">bool read_chunk(Buffer &read_chunk) const</div><div class="ttdef"><b>Definition:</b> <a href="handle_8cpp_source.html#l00067">handle.cpp:67</a></div></div>
<div class="ttc" id="aclasswinapi_1_1Handle_html_a6f28cc73ae2e3e447251cef0160e3555"><div class="ttname"><a href="classwinapi_1_1Handle.html#a6f28cc73ae2e3e447251cef0160e3555">winapi::Handle::close</a></div><div class="ttdeci">void close()</div><div class="ttdef"><b>Definition:</b> <a href="handle_8cpp_source.html#l00047">handle.cpp:47</a></div></div>
<div class="ttc" id="aclasswinapi_1_1Handle_html_a76e96327afd0b943d996c90289f2883e"><div class="ttname"><a href="classwinapi_1_1Handle.html#a76e96327afd0b943d996c90289f2883e">winapi::Handle::std_out</a></div><div class="ttdeci">static Handle std_out()</div><div class="ttdef"><b>Definition:</b> <a href="handle_8cpp_source.html#l00059">handle.cpp:59</a></div></div>
<div class="ttc" id="aclasswinapi_1_1Handle_html_a894d880e1241c9516889a7a63a0c1750"><div class="ttname"><a href="classwinapi_1_1Handle.html#a894d880e1241c9516889a7a63a0c1750">winapi::Handle::std_err</a></div><div class="ttdeci">static Handle std_err()</div><div class="ttdef"><b>Definition:</b> <a href="handle_8cpp_source.html#l00063">handle.cpp:63</a></div></div>
<div class="ttc" id="aclasswinapi_1_1Handle_html_ab78fab4796ef5ec3f9576f19b54cfd04"><div class="ttname"><a href="classwinapi_1_1Handle.html#ab78fab4796ef5ec3f9576f19b54cfd04">winapi::Handle::write</a></div><div class="ttdeci">void write(const std::basic_string< CharT > &src) const</div><div class="ttdef"><b>Definition:</b> <a href="handle_8hpp_source.html#l00078">handle.hpp:78</a></div></div>
<div class="ttc" id="aclasswinapi_1_1Handle_html_acc001a0f466d9c92cf7f2ef62896afc5"><div class="ttname"><a href="classwinapi_1_1Handle.html#acc001a0f466d9c92cf7f2ef62896afc5">winapi::Handle::is_std</a></div><div class="ttdeci">bool is_std() const</div><div class="ttdef"><b>Definition:</b> <a href="handle_8cpp_source.html#l00051">handle.cpp:51</a></div></div>
<div class="ttc" id="aclasswinapi_1_1Handle_html_ae340b095569654f8b709614f23577f2e"><div class="ttname"><a href="classwinapi_1_1Handle.html#ae340b095569654f8b709614f23577f2e">winapi::Handle::read</a></div><div class="ttdeci">Buffer read() const</div><div class="ttdef"><b>Definition:</b> <a href="handle_8cpp_source.html#l00093">handle.cpp:93</a></div></div>
<div class="ttc" id="aclasswinapi_1_1Handle_html_afbfe1b7de229eb5656504e05acf9bbcc"><div class="ttname"><a href="classwinapi_1_1Handle.html#afbfe1b7de229eb5656504e05acf9bbcc">winapi::Handle::write</a></div><div class="ttdeci">void write(const void *data, std::size_t nb) const</div><div class="ttdef"><b>Definition:</b> <a href="handle_8cpp_source.html#l00109">handle.cpp:109</a></div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
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.1
</small></address>
</body>
</html>
|