2
0
mirror of https://github.com/boostorg/gil.git synced 2026-01-28 07:12:14 +00:00
Files
gil/develop/doc/html/histogram/extend.html
github-actions[bot] d08b6baeec deploy: cf1e6b11ba
2022-04-09 09:52:50 +00:00

145 lines
8.3 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://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/html; charset=utf-8" />
<title>Extending the class - Boost.GIL documentation</title>
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/style.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '',
COLLAPSE_MODINDEX: false,
FILE_SUFFIX: '.html'
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="../_static/language_data.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="top" title="Boost.GIL documentation" href="../index.html" />
<link rel="up" title="Histogram" href="index.html" />
<link rel="next" title="Limitations" href="limitations.html" />
<link rel="prev" title="Utilities" href="utilities.html" />
</head>
<body>
<div class="header">
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
"header">
<tr>
<td valign="top" width="300">
<h3><a href="../index.html"><img
alt="C++ Boost" src="../_static/gil.png" border="0"></a></h3>
</td>
<td >
<h1 align="center"><a href="../index.html"></a></h1>
</td>
<td>
<div id="searchbox" style="display: none">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Search" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</td>
</tr>
</table>
</div>
<hr/>
<div class="content">
<div class="navbar" style="text-align:right;">
<a class="prev" title="Utilities" href="utilities.html"><img src="../_static/prev.png" alt="prev"/></a>
<a class="up" title="Histogram" href="index.html"><img src="../_static/up.png" alt="up"/></a>
<a class="next" title="Limitations" href="limitations.html"><img src="../_static/next.png" alt="next"/></a>
</div>
<div class="section" id="extending-the-class">
<span id="extend-support"></span><h1>Extending the class</h1>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#user-defined-axes" id="id1">User defined Axes</a></li>
</ul>
</div>
<div class="section" id="user-defined-axes">
<h2><a class="toc-backref" href="#id1">User defined Axes</a></h2>
<p>In case you need a histogram with an axes of an arbitrary type that is not identified by
the C++ Standard Library, you need to provide a overload for the hashing function that is
used in the histogram class.</p>
<p>GILs histogram class uses <code class="docutils literal notranslate"><span class="pre">boost::hash_combine</span></code> in a sub routine to generate a hash from
the key.</p>
<p>So we need to provide an overload of <code class="docutils literal notranslate"><span class="pre">boost::hash_combine</span></code> for the purpose.</p>
<p>For example, lets consider you need a histogram with an axis over class Test.</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="c1">// File : ./test.hpp</span>
<span class="cp">#include</span> <span class="cpf">&lt;cstddef&gt;</span><span class="cp"></span>
<span class="cp">#include</span> <span class="cpf">&lt;functional&gt;</span><span class="cp"></span>
<span class="k">struct</span> <span class="n">Test</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">a</span><span class="p">{</span><span class="mi">0</span><span class="p">};</span>
<span class="n">Test</span><span class="p">()</span> <span class="o">=</span> <span class="k">default</span><span class="p">;</span>
<span class="n">Test</span><span class="p">(</span><span class="kt">int</span> <span class="n">c</span><span class="p">)</span> <span class="o">:</span> <span class="n">a</span><span class="p">(</span><span class="n">c</span><span class="p">)</span> <span class="p">{}</span>
<span class="kt">bool</span> <span class="k">operator</span><span class="o">==</span><span class="p">(</span><span class="n">Test</span> <span class="k">const</span><span class="o">&amp;</span> <span class="n">other</span><span class="p">)</span> <span class="k">const</span>
<span class="p">{</span>
<span class="k">return</span> <span class="p">(</span><span class="n">a</span> <span class="o">==</span> <span class="n">other</span><span class="p">.</span><span class="n">a</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">};</span>
<span class="k">namespace</span> <span class="n">boost</span> <span class="p">{</span>
<span class="n">std</span><span class="o">::</span><span class="kt">size_t</span> <span class="n">hash_value</span><span class="p">(</span><span class="n">Test</span> <span class="k">const</span><span class="o">&amp;</span> <span class="n">t</span><span class="p">)</span>
<span class="p">{</span>
<span class="c1">// Replace with your hashing code</span>
<span class="n">std</span><span class="o">::</span><span class="n">hash</span><span class="o">&lt;</span><span class="kt">int</span><span class="o">&gt;</span> <span class="n">hasher</span><span class="p">;</span>
<span class="k">return</span> <span class="nf">hasher</span><span class="p">(</span><span class="n">t</span><span class="p">.</span><span class="n">a</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<p>Now lets get to the usage example.</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="cp">#include</span> <span class="cpf">&lt;test.hpp&gt;</span><span class="cp"></span>
<span class="cp">#include</span> <span class="cpf">&lt;boost/gil.hpp&gt;</span><span class="cp"></span>
<span class="cp">#include</span> <span class="cpf">&lt;iostream&gt;</span><span class="cp"></span>
<span class="c1">// Mind the order of include i.e. test.hpp before boost/gil.hpp</span>
<span class="k">using</span> <span class="k">namespace</span> <span class="n">boost</span><span class="o">::</span><span class="n">gil</span><span class="p">;</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="n">boost</span><span class="o">::</span><span class="n">gil</span><span class="o">::</span><span class="n">histogram</span><span class="o">&lt;</span><span class="n">Test</span><span class="o">&gt;</span> <span class="n">h</span><span class="p">;</span>
<span class="n">Test</span> <span class="n">t</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
<span class="n">h</span><span class="p">(</span><span class="n">t</span><span class="p">)</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="n">std</span><span class="o">::</span><span class="n">cout</span><span class="o">&lt;&lt;</span><span class="n">h</span><span class="p">(</span><span class="n">t</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
</div>
<div class="navbar" style="text-align:right;">
<a class="prev" title="Utilities" href="utilities.html"><img src="../_static/prev.png" alt="prev"/></a>
<a class="up" title="Histogram" href="index.html"><img src="../_static/up.png" alt="up"/></a>
<a class="next" title="Limitations" href="limitations.html"><img src="../_static/next.png" alt="next"/></a>
</div>
</div>
<div class="footer" role="contentinfo">
Last updated on 2022-04-09 09:04:37.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.8.5.
</div>
</body>
</html>