aboutsummaryrefslogtreecommitdiffstats
path: root/doc/api-documentation/html/multimapwdef_8h-source.html
blob: e17bed91488ac98d53b4b0cf8a4f20a66b4a0401 (plain) (blame)
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
<!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.15 -->
<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="functions.html">Compound Members</a> &nbsp; </center>
<hr><h1>multimapwdef.h</h1><div class="fragment"><pre>00001 <font class="preprocessor">#ifndef MULTIMAPWDEF</font>
00002 <font class="preprocessor"></font><font class="preprocessor">#define MULTIMAPWDEF</font>
00003 <font class="preprocessor"></font>
00004 <font class="preprocessor">#include &lt;map&gt;</font>
00005 
00006 <font class="keyword">using</font> <font class="keyword">namespace </font>std;
00007 
00008 <font class="comment">// multmap that still lets you use [] to reference FIRST</font>
00009 <font class="comment">// entry of a key if multiples exist</font>
00010 <font class="keyword">template</font> &lt;<font class="keyword">class</font> Key, <font class="keyword">class</font> T, <font class="keyword">class</font> Compare&gt;
00011 <font class="keyword">class </font>multimapwithdefault : <font class="keyword">public</font> multimap&lt;Key, T, Compare&gt; {
00012 <font class="keyword">public</font>:
00013         <font class="keyword">typedef</font> pair&lt;const Key, T&gt; value_type;
00014         T&amp; operator[](<font class="keyword">const</font> Key&amp; k) {
00015                 <font class="keywordflow">if</font> (find(k) == end()) {
00016                         insert(value_type(k, T()));
00017                 }
00018                 <font class="keywordflow">return</font> (*(find(k))).second;
00019         }
00020         <font class="keywordtype">bool</font> has(<font class="keyword">const</font> Key&amp; k, <font class="keyword">const</font> T &amp;val)<font class="keyword"> const </font>{
00021                 <font class="keyword">typename</font> multimap&lt;Key, T, Compare&gt;::const_iterator start = lower_bound(k);
00022                 <font class="keyword">typename</font> multimap&lt;Key, T, Compare&gt;::const_iterator end = upper_bound(k);
00023                 <font class="keywordflow">for</font> (; start!=end; start++) {
00024                         <font class="keywordflow">if</font> (start-&gt;second == val)
00025                                 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00026                 }
00027                 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00028         }
00029 };
00030 
00031 <font class="preprocessor">#endif</font>
</pre></div><hr><address align="right"><small>Generated on Thu Jun 20 22:12:59 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.15 </small></address>
</body>
</html>