]> git.decadent.org.uk Git - dak.git/blob - tools/dsync-0.0/libdsync/filelistdb.h
Merge mainline
[dak.git] / tools / dsync-0.0 / libdsync / filelistdb.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description                                                          /*{{{*/
3 // $Id: filelistdb.h,v 1.2 1999/01/10 07:34:05 jgg Exp $
4 /* ######################################################################
5    
6    File List DB
7    
8    This scans a file list and generates a searchable list of all 
9    directories in the list. It can then do a lookup of a given file,
10    directory pair.
11    
12    The memory mapped IO class is recommended for use with the DB class 
13    for speed.
14    
15    ##################################################################### */
16                                                                         /*}}}*/
17 #ifndef DSYNC_FILELISTDB
18 #define DSYNC_FILELISTDB
19
20 #ifdef __GNUG__
21 #pragma interface "dsync/filelistdb.h"
22 #endif 
23
24 #include <dsync/filelist.h>
25 #include <dsync/mmap.h>
26 #include <map>
27
28 class dsFileListDB
29 {
30    struct Location
31    {
32       unsigned long Offset;
33       string LastSymlink;
34    };
35    
36    dsFList::IO *IO;
37    map<string,Location> Map;
38    string LastDir;
39    public:
40
41    bool Generate(dsFList::IO &IO);
42    bool Lookup(dsFList::IO &IO,const char *Dir,const char *File,dsFList &List);
43    
44    dsFileListDB();
45 };
46
47 class dsMMapIO : public dsFList::IO
48 {
49    FileFd Fd;
50    MMap Map;
51    unsigned long Pos;
52    
53    public:
54    
55    virtual bool Read(void *Buf,unsigned long Len);
56    virtual bool Write(const void *Buf,unsigned long Len);
57    virtual bool Seek(unsigned long Bytes);
58    virtual unsigned long Tell();
59    
60    dsMMapIO(string File);
61 };
62
63 #endif