File: _2Users_2hauk_2src_2libzdb_2zdb_2zdb_8h-example.html

package info (click to toggle)
libzdb 3.4.0-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 4,524 kB
  • sloc: javascript: 7,158; ansic: 6,331; sh: 3,854; cpp: 580; makefile: 114; xml: 59; lex: 35
file content (173 lines) | stat: -rw-r--r-- 14,369 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>/Users/hauk/src/libzdb/zdb/zdb.h</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="libzdb.css">
</head><body>
<a href="" class="back" onclick="history.back();return false;">⬅</a>
<!-- Generated by Doxygen 1.11.0 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() { codefold.init(0); });
/* @license-end */
</script>
</div><!-- top -->
<div id="doc-content">
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function(){ initResizable(false); });
/* @license-end */
</script>
<div class="header">
  <div class="headertitle"><div class="title">/Users/hauk/src/libzdb/zdb/zdb.h</div></div>
</div><!--header-->
<div class="contents">
<p>Provides a default value if the expression is NULL, 0, or negative.</p>
<p>Provides a default value if the expression is NULL, 0, or negative.The valueOr macro is a convenient way to handle potentially unset or error values returned by libzdb functions. It works with pointers, integers, and floating-point types.</p>
<p>This macro evaluates the expression only once, making it safe to use with function calls or expressions that may have side effects.</p>
<p>For pointers:</p><ul>
<li>Returns the default value if the expression evaluates to NULL.</li>
<li>Otherwise, returns the original pointer value.</li>
</ul>
<p>For integers and floating-point types:</p><ul>
<li>Returns the default value if the expression evaluates to 0 or any negative value.</li>
<li>Otherwise, returns the original numeric value.</li>
</ul>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">expr</td><td>The expression to evaluate (typically a libzdb function call) </td></tr>
    <tr><td class="paramname">default_value</td><td>The value to return if expr is NULL, 0, or negative</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>If expr is not NULL, 0, or negative, returns expr. Otherwise, returns default_value.</dd></dl>
<dl class="section note"><dt>Note</dt><dd>This macro uses a GNU C extension and is compatible with GCC and Clang. It may not work with other C compilers.</dd></dl>
<p>// Usage with string (pointer) return type const char* host = valueOr(URL_getHost(url), "localhost"); printf("Host: %s\n", host);</p>
<p>// Usage with integer return type int port = <a class="el" href="zdb_8h.html#a297ccf9a42e722258e3b51f9dabeab0a">valueOr(ResultSet_getInt(r, 1), 5432)</a>; printf("Port: %d\n", port);</p>
<p>// Usage with floating-point return type double percent = valueOr(ResultSet_getDouble(r, 1), 1.0); printf("Percent: %.1f\n", percent);</p>
<div class="fragment"><div class="line"><span class="comment">/*</span></div>
<div class="line"><span class="comment"> * Copyright (C) Tildeslash Ltd. All rights reserved.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * This program is free software: you can redistribute it and/or modify</span></div>
<div class="line"><span class="comment"> * it under the terms of the GNU General Public License version 3.</span></div>
<div class="line"><span class="comment"> * </span></div>
<div class="line"><span class="comment"> * This program is distributed in the hope that it will be useful,</span></div>
<div class="line"><span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div>
<div class="line"><span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span></div>
<div class="line"><span class="comment"> * GNU General Public License for more details.</span></div>
<div class="line"><span class="comment"> * </span></div>
<div class="line"><span class="comment"> * You should have received a copy of the GNU General Public License</span></div>
<div class="line"><span class="comment"> * along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * In addition, as a special exception, the copyright holders give</span></div>
<div class="line"><span class="comment"> * permission to link the code of portions of this program with the</span></div>
<div class="line"><span class="comment"> * OpenSSL library under certain conditions as described in each</span></div>
<div class="line"><span class="comment"> * individual source file, and distribute linked combinations</span></div>
<div class="line"><span class="comment"> * including the two.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * You must obey the GNU General Public License in all respects</span></div>
<div class="line"><span class="comment"> * for all of the code used other than OpenSSL.</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#ifndef ZDB_INCLUDED</span></div>
<div class="line"><span class="preprocessor">#define ZDB_INCLUDED</span></div>
<div class="line"><span class="preprocessor">#ifdef __cplusplus</span></div>
<div class="line"><span class="keyword">extern</span> <span class="stringliteral">&quot;C&quot;</span> {</div>
<div class="line"><span class="preprocessor">#endif</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include &lt;stdbool.h&gt;</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">/**</span></div>
<div class="line"><span class="comment"> * Include this interface in your C code to import the libzdb API.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * @file</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"> </div>
<div class="line"><span class="comment">/* --------------------------------------------------------------- Version */</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#define LIBZDB_MAJOR    3</span></div>
<div class="line"><span class="preprocessor">#define LIBZDB_MINOR    4</span></div>
<div class="line"><span class="preprocessor">#define LIBZDB_REVISION 0</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#define LIBZDB_VERSION  &quot;3.4.0&quot;</span></div>
<div class="line"><span class="preprocessor">#define LIBZDB_VERSION_NUMBER ((LIBZDB_MAJOR * 1000000) + (LIBZDB_MINOR * 1000) + LIBZDB_REVISION)</span></div>
<div class="line"> </div>
<div class="line"><span class="comment">/* ------------------------------------------------- libzdb API interfaces */</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="SQLException_8h.html">SQLException.h</a>&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="URL_8h.html">URL.h</a>&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="ResultSet_8h.html">ResultSet.h</a>&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="PreparedStatement_8h.html">PreparedStatement.h</a>&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="Connection_8h.html">Connection.h</a>&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="ConnectionPool_8h.html">ConnectionPool.h</a>&gt;</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#ifdef __cplusplus</span></div>
<div class="line">}</div>
<div class="line"><span class="preprocessor">#endif</span></div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#ifndef __cplusplus</span></div>
<div class="line"><span class="comment">/* --------------------------------------------------------- Utility Macro */</span></div>
<div class="line"> </div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">/**</span></div>
<div class="line"><span class="comment"> * @brief Provides a default value if the expression is NULL, 0, or negative.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * The valueOr macro is a convenient way to handle potentially unset or error</span></div>
<div class="line"><span class="comment"> * values returned by libzdb functions. It works with pointers, integers, and</span></div>
<div class="line"><span class="comment"> * floating-point types.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * This macro evaluates the expression only once, making it safe to use with</span></div>
<div class="line"><span class="comment"> * function calls or expressions that may have side effects.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * For pointers:</span></div>
<div class="line"><span class="comment"> *   - Returns the default value if the expression evaluates to NULL.</span></div>
<div class="line"><span class="comment"> *   - Otherwise, returns the original pointer value.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * For integers and floating-point types:</span></div>
<div class="line"><span class="comment"> *   - Returns the default value if the expression evaluates to 0 or any negative value.</span></div>
<div class="line"><span class="comment"> *   - Otherwise, returns the original numeric value.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * @param expr The expression to evaluate (typically a libzdb function call)</span></div>
<div class="line"><span class="comment"> * @param default_value The value to return if expr is NULL, 0, or negative</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * @return If expr is not NULL, 0, or negative, returns expr.</span></div>
<div class="line"><span class="comment"> *         Otherwise, returns default_value.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * @note This macro uses a GNU C extension and is compatible with GCC and Clang.</span></div>
<div class="line"><span class="comment"> *       It may not work with other C compilers.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * @example</span></div>
<div class="line"><span class="comment"> * // Usage with string (pointer) return type</span></div>
<div class="line"><span class="comment"> * const char* host = valueOr(URL_getHost(url), &quot;localhost&quot;);</span></div>
<div class="line"><span class="comment"> * printf(&quot;Host: %s\n&quot;, host);</span></div>
<div class="line"><span class="comment"> * </span></div>
<div class="line"><span class="comment"> * // Usage with integer return type</span></div>
<div class="line"><span class="comment"> * int port = valueOr(ResultSet_getInt(r, 1), 5432);</span></div>
<div class="line"><span class="comment"> * printf(&quot;Port: %d\n&quot;, port);</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * // Usage with floating-point return type</span></div>
<div class="line"><span class="comment"> * double percent = valueOr(ResultSet_getDouble(r, 1), 1.0);</span></div>
<div class="line"><span class="comment"> * printf(&quot;Percent: %.1f\n&quot;, percent);</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"><span class="preprocessor">#define valueOr(expr, default_value) \</span></div>
<div class="line"><span class="preprocessor">    ({ \</span></div>
<div class="line"><span class="preprocessor">        __typeof__(expr) _t = (expr); \</span></div>
<div class="line"><span class="preprocessor">        (_t &lt; 0 || _t == 0) ? (default_value) : _t; \</span></div>
<div class="line"><span class="preprocessor">    })</span></div>
<div class="line">    </div>
<div class="line"><span class="preprocessor">#endif </span><span class="comment">/* not __cplusplus */</span><span class="preprocessor"></span></div>
<div class="line"><span class="preprocessor">#endif</span></div>
<div class="ttc" id="aConnectionPool_8h_html"><div class="ttname"><a href="ConnectionPool_8h.html">ConnectionPool.h</a></div><div class="ttdoc">A ConnectionPool represents a database connection pool.</div></div>
<div class="ttc" id="aConnection_8h_html"><div class="ttname"><a href="Connection_8h.html">Connection.h</a></div><div class="ttdoc">A Connection represents a connection to a SQL database system.</div></div>
<div class="ttc" id="aPreparedStatement_8h_html"><div class="ttname"><a href="PreparedStatement_8h.html">PreparedStatement.h</a></div><div class="ttdoc">A PreparedStatement represents a single SQL statement pre-compiled into byte code for later execution...</div></div>
<div class="ttc" id="aResultSet_8h_html"><div class="ttname"><a href="ResultSet_8h.html">ResultSet.h</a></div><div class="ttdoc">A ResultSet represents a database result set.</div></div>
<div class="ttc" id="aSQLException_8h_html"><div class="ttname"><a href="SQLException_8h.html">SQLException.h</a></div><div class="ttdoc">Signals that an SQL specific exception has occurred.</div></div>
<div class="ttc" id="aURL_8h_html"><div class="ttname"><a href="URL_8h.html">URL.h</a></div><div class="ttdoc">URL represents an immutable Uniform Resource Locator.</div></div>
</div><!-- fragment --> </div><!-- contents -->
<p style="text-align:center;color:#808080;font-size:90%;margin:40px 0 20px 0;">
Copyright &copy; <a href="https://tildeslash.com/">Tildeslash Ltd</a>. All
rights reserved.</p>
</body></html>