filelistdb.h 1.4 KB

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