blob: 0a7ec1952c77a1efcff48634a04f9853176dac6c (
plain) (
tree)
|
|
<!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> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> </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 <map></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> <<span class="keyword">class</span> Key, <span class="keyword">class</span> T, <span class="keyword">class</span> Compare>
00011 <span class="keyword">class </span>multimapwithdefault : <span class="keyword">public</span> std::multimap<Key, T, Compare> {
00012 <span class="keyword">public</span>:
00013 <span class="keyword">typedef</span> std::pair<const Key, T> value_type;
00014 T& getWithDefault(<span class="keyword">const</span> Key& k, <span class="keyword">const</span> T& 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& operator[](<span class="keyword">const</span> Key& 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& k, <span class="keyword">const</span> T &val)<span class="keyword"> const </span>{
00028 <span class="keyword">typename</span> std::multimap<Key, T, Compare>::const_iterator start = lower_bound(k);
00029 <span class="keyword">typename</span> std::multimap<Key, T, Compare>::const_iterator end = upper_bound(k);
00030 <span class="keywordflow">for</span> (; start!=end; start++) {
00031 <span class="keywordflow">if</span> (start->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>
|