• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kviewshell

DjVuFileCache.h

Go to the documentation of this file.
00001 //C-  -*- C++ -*-
00002 //C- -------------------------------------------------------------------
00003 //C- DjVuLibre-3.5
00004 //C- Copyright (c) 2002  Leon Bottou and Yann Le Cun.
00005 //C- Copyright (c) 2001  AT&T
00006 //C-
00007 //C- This software is subject to, and may be distributed under, the
00008 //C- GNU General Public License, Version 2. The license should have
00009 //C- accompanied the software or you may obtain a copy of the license
00010 //C- from the Free Software Foundation at http://www.fsf.org .
00011 //C-
00012 //C- This program is distributed in the hope that it will be useful,
00013 //C- but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //C- GNU General Public License for more details.
00016 //C- 
00017 //C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library
00018 //C- distributed by Lizardtech Software.  On July 19th 2002, Lizardtech 
00019 //C- Software authorized us to replace the original DjVu(r) Reference 
00020 //C- Library notice by the following text (see doc/lizard2002.djvu):
00021 //C-
00022 //C-  ------------------------------------------------------------------
00023 //C- | DjVu (r) Reference Library (v. 3.5)
00024 //C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
00025 //C- | The DjVu Reference Library is protected by U.S. Pat. No.
00026 //C- | 6,058,214 and patents pending.
00027 //C- |
00028 //C- | This software is subject to, and may be distributed under, the
00029 //C- | GNU General Public License, Version 2. The license should have
00030 //C- | accompanied the software or you may obtain a copy of the license
00031 //C- | from the Free Software Foundation at http://www.fsf.org .
00032 //C- |
00033 //C- | The computer code originally released by LizardTech under this
00034 //C- | license and unmodified by other parties is deemed "the LIZARDTECH
00035 //C- | ORIGINAL CODE."  Subject to any third party intellectual property
00036 //C- | claims, LizardTech grants recipient a worldwide, royalty-free, 
00037 //C- | non-exclusive license to make, use, sell, or otherwise dispose of 
00038 //C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the 
00039 //C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU 
00040 //C- | General Public License.   This grant only confers the right to 
00041 //C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to 
00042 //C- | the extent such infringement is reasonably necessary to enable 
00043 //C- | recipient to make, have made, practice, sell, or otherwise dispose 
00044 //C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to 
00045 //C- | any greater extent that may be necessary to utilize further 
00046 //C- | modifications or combinations.
00047 //C- |
00048 //C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
00049 //C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
00050 //C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
00051 //C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
00052 //C- +------------------------------------------------------------------
00053 // 
00054 // $Id: DjVuFileCache.h,v 1.8 2003/11/07 22:08:20 leonb Exp $
00055 // $Name: release_3_5_15 $
00056 
00057 #ifndef _DJVUFILECACHE_H
00058 #define _DJVUFILECACHE_H
00059 #ifdef HAVE_CONFIG_H
00060 #include "config.h"
00061 #endif
00062 #if NEED_GNUG_PRAGMAS
00063 # pragma interface
00064 #endif
00065 
00066 
00067 #include "DjVuFile.h"
00068 
00069 #ifndef macintosh //MCW can't compile
00070 # ifndef UNDER_CE
00071 #  include <sys/types.h>
00072 #  include <time.h>
00073 # endif 
00074 #else
00075 # include <time.h>
00076 #endif
00077 
00078 
00079 #ifdef HAVE_NAMESPACES
00080 namespace DJVU {
00081 # ifdef NOT_DEFINED // Just to fool emacs c++ mode
00082 }
00083 #endif
00084 #endif
00085 
00100 
00109 #ifdef UNDER_CE
00110 class DjVuFileCache : public GPEnabled
00111 {
00112 protected:
00113    DjVuFileCache(const int) {}
00114 public:
00115    static GP<DjVuFileCache> create(const int);
00116    virtual ~DjVuFileCache(void);
00117    void del_file(const DjVuFile *) {}
00118    void add_file(const GP<DjVuFile> &) {}
00119    void clear(void) {}
00120    void set_max_size(int) {}
00121    int get_max_size(void) const {return 0;}
00122    void enable(bool en) {}
00123    bool is_enabled(void) const {return false;}
00124 } ;
00125 #else
00126 class DjVuFileCache : public GPEnabled
00127 {
00128 protected:
00129    DjVuFileCache(const int max_size=5*2*1024*1024);
00130 public:
00133    static GP<DjVuFileCache> create(const int max_size=5*2*1024*1024);
00134 
00135    virtual ~DjVuFileCache(void);
00136 
00138    void     del_file(const DjVuFile * file);
00139 
00142    void     add_file(const GP<DjVuFile> & file);
00143 
00145    void     clear(void);
00149    void     set_max_size(int max_size);
00150 
00152    int      get_max_size(void) const;
00153 
00158    void     enable(bool en);
00159 
00167    bool     is_enabled(void) const;
00168 
00169 public:
00170    class Item;
00171    
00172    class Item : public GPEnabled
00173     {
00174     public:
00175        virtual ~Item(void);
00176        time_t       get_time(void) const;
00177 
00178        GP<DjVuFile> get_file(void) const;
00179        unsigned int get_size(void) const;
00180        
00181        void     refresh(void);
00182 
00183     public:
00184        GP<DjVuFile> file;
00185        time_t       time;
00186        GPosition        list_pos;
00187        static int   qsort_func(const void * el1, const void * el2);
00188 
00189        Item(void);
00190        Item(const GP<DjVuFile> & xfile);
00191     };
00192 
00193 protected:
00194    GCriticalSection class_lock;
00195    
00198    virtual void file_added(const GP<DjVuFile> & file);
00201    virtual void file_deleted(const GP<DjVuFile> & file);
00204    virtual void file_cleared(const GP<DjVuFile> & file);
00205 
00206    GPList<Item> get_items(void);
00207 private:
00208    GPList<Item> list;
00209    bool     enabled;
00210    int      max_size;
00211    int      cur_size;
00212 
00213    int      calculate_size(void);
00214    void     clear_to_size(int size);
00215 };
00216 
00217 
00218 
00220    
00221 inline
00222 DjVuFileCache::Item::Item(void) : time(::time(0)) {}
00223 
00224 inline
00225 DjVuFileCache::Item::Item(const GP<DjVuFile> & xfile) :
00226       file(xfile), time(::time(0)) {}
00227 
00228 inline
00229 DjVuFileCache::Item::~Item(void) {}
00230 
00231 inline GP<DjVuFile>
00232 DjVuFileCache::Item::get_file(void) const
00233 {
00234    return file;
00235 }
00236 
00237 inline unsigned int
00238 DjVuFileCache::Item::get_size(void) const
00239 {
00240    return file->get_memory_usage();
00241 }
00242 
00243 inline time_t
00244 DjVuFileCache::Item::get_time(void) const
00245 {
00246    return time;
00247 }
00248 
00249 inline void
00250 DjVuFileCache::Item::refresh(void)
00251 {
00252    time=::time(0);
00253 }
00254 
00255 inline
00256 DjVuFileCache::DjVuFileCache(const int xmax_size) :
00257       enabled(true), max_size(xmax_size), cur_size(0) {}
00258 
00259 inline void
00260 DjVuFileCache::clear(void)
00261 {
00262    clear_to_size(0);
00263 }
00264 
00265 inline bool
00266 DjVuFileCache::is_enabled(void) const
00267 {
00268    return enabled;
00269 }
00270 
00271 inline int
00272 DjVuFileCache::get_max_size(void) const
00273 {
00274    return max_size;
00275 }
00276 
00277 #endif
00278 
00279 inline GP<DjVuFileCache>
00280 DjVuFileCache::create(const int max_size)
00281 {
00282   return new DjVuFileCache(max_size);
00283 }
00284 
00285 
00286 #ifdef HAVE_NAMESPACES
00287 }
00288 # ifndef NOT_USING_DJVU_NAMESPACE
00289 using namespace DJVU;
00290 # endif
00291 #endif
00292 #endif

kviewshell

Skip menu "kviewshell"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • kviewshell
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal