Sophie

Sophie

distrib > Fedora > 18 > x86_64 > by-pkgid > ff187cb994c94c614ecc64c5a8528b1b > files > 4934

qt-doc-4.8.5-10.fc18.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qcache.qdoc -->
  <title>Qt 4.8: QCache Class Reference</title>
  <link rel="stylesheet" type="text/css" href="style/style.css" />
  <script src="scripts/jquery.js" type="text/javascript"></script>
  <script src="scripts/functions.js" type="text/javascript"></script>
  <link rel="stylesheet" type="text/css" href="style/superfish.css" />
  <link rel="stylesheet" type="text/css" href="style/narrow.css" />
  <!--[if IE]>
<meta name="MSSmartTagsPreventParsing" content="true">
<meta http-equiv="imagetoolbar" content="no">
<![endif]-->
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" href="style/style_ie6.css">
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="style/style_ie7.css">
<![endif]-->
<!--[if IE 8]>
<link rel="stylesheet" type="text/css" href="style/style_ie8.css">
<![endif]-->

<script src="scripts/superfish.js" type="text/javascript"></script>
<script src="scripts/narrow.js" type="text/javascript"></script>

</head>
<body class="" onload="CheckEmptyAndLoadList();">
 <div class="header" id="qtdocheader">
    <div class="content"> 
    <div id="nav-logo">
      <a href="index.html">Home</a></div>
    <a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
    <div id="narrowsearch"></div>
    <div id="nav-topright">
      <ul>
        <li class="nav-topright-home"><a href="http://qt.digia.com/">Qt HOME</a></li>
        <li class="nav-topright-dev"><a href="http://qt-project.org/">DEV</a></li>
        <li class="nav-topright-doc nav-topright-doc-active"><a href="http://qt-project.org/doc/">
          DOC</a></li>
        <li class="nav-topright-blog"><a href="http://blog.qt.digia.com/">BLOG</a></li>
      </ul>
    </div>
    <div id="shortCut">
      <ul>
        <li class="shortCut-topleft-inactive"><span><a href="index.html">Qt 4.8</a></span></li>
        <li class="shortCut-topleft-active"><a href="http://qt-project.org/doc/">ALL VERSIONS        </a></li>
      </ul>
     </div>
 <ul class="sf-menu" id="narrowmenu"> 
             <li><a href="#">API Lookup</a> 
                 <ul> 
                     <li><a href="classes.html">Class index</a></li> 
           <li><a href="functions.html">Function index</a></li> 
           <li><a href="modules.html">Modules</a></li> 
           <li><a href="namespaces.html">Namespaces</a></li> 
           <li><a href="qtglobal.html">Global Declarations</a></li> 
           <li><a href="qdeclarativeelements.html">QML elements</a></li> 
             </ul> 
             </li> 
             <li><a href="#">Qt Topics</a> 
                 <ul> 
                        <li><a href="qt-basic-concepts.html">Programming with Qt</a></li>  
                        <li><a href="qtquick.html">Device UIs &amp; Qt Quick</a></li>  
                        <li><a href="qt-gui-concepts.html">UI Design with Qt</a></li>  
                        <li><a href="supported-platforms.html">Supported Platforms</a></li>  
                        <li><a href="technology-apis.html">Qt and Key Technologies</a></li>  
                        <li><a href="best-practices.html">How-To's and Best Practices</a></li>  
              </ul> 
                 </li> 
                 <li><a href="#">Examples</a> 
                     <ul> 
                       <li><a href="all-examples.html">Examples</a></li> 
                       <li><a href="tutorials.html">Tutorials</a></li> 
                       <li><a href="demos.html">Demos</a></li> 
                       <li><a href="qdeclarativeexamples.html">QML Examples</a></li> 
                </ul> 
                     </li> 
                 </ul> 
    </div>
  </div>
  <div class="wrapper">
    <div class="hd">
      <span></span>
    </div>
    <div class="bd group">
      <div class="sidebar">
        <div class="searchlabel">
          Search index:</div>
        <div class="search" id="sidebarsearch">
          <form id="qtdocsearch" action="" onsubmit="return false;">
            <fieldset>
              <input type="text" name="searchstring" id="pageType" value="" />
 <div id="resultdialog"> 
 <a href="#" id="resultclose">Close</a> 
 <p id="resultlinks" class="all"><a href="#" id="showallresults">All</a> | <a href="#" id="showapiresults">API</a> | <a href="#" id="showarticleresults">Articles</a> | <a href="#" id="showexampleresults">Examples</a></p> 
 <p id="searchcount" class="all"><span id="resultcount"></span><span id="apicount"></span><span id="articlecount"></span><span id="examplecount"></span>&nbsp;results:</p> 
 <ul id="resultlist" class="all"> 
 </ul> 
 </div> 
            </fieldset>
          </form>
        </div>
        <div class="box first bottombar" id="lookup">
          <h2 title="API Lookup"><span></span>
            API Lookup</h2>
          <div  id="list001" class="list">
          <ul id="ul001" >
              <li class="defaultLink"><a href="classes.html">Class index</a></li>
              <li class="defaultLink"><a href="functions.html">Function index</a></li>
              <li class="defaultLink"><a href="modules.html">Modules</a></li>
              <li class="defaultLink"><a href="namespaces.html">Namespaces</a></li>
              <li class="defaultLink"><a href="qtglobal.html">Global Declarations</a></li>
              <li class="defaultLink"><a href="qdeclarativeelements.html">QML elements</a></li>
            </ul> 
          </div>
        </div>
        <div class="box bottombar" id="topics">
          <h2 title="Qt Topics"><span></span>
            Qt Topics</h2>
          <div id="list002" class="list">
            <ul id="ul002" >
               <li class="defaultLink"><a href="qt-basic-concepts.html">Programming with Qt</a></li> 
               <li class="defaultLink"><a href="qtquick.html">Device UIs &amp; Qt Quick</a></li> 
               <li class="defaultLink"><a href="qt-gui-concepts.html">UI Design with Qt</a></li> 
               <li class="defaultLink"><a href="supported-platforms.html">Supported Platforms</a></li>  
               <li class="defaultLink"><a href="technology-apis.html">Qt and Key Technologies</a></li> 
               <li class="defaultLink"><a href="best-practices.html">How-To's and Best Practices</a></li> 
            </ul>  
          </div>
        </div>
        <div class="box" id="examples">
          <h2 title="Examples"><span></span>
            Examples</h2>
          <div id="list003" class="list">
        <ul id="ul003">
              <li class="defaultLink"><a href="all-examples.html">Examples</a></li>
              <li class="defaultLink"><a href="tutorials.html">Tutorials</a></li>
              <li class="defaultLink"><a href="demos.html">Demos</a></li>
              <li class="defaultLink"><a href="qdeclarativeexamples.html">QML Examples</a></li>
            </ul> 
          </div>
        </div>
      </div>
      <div class="wrap">
        <div class="toolbar">
          <div class="breadcrumb toolblock">
            <ul>
              <li class="first"><a href="index.html">Home</a></li>
              <!--  Breadcrumbs go here -->
<li><a href="modules.html">Modules</a></li>
<li><a href="qtcore.html">QtCore</a></li>
<li>QCache</li>
            </ul>
          </div>
          <div class="toolbuttons toolblock">
            <ul>
              <li id="smallA" class="t_button">A</li>
              <li id="medA" class="t_button active">A</li>
              <li id="bigA" class="t_button">A</li>
              <li id="print" class="t_button"><a href="javascript:this.print();">
                <span>Print</span></a></li>
            </ul>
        </div>
        </div>
        <div class="content mainContent">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#public-functions">Public Functions</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
</ul>
</div>
<h1 class="title">QCache Class Reference</h1>
<!-- $$$QCache-brief -->
<p>The QCache class is a template class that provides a cache. <a href="#details">More...</a></p>
<!-- @@@QCache -->
<pre class="cpp"> <span class="preprocessor">#include &lt;QCache&gt;</span></pre><p><b>Note:</b> All functions in this class are <a href="threads-reentrancy.html#reentrant">reentrant</a>.</p>
<ul>
<li><a href="qcache-members.html">List of all members, including inherited members</a></li>
<li><a href="qcache-qt3.html">Qt 3 support members</a></li>
</ul>
<a name="public-functions"></a>
<h2>Public Functions</h2>
<table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qcache.html#QCache">QCache</a></b> ( int <i>maxCost</i> = 100 )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qcache.html#dtor.QCache">~QCache</a></b> ()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qcache.html#clear">clear</a></b> ()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qcache.html#contains">contains</a></b> ( const Key &amp; <i>key</i> ) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qcache.html#count">count</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qcache.html#insert">insert</a></b> ( const Key &amp; <i>key</i>, T * <i>object</i>, int <i>cost</i> = 1 )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qcache.html#isEmpty">isEmpty</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QList&lt;Key&gt; </td><td class="memItemRight bottomAlign"><b><a href="qcache.html#keys">keys</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qcache.html#maxCost">maxCost</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> T * </td><td class="memItemRight bottomAlign"><b><a href="qcache.html#object">object</a></b> ( const Key &amp; <i>key</i> ) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qcache.html#remove">remove</a></b> ( const Key &amp; <i>key</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qcache.html#setMaxCost">setMaxCost</a></b> ( int <i>cost</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qcache.html#size">size</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> T * </td><td class="memItemRight bottomAlign"><b><a href="qcache.html#take">take</a></b> ( const Key &amp; <i>key</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qcache.html#totalCost">totalCost</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> T * </td><td class="memItemRight bottomAlign"><b><a href="qcache.html#operator-5b-5d">operator[]</a></b> ( const Key &amp; <i>key</i> ) const</td></tr>
</table>
<a name="details"></a>
<!-- $$$QCache-description -->
<div class="descr">
<h2>Detailed Description</h2>
<p>The QCache class is a template class that provides a cache.</p>
<p>QCache&lt;Key, T&gt; defines a cache that stores objects of type T associated with keys of type Key. For example, here's the definition of a cache that stores objects of type Employee associated with an integer key:</p>
<pre class="cpp"> <span class="type">QCache</span><span class="operator">&lt;</span><span class="type">int</span><span class="operator">,</span> Employee<span class="operator">&gt;</span> cache;</pre>
<p>Here's how to insert an object in the cache:</p>
<pre class="cpp"> Employee <span class="operator">*</span>employee <span class="operator">=</span> <span class="keyword">new</span> Employee;
 employee<span class="operator">-</span><span class="operator">&gt;</span>setId(<span class="number">37</span>);
 employee<span class="operator">-</span><span class="operator">&gt;</span>setName(<span class="string">&quot;Richard Schmit&quot;</span>);
 <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
 cache<span class="operator">.</span><a href="qcache.html#insert">insert</a>(employee<span class="operator">-</span><span class="operator">&gt;</span>id()<span class="operator">,</span> employee);</pre>
<p>The advantage of using QCache over some other key-based data structure (such as <a href="qmap.html">QMap</a> or <a href="qhash.html">QHash</a>) is that QCache automatically takes ownership of the objects that are inserted into the cache and deletes them to make room for new objects, if necessary. When inserting an object into the cache, you can specify a <i>cost</i>, which should bear some approximate relationship to the amount of memory taken by the object. When the sum of all objects' costs (<a href="qcache.html#totalCost">totalCost</a>()) exceeds the cache's limit (<a href="qcache.html#maxCost">maxCost</a>()), QCache starts deleting objects in the cache to keep under the limit, starting with less recently accessed objects.</p>
<p>By default, QCache's <a href="qcache.html#maxCost">maxCost</a>() is 100. You can specify a different value in the QCache constructor:</p>
<pre class="cpp"> <span class="type">QCache</span><span class="operator">&lt;</span><span class="type">int</span><span class="operator">,</span> MyDataStructure<span class="operator">&gt;</span> cache(<span class="number">5000</span>);</pre>
<p>Each time you call <a href="qcache.html#insert">insert</a>(), you can specify a cost as third argument (after the key and a pointer to the object to insert). After the call, the inserted object is owned by the QCache, which may delete it at any time to make room for other objects.</p>
<p>To look up objects in the cache, use <a href="qcache.html#object">object</a>() or operator[](). This function looks up an object by its key, and returns either a pointer to the cached object (which is owned by the cache) or 0.</p>
<p>If you want to remove an object from the cache for a particular key, call <a href="qcache.html#remove">remove</a>(). This will also delete the object. If you want to remove an object from the cache without the QCache deleting it, use <a href="qcache.html#take">take</a>().</p>
</div>
<p><b>See also </b><a href="qpixmapcache.html">QPixmapCache</a>, <a href="qhash.html">QHash</a>, and <a href="qmap.html">QMap</a>.</p>
<!-- @@@QCache -->
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QCache[overload1]$$$QCacheint -->
<h3 class="fn"><a name="QCache"></a>QCache::<span class="name">QCache</span> ( <span class="type">int</span> <i>maxCost</i> = 100 )</h3>
<p>Constructs a cache whose contents will never have a total cost greater than <i>maxCost</i>.</p>
<!-- @@@QCache -->
<!-- $$$~QCache[overload1]$$$~QCache -->
<h3 class="fn"><a name="dtor.QCache"></a>QCache::<span class="name">~QCache</span> ()</h3>
<p>Destroys the cache. Deletes all the objects in the cache.</p>
<!-- @@@~QCache -->
<!-- $$$clear[overload1]$$$clear -->
<h3 class="fn"><a name="clear"></a><span class="type">void</span> QCache::<span class="name">clear</span> ()</h3>
<p>Deletes all the objects in the cache.</p>
<p><b>See also </b><a href="qcache.html#remove">remove</a>() and <a href="qcache.html#take">take</a>().</p>
<!-- @@@clear -->
<!-- $$$contains[overload1]$$$containsconstKey& -->
<h3 class="fn"><a name="contains"></a><span class="type">bool</span> QCache::<span class="name">contains</span> ( const <span class="type">Key</span> &amp; <i>key</i> ) const</h3>
<p>Returns true if the cache contains an object associated with key <i>key</i>; otherwise returns false.</p>
<p><b>See also </b><a href="qcache.html#take">take</a>() and <a href="qcache.html#remove">remove</a>().</p>
<!-- @@@contains -->
<!-- $$$count[overload1]$$$count -->
<h3 class="fn"><a name="count"></a><span class="type">int</span> QCache::<span class="name">count</span> () const</h3>
<p>Same as <a href="qcache.html#size">size</a>().</p>
<!-- @@@count -->
<!-- $$$insert[overload1]$$$insertconstKey&T*int -->
<h3 class="fn"><a name="insert"></a><span class="type">bool</span> QCache::<span class="name">insert</span> ( const <span class="type">Key</span> &amp; <i>key</i>, <span class="type">T</span> * <i>object</i>, <span class="type">int</span> <i>cost</i> = 1 )</h3>
<p>Inserts <i>object</i> into the cache with key <i>key</i> and associated cost <i>cost</i>. Any object with the same key already in the cache will be removed.</p>
<p>After this call, <i>object</i> is owned by the <a href="qcache.html">QCache</a> and may be deleted at any time. In particular, if <i>cost</i> is greater than <a href="qcache.html#maxCost">maxCost</a>(), the object will be deleted immediately.</p>
<p>The function returns true if the object was inserted into the cache; otherwise it returns false.</p>
<p><b>See also </b><a href="qcache.html#take">take</a>() and <a href="qcache.html#remove">remove</a>().</p>
<!-- @@@insert -->
<!-- $$$isEmpty[overload1]$$$isEmpty -->
<h3 class="fn"><a name="isEmpty"></a><span class="type">bool</span> QCache::<span class="name">isEmpty</span> () const</h3>
<p>Returns true if the cache contains no objects; otherwise returns false.</p>
<p><b>See also </b><a href="qcache.html#size">size</a>().</p>
<!-- @@@isEmpty -->
<!-- $$$keys[overload1]$$$keys -->
<h3 class="fn"><a name="keys"></a><span class="type"><a href="qlist.html">QList</a></span>&lt;<span class="type">Key</span>&gt; QCache::<span class="name">keys</span> () const</h3>
<p>Returns a list of the keys in the cache.</p>
<!-- @@@keys -->
<!-- $$$maxCost[overload1]$$$maxCost -->
<h3 class="fn"><a name="maxCost"></a><span class="type">int</span> QCache::<span class="name">maxCost</span> () const</h3>
<p>Returns the maximum allowed total cost of the cache.</p>
<p><b>See also </b><a href="qcache.html#setMaxCost">setMaxCost</a>() and <a href="qcache.html#totalCost">totalCost</a>().</p>
<!-- @@@maxCost -->
<!-- $$$object[overload1]$$$objectconstKey& -->
<h3 class="fn"><a name="object"></a><span class="type">T</span> * QCache::<span class="name">object</span> ( const <span class="type">Key</span> &amp; <i>key</i> ) const</h3>
<p>Returns the object associated with key <i>key</i>, or 0 if the key does not exist in the cache.</p>
<p><b>Warning:</b> The returned object is owned by <a href="qcache.html">QCache</a> and may be deleted at any time.</p>
<p><b>See also </b><a href="qcache.html#take">take</a>() and <a href="qcache.html#remove">remove</a>().</p>
<!-- @@@object -->
<!-- $$$remove[overload1]$$$removeconstKey& -->
<h3 class="fn"><a name="remove"></a><span class="type">bool</span> QCache::<span class="name">remove</span> ( const <span class="type">Key</span> &amp; <i>key</i> )</h3>
<p>Deletes the object associated with key <i>key</i>. Returns true if the object was found in the cache; otherwise returns false.</p>
<p><b>See also </b><a href="qcache.html#take">take</a>() and <a href="qcache.html#clear">clear</a>().</p>
<!-- @@@remove -->
<!-- $$$setMaxCost[overload1]$$$setMaxCostint -->
<h3 class="fn"><a name="setMaxCost"></a><span class="type">void</span> QCache::<span class="name">setMaxCost</span> ( <span class="type">int</span> <i>cost</i> )</h3>
<p>Sets the maximum allowed total cost of the cache to <i>cost</i>. If the current total cost is greater than <i>cost</i>, some objects are deleted immediately.</p>
<p><b>See also </b><a href="qcache.html#maxCost">maxCost</a>() and <a href="qcache.html#totalCost">totalCost</a>().</p>
<!-- @@@setMaxCost -->
<!-- $$$size[overload1]$$$size -->
<h3 class="fn"><a name="size"></a><span class="type">int</span> QCache::<span class="name">size</span> () const</h3>
<p>Returns the number of objects in the cache.</p>
<p><b>See also </b><a href="qcache.html#isEmpty">isEmpty</a>().</p>
<!-- @@@size -->
<!-- $$$take[overload1]$$$takeconstKey& -->
<h3 class="fn"><a name="take"></a><span class="type">T</span> * QCache::<span class="name">take</span> ( const <span class="type">Key</span> &amp; <i>key</i> )</h3>
<p>Takes the object associated with key <i>key</i> out of the cache without deleting it. Returns a pointer to the object taken out, or 0 if the key does not exist in the cache.</p>
<p>The ownership of the returned object is passed to the caller.</p>
<p><b>See also </b><a href="qcache.html#remove">remove</a>().</p>
<!-- @@@take -->
<!-- $$$totalCost[overload1]$$$totalCost -->
<h3 class="fn"><a name="totalCost"></a><span class="type">int</span> QCache::<span class="name">totalCost</span> () const</h3>
<p>Returns the total cost of the objects in the cache.</p>
<p>This value is normally below <a href="qcache.html#maxCost">maxCost</a>(), but <a href="qcache.html">QCache</a> makes an exception for Qt's <a href="implicit-sharing.html#implicitly-shared">implicitly shared</a> classes. If a cached object shares its internal data with another instance, <a href="qcache.html">QCache</a> may keep the object lying around, possibly contributing to making totalCost() larger than <a href="qcache.html#maxCost">maxCost</a>().</p>
<p><b>See also </b><a href="qcache.html#setMaxCost">setMaxCost</a>().</p>
<!-- @@@totalCost -->
<!-- $$$operator[][overload1]$$$operator[]constKey& -->
<h3 class="fn"><a name="operator-5b-5d"></a><span class="type">T</span> * QCache::<span class="name">operator[]</span> ( const <span class="type">Key</span> &amp; <i>key</i> ) const</h3>
<p>Returns the object associated with key <i>key</i>, or 0 if the key does not exist in the cache.</p>
<p>This is the same as <a href="qcache.html#object">object</a>().</p>
<p><b>Warning:</b> The returned object is owned by <a href="qcache.html">QCache</a> and may be deleted at any time.</p>
<!-- @@@operator[] -->
</div>
      </div>
    </div>
    </div> 
    <div class="ft">
      <span></span>
    </div>
  </div> 
  <div class="footer">
    <p>
      <acronym title="Copyright">&copy;</acronym> 2013 Digia Plc and/or its
      subsidiaries. Documentation contributions included herein are the copyrights of
      their respective owners.</p>
    <br />
    <p>
      The documentation provided herein is licensed under the terms of the
      <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation
      License version 1.3</a> as published by the Free Software Foundation.</p>
    <p>
      Documentation sources may be obtained from <a href="http://www.qt-project.org">
      www.qt-project.org</a>.</p>
    <br />
    <p>
      Digia, Qt and their respective logos are trademarks of Digia Plc 
      in Finland and/or other countries worldwide. All other trademarks are property
      of their respective owners. <a title="Privacy Policy"
      href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p>
  </div>

  <script src="scripts/functions.js" type="text/javascript"></script>
</body>
</html>