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  <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&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&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> <span class="comment">/*</span></div><div class="line"><a name="l00002"></a><span class="lineno"> 2</span> <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> <span class="comment"> *</span></div><div class="line"><a name="l00004"></a><span class="lineno"> 4</span> <span class="comment"> * Licensed under the Apache License, Version 2.0 (the "License");</span></div><div class="line"><a name="l00005"></a><span class="lineno"> 5</span> <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> <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> <span class="comment"> *</span></div><div class="line"><a name="l00008"></a><span class="lineno"> 8</span> <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> <span class="comment"> *</span></div><div class="line"><a name="l00010"></a><span class="lineno"> 10</span> <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> <span class="comment"> * distributed under the License is distributed on an "AS IS" BASIS,</span></div><div class="line"><a name="l00012"></a><span class="lineno"> 12</span> <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> <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> <span class="comment"> * limitations under the License.</span></div><div class="line"><a name="l00015"></a><span class="lineno"> 15</span> <span class="comment"> */</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="preprocessor">#ifndef OBOE_RESULT_WITH_VALUE_H</span></div><div class="line"><a name="l00018"></a><span class="lineno"> 18</span> <span class="preprocessor">#define OBOE_RESULT_WITH_VALUE_H</span></div><div class="line"><a name="l00019"></a><span class="lineno"> 19</span> </div><div class="line"><a name="l00020"></a><span class="lineno"> 20</span> <span class="preprocessor">#include "oboe/Definitions.h"</span></div><div class="line"><a name="l00021"></a><span class="lineno"> 21</span> <span class="preprocessor">#include <iostream></span></div><div class="line"><a name="l00022"></a><span class="lineno"> 22</span> <span class="preprocessor">#include <sstream></span></div><div class="line"><a name="l00023"></a><span class="lineno"> 23</span> </div><div class="line"><a name="l00024"></a><span class="lineno"> 24</span> <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> </div><div class="line"><a name="l00046"></a><span class="lineno"> 46</span> <span class="keyword">template</span> <<span class="keyword">typename</span> T></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> <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> <span class="keyword">public</span>:</div><div class="line"><a name="l00049"></a><span class="lineno"> 49</span> </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>  <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>  : mValue{}</div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span>  , 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> </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>  <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>  : 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>  , 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> </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>  <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>  <span class="keywordflow">return</span> mError;</div><div class="line"><a name="l00075"></a><span class="lineno"> 75</span>  }</div><div class="line"><a name="l00076"></a><span class="lineno"> 76</span> </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>  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>  <span class="keywordflow">return</span> mValue;</div><div class="line"><a name="l00083"></a><span class="lineno"> 83</span>  }</div><div class="line"><a name="l00084"></a><span class="lineno"> 84</span> </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>  <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> </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>  <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> </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>  <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>  <span class="keywordflow">return</span> mError;</div><div class="line"><a name="l00112"></a><span class="lineno"> 112</span>  }</div><div class="line"><a name="l00113"></a><span class="lineno"> 113</span> </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>  <span class="keyword">static</span> <a class="code" href="classoboe_1_1_result_with_value.html">ResultWithValue<T></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> </div><div class="line"><a name="l00123"></a><span class="lineno"> 123</span>  <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>  static_assert(std::is_arithmetic<T>::value,</div><div class="line"><a name="l00125"></a><span class="lineno"> 125</span>  <span class="stringliteral">"createBasedOnSign can only be called for numeric types (int or float)"</span>);</div><div class="line"><a name="l00126"></a><span class="lineno"> 126</span> </div><div class="line"><a name="l00127"></a><span class="lineno"> 127</span>  <span class="keywordflow">if</span> (numericResult >= 0){</div><div class="line"><a name="l00128"></a><span class="lineno"> 128</span>  <span class="keywordflow">return</span> <a class="code" href="classoboe_1_1_result_with_value.html">ResultWithValue<T></a>(numericResult);</div><div class="line"><a name="l00129"></a><span class="lineno"> 129</span>  } <span class="keywordflow">else</span> {</div><div class="line"><a name="l00130"></a><span class="lineno"> 130</span>  <span class="keywordflow">return</span> <a class="code" href="classoboe_1_1_result_with_value.html">ResultWithValue<T></a>(static_cast<Result>(numericResult));</div><div class="line"><a name="l00131"></a><span class="lineno"> 131</span>  }</div><div class="line"><a name="l00132"></a><span class="lineno"> 132</span>  }</div><div class="line"><a name="l00133"></a><span class="lineno"> 133</span> </div><div class="line"><a name="l00134"></a><span class="lineno"> 134</span> <span class="keyword">private</span>:</div><div class="line"><a name="l00135"></a><span class="lineno"> 135</span>  <span class="keyword">const</span> T mValue;</div><div class="line"><a name="l00136"></a><span class="lineno"> 136</span>  <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> };</div><div class="line"><a name="l00138"></a><span class="lineno"> 138</span> </div><div class="line"><a name="l00142"></a><span class="lineno"> 142</span> <span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><a name="l00143"></a><span class="lineno"><a class="line" href="namespaceoboe.html#aa403103686222502d1cfc47bafc10aeb"> 143</a></span> std::ostream& <a class="code" href="namespaceoboe.html#aa403103686222502d1cfc47bafc10aeb">operator<<</a>(std::ostream &strm, <span class="keyword">const</span> <a class="code" href="classoboe_1_1_result_with_value.html">ResultWithValue<T></a> &result) {</div><div class="line"><a name="l00144"></a><span class="lineno"> 144</span>  <span class="keywordflow">if</span> (!result) {</div><div class="line"><a name="l00145"></a><span class="lineno"> 145</span>  strm << <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>  } <span class="keywordflow">else</span> {</div><div class="line"><a name="l00147"></a><span class="lineno"> 147</span>  strm << 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>  }</div><div class="line"><a name="l00149"></a><span class="lineno"> 149</span>  <span class="keywordflow">return</span> strm;</div><div class="line"><a name="l00150"></a><span class="lineno"> 150</span> }</div><div class="line"><a name="l00151"></a><span class="lineno"> 151</span> </div><div class="line"><a name="l00152"></a><span class="lineno"> 152</span> } <span class="comment">// namespace oboe</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> </div><div class="line"><a name="l00155"></a><span class="lineno"> 155</span> <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< T > 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<<</a></div><div class="ttdeci">std::ostream & operator<<(std::ostream &strm, const ResultWithValue< T > &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  <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