gcache.h

Go to the documentation of this file.
00001 // $Id: gcache.h 754 2006-04-01 15:29:59Z alex $
00003 //
00004 // GCache.h
00005 //
00007 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00008 ================================XARAHEADERSTART===========================
00009  
00010                Xara LX, a vector drawing and manipulation program.
00011                     Copyright (C) 1993-2006 Xara Group Ltd.
00012        Copyright on certain contributions may be held in joint with their
00013               respective authors. See AUTHORS file for details.
00014 
00015 LICENSE TO USE AND MODIFY SOFTWARE
00016 ----------------------------------
00017 
00018 This file is part of Xara LX.
00019 
00020 Xara LX is free software; you can redistribute it and/or modify it
00021 under the terms of the GNU General Public License version 2 as published
00022 by the Free Software Foundation.
00023 
00024 Xara LX and its component source files are distributed in the hope
00025 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00026 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00027 See the GNU General Public License for more details.
00028 
00029 You should have received a copy of the GNU General Public License along
00030 with Xara LX (see the file GPL in the root directory of the
00031 distribution); if not, write to the Free Software Foundation, Inc., 51
00032 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00033 
00034 
00035 ADDITIONAL RIGHTS
00036 -----------------
00037 
00038 Conditional upon your continuing compliance with the GNU General Public
00039 License described above, Xara Group Ltd grants to you certain additional
00040 rights. 
00041 
00042 The additional rights are to use, modify, and distribute the software
00043 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00044 library and any other such library that any version of Xara LX relased
00045 by Xara Group Ltd requires in order to compile and execute, including
00046 the static linking of that library to XaraLX. In the case of the
00047 "CDraw" library, you may satisfy obligation under the GNU General Public
00048 License to provide source code by providing a binary copy of the library
00049 concerned and a copy of the license accompanying it.
00050 
00051 Nothing in this section restricts any of the rights you have under
00052 the GNU General Public License.
00053 
00054 
00055 SCOPE OF LICENSE
00056 ----------------
00057 
00058 This license applies to this program (XaraLX) and its constituent source
00059 files only, and does not necessarily apply to other Xara products which may
00060 in part share the same code base, and are subject to their own licensing
00061 terms.
00062 
00063 This license does not apply to files in the wxXtra directory, which
00064 are built into a separate library, and are subject to the wxWindows
00065 license contained within that directory in the file "WXXTRA-LICENSE".
00066 
00067 This license does not apply to the binary libraries (if any) within
00068 the "libs" directory, which are subject to a separate license contained
00069 within that directory in the file "LIBS-LICENSE".
00070 
00071 
00072 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00073 ----------------------------------------------
00074 
00075 Subject to the terms of the GNU Public License (see above), you are
00076 free to do whatever you like with your modifications. However, you may
00077 (at your option) wish contribute them to Xara's source tree. You can
00078 find details of how to do this at:
00079   http://www.xaraxtreme.org/developers/
00080 
00081 Prior to contributing your modifications, you will need to complete our
00082 contributor agreement. This can be found at:
00083   http://www.xaraxtreme.org/developers/contribute/
00084 
00085 Please note that Xara will not accept modifications which modify any of
00086 the text between the start and end of this header (marked
00087 XARAHEADERSTART and XARAHEADEREND).
00088 
00089 
00090 MARKS
00091 -----
00092 
00093 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00094 designs are registered or unregistered trademarks, design-marks, and/or
00095 service marks of Xara Group Ltd. All rights in these marks are reserved.
00096 
00097 
00098       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00099                         http://www.xara.com/
00100 
00101 =================================XARAHEADEREND============================
00102  */
00103 
00104 CONST UINT32 FREE = 0xffffffff ;
00105 
00106 struct CacheBlock {
00107     CacheBlock  *Prev ;
00108     CacheBlock  *Next ;
00109     union {
00110         struct {
00111             CacheBlock  *PrevFree ;
00112             CacheBlock  *NextFree ;
00113             UINT32      State ;
00114         } ;
00115         struct {
00116             CacheBlock  *PrevUsed ;
00117             CacheBlock  *NextUsed ;
00118             CacheBlock  *Link ;
00119             UINT32      Handle ;
00120             INT32       Object[1] ;
00121         } ;
00122     } ;
00123 } ;
00124 
00125 // For some reason the size of Object[] is not included in the latter calc, presumably because
00126 // it's not really of size[1] - AMB
00127 const size_t FreeCacheBlockSize = 4 * sizeof(CacheBlock *) + sizeof (UINT32) ;
00128 const size_t UsedCacheBlockSize = 5 * sizeof(CacheBlock *) + sizeof (UINT32) ;
00129 
00131 
00132 /************************************************************************************************
00133 // Gavin's original defaults
00134 //GCache( size_t Size = 0x40000, UINT32 Log2MaxEntries = 12 ) ;
00135 
00136 // The size of the cache is 128k, average character size = 1k, We allow a maximum of 1K entries
00137 //GCache( size_t Size = 0x20000, UINT32 Log2MaxEntries = 10 ) ;
00138 
00139 
00140     Size specifies the byte size of the cache. Log2MaxEntries specifes the number of entries in
00141     the hash table. Note that the cache will still work even if there are more characters than
00142     the size of the hash table.
00143 
00144 BOOL Verify() ;
00145     This will return TRUE if the cache is in use. Use after construction to ensure that
00146     construction succeeded.
00147 
00148 BOOL FindPath( UINT32 Handle, INT32* &Points, BYTE* &Types, UINT32 &Length ) ;
00149 
00150     Searches for the given handle. If found it returns TRUE and returns the associated path in
00151     Points, Types and Length, else it returns FALSE.
00152 
00153 void AddPath( UINT32 Handle, INT32*  Points, BYTE*  Types, UINT32  Length ) ;
00154 
00155     Stores the given path in the cache using the specified handle.
00156 
00157 char* FindString( UINT32 Handle ) ;
00158 
00159     Searches for the given handle. If found it returns the string associated with the handle,
00160     else it returns FALSE.
00161 
00162 void  AddString( UINT32 Handle, char* String ) ;
00163 
00164     Stores the given string in the cache using the specified handle.
00165 
00166 ************************************************************************************************/
00167 
00168 class CamCache
00169 {
00170 #ifdef _DEBUG
00171     friend ostream& operator << ( ostream& os, CamCache& Cache ) ;
00172 #endif
00173 
00174 public:
00175     CamCache( size_t Size = 0x40000, UINT32 Log2MaxEntries = 12 ) ;
00176     ~CamCache() ;
00177     BOOL Verify() ;
00178 
00179     BOOL FindPath( UINT32 Handle, INT32* &Points, BYTE* &Types, UINT32 &Length ) ;
00180     void  AddPath( UINT32 Handle, INT32*  Points, BYTE*  Types, UINT32  Length ) ;
00181 
00182     char* FindString( UINT32 Handle ) ;
00183     void   AddString( UINT32 Handle, char* String ) ;
00184 
00185 private:
00186     size_t      HashTableSize ;
00187     UINT32      HashTableMask ;
00188     CacheBlock  **HashTable ;
00189 
00190     CacheBlock  *CacheStart ;
00191     CacheBlock  *CacheEnd ;
00192 
00193     CacheBlock  *LeastUsed ;
00194     CacheBlock  *MostUsed ;
00195 
00196     void* FindEntry( UINT32 Handle ) ;
00197     void*  AddEntry( UINT32 Handle, size_t ObjectSize ) ;
00198 
00199     inline size_t BlockSize( CacheBlock* Block )
00200     {
00201         return (size_t)((BYTE*)Block->Next-(BYTE*)Block) ;
00202     } ;
00203 } ;
00204 

Generated on Sat Nov 10 03:45:25 2007 for Camelot by  doxygen 1.4.4