• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html xmlns="http://www.w3.org/1999/xhtml">
3<head>
4<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
5<meta http-equiv="X-UA-Compatible" content="IE=9"/>
6<meta name="generator" content="Doxygen 1.8.15"/>
7<meta name="viewport" content="width=device-width, initial-scale=1"/>
8<title>Oboe: include/oboe/ResultWithValue.h Source File</title>
9<link href="tabs.css" rel="stylesheet" type="text/css"/>
10<script type="text/javascript" src="jquery.js"></script>
11<script type="text/javascript" src="dynsections.js"></script>
12<link href="search/search.css" rel="stylesheet" type="text/css"/>
13<script type="text/javascript" src="search/searchdata.js"></script>
14<script type="text/javascript" src="search/search.js"></script>
15<link href="doxygen.css" rel="stylesheet" type="text/css" />
16</head>
17<body>
18<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
19<div id="titlearea">
20<table cellspacing="0" cellpadding="0">
21 <tbody>
22 <tr style="height: 56px;">
23  <td id="projectalign" style="padding-left: 0.5em;">
24   <div id="projectname">Oboe
25   &#160;<span id="projectnumber">1.5</span>
26   </div>
27   <div id="projectbrief">A library for creating real-time audio apps on Android</div>
28  </td>
29 </tr>
30 </tbody>
31</table>
32</div>
33<!-- end header part -->
34<!-- Generated by Doxygen 1.8.15 -->
35<script type="text/javascript">
36/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
37var searchBox = new SearchBox("searchBox", "search",false,'Search');
38/* @license-end */
39</script>
40<script type="text/javascript" src="menudata.js"></script>
41<script type="text/javascript" src="menu.js"></script>
42<script type="text/javascript">
43/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
44$(function() {
45  initMenu('',true,false,'search.php','Search');
46  $(document).ready(function() { init_search(); });
47});
48/* @license-end */</script>
49<div id="main-nav"></div>
50<!-- window showing the filter options -->
51<div id="MSearchSelectWindow"
52     onmouseover="return searchBox.OnSearchSelectShow()"
53     onmouseout="return searchBox.OnSearchSelectHide()"
54     onkeydown="return searchBox.OnSearchSelectKey(event)">
55</div>
56
57<!-- iframe showing the search results (closed by default) -->
58<div id="MSearchResultsWindow">
59<iframe src="javascript:void(0)" frameborder="0"
60        name="MSearchResults" id="MSearchResults">
61</iframe>
62</div>
63
64<div id="nav-path" class="navpath">
65  <ul>
66<li class="navelem"><a class="el" href="dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="dir_768f6301d9838e45d679001914ab2803.html">oboe</a></li>  </ul>
67</div>
68</div><!-- top -->
69<div class="header">
70  <div class="headertitle">
71<div class="title">ResultWithValue.h</div>  </div>
72</div><!--header-->
73<div class="contents">
74<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="comment">/*</span></div><div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment"> * Copyright (C) 2018 The Android Open Source Project</span></div><div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment"> *</span></div><div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment"> * Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span></div><div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment"> * you may not use this file except in compliance with the License.</span></div><div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment"> * You may obtain a copy of the License at</span></div><div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="comment"> *</span></div><div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="comment"> *      http://www.apache.org/licenses/LICENSE-2.0</span></div><div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="comment"> *</span></div><div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="comment"> * Unless required by applicable law or agreed to in writing, software</span></div><div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="comment"> * distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span></div><div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="comment"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span></div><div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="comment"> * See the License for the specific language governing permissions and</span></div><div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="comment"> * limitations under the License.</span></div><div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="comment"> */</span></div><div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;</div><div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;<span class="preprocessor">#ifndef OBOE_RESULT_WITH_VALUE_H</span></div><div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="preprocessor">#define OBOE_RESULT_WITH_VALUE_H</span></div><div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;</div><div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;<span class="preprocessor">#include &quot;oboe/Definitions.h&quot;</span></div><div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="preprocessor">#include &lt;iostream&gt;</span></div><div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="preprocessor">#include &lt;sstream&gt;</span></div><div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;</div><div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespaceoboe.html">oboe</a> {</div><div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;</div><div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div><div class="line"><a name="l00047"></a><span class="lineno"><a class="line" href="classoboe_1_1_result_with_value.html">   47</a></span>&#160;<span class="keyword">class </span><a class="code" href="classoboe_1_1_result_with_value.html">ResultWithValue</a> {</div><div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;<span class="keyword">public</span>:</div><div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;</div><div class="line"><a name="l00055"></a><span class="lineno"><a class="line" href="classoboe_1_1_result_with_value.html#aae75caa0d16a9e23a012f77fb50c5927">   55</a></span>&#160;    <a class="code" href="classoboe_1_1_result_with_value.html#aae75caa0d16a9e23a012f77fb50c5927">ResultWithValue</a>(<a class="code" href="namespaceoboe.html#a486512e787b609c80ba4436f23929af1">oboe::Result</a> <a class="code" href="classoboe_1_1_result_with_value.html#adfc76ae6db81535c2e82b856975eed41">error</a>)</div><div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;            : mValue{}</div><div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;            , mError(<a class="code" href="classoboe_1_1_result_with_value.html#adfc76ae6db81535c2e82b856975eed41">error</a>) {}</div><div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;</div><div class="line"><a name="l00064"></a><span class="lineno"><a class="line" href="classoboe_1_1_result_with_value.html#a600309367db58d71f0ec16e90f7ebea5">   64</a></span>&#160;    <span class="keyword">explicit</span> <a class="code" href="classoboe_1_1_result_with_value.html#a600309367db58d71f0ec16e90f7ebea5">ResultWithValue</a>(T <a class="code" href="classoboe_1_1_result_with_value.html#a45f5c99a2c9f8fbaca502276f7ebb434">value</a>)</div><div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;            : mValue(<a class="code" href="classoboe_1_1_result_with_value.html#a45f5c99a2c9f8fbaca502276f7ebb434">value</a>)</div><div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;            , mError(<a class="code" href="namespaceoboe.html">oboe</a>::<a class="code" href="namespaceoboe.html#a486512e787b609c80ba4436f23929af1">Result</a>::OK) {}</div><div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;</div><div class="line"><a name="l00073"></a><span class="lineno"><a class="line" href="classoboe_1_1_result_with_value.html#adfc76ae6db81535c2e82b856975eed41">   73</a></span>&#160;    <a class="code" href="namespaceoboe.html#a486512e787b609c80ba4436f23929af1">oboe::Result</a> <a class="code" href="classoboe_1_1_result_with_value.html#adfc76ae6db81535c2e82b856975eed41">error</a>()<span class="keyword"> const </span>{</div><div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;        <span class="keywordflow">return</span> mError;</div><div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;    }</div><div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;</div><div class="line"><a name="l00081"></a><span class="lineno"><a class="line" href="classoboe_1_1_result_with_value.html#a45f5c99a2c9f8fbaca502276f7ebb434">   81</a></span>&#160;    T <a class="code" href="classoboe_1_1_result_with_value.html#a45f5c99a2c9f8fbaca502276f7ebb434">value</a>()<span class="keyword"> const </span>{</div><div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;        <span class="keywordflow">return</span> mValue;</div><div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;    }</div><div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;</div><div class="line"><a name="l00088"></a><span class="lineno"><a class="line" href="classoboe_1_1_result_with_value.html#ae32b1953b777af7d1d0c94862ca39986">   88</a></span>&#160;    <span class="keyword">explicit</span> <span class="keyword">operator</span> bool()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> mError == oboe::Result::OK; }</div><div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;</div><div class="line"><a name="l00100"></a><span class="lineno"><a class="line" href="classoboe_1_1_result_with_value.html#a6fb3c61c5716a045ba48dc5a5dfc8169">  100</a></span>&#160;    <span class="keywordtype">bool</span> <a class="code" href="classoboe_1_1_result_with_value.html#a6fb3c61c5716a045ba48dc5a5dfc8169">operator !</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> mError != oboe::Result::OK; }</div><div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;</div><div class="line"><a name="l00110"></a><span class="lineno"><a class="line" href="classoboe_1_1_result_with_value.html#af62107817c0bc76047e6b655a78504ba">  110</a></span>&#160;    <span class="keyword">operator</span> <a class="code" href="namespaceoboe.html#a486512e787b609c80ba4436f23929af1">Result</a>()<span class="keyword"> const </span>{</div><div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;        <span class="keywordflow">return</span> mError;</div><div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;    }</div><div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;</div><div class="line"><a name="l00121"></a><span class="lineno"><a class="line" href="classoboe_1_1_result_with_value.html#a2304c6120e2aad8f2189383a98c7b0a7">  121</a></span>&#160;    <span class="keyword">static</span> <a class="code" href="classoboe_1_1_result_with_value.html">ResultWithValue&lt;T&gt;</a> <a class="code" href="classoboe_1_1_result_with_value.html#a2304c6120e2aad8f2189383a98c7b0a7">createBasedOnSign</a>(T numericResult){</div><div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;</div><div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;        <span class="comment">// Ensure that the type is either an integer or float</span></div><div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;        static_assert(std::is_arithmetic&lt;T&gt;::value,</div><div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;                      <span class="stringliteral">&quot;createBasedOnSign can only be called for numeric types (int or float)&quot;</span>);</div><div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;</div><div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;        <span class="keywordflow">if</span> (numericResult &gt;= 0){</div><div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;            <span class="keywordflow">return</span> <a class="code" href="classoboe_1_1_result_with_value.html">ResultWithValue&lt;T&gt;</a>(numericResult);</div><div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;        } <span class="keywordflow">else</span> {</div><div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;            <span class="keywordflow">return</span> <a class="code" href="classoboe_1_1_result_with_value.html">ResultWithValue&lt;T&gt;</a>(static_cast&lt;Result&gt;(numericResult));</div><div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;        }</div><div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;    }</div><div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;</div><div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;<span class="keyword">private</span>:</div><div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;    <span class="keyword">const</span> T             mValue;</div><div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;    <span class="keyword">const</span> <a class="code" href="namespaceoboe.html#a486512e787b609c80ba4436f23929af1">oboe::Result</a>  mError;</div><div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;};</div><div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;</div><div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div><div class="line"><a name="l00143"></a><span class="lineno"><a class="line" href="namespaceoboe.html#aa403103686222502d1cfc47bafc10aeb">  143</a></span>&#160;std::ostream&amp; <a class="code" href="namespaceoboe.html#aa403103686222502d1cfc47bafc10aeb">operator&lt;&lt;</a>(std::ostream &amp;strm, <span class="keyword">const</span> <a class="code" href="classoboe_1_1_result_with_value.html">ResultWithValue&lt;T&gt;</a> &amp;result) {</div><div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;    <span class="keywordflow">if</span> (!result) {</div><div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;        strm &lt;&lt; <a class="code" href="namespaceoboe.html#af65aaea3c5d82eee6906664d61c094b3">convertToText</a>(result.<a class="code" href="classoboe_1_1_result_with_value.html#adfc76ae6db81535c2e82b856975eed41">error</a>());</div><div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;    } <span class="keywordflow">else</span> {</div><div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;        strm &lt;&lt; result.<a class="code" href="classoboe_1_1_result_with_value.html#a45f5c99a2c9f8fbaca502276f7ebb434">value</a>();</div><div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160;    }</div><div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;   <span class="keywordflow">return</span> strm;</div><div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;}</div><div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;</div><div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;} <span class="comment">// namespace oboe</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;</div><div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;<span class="preprocessor">#endif //OBOE_RESULT_WITH_VALUE_H</span></div><div class="ttc" id="classoboe_1_1_result_with_value_html_a45f5c99a2c9f8fbaca502276f7ebb434"><div class="ttname"><a href="classoboe_1_1_result_with_value.html#a45f5c99a2c9f8fbaca502276f7ebb434">oboe::ResultWithValue::value</a></div><div class="ttdeci">T value() const</div><div class="ttdef"><b>Definition:</b> ResultWithValue.h:81</div></div>
75<div class="ttc" id="classoboe_1_1_result_with_value_html_aae75caa0d16a9e23a012f77fb50c5927"><div class="ttname"><a href="classoboe_1_1_result_with_value.html#aae75caa0d16a9e23a012f77fb50c5927">oboe::ResultWithValue::ResultWithValue</a></div><div class="ttdeci">ResultWithValue(oboe::Result error)</div><div class="ttdef"><b>Definition:</b> ResultWithValue.h:55</div></div>
76<div class="ttc" id="classoboe_1_1_result_with_value_html_a2304c6120e2aad8f2189383a98c7b0a7"><div class="ttname"><a href="classoboe_1_1_result_with_value.html#a2304c6120e2aad8f2189383a98c7b0a7">oboe::ResultWithValue::createBasedOnSign</a></div><div class="ttdeci">static ResultWithValue&lt; T &gt; createBasedOnSign(T numericResult)</div><div class="ttdef"><b>Definition:</b> ResultWithValue.h:121</div></div>
77<div class="ttc" id="namespaceoboe_html_aa403103686222502d1cfc47bafc10aeb"><div class="ttname"><a href="namespaceoboe.html#aa403103686222502d1cfc47bafc10aeb">oboe::operator&lt;&lt;</a></div><div class="ttdeci">std::ostream &amp; operator&lt;&lt;(std::ostream &amp;strm, const ResultWithValue&lt; T &gt; &amp;result)</div><div class="ttdef"><b>Definition:</b> ResultWithValue.h:143</div></div>
78<div class="ttc" id="namespaceoboe_html_af65aaea3c5d82eee6906664d61c094b3"><div class="ttname"><a href="namespaceoboe.html#af65aaea3c5d82eee6906664d61c094b3">oboe::convertToText</a></div><div class="ttdeci">const char * convertToText(FromType input)</div></div>
79<div class="ttc" id="classoboe_1_1_result_with_value_html_adfc76ae6db81535c2e82b856975eed41"><div class="ttname"><a href="classoboe_1_1_result_with_value.html#adfc76ae6db81535c2e82b856975eed41">oboe::ResultWithValue::error</a></div><div class="ttdeci">oboe::Result error() const</div><div class="ttdef"><b>Definition:</b> ResultWithValue.h:73</div></div>
80<div class="ttc" id="classoboe_1_1_result_with_value_html_a6fb3c61c5716a045ba48dc5a5dfc8169"><div class="ttname"><a href="classoboe_1_1_result_with_value.html#a6fb3c61c5716a045ba48dc5a5dfc8169">oboe::ResultWithValue::operator !</a></div><div class="ttdeci">bool operator !() const</div><div class="ttdef"><b>Definition:</b> ResultWithValue.h:100</div></div>
81<div class="ttc" id="namespaceoboe_html_a486512e787b609c80ba4436f23929af1"><div class="ttname"><a href="namespaceoboe.html#a486512e787b609c80ba4436f23929af1">oboe::Result</a></div><div class="ttdeci">Result</div><div class="ttdef"><b>Definition:</b> Definitions.h:131</div></div>
82<div class="ttc" id="classoboe_1_1_result_with_value_html_a600309367db58d71f0ec16e90f7ebea5"><div class="ttname"><a href="classoboe_1_1_result_with_value.html#a600309367db58d71f0ec16e90f7ebea5">oboe::ResultWithValue::ResultWithValue</a></div><div class="ttdeci">ResultWithValue(T value)</div><div class="ttdef"><b>Definition:</b> ResultWithValue.h:64</div></div>
83<div class="ttc" id="namespaceoboe_html"><div class="ttname"><a href="namespaceoboe.html">oboe</a></div><div class="ttdef"><b>Definition:</b> AudioStream.h:31</div></div>
84<div class="ttc" id="classoboe_1_1_result_with_value_html"><div class="ttname"><a href="classoboe_1_1_result_with_value.html">oboe::ResultWithValue</a></div><div class="ttdef"><b>Definition:</b> ResultWithValue.h:47</div></div>
85</div><!-- fragment --></div><!-- contents -->
86<!-- start footer part -->
87<hr class="footer"/><address class="footer"><small>
88Generated by &#160;<a href="http://www.doxygen.org/index.html">
89<img class="footer" src="doxygen.png" alt="doxygen"/>
90</a> 1.8.15
91</small></address>
92</body>
93</html>
94