Sophie

Sophie

distrib > Fedora > 16 > i386 > by-pkgid > 4bc66056a634db26a1f4d0845dc41ca6 > files > 11334

mrpt-doc-0.9.5-0.1.20110925svn2670.fc16.i686.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>map_as_vector.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<div align="left"><a href="http://www.mrpt.org/">Main MRPT website</a> &gt; <b>C++ reference</b> </div>
<div align="right">
<a href="index.html"><img border="0" src="mrpt_logo.png" alt="MRPT logo"></a>
</div>
<!-- Generated by Doxygen 1.7.5 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
          <div class="left">
            <form id="FSearchBox" action="search.php" method="get">
              <img id="MSearchSelect" src="search/mag.png" alt=""/>
              <input type="text" id="MSearchField" name="query" value="Search" size="20" accesskey="S" 
                     onfocus="searchBox.OnSearchFieldFocus(true)" 
                     onblur="searchBox.OnSearchFieldFocus(false)"/>
            </form>
          </div><div class="right"></div>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">map_as_vector.h</div>  </div>
</div>
<div class="contents">
<a href="map__as__vector_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* +---------------------------------------------------------------------------+</span>
<a name="l00002"></a>00002 <span class="comment">   |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |</span>
<a name="l00003"></a>00003 <span class="comment">   |                                                                           |</span>
<a name="l00004"></a>00004 <span class="comment">   |                       http://www.mrpt.org/                                |</span>
<a name="l00005"></a>00005 <span class="comment">   |                                                                           |</span>
<a name="l00006"></a>00006 <span class="comment">   |   Copyright (C) 2005-2011  University of Malaga                           |</span>
<a name="l00007"></a>00007 <span class="comment">   |                                                                           |</span>
<a name="l00008"></a>00008 <span class="comment">   |    This software was written by the Machine Perception and Intelligent    |</span>
<a name="l00009"></a>00009 <span class="comment">   |      Robotics Lab, University of Malaga (Spain).                          |</span>
<a name="l00010"></a>00010 <span class="comment">   |    Contact: Jose-Luis Blanco  &lt;jlblanco@ctima.uma.es&gt;                     |</span>
<a name="l00011"></a>00011 <span class="comment">   |                                                                           |</span>
<a name="l00012"></a>00012 <span class="comment">   |  This file is part of the MRPT project.                                   |</span>
<a name="l00013"></a>00013 <span class="comment">   |                                                                           |</span>
<a name="l00014"></a>00014 <span class="comment">   |     MRPT is free software: you can redistribute it and/or modify          |</span>
<a name="l00015"></a>00015 <span class="comment">   |     it under the terms of the GNU General Public License as published by  |</span>
<a name="l00016"></a>00016 <span class="comment">   |     the Free Software Foundation, either version 3 of the License, or     |</span>
<a name="l00017"></a>00017 <span class="comment">   |     (at your option) any later version.                                   |</span>
<a name="l00018"></a>00018 <span class="comment">   |                                                                           |</span>
<a name="l00019"></a>00019 <span class="comment">   |   MRPT is distributed in the hope that it will be useful,                 |</span>
<a name="l00020"></a>00020 <span class="comment">   |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |</span>
<a name="l00021"></a>00021 <span class="comment">   |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |</span>
<a name="l00022"></a>00022 <span class="comment">   |     GNU General Public License for more details.                          |</span>
<a name="l00023"></a>00023 <span class="comment">   |                                                                           |</span>
<a name="l00024"></a>00024 <span class="comment">   |     You should have received a copy of the GNU General Public License     |</span>
<a name="l00025"></a>00025 <span class="comment">   |     along with MRPT.  If not, see &lt;http://www.gnu.org/licenses/&gt;.         |</span>
<a name="l00026"></a>00026 <span class="comment">   |                                                                           |</span>
<a name="l00027"></a>00027 <span class="comment">   +---------------------------------------------------------------------------+ */</span>
<a name="l00028"></a>00028 <span class="preprocessor">#ifndef  mrpt_map_as_vector_H</span>
<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define  mrpt_map_as_vector_H</span>
<a name="l00030"></a>00030 <span class="preprocessor"></span>
<a name="l00031"></a>00031 <span class="comment">// Note: This file is included from &quot;stl_extensions.h&quot;</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include &lt;<a class="code" href="utils__defs_8h.html">mrpt/utils/utils_defs.h</a>&gt;</span>
<a name="l00033"></a>00033 <span class="preprocessor">#include &lt;map&gt;</span>
<a name="l00034"></a>00034 <span class="preprocessor">#include &lt;vector&gt;</span>
<a name="l00035"></a>00035 
<a name="l00036"></a>00036 <span class="keyword">namespace </span>mrpt
<a name="l00037"></a>00037 {
<a name="l00038"></a>00038         <span class="keyword">namespace </span>utils
<a name="l00039"></a>00039         {<span class="comment"></span>
<a name="l00040"></a>00040 <span class="comment">                /** A STL-like container which looks and behaves (almost exactly) like a std::map&lt;&gt; but is implemented as a linear std::vector&lt;&gt; indexed by KEY.</span>
<a name="l00041"></a>00041 <span class="comment">                  *  Note that KEY must be integer types only (size_t, uint32_t, etc.)</span>
<a name="l00042"></a>00042 <span class="comment">                  *  This implementation is much more efficient than std::map&lt;&gt; when the most common operation is accesing elements</span>
<a name="l00043"></a>00043 <span class="comment">                  *   by KEY with find() or [], and the range of KEY values starts at 0 (or a reasonable low number).</span>
<a name="l00044"></a>00044 <span class="comment">                  *</span>
<a name="l00045"></a>00045 <span class="comment">                  * This container is internally implemented as a linear array (std::vector) of the same fundamental type than the equivalent std::map&lt;K,V&gt;,</span>
<a name="l00046"></a>00046 <span class="comment">                  *  that is, elements are &lt;code&gt; std::pair&lt;K,V&gt; &lt;/code&gt; (note that K is NOT const as in std::map).</span>
<a name="l00047"></a>00047 <span class="comment">                  * I know, I know... this implementation wastes a lot of useless key elements in the pair.first when indices</span>
<a name="l00048"></a>00048 <span class="comment">                  * are already implicit in the std::vector&lt;&gt; order... but I promise I&#39;ll pay a beer to whoever show me an</span>
<a name="l00049"></a>00049 <span class="comment">                  *  *efficient* alternative. If failed, update this comment: COUNTER OF WASTED HOURS WITH THIS: 3h</span>
<a name="l00050"></a>00050 <span class="comment">                  *</span>
<a name="l00051"></a>00051 <span class="comment">                  * Note that there is one &lt;b&gt;fundamental difference&lt;/b&gt; wrt std::map&lt;&gt;: if you start with an empty map_as_vector&lt;&gt; and</span>
<a name="l00052"></a>00052 <span class="comment">                  *   insert one element at the i&#39;th position (with either [] or insert), the elements [0,i-1] will also exist then, but both</span>
<a name="l00053"></a>00053 <span class="comment">                  *   their first &amp; second entries (for the corresponding std::pair) will be &lt;b&gt;undefined&lt;/b&gt;. This was intentional in order to</span>
<a name="l00054"></a>00054 <span class="comment">                  *   gain efficiency (in particular, each std::pair&lt;&gt; doesn&#39;t have a constructor when resizing the underlying std::vector).</span>
<a name="l00055"></a>00055 <span class="comment">                  *</span>
<a name="l00056"></a>00056 <span class="comment">                  * \ingroup stlext_grp</span>
<a name="l00057"></a>00057 <span class="comment">                  */</span>
<a name="l00058"></a>00058                 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> KEY,<span class="keyword">typename</span> VALUE&gt;
<a name="l00059"></a>00059                 <span class="keyword">class </span>map_as_vector
<a name="l00060"></a>00060                 {
<a name="l00061"></a>00061                 <span class="keyword">public</span>:<span class="comment"></span>
<a name="l00062"></a>00062 <span class="comment">                        /** @name Iterators stuff and other types</span>
<a name="l00063"></a>00063 <span class="comment">                            @{ */</span>
<a name="l00064"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a316d42e0ed7359d69f517c2d52155a92">00064</a>                         <span class="keyword">typedef</span> KEY                                     <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a316d42e0ed7359d69f517c2d52155a92">key_type</a>;
<a name="l00065"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#ac5bb0ecc636b3b94568fa65941bb509f">00065</a>                         <span class="keyword">typedef</span> std::pair&lt;KEY,VALUE&gt;                    <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#ac5bb0ecc636b3b94568fa65941bb509f">value_type</a>;
<a name="l00066"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a5b3e426bd3d1d66e0baf56ea29e0b217">00066</a>                         <span class="keyword">typedef</span> <span class="keyword">typename</span> mrpt<a class="code" href="classstd_1_1vector.html" title="STL class.">::aligned_containers&lt;value_type&gt;::vector_t</a>  <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a5b3e426bd3d1d66e0baf56ea29e0b217">vec_t</a>;
<a name="l00067"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a690781f95013fe4de1f6890d359944a8">00067</a>                         <span class="keyword">typedef</span> <span class="keyword">typename</span> <a class="code" href="classstd_1_1vector.html" title="STL class.">vec_t</a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a690781f95013fe4de1f6890d359944a8">::size_type</a>               <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a690781f95013fe4de1f6890d359944a8">size_type</a>;
<a name="l00068"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a2ff2befcd9d77123c0f61ab656fabefa">00068</a>                         <span class="keyword">typedef</span> <span class="keyword">typename</span> <a class="code" href="classstd_1_1vector.html" title="STL class.">vec_t</a><a class="code" href="classstd_1_1vector_1_1iterator.html" title="STL iterator class.">::iterator</a>                <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a2ff2befcd9d77123c0f61ab656fabefa">iterator</a>;
<a name="l00069"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#ae0b4cb8f8591b275fb6509ed17f8f2db">00069</a>                         <span class="keyword">typedef</span> <span class="keyword">typename</span> <a class="code" href="classstd_1_1vector.html" title="STL class.">vec_t</a><a class="code" href="classstd_1_1vector_1_1const__iterator.html" title="STL iterator class.">::const_iterator</a>          <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#ae0b4cb8f8591b275fb6509ed17f8f2db">const_iterator</a>;
<a name="l00070"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a34b0935311f89f2aca6c58c5da363d50">00070</a>                         <span class="keyword">typedef</span> std<a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a34b0935311f89f2aca6c58c5da363d50">::reverse_iterator&lt;iterator&gt;</a>                 <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a34b0935311f89f2aca6c58c5da363d50">reverse_iterator</a>;
<a name="l00071"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a2350c776336475afd217f61652106d6d">00071</a>                         <span class="keyword">typedef</span> std<a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a34b0935311f89f2aca6c58c5da363d50">::reverse_iterator&lt;const_iterator&gt;</a>   <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a2350c776336475afd217f61652106d6d">const_reverse_iterator</a>;
<a name="l00072"></a>00072 
<a name="l00073"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a4f3ed56e533fce88c74c918815b4f3c2">00073</a>                         <span class="keyword">inline</span> <a class="code" href="classstd_1_1vector_1_1iterator.html" title="STL iterator class.">iterator</a>                 <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a4f3ed56e533fce88c74c918815b4f3c2">begin</a>()   { <span class="keywordflow">return</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a58d26c004536321266563dea651adeca" title="The actual container.">m_vec</a>.begin(); }
<a name="l00074"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a0ab161f4f6cd15e2cbbb63afec80eeba">00074</a>                         <span class="keyword">inline</span> <a class="code" href="classstd_1_1vector_1_1iterator.html" title="STL iterator class.">iterator</a>                 <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a0ab161f4f6cd15e2cbbb63afec80eeba">end</a>()     { <span class="keywordflow">return</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a58d26c004536321266563dea651adeca" title="The actual container.">m_vec</a>.end(); }
<a name="l00075"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a38db9c7a818814227ed8be760b5e3a09">00075</a>                         <span class="keyword">inline</span> <a class="code" href="classstd_1_1vector_1_1const__iterator.html" title="STL iterator class.">const_iterator</a>   <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a38db9c7a818814227ed8be760b5e3a09">begin</a>()<span class="keyword"> const   </span>{ <span class="keywordflow">return</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a58d26c004536321266563dea651adeca" title="The actual container.">m_vec</a>.begin(); }
<a name="l00076"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#ab49656feaad74ba51193d9ee1c5beb9b">00076</a>                         <span class="keyword">inline</span> <a class="code" href="classstd_1_1vector_1_1const__iterator.html" title="STL iterator class.">const_iterator</a>   <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#ab49656feaad74ba51193d9ee1c5beb9b">end</a>()<span class="keyword"> const             </span>{ <span class="keywordflow">return</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a58d26c004536321266563dea651adeca" title="The actual container.">m_vec</a>.end(); }
<a name="l00077"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#aada156933a9326d82a2e86ffa02518bf">00077</a>                         <span class="keyword">inline</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a34b0935311f89f2aca6c58c5da363d50">reverse_iterator</a>                 <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#aada156933a9326d82a2e86ffa02518bf">rbegin</a>()                { <span class="keywordflow">return</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a34b0935311f89f2aca6c58c5da363d50">reverse_iterator</a>(<a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a0ab161f4f6cd15e2cbbb63afec80eeba">end</a>()); }
<a name="l00078"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a8e092084f07459f055c9cac6f7265a09">00078</a>                         <span class="keyword">inline</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a2350c776336475afd217f61652106d6d">const_reverse_iterator</a>   <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a8e092084f07459f055c9cac6f7265a09">rbegin</a>()<span class="keyword"> const  </span>{ <span class="keywordflow">return</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a2350c776336475afd217f61652106d6d">const_reverse_iterator</a>(<a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a0ab161f4f6cd15e2cbbb63afec80eeba">end</a>()); }
<a name="l00079"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a1f145c554ac66693aaab9beaebb58b3d">00079</a>                         <span class="keyword">inline</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a34b0935311f89f2aca6c58c5da363d50">reverse_iterator</a>                 <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a1f145c554ac66693aaab9beaebb58b3d">rend</a>()                  { <span class="keywordflow">return</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a34b0935311f89f2aca6c58c5da363d50">reverse_iterator</a>(<a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a4f3ed56e533fce88c74c918815b4f3c2">begin</a>()); }
<a name="l00080"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#ac17782b3d645cb4e3492e370dd5a05c0">00080</a>                         <span class="keyword">inline</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a2350c776336475afd217f61652106d6d">const_reverse_iterator</a>   <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#ac17782b3d645cb4e3492e370dd5a05c0">rend</a>()<span class="keyword"> const    </span>{ <span class="keywordflow">return</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a2350c776336475afd217f61652106d6d">const_reverse_iterator</a>(<a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a4f3ed56e533fce88c74c918815b4f3c2">begin</a>()); }<span class="comment"></span>
<a name="l00081"></a>00081 <span class="comment">                        /** @} */</span>
<a name="l00082"></a>00082                 <span class="keyword">private</span>:
<a name="l00083"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a58d26c004536321266563dea651adeca">00083</a>                         <a class="code" href="classstd_1_1vector.html" title="STL class.">vec_t</a>  <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a58d26c004536321266563dea651adeca" title="The actual container.">m_vec</a>; <span class="comment">//!&lt; The actual container</span>
<a name="l00084"></a>00084 <span class="comment"></span>
<a name="l00085"></a>00085                 <span class="keyword">public</span>:<span class="comment"></span>
<a name="l00086"></a>00086 <span class="comment">                        /** @name Constructors, read/write access and other operations</span>
<a name="l00087"></a>00087 <span class="comment">                            @{ */</span><span class="comment"></span>
<a name="l00088"></a>00088 <span class="comment">                        //!&lt; Default constructor - does nothing */</span>
<a name="l00089"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#ab6a467210aff649804e1497264ff30fe">00089</a> <span class="comment"></span>                        <span class="keyword">inline</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#ab6a467210aff649804e1497264ff30fe" title="&lt; Default constructor - does nothing */">map_as_vector</a>() { }<span class="comment"></span>
<a name="l00090"></a>00090 <span class="comment">                        /** Copy constructor */</span>
<a name="l00091"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#adbf2229e6388a8aa36ca0ba9fe0290b4">00091</a>                         <span class="keyword">inline</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#adbf2229e6388a8aa36ca0ba9fe0290b4" title="Copy constructor.">map_as_vector</a>(<span class="keyword">const</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html">map_as_vector&lt;KEY,VALUE&gt;</a> &amp;o) : <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a58d26c004536321266563dea651adeca" title="The actual container.">m_vec</a>(o.<a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a58d26c004536321266563dea651adeca" title="The actual container.">m_vec</a>) { }
<a name="l00092"></a>00092 
<a name="l00093"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#aaa3501f31664e74f44c7f506ed077083">00093</a>                         <span class="keyword">inline</span> <span class="keywordtype">size_t</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#aaa3501f31664e74f44c7f506ed077083">size</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a58d26c004536321266563dea651adeca" title="The actual container.">m_vec</a>.size(); }
<a name="l00094"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a99b53bfab357f82d857f0a93aaae51f6">00094</a>                         <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a99b53bfab357f82d857f0a93aaae51f6">empty</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a58d26c004536321266563dea651adeca" title="The actual container.">m_vec</a>.empty(); }
<a name="l00095"></a>00095 <span class="comment"></span>
<a name="l00096"></a>00096 <span class="comment">                        /** Count how many entries have a given key value - unlike std::map&lt;K,V&gt;, recall that this class will say an element i&lt;N-1 exists just due to an insertion of element at N */</span>
<a name="l00097"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a71b3a958a5675307def93e2b00d3db82">00097</a>                         <span class="keyword">inline</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a690781f95013fe4de1f6890d359944a8">size_type</a> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a71b3a958a5675307def93e2b00d3db82" title="Count how many entries have a given key value - unlike std::map&lt;K,V&gt;, recall that this class will say...">count</a> ( <span class="keyword">const</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a316d42e0ed7359d69f517c2d52155a92">key_type</a> i )<span class="keyword"> const </span>{ <span class="keywordflow">return</span> (i&lt;<a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a58d26c004536321266563dea651adeca" title="The actual container.">m_vec</a>.size()) ? 1 : 0; }
<a name="l00098"></a>00098 <span class="comment"></span>
<a name="l00099"></a>00099 <span class="comment">                        /** Maximum size due to system limits */</span>
<a name="l00100"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a924c39bcfd1e1197065aaf4df6da1b74">00100</a>                         <span class="keyword">inline</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a690781f95013fe4de1f6890d359944a8">size_type</a> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a924c39bcfd1e1197065aaf4df6da1b74" title="Maximum size due to system limits.">max_size</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a58d26c004536321266563dea651adeca" title="The actual container.">m_vec</a>.max_size(); }
<a name="l00101"></a>00101 <span class="comment"></span>
<a name="l00102"></a>00102 <span class="comment">                        /** Return a read-only reference to the internal vector */</span>
<a name="l00103"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a9ebd7e13ccd22c5b50dd0cb5498ecd8e">00103</a>                         <span class="keyword">inline</span> <span class="keyword">const</span> <a class="code" href="classstd_1_1vector.html" title="STL class.">vec_t</a> &amp;<a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a9ebd7e13ccd22c5b50dd0cb5498ecd8e" title="Return a read-only reference to the internal vector.">getVector</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a58d26c004536321266563dea651adeca" title="The actual container.">m_vec</a>; }
<a name="l00104"></a>00104 <span class="comment"></span>
<a name="l00105"></a>00105 <span class="comment">                        /** Clear the contents of this container */</span>
<a name="l00106"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#aece0b572a71028d1b2673ba5e681ef9e">00106</a>                         <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#aece0b572a71028d1b2673ba5e681ef9e" title="Clear the contents of this container.">clear</a>() { <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a58d26c004536321266563dea651adeca" title="The actual container.">m_vec</a>.clear(); }
<a name="l00107"></a>00107 <span class="comment"></span>
<a name="l00108"></a>00108 <span class="comment">                        /** Efficient swap with another object */</span>
<a name="l00109"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#ae1392420b1be780b30b95ccaab1d1ee4">00109</a>                         <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#ae1392420b1be780b30b95ccaab1d1ee4" title="Efficient swap with another object.">swap</a>(<a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html">map_as_vector&lt;KEY,VALUE&gt;</a>&amp; o) { <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a58d26c004536321266563dea651adeca" title="The actual container.">m_vec</a>.swap(o.<a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a58d26c004536321266563dea651adeca" title="The actual container.">m_vec</a>); }
<a name="l00110"></a>00110 <span class="comment"></span>
<a name="l00111"></a>00111 <span class="comment">                        /** Write/read via [i] operator, that creates all elements up to (and including) the i&#39;th if they didn&#39;t exist already. */</span>
<a name="l00112"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a8d15b24c55d3c09aa576c7ac060445a4">00112</a>                         <span class="keyword">inline</span> VALUE &amp; <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a8d15b24c55d3c09aa576c7ac060445a4" title="Write/read via [i] operator, that creates all elements up to (and including) the i&#39;th if they didn&#39;t ...">operator[]</a>(<span class="keyword">const</span> <span class="keywordtype">size_t</span> i) {
<a name="l00113"></a>00113                                 <span class="keywordflow">if</span> (<a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a58d26c004536321266563dea651adeca" title="The actual container.">m_vec</a>.size()&lt;=i) <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a58d26c004536321266563dea651adeca" title="The actual container.">m_vec</a>.resize(i+1);
<a name="l00114"></a>00114                                 <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a58d26c004536321266563dea651adeca" title="The actual container.">m_vec</a>[i].first=i;
<a name="l00115"></a>00115                                 <span class="keywordflow">return</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a58d26c004536321266563dea651adeca" title="The actual container.">m_vec</a>[i].second;
<a name="l00116"></a>00116                         }
<a name="l00117"></a>00117 <span class="comment"></span>
<a name="l00118"></a>00118 <span class="comment">                        /** Insert pair&lt;key,val&gt;, as in std::map (guess_point is actually ignored in this class) */</span>
<a name="l00119"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a673c4c358eb620138685b240dc834b09">00119</a>                         <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a673c4c358eb620138685b240dc834b09" title="Insert pair&lt;key,val&gt;, as in std::map (guess_point is actually ignored in this class)">insert</a>(<span class="keyword">const</span> <a class="code" href="classstd_1_1vector_1_1iterator.html" title="STL iterator class.">iterator</a> &amp;guess_point, <span class="keyword">const</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#ac5bb0ecc636b3b94568fa65941bb509f">value_type</a> &amp;keyvalpair ) { this-&gt;<a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a8d15b24c55d3c09aa576c7ac060445a4" title="Write/read via [i] operator, that creates all elements up to (and including) the i&#39;th if they didn&#39;t ...">operator[]</a>(keyvalpair.first)=keyvalpair; }<span class="comment"></span>
<a name="l00120"></a>00120 <span class="comment">                        /** Insert pair&lt;key,val&gt;, as in std::map */</span>
<a name="l00121"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a78fc7aaa17eddcfe9c8ce9d3832f8b72">00121</a>                         <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a78fc7aaa17eddcfe9c8ce9d3832f8b72" title="Insert pair&lt;key,val&gt;, as in std::map.">insert</a>(<span class="keyword">const</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#ac5bb0ecc636b3b94568fa65941bb509f">value_type</a> &amp;keyvalpair ) { this-&gt;<a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a8d15b24c55d3c09aa576c7ac060445a4" title="Write/read via [i] operator, that creates all elements up to (and including) the i&#39;th if they didn&#39;t ...">operator[]</a>(keyvalpair.first)=keyvalpair; }
<a name="l00122"></a>00122 <span class="comment"></span>
<a name="l00123"></a>00123 <span class="comment">                        /** Constant-time find, returning an iterator to the &lt;key,val&gt; pair or to end() if not found (that is, if it&#39;s above the maximum index in the vector) */</span>
<a name="l00124"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#ae981536cf1a092bf0839d55c3d78c8e3">00124</a>                         <span class="keyword">inline</span> <a class="code" href="classstd_1_1vector_1_1iterator.html" title="STL iterator class.">iterator</a>       <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#ae981536cf1a092bf0839d55c3d78c8e3" title="Constant-time find, returning an iterator to the &lt;key,val&gt; pair or to end() if not found (that is...">find</a>(<span class="keyword">const</span> <span class="keywordtype">size_t</span> i)       { <span class="keywordflow">if</span> (i&lt;<a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a58d26c004536321266563dea651adeca" title="The actual container.">m_vec</a>.size()) <span class="keywordflow">return</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a58d26c004536321266563dea651adeca" title="The actual container.">m_vec</a>.begin()+i; <span class="keywordflow">else</span> <span class="keywordflow">return</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a58d26c004536321266563dea651adeca" title="The actual container.">m_vec</a>.end(); }<span class="comment"></span>
<a name="l00125"></a>00125 <span class="comment">                        /** Constant-time find, returning an iterator to the &lt;key,val&gt; pair or to end() if not found (that is, if it&#39;s above the maximum index in the vector) */</span>
<a name="l00126"></a><a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a158d4f0dea3f66b3e27333dae0bb8f34">00126</a>                         <span class="keyword">inline</span> <a class="code" href="classstd_1_1vector_1_1const__iterator.html" title="STL iterator class.">const_iterator</a> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a158d4f0dea3f66b3e27333dae0bb8f34" title="Constant-time find, returning an iterator to the &lt;key,val&gt; pair or to end() if not found (that is...">find</a>(<span class="keyword">const</span> <span class="keywordtype">size_t</span> i)<span class="keyword"> const </span>{ <span class="keywordflow">if</span> (i&lt;<a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a58d26c004536321266563dea651adeca" title="The actual container.">m_vec</a>.size()) <span class="keywordflow">return</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a58d26c004536321266563dea651adeca" title="The actual container.">m_vec</a>.begin()+i; <span class="keywordflow">else</span> <span class="keywordflow">return</span> <a class="code" href="classmrpt_1_1utils_1_1map__as__vector.html#a58d26c004536321266563dea651adeca" title="The actual container.">m_vec</a>.end(); }
<a name="l00127"></a>00127 <span class="comment"></span>
<a name="l00128"></a>00128 <span class="comment">                        /** @} */</span>
<a name="l00129"></a>00129 
<a name="l00130"></a>00130 
<a name="l00131"></a>00131                 };  <span class="comment">// end class map_as_vector</span>
<a name="l00132"></a>00132 
<a name="l00133"></a>00133         } <span class="comment">// End of namespace</span>
<a name="l00134"></a>00134 } <span class="comment">// End of namespace</span>
<a name="l00135"></a>00135 <span class="preprocessor">#endif</span>
</pre></div></div>
</div>
<br><hr><br> <table border="0" width="100%"> <tr> <td> Page generated by <a href="http://www.doxygen.org" target="_blank">Doxygen 1.7.5</a> for MRPT 0.9.5 SVN: at Sun Sep 25 17:20:18 UTC 2011</td><td></td> <td width="100"> </td> <td width="150">  </td></tr> </table>  </body></html>