OpendTect  6.3
netfilecache.h
Go to the documentation of this file.
1 #pragma once
2 
3 /*+
4 ________________________________________________________________________
5 
6  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
7  Author: Bert
8  Date: April 2016
9 ________________________________________________________________________
10 
11 -*/
12 
13 #include "networkmod.h"
14 #include "ranges.h"
15 #include "sets.h"
16 #include "od_iosfwd.h"
17 
18 
19 namespace Network
20 {
21 
25 {
26 public:
27 
28  typedef unsigned char BufType;
29  typedef int ChunkSizeType;
34 
35  virtual ~FileCache();
36 
37  FileSizeType size() const;
38  bool isEmpty() const { return size() < 1; }
39  virtual void clearData() = 0;
40 
41  virtual void setMinCacheSize(FileSizeType) = 0;
42 
43 protected:
44 
45  FileCache(FileSizeType);
46 
47  class Block
48  {
49  public:
50 
51  typedef ChunkSizeType SizeType;
52  typedef SizeType PosType;
53  static const SizeType cFullSize;
54 
55  Block(PosType);
56  ~Block();
57 
58  BufType* buf_;
59  SizeType bufsz_;
60 
61  };
62 
63 public:
64 
65  // Block-based access
66 
69 
70  BlockIdxType blockIdx(FilePosType) const;
71  static FilePosType blockStart(BlockIdxType);
72  BlockSizeType blockSize(BlockIdxType) const;
73  inline bool validBlockIdx( BlockIdxType bidx ) const
74  { return blocks_.validIdx(bidx); }
75 
76  bool isLiveBlock(BlockIdxType) const;
77  BufType* getBlock(BlockIdxType);
78  const BufType* getBlock(BlockIdxType) const;
79 
80 protected:
81 
83  const BlockSizeType lastblocksz_;
84  const FileSizeType knownfilesize_;
85 
86  Block* gtBlk(BlockIdxType) const;
87  void dismissBlock(BlockIdxType);
88  void clearBlocks();
89  inline FilePosType lastBlockPos() const
90  { return blockStart(blocks_.size()-1); }
91  inline FilePosType lastFilePos() const
92  { return lastBlockPos() + lastblocksz_ - 1; }
93 
94  virtual void handleNewLiveBlock(BlockIdxType) {}
95 
96 };
97 
98 
110 {
111 public:
112 
113  ReadCache(FileSizeType knownsize=0);
114  ~ReadCache();
115 
116  virtual void clearData();
117  virtual void setMinCacheSize(FileSizeType);
118 
119  // Free-sized access of buffered data
120  bool isAvailable(FilePosType,FileSizeType) const;
122  // returns actual nr bytes handled
123 
124  // Stuff data, presumably obtained from remote source
125  FileChunkSetType stillNeededDataFor(FilePosType,ChunkSizeType) const;
126  bool setData(FileChunkType,const BufType*);
128 
129 protected:
130 
133 
134  virtual void handleNewLiveBlock(BlockIdxType);
135 
136 };
137 
138 
150 {
151 public:
152 
153  WriteCache();
154  ~WriteCache();
155 
156  virtual void clearData();
157  virtual void setMinCacheSize(FileSizeType);
158 
159 
160 protected:
161 
163 
164  virtual void handleNewLiveBlock(BlockIdxType);
165 
166 };
167 
168 } // namespace Network
#define mExpClass(module)
Definition: commondefs.h:157
TypeSet< BlockIdxType > liveblockidxs_
Definition: netfilecache.h:131
FilePosType lastFilePos() const
Definition: netfilecache.h:91
SizeType PosType
Definition: netfilecache.h:52
Definition: jobcommunic.h:22
BlockIdxType maxnrliveblocks_
Definition: netfilecache.h:132
ChunkSizeType SizeType
Definition: netfilecache.h:51
Definition: netfilecache.h:47
Definition: netfilecache.h:24
od_int64 od_stream_Pos
Definition: od_iosfwd.h:19
Definition: netfilecache.h:149
int size_type
Definition: objectset.h:37
static const SizeType cFullSize
Definition: netfilecache.h:53
bool validBlockIdx(BlockIdxType bidx) const
Definition: netfilecache.h:73
od_uint64 od_stream_Count
Definition: od_iosfwd.h:16
Interval of values.
Definition: commontypes.h:27
BufType * buf_
Definition: netfilecache.h:58
size_type size() const
Definition: objectset.h:48
Set of pointers to objects.
Definition: commontypes.h:28
Set of (small) copyable elements.
Definition: commontypes.h:26
unsigned char BufType
Definition: netfilecache.h:28
SizeType bufsz_
Definition: netfilecache.h:59
od_stream_Count FileSizeType
Definition: netfilecache.h:30
Definition: netfilecache.h:109
const BlockSizeType lastblocksz_
Definition: netfilecache.h:83
ObjectSet< Block >::size_type BlockIdxType
Definition: netfilecache.h:67
Block::SizeType BlockSizeType
Definition: netfilecache.h:68
bool isEmpty() const
Definition: netfilecache.h:38
virtual void handleNewLiveBlock(BlockIdxType)
Definition: netfilecache.h:94
int ChunkSizeType
Definition: netfilecache.h:29
const FileSizeType knownfilesize_
Definition: netfilecache.h:84
TypeSet< FileChunkType > FileChunkSetType
Definition: netfilecache.h:33
od_stream_Pos FilePosType
Definition: netfilecache.h:31
FilePosType lastBlockPos() const
Definition: netfilecache.h:89
BlockIdxType nrblocksmem_
Definition: netfilecache.h:162
Interval< FilePosType > FileChunkType
Definition: netfilecache.h:32
ObjectSet< Block > blocks_
Definition: netfilecache.h:82

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2017