blob: cabf50ce55cdff474aed2b64d387533d950c865c [file] [log] [blame]
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Conventions &mdash; Apache Arrow v3.0.0</title>
<link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/theme_overrides.css" type="text/css" />
<!--[if lt IE 9]>
<script src="../_static/js/html5shiv.min.js"></script>
<![endif]-->
<script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/language_data.js"></script>
<script type="text/javascript" src="../_static/js/theme.js"></script>
<link rel="canonical" href="https://arrow.apache.org/docs/cpp/conventions.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="Using Arrow C++ in your own project" href="cmake.html" />
<link rel="prev" title="High-Level Overview" href="overview.html" />
<!-- Matomo -->
<script>
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(["setDoNotTrack", true]);
_paq.push(["disableCookies"]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="https://analytics.apache.org/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '20']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Matomo Code -->
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../index.html" class="icon icon-home"> Apache Arrow
</a>
<div class="version">
3.0.0
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<p class="caption"><span class="caption-text">Specifications and Protocols</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../format/Versioning.html">Format Versioning and Stability</a></li>
<li class="toctree-l1"><a class="reference internal" href="../format/Columnar.html">Arrow Columnar Format</a></li>
<li class="toctree-l1"><a class="reference internal" href="../format/Flight.html">Arrow Flight RPC</a></li>
<li class="toctree-l1"><a class="reference internal" href="../format/Integration.html">Integration Testing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../format/CDataInterface.html">The Arrow C data interface</a></li>
<li class="toctree-l1"><a class="reference internal" href="../format/CStreamInterface.html">The Arrow C stream interface</a></li>
<li class="toctree-l1"><a class="reference internal" href="../format/Other.html">Other Data Structures</a></li>
</ul>
<p class="caption"><span class="caption-text">Libraries</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../status.html">Implementation Status</a></li>
<li class="toctree-l1"><a class="reference external" href="https://arrow.apache.org/docs/c_glib/">C/GLib</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="index.html">C++</a><ul class="current">
<li class="toctree-l2 current"><a class="reference internal" href="getting_started.html">User Guide</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="overview.html">High-Level Overview</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">Conventions</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#language-version">Language version</a></li>
<li class="toctree-l4"><a class="reference internal" href="#namespacing">Namespacing</a></li>
<li class="toctree-l4"><a class="reference internal" href="#safe-pointers">Safe pointers</a></li>
<li class="toctree-l4"><a class="reference internal" href="#immutability">Immutability</a></li>
<li class="toctree-l4"><a class="reference internal" href="#error-reporting">Error reporting</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="cmake.html">Using Arrow C++ in your own project</a></li>
<li class="toctree-l3"><a class="reference internal" href="memory.html">Memory Management</a></li>
<li class="toctree-l3"><a class="reference internal" href="arrays.html">Arrays</a></li>
<li class="toctree-l3"><a class="reference internal" href="datatypes.html">Data Types</a></li>
<li class="toctree-l3"><a class="reference internal" href="tables.html">Tabular Data</a></li>
<li class="toctree-l3"><a class="reference internal" href="compute.html">Compute Functions</a></li>
<li class="toctree-l3"><a class="reference internal" href="io.html">Input / output and filesystems</a></li>
<li class="toctree-l3"><a class="reference internal" href="ipc.html">Reading and writing the Arrow IPC format</a></li>
<li class="toctree-l3"><a class="reference internal" href="parquet.html">Reading and writing Parquet files</a></li>
<li class="toctree-l3"><a class="reference internal" href="csv.html">Reading CSV files</a></li>
<li class="toctree-l3"><a class="reference internal" href="json.html">Reading JSON files</a></li>
<li class="toctree-l3"><a class="reference internal" href="flight.html">Arrow Flight RPC</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="examples/index.html">Examples</a></li>
<li class="toctree-l2"><a class="reference internal" href="api.html">API Reference</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference external" href="https://github.com/apache/arrow/blob/master/csharp/README.md">C#</a></li>
<li class="toctree-l1"><a class="reference external" href="https://godoc.org/github.com/apache/arrow/go/arrow">Go</a></li>
<li class="toctree-l1"><a class="reference internal" href="../java/index.html">Java</a></li>
<li class="toctree-l1"><a class="reference external" href="https://arrow.apache.org/docs/js/">JavaScript</a></li>
<li class="toctree-l1"><a class="reference external" href="https://github.com/apache/arrow/blob/master/julia/Arrow/README.md">Julia</a></li>
<li class="toctree-l1"><a class="reference external" href="https://github.com/apache/arrow/blob/master/matlab/README.md">MATLAB</a></li>
<li class="toctree-l1"><a class="reference internal" href="../python/index.html">Python</a></li>
<li class="toctree-l1"><a class="reference external" href="https://arrow.apache.org/docs/r/">R</a></li>
<li class="toctree-l1"><a class="reference external" href="https://github.com/apache/arrow/blob/master/ruby/README.md">Ruby</a></li>
<li class="toctree-l1"><a class="reference external" href="https://docs.rs/crate/arrow/">Rust</a></li>
</ul>
<p class="caption"><span class="caption-text">Development</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../developers/contributing.html">Contributing to Apache Arrow</a></li>
<li class="toctree-l1"><a class="reference internal" href="../developers/cpp/index.html">C++ Development</a></li>
<li class="toctree-l1"><a class="reference internal" href="../developers/python.html">Python Development</a></li>
<li class="toctree-l1"><a class="reference internal" href="../developers/archery.html">Daily Development using Archery</a></li>
<li class="toctree-l1"><a class="reference internal" href="../developers/crossbow.html">Packaging and Testing with Crossbow</a></li>
<li class="toctree-l1"><a class="reference internal" href="../developers/docker.html">Running Docker Builds</a></li>
<li class="toctree-l1"><a class="reference internal" href="../developers/benchmarks.html">Benchmarks</a></li>
<li class="toctree-l1"><a class="reference internal" href="../developers/documentation.html">Building the Documentation</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../index.html">Apache Arrow</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../index.html" class="icon icon-home"></a> &raquo;</li>
<li><a href="index.html">C++ Implementation</a> &raquo;</li>
<li><a href="getting_started.html">User Guide</a> &raquo;</li>
<li>Conventions</li>
<li class="wy-breadcrumbs-aside">
<a href="../_sources/cpp/conventions.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="conventions">
<h1>Conventions<a class="headerlink" href="#conventions" title="Permalink to this headline"></a></h1>
<p>The Arrow C++ API follows a few simple guidelines. As with many rules,
there may be exceptions.</p>
<div class="section" id="language-version">
<h2>Language version<a class="headerlink" href="#language-version" title="Permalink to this headline"></a></h2>
<p>Arrow is C++11-compatible. A few backports are used for newer functionality,
for example the <code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">std::string_view</span></code> class.</p>
</div>
<div class="section" id="namespacing">
<h2>Namespacing<a class="headerlink" href="#namespacing" title="Permalink to this headline"></a></h2>
<p>All the Arrow API (except macros) is namespaced inside a <code class="docutils literal notranslate"><span class="pre">arrow</span></code> namespace,
and nested namespaces thereof.</p>
</div>
<div class="section" id="safe-pointers">
<h2>Safe pointers<a class="headerlink" href="#safe-pointers" title="Permalink to this headline"></a></h2>
<p>Arrow objects are usually passed and stored using safe pointers – most of
the time <code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">std::shared_ptr</span></code> but sometimes also <code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">std::unique_ptr</span></code>.</p>
</div>
<div class="section" id="immutability">
<h2>Immutability<a class="headerlink" href="#immutability" title="Permalink to this headline"></a></h2>
<p>Many Arrow objects are immutable: once constructed, their logical properties
cannot change anymore. This makes it possible to use them in multi-threaded
scenarios without requiring tedious and error-prone synchronization.</p>
<p>There are obvious exceptions to this, such as IO objects or mutable data buffers.</p>
</div>
<div class="section" id="error-reporting">
<h2>Error reporting<a class="headerlink" href="#error-reporting" title="Permalink to this headline"></a></h2>
<p>Most APIs indicate a successful or erroneous outcome by returning a
<a class="reference internal" href="api/support.html#_CPPv4N5arrow6StatusE" title="arrow::Status"><code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">arrow::Status</span></code></a> instance. Arrow doesn’t throw exceptions of its
own, but third-party exceptions might propagate through, especially
<code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">std::bad_alloc</span></code> (but Arrow doesn’t use the standard allocators for
large data).</p>
<p>When an API can return either an error code or a successful value, it usually
does so by returning the template class
<a class="reference internal" href="api/support.html#_CPPv4I0EN5arrow6ResultE" title="arrow::Result"><code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">arrow::Result</span></code></a>. However,
some APIs (usually deprecated) return <a class="reference internal" href="api/support.html#_CPPv4N5arrow6StatusE" title="arrow::Status"><code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">arrow::Status</span></code></a> and pass the
result value as an out-pointer parameter.</p>
<p>Here is an example of checking the outcome of an operation:</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="k">const</span> <span class="kt">int64_t</span> <span class="n">buffer_size</span> <span class="o">=</span> <span class="mi">4096</span><span class="p">;</span>
<span class="k">auto</span> <span class="n">maybe_buffer</span> <span class="o">=</span> <span class="n">arrow</span><span class="o">::</span><span class="n">AllocateBuffer</span><span class="p">(</span><span class="n">buffer_size</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">buffer</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">maybe_buffer</span><span class="p">.</span><span class="n">ok</span><span class="p">())</span> <span class="p">{</span>
<span class="c1">// ... handle error</span>
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
<span class="n">std</span><span class="o">::</span><span class="n">shared_ptr</span><span class="o">&lt;</span><span class="n">arrow</span><span class="o">::</span><span class="n">Buffer</span><span class="o">&gt;</span> <span class="n">buffer</span> <span class="o">=</span> <span class="o">*</span><span class="n">maybe_buffer</span><span class="p">;</span>
<span class="c1">// ... use allocated buffer</span>
<span class="p">}</span>
</pre></div>
</div>
<p>If the caller function itself returns a <a class="reference internal" href="api/support.html#_CPPv4I0EN5arrow6ResultE" title="arrow::Result"><code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">arrow::Result</span></code></a> or
<a class="reference internal" href="api/support.html#_CPPv4N5arrow6StatusE" title="arrow::Status"><code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">arrow::Status</span></code></a> and wants to propagate any non-successful outcome, two
convenience macros are available:</p>
<ul class="simple">
<li><p><a class="reference internal" href="api/support.html#c.ARROW_RETURN_NOT_OK" title="ARROW_RETURN_NOT_OK"><code class="xref c c-macro docutils literal notranslate"><span class="pre">ARROW_RETURN_NOT_OK</span></code></a> takes a <a class="reference internal" href="api/support.html#_CPPv4N5arrow6StatusE" title="arrow::Status"><code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">arrow::Status</span></code></a> parameter
and returns it if not successful.</p></li>
<li><p><a class="reference internal" href="api/support.html#c.ARROW_ASSIGN_OR_RAISE" title="ARROW_ASSIGN_OR_RAISE"><code class="xref c c-macro docutils literal notranslate"><span class="pre">ARROW_ASSIGN_OR_RAISE</span></code></a> takes a <a class="reference internal" href="api/support.html#_CPPv4I0EN5arrow6ResultE" title="arrow::Result"><code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">arrow::Result</span></code></a> parameter,
assigns its result to a <em>lvalue</em> if successful, or returns the corresponding
<a class="reference internal" href="api/support.html#_CPPv4N5arrow6StatusE" title="arrow::Status"><code class="xref cpp cpp-class docutils literal notranslate"><span class="pre">arrow::Status</span></code></a> on error.</p></li>
</ul>
<p>For example:</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="n">arrow</span><span class="o">::</span><span class="n">Status</span> <span class="n">DoSomething</span><span class="p">()</span> <span class="p">{</span>
<span class="k">const</span> <span class="kt">int64_t</span> <span class="n">buffer_size</span> <span class="o">=</span> <span class="mi">4096</span><span class="p">;</span>
<span class="n">std</span><span class="o">::</span><span class="n">shared_ptr</span><span class="o">&lt;</span><span class="n">arrow</span><span class="o">::</span><span class="n">Buffer</span><span class="o">&gt;</span> <span class="n">buffer</span><span class="p">;</span>
<span class="n">ARROW_ASSIGN_OR_RAISE</span><span class="p">(</span><span class="n">buffer</span><span class="p">,</span> <span class="n">arrow</span><span class="o">::</span><span class="n">AllocateBuffer</span><span class="p">(</span><span class="n">buffer_size</span><span class="p">));</span>
<span class="c1">// ... allocation successful, do something with buffer below</span>
<span class="c1">// return success at the end</span>
<span class="k">return</span> <span class="n">Status</span><span class="o">::</span><span class="n">OK</span><span class="p">();</span>
<span class="p">}</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="api/support.html"><span class="doc">API reference for error reporting</span></a></p>
</div>
</div>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="cmake.html" class="btn btn-neutral float-right" title="Using Arrow C++ in your own project" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
<a href="overview.html" class="btn btn-neutral float-left" title="High-Level Overview" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
&#169; Copyright 2016-2019 Apache Software Foundation.
</p>
</div>
Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
<script type="text/javascript" src="/docs/_static/versionwarning.js"></script></body>
</html>