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

NVcontainer.h

Go to the documentation of this file.
00001 #ifndef _NVcontainer_h_
00002 #define _NVcontainer_h_
00003 
00004 #include <fcntl.h>
00005 #include <sys/file.h>
00006 #include <sys/param.h>
00007 #include <unistd.h>
00008 
00009 #include "Debug.h"
00010 
00011 #define NVcontainer_LOCKSTACKSIZE 16
00012 
00013 typedef unsigned long nvtime_t;
00014 typedef unsigned long nvoff_t;
00015 
00016 extern nvtime_t nvtime(nvtime_t * nvt);
00017 
00029 class NVcontainer {
00030         struct Header {
00031                 unsigned int hlen;      /* 32 */
00032                 unsigned int version;   /* 32 */
00033                 nvoff_t size;           /* 32/64 */
00034                 nvtime_t mtime;         /* 32/64 */
00035                 nvoff_t freelist;       /* 32/64 */
00036                 nvoff_t bytes_free;     /* 32/64 */
00037                 nvoff_t userdata;       /* 32/64 */
00038                  Header() {
00039                         clear();
00040                 } void clear() {
00041                         hlen = sizeof(Header);
00042                         version = 2;
00043                         size = hlen;
00044                         mtime = 0;
00045                         freelist = userdata = 0;
00046                         bytes_free = 0;
00047         }};
00048         struct FreeList {
00049                 nvoff_t next;   /* 32/64 */
00050                 nvoff_t size;   /* 32/64 */
00051         };
00052         int lck_stack[NVcontainer_LOCKSTACKSIZE];
00053         int lck_stackp;
00054 
00055         char mem_fn[MAXPATHLEN];
00056         int mem_fd;
00057         Header *mem_hdr;
00058 
00059         FreeList *o2fl(nvoff_t o) {
00060                 return (FreeList *) (o ? mem_p + o : NULL);
00061         }
00062         nvoff_t fl2o(FreeList * r) {
00063                 return r ? (char *) r - mem_p : 0;
00064         }
00065 
00066       protected:
00067         NVcontainer(void);
00068         NVcontainer(const char *dbname, int flags = 0);
00069         virtual ~ NVcontainer(void);
00070 
00071         char *mem_p;
00072         size_t mem_sz;
00073 
00074         virtual void make_current(void);
00075         virtual int is_current(void) {
00076                 return mem_sz == mem_hdr->size;
00077         }
00078         virtual size_t resize(size_t nsz);
00079 
00080         nvoff_t getdata();
00081         nvoff_t getdatap();
00082         void setdata(nvoff_t d);
00083 
00084         nvoff_t nvalloc(size_t rsz);
00085         void nvfree(nvoff_t f);
00086       public:
00087         enum {
00088                 UnLock = F_UNLCK,
00089                 ShrdLock = F_RDLCK,
00090                 ExclLock = F_WRLCK
00091         };
00092         enum {
00093                 Block = 0x0,
00094                 NoBlock = 0x1
00095         };
00096 
00097         int lock(int command, int block = Block);
00098         int get_lock(void);
00099 
00100         virtual void open(const char *dbname, int flags = 0);
00101         virtual int is_open(void);
00102         virtual void close(void);
00103 
00104         void setmtime(nvtime_t tm, int force = 0);
00105         void getmtime(nvtime_t * tm);
00106 };
00107 
00108 /* We should add a general iterator class */
00109 /*
00110 class NVcontainterIter {
00111 ...
00112 };
00113 */
00114 
00115 #endif

Generated on Fri Aug 20 10:58:07 2004 for NewsCache by doxygen 1.3.6-20040222