1 // -*- mode: cpp; mode: fold -*-
3 // $Id: slidingwindow.h,v 1.2 1999/11/15 07:59:49 jgg Exp $
4 /* ######################################################################
6 Sliding Window - Implements a sliding buffer over a file.
8 The buffer can be of arbitary size and where possible mmap is used
11 To use, init the class and then call Extend with a 0 input pointer
12 to receive the first block and then call extend with Start <= End
13 to get the next block. If Start != End then Start will be returned
14 with a new value, but pointing at the same byte, that is the new
15 region will contain the subregion Start -> End(o) but with a new
16 length End-Start, End != End(o).
18 After the file has been exhausted Start == End will be returned, but
19 the old region Start -> End(o) will remain valid.
21 ##################################################################### */
23 #ifndef SLIDING_WINDOW_H
24 #define SLIDING_WINDOW_H
27 #pragma interface "dsync/slidingwindow.h"
30 #include <sys/types.h>
31 #include <dsync/fileutl.h>
35 unsigned char *Buffer;
37 unsigned long MinSize;
39 unsigned long PageSize;
43 inline unsigned long Align(off_t V) const {return ((V % PageSize) == 0)?V:V + PageSize - (V % PageSize);};
44 inline unsigned long Align(unsigned long V) const {return ((V % PageSize) == 0)?V:V + PageSize - (V % PageSize);};
45 inline unsigned long AlignDn(off_t V) const {return ((V % PageSize) == 0)?V:V - (V % PageSize);};
46 inline unsigned long AlignDn(unsigned long V) const {return ((V % PageSize) == 0)?V:V - (V % PageSize);};
50 // Make the distance Start - End longer if possible
51 bool Extend(unsigned char *&Start,unsigned char *&End);
53 SlidingWindow(FileFd &Fd,unsigned long MinSize = 0);