Sophie

Sophie

distrib > Mandriva > current > i586 > media > main-updates > by-pkgid > 8e6051afcdb111a0317a58fb64c2abf5 > files > 4541

qt4-doc-4.6.3-0.2mdv2010.2.i586.rpm

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- qhash.cpp -->
<head>
  <title>Qt 4.6: QMultiHash Class Reference</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<a name="//apple_ref/cpp/cl//QMultiHash"></a>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://qt.nokia.com/"><img src="images/qt-logo.png" align="left" border="0" /></a></td>
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">All&nbsp;Functions</font></a>&nbsp;&middot; <a href="overviews.html"><font color="#004faf">Overviews</font></a></td></tr></table><h1 class="title">QMultiHash Class Reference<br /><span class="small-subtitle">[<a href="qtcore.html">QtCore</a> module]</span>
</h1>
<p>The QMultiHash class is a convenience <a href="qhash.html">QHash</a> subclass that provides multi-valued hashes. <a href="#details">More...</a></p>
<pre> #include &lt;QMultiHash&gt;</pre><p>Inherits <a href="qhash.html">QHash&lt;Key, T&gt;</a>.</p>
<p><b>Note:</b> All functions in this class are <a href="threads-reentrancy.html#reentrant">reentrant</a>.</p>
<ul>
<li><a href="qmultihash-members.html">List of all members, including inherited members</a></li>
</ul>
<hr />
<a name="public-functions"></a>
<h2>Public Functions</h2>
<table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td class="memItemLeft" align="right" valign="top"></td><td class="memItemRight" valign="bottom"><b><a href="qmultihash.html#QMultiHash">QMultiHash</a></b> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top"></td><td class="memItemRight" valign="bottom"><b><a href="qmultihash.html#QMultiHash-2">QMultiHash</a></b> ( const QHash&lt;Key, T&gt; &amp; <i>other</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">QHash&lt;Key, T&gt;::const_iterator </td><td class="memItemRight" valign="bottom"><b><a href="qmultihash.html#constFind">constFind</a></b> ( const Key &amp; <i>key</i>, const T &amp; <i>value</i> ) const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">QHash&lt;Key, T&gt;::const_iterator </td><td class="memItemRight" valign="bottom"><b><a href="qmultihash.html#constFind-2">constFind</a></b> ( const Key &amp; <i>key</i> ) const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qmultihash.html#contains">contains</a></b> ( const Key &amp; <i>key</i>, const T &amp; <i>value</i> ) const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qmultihash.html#contains-2">contains</a></b> ( const Key &amp; <i>key</i> ) const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><b><a href="qmultihash.html#count">count</a></b> ( const Key &amp; <i>key</i>, const T &amp; <i>value</i> ) const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><b><a href="qmultihash.html#count-2">count</a></b> ( const Key &amp; <i>key</i> ) const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><b><a href="qmultihash.html#count-3">count</a></b> () const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">QHash&lt;Key, T&gt;::iterator </td><td class="memItemRight" valign="bottom"><b><a href="qmultihash.html#find">find</a></b> ( const Key &amp; <i>key</i>, const T &amp; <i>value</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">QHash&lt;Key, T&gt;::iterator </td><td class="memItemRight" valign="bottom"><b><a href="qmultihash.html#find-2">find</a></b> ( const Key &amp; <i>key</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">QHash&lt;Key, T&gt;::const_iterator </td><td class="memItemRight" valign="bottom"><b><a href="qmultihash.html#find-3">find</a></b> ( const Key &amp; <i>key</i>, const T &amp; <i>value</i> ) const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">QHash&lt;Key, T&gt;::const_iterator </td><td class="memItemRight" valign="bottom"><b><a href="qmultihash.html#find-4">find</a></b> ( const Key &amp; <i>key</i> ) const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">QHash&lt;Key, T&gt;::iterator </td><td class="memItemRight" valign="bottom"><b><a href="qmultihash.html#insert">insert</a></b> ( const Key &amp; <i>key</i>, const T &amp; <i>value</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><b><a href="qmultihash.html#remove">remove</a></b> ( const Key &amp; <i>key</i>, const T &amp; <i>value</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><b><a href="qmultihash.html#remove-2">remove</a></b> ( const Key &amp; <i>key</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">QHash&lt;Key, T&gt;::iterator </td><td class="memItemRight" valign="bottom"><b><a href="qmultihash.html#replace">replace</a></b> ( const Key &amp; <i>key</i>, const T &amp; <i>value</i> )</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">QMultiHash </td><td class="memItemRight" valign="bottom"><b><a href="qmultihash.html#operator-2b">operator+</a></b> ( const QMultiHash &amp; <i>other</i> ) const</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">QMultiHash &amp; </td><td class="memItemRight" valign="bottom"><b><a href="qmultihash.html#operator-2b-eq">operator+=</a></b> ( const QMultiHash &amp; <i>other</i> )</td></tr>
</table>
<ul>
<li><div bar="2" class="fn"></div>39 public functions inherited from <a href="qhash.html#public-functions">QHash</a></li>
</ul>
<a name="details"></a>
<hr />
<h2>Detailed Description</h2>
<p>The QMultiHash class is a convenience <a href="qhash.html">QHash</a> subclass that provides multi-valued hashes.</p>
<p>QMultiHash&lt;Key, T&gt; is one of Qt's generic <a href="containers.html#container-classes">container classes</a>. It inherits <a href="qhash.html">QHash</a> and extends it with a few convenience functions that make it more suitable than <a href="qhash.html">QHash</a> for storing multi-valued hashes. A multi-valued hash is a hash that allows multiple values with the same key; <a href="qhash.html">QHash</a> normally doesn't allow that, unless you call <a href="qhash.html#insertMulti">QHash::insertMulti</a>().</p>
<p>Because QMultiHash inherits <a href="qhash.html">QHash</a>, all of <a href="qhash.html">QHash</a>'s functionality also applies to QMultiHash. For example, you can use <a href="qhash.html#isEmpty">isEmpty</a>() to test whether the hash is empty, and you can traverse a QMultiHash using <a href="qhash.html">QHash</a>'s iterator classes (for example, <a href="qhashiterator.html">QHashIterator</a>). But in addition, it provides an <a href="qmultihash.html#insert">insert</a>() function that corresponds to <a href="qhash.html#insertMulti">QHash::insertMulti</a>(), and a <a href="qmultihash.html#replace">replace</a>() function that corresponds to <a href="qhash.html#insert">QHash::insert</a>(). It also provides convenient operator+() and operator+=().</p>
<p>Example:</p>
<pre> QMultiHash&lt;QString, int&gt; hash1, hash2, hash3;

 hash1.insert(&quot;plenty&quot;, 100);
 hash1.insert(&quot;plenty&quot;, 2000);
<span class="comment"> // hash1.size() == 2</span>

 hash2.insert(&quot;plenty&quot;, 5000);
<span class="comment"> // hash2.size() == 1</span>

 hash3 = hash1 + hash2;
<span class="comment"> // hash3.size() == 3</span></pre>
<p>Unlike <a href="qhash.html">QHash</a>, QMultiHash provides no operator[]. Use <a href="qhash.html#value">value</a>() or <a href="qmultihash.html#replace">replace</a>() if you want to access the most recently inserted item with a certain key.</p>
<p>If you want to retrieve all the values for a single key, you can use values(const Key &amp;key), which returns a <a href="qlist.html">QList</a>&lt;T&gt;:</p>
<pre> QList&lt;int&gt; values = hash.values(&quot;plenty&quot;);
 for (int i = 0; i &lt; values.size(); ++i)
     cout &lt;&lt; values.at(i) &lt;&lt; endl;</pre>
<p>The items that share the same key are available from most recently to least recently inserted.</p>
<p>A more efficient approach is to call <a href="qmultihash.html#find">find</a>() to get the STL-style iterator for the first item with a key and iterate from there:</p>
<pre> QMultiHash&lt;QString, int&gt;::iterator i = hash.find(&quot;plenty&quot;);
 while (i != hash.end() &amp;&amp; i.key() == &quot;plenty&quot;) {
     cout &lt;&lt; i.value() &lt;&lt; endl;
     ++i;
 }</pre>
<p>QMultiHash's key and value data types must be <a href="containers.html#assignable-data-types">assignable data types</a>. You cannot, for example, store a <a href="qwidget.html">QWidget</a> as a value; instead, store a <a href="qwidget.html">QWidget</a> *. In addition, QMultiHash's key type must provide operator==(), and there must also be a global <a href="qhash.html#qHashx">qHash</a>() function that returns a hash value for an argument of the key's type. See the <a href="qhash.html">QHash</a> documentation for details.</p>
<p>See also <a href="qhash.html">QHash</a>, <a href="qhashiterator.html">QHashIterator</a>, <a href="qmutablehashiterator.html">QMutableHashIterator</a>, and <a href="qmultimap.html">QMultiMap</a>.</p>
<hr />
<h2>Member Function Documentation</h2>
<a name="//apple_ref/cpp/instm/QMultiHash/QMultiHash"></a>
<h3 class="fn"><a name="QMultiHash"></a>QMultiHash::QMultiHash ()</h3>
<p>Constructs an empty hash.</p>
<h3 class="fn"><a name="QMultiHash-2"></a>QMultiHash::QMultiHash ( const <a href="qhash.html">QHash</a>&lt;Key, T&gt; &amp; <i>other</i> )</h3>
<p>Constructs a copy of <i>other</i> (which can be a <a href="qhash.html">QHash</a> or a <a href="qmultihash.html">QMultiHash</a>).</p>
<p>See also <a href="qhash.html#operator-eq">operator=</a>().</p>
<a name="//apple_ref/cpp/instm/QMultiHash/constFind"></a>
<h3 class="fn"><a name="constFind"></a><a href="qhash.html">QHash</a>&lt;Key, T&gt;::const_iterator QMultiHash::constFind ( const Key &amp; <i>key</i>, const T &amp; <i>value</i> ) const</h3>
<p>Returns an iterator pointing to the item with the <i>key</i> and the <i>value</i> in the hash.</p>
<p>If the hash contains no such item, the function returns <a href="qhash.html#constEnd">constEnd</a>().</p>
<p>This function was introduced in Qt 4.3.</p>
<p>See also <a href="qhash.html#constFind">QHash::constFind</a>().</p>
<h3 class="fn"><a name="constFind-2"></a><a href="qhash.html">QHash</a>&lt;Key, T&gt;::const_iterator QMultiHash::constFind ( const Key &amp; <i>key</i> ) const</h3>
<p>This is an overloaded function.</p>
<p>See also <a href="qhash.html#constFind">QHash::constFind</a>().</p>
<a name="//apple_ref/cpp/instm/QMultiHash/contains"></a>
<h3 class="fn"><a name="contains"></a>bool QMultiHash::contains ( const Key &amp; <i>key</i>, const T &amp; <i>value</i> ) const</h3>
<p>Returns true if the hash contains an item with the <i>key</i> and <i>value</i>; otherwise returns false.</p>
<p>This function was introduced in Qt 4.3.</p>
<p>See also <a href="qhash.html#contains">QHash::contains</a>().</p>
<h3 class="fn"><a name="contains-2"></a>bool QMultiHash::contains ( const Key &amp; <i>key</i> ) const</h3>
<p>This is an overloaded function.</p>
<p>See also <a href="qhash.html#contains">QHash::contains</a>().</p>
<a name="//apple_ref/cpp/instm/QMultiHash/count"></a>
<h3 class="fn"><a name="count"></a>int QMultiHash::count ( const Key &amp; <i>key</i>, const T &amp; <i>value</i> ) const</h3>
<p>Returns the number of items with the <i>key</i> and <i>value</i>.</p>
<p>This function was introduced in Qt 4.3.</p>
<p>See also <a href="qhash.html#count">QHash::count</a>().</p>
<h3 class="fn"><a name="count-2"></a>int QMultiHash::count ( const Key &amp; <i>key</i> ) const</h3>
<p>This is an overloaded function.</p>
<p>See also <a href="qhash.html#count">QHash::count</a>().</p>
<h3 class="fn"><a name="count-3"></a>int QMultiHash::count () const</h3>
<p>This is an overloaded function.</p>
<p>See also <a href="qhash.html#count">QHash::count</a>().</p>
<a name="//apple_ref/cpp/instm/QMultiHash/find"></a>
<h3 class="fn"><a name="find"></a><a href="qhash.html">QHash</a>&lt;Key, T&gt;::iterator QMultiHash::find ( const Key &amp; <i>key</i>, const T &amp; <i>value</i> )</h3>
<p>Returns an iterator pointing to the item with the <i>key</i> and <i>value</i>. If the hash contains no such item, the function returns <a href="qhash.html#end">end</a>().</p>
<p>If the hash contains multiple items with the <i>key</i> and <i>value</i>, the iterator returned points to the most recently inserted item.</p>
<p>This function was introduced in Qt 4.3.</p>
<p>See also <a href="qhash.html#find">QHash::find</a>().</p>
<h3 class="fn"><a name="find-2"></a><a href="qhash.html">QHash</a>&lt;Key, T&gt;::iterator QMultiHash::find ( const Key &amp; <i>key</i> )</h3>
<p>This is an overloaded function.</p>
<p>See also <a href="qhash.html#find">QHash::find</a>().</p>
<h3 class="fn"><a name="find-3"></a><a href="qhash.html">QHash</a>&lt;Key, T&gt;::const_iterator QMultiHash::find ( const Key &amp; <i>key</i>, const T &amp; <i>value</i> ) const</h3>
<p>This is an overloaded function.</p>
<p>This function was introduced in Qt 4.3.</p>
<h3 class="fn"><a name="find-4"></a><a href="qhash.html">QHash</a>&lt;Key, T&gt;::const_iterator QMultiHash::find ( const Key &amp; <i>key</i> ) const</h3>
<p>This is an overloaded function.</p>
<p>See also <a href="qhash.html#find">QHash::find</a>().</p>
<a name="//apple_ref/cpp/instm/QMultiHash/insert"></a>
<h3 class="fn"><a name="insert"></a><a href="qhash.html">QHash</a>&lt;Key, T&gt;::iterator QMultiHash::insert ( const Key &amp; <i>key</i>, const T &amp; <i>value</i> )</h3>
<p>Inserts a new item with the <i>key</i> and a value of <i>value</i>.</p>
<p>If there is already an item with the same key in the hash, this function will simply create a new one. (This behavior is different from <a href="qmultihash.html#replace">replace</a>(), which overwrites the value of an existing item.)</p>
<p>See also <a href="qmultihash.html#replace">replace</a>().</p>
<a name="//apple_ref/cpp/instm/QMultiHash/remove"></a>
<h3 class="fn"><a name="remove"></a>int QMultiHash::remove ( const Key &amp; <i>key</i>, const T &amp; <i>value</i> )</h3>
<p>Removes all the items that have the <i>key</i> and the value <i>value</i> from the hash. Returns the number of items removed.</p>
<p>This function was introduced in Qt 4.3.</p>
<p>See also <a href="qhash.html#remove">QHash::remove</a>().</p>
<h3 class="fn"><a name="remove-2"></a>int QMultiHash::remove ( const Key &amp; <i>key</i> )</h3>
<p>This is an overloaded function.</p>
<p>See also <a href="qhash.html#remove">QHash::remove</a>().</p>
<a name="//apple_ref/cpp/instm/QMultiHash/replace"></a>
<h3 class="fn"><a name="replace"></a><a href="qhash.html">QHash</a>&lt;Key, T&gt;::iterator QMultiHash::replace ( const Key &amp; <i>key</i>, const T &amp; <i>value</i> )</h3>
<p>Inserts a new item with the <i>key</i> and a value of <i>value</i>.</p>
<p>If there is already an item with the <i>key</i>, that item's value is replaced with <i>value</i>.</p>
<p>If there are multiple items with the <i>key</i>, the most recently inserted item's value is replaced with <i>value</i>.</p>
<p>See also <a href="qmultihash.html#insert">insert</a>().</p>
<a name="//apple_ref/cpp/instm/QMultiHash/operator+"></a>
<h3 class="fn"><a name="operator-2b"></a>QMultiHash QMultiHash::operator+ ( const QMultiHash &amp; <i>other</i> ) const</h3>
<p>Returns a hash that contains all the items in this hash in addition to all the items in <i>other</i>. If a key is common to both hashes, the resulting hash will contain the key multiple times.</p>
<p>See also <a href="qmultihash.html#operator-2b-eq">operator+=</a>().</p>
<a name="//apple_ref/cpp/instm/QMultiHash/operator+="></a>
<h3 class="fn"><a name="operator-2b-eq"></a>QMultiHash &amp; QMultiHash::operator+= ( const QMultiHash &amp; <i>other</i> )</h3>
<p>Inserts all the items in the <i>other</i> hash into this hash and returns a reference to this hash.</p>
<p>See also <a href="qmultihash.html#insert">insert</a>().</p>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="40%" align="left">Copyright &copy; 2010 Nokia Corporation and/or its subsidiary(-ies)</td>
<td width="20%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="40%" align="right"><div align="right">Qt 4.6.3</div></td>
</tr></table></div></address></body>
</html>