Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

/ray/src/lib/sourcepos/spcache.h

Go to the documentation of this file.
00001 /*
00002  * lib/sourcepos/spcache.h
00003  * 
00004  * Classes for sophisticated source position (file/line/lpos, 
00005  * include hierarchy) handling. 
00006  * 
00007  * Copyright (c) 2003--2004 by Wolfgang Wieser ] wwieser (a) gmx <*> de [ 
00008  * 
00009  * This file may be distributed and/or modified under the terms of the 
00010  * GNU General Public License version 2 as published by the Free Software 
00011  * Foundation. (See COPYING.GPL for details.)
00012  * 
00013  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00014  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00015  * 
00016  */
00017 
00018 #ifndef _LIB_SOURCEPOS_SOURCEPOSCACHE_H_
00019 #define _LIB_SOURCEPOS_SOURCEPOSCACHE_H_ 1
00020 
00030 #include <lib/sconfig.h>    /* MUST be first */
00031 
00032 #include <lib/sourcepos/sourcepos.h>
00033 
00043 class SourcePositionCache
00044 {
00045     private:
00046         // The actual cache is just an array; it is short because 
00047         // the parser reads the file top-to-bottom so there is no 
00048         // need to hold a lot of positions. Actually, 1 or 2 should 
00049         // be enough...
00050         static const int cache_size=6;
00051         SourcePosition cache[cache_size];
00052         
00053         // Index of the newest element (they are rotated): 
00054         int top;
00055         
00056         // Record some statistics: 
00057         int hits;
00058         int misses;
00059         
00060     public:
00061         SourcePositionCache();
00062         ~SourcePositionCache();
00063         
00064         // Add this element to the cache (removing the oldest 
00065         // one): 
00066         void store(const SourcePosition &sp)
00067             {  top=(top+1)%cache_size;  cache[top]=sp;  }
00068         
00069         // Find a SourcePosition in the cache. 
00070         // Returns NULL position if not found. 
00071         SourcePosition find(int line,int lpos);
00072 };
00073 
00074 #endif  /* _LIB_SOURCEPOS_SOURCEPOSCACHE_H_ */

Generated on Sat Feb 19 22:33:46 2005 for Ray by doxygen 1.3.5