aboutsummaryrefslogblamecommitdiffstats
path: root/doc/api-documentation/html/multimapwdef_8h-source.html
blob: 0a7ec1952c77a1efcff48634a04f9853176dac6c (plain) (tree)
1
2
3
4
5
6
7




                                                                                   
                                    
        




                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
      
                           
      








                                                                                                                                                                            
                       
                                                                                  
               




















                                                                                                                                                                                          

                                                             
                                                 

       
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>multimapwdef.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.2.17 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="namespacemembers.html">Namespace Members</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; </center>
<hr><h1>multimapwdef.h</h1><div class="fragment"><pre>00001 <span class="preprocessor">#ifndef MULTIMAPWDEF</span>
00002 <span class="preprocessor"></span><span class="preprocessor">#define MULTIMAPWDEF</span>
00003 <span class="preprocessor"></span>
00004 <span class="preprocessor">#include &lt;map&gt;</span>
00005 
00006 SWORD_NAMESPACE_START
00007 
00008 <span class="comment">// multmap that still lets you use [] to reference FIRST</span>
00009 <span class="comment">// entry of a key if multiples exist</span>
00010 <span class="keyword">template</span> &lt;<span class="keyword">class</span> Key, <span class="keyword">class</span> T, <span class="keyword">class</span> Compare&gt;
00011 <span class="keyword">class </span>multimapwithdefault : <span class="keyword">public</span> std::multimap&lt;Key, T, Compare&gt; {
00012 <span class="keyword">public</span>:
00013         <span class="keyword">typedef</span> std::pair&lt;const Key, T&gt; value_type;
00014         T&amp; getWithDefault(<span class="keyword">const</span> Key&amp; k, <span class="keyword">const</span> T&amp; defaultValue) {
00015                 <span class="keywordflow">if</span> (find(k) == end()) {
00016                         insert(value_type(k, defaultValue));
00017                 }
00018                 <span class="keywordflow">return</span> (*(find(k))).second;
00019         }
00020 
00021         T&amp; operator[](<span class="keyword">const</span> Key&amp; k) {
00022                 <span class="keywordflow">if</span> (find(k) == end()) {
00023                         insert(value_type(k, T()));
00024                 }
00025                 <span class="keywordflow">return</span> (*(find(k))).second;
00026         }
00027         <span class="keywordtype">bool</span> has(<span class="keyword">const</span> Key&amp; k, <span class="keyword">const</span> T &amp;val)<span class="keyword"> const </span>{
00028                 <span class="keyword">typename</span> std::multimap&lt;Key, T, Compare&gt;::const_iterator start = lower_bound(k);
00029                 <span class="keyword">typename</span> std::multimap&lt;Key, T, Compare&gt;::const_iterator end = upper_bound(k);
00030                 <span class="keywordflow">for</span> (; start!=end; start++) {
00031                         <span class="keywordflow">if</span> (start-&gt;second == val)
00032                                 <span class="keywordflow">return</span> <span class="keyword">true</span>;
00033                 }
00034                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00035         }
00036 };
00037 
00038 SWORD_NAMESPACE_END
00039 <span class="preprocessor">#endif</span>
</pre></div><hr><address style="align: right;"><small>Generated on Thu Oct 31 12:11:28 2002 for The Sword Project by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0 
width=110 height=53></a>1.2.17 </small></address>
</body>
</html>