source: trunk/poppler/mypoppler/poppler/CachedFile.h @ 461

Last change on this file since 461 was 461, checked in by Silvan Scherrer, 11 years ago

poppler update to 0.14.2

File size: 3.7 KB
Line 
1//========================================================================
2//
3// CachedFile.h
4//
5// Caching files support.
6//
7// This file is licensed under the GPLv2 or later
8//
9// Copyright 2009 Stefan Thomas <thomas@eload24.com>
10// Copyright 2010 Hib Eris <hib@hiberis.nl>
11// Copyright 2010 Albert Astals Cid <aacid@kde.org>
12//
13//========================================================================
14
15#ifndef CACHEDFILE_H
16#define CACHEDFILE_H
17
18#include "poppler-config.h"
19
20#include "goo/gtypes.h"
21#include "Object.h"
22#include "Stream.h"
23#include "goo/GooVector.h"
24
25//------------------------------------------------------------------------
26
27#define CachedFileChunkSize 8192
28
29class GooString;
30class CachedFileLoader;
31
32//------------------------------------------------------------------------
33// CachedFile
34//
35// CachedFile gives FILE-like access to a document at a specified URI.
36// In the constructor, you specify a CachedFileLoader that handles loading
37// the data from the document. The CachedFile requests no more data then it
38// needs from the CachedFileLoader.
39//------------------------------------------------------------------------
40
41class CachedFile {
42
43friend class CachedFileWriter;
44
45public:
46
47  CachedFile(CachedFileLoader *cacheLoader, GooString *uri);
48
49  Guint getLength() { return length; }
50  long int tell();
51  int seek(long int offset, int origin);
52  size_t read(void * ptr, size_t unitsize, size_t count);
53  size_t write(const char *ptr, size_t size, size_t fromByte);
54  int cache(const GooVector<ByteRange> &ranges);
55
56  // Reference counting.
57  void incRefCnt();
58  void decRefCnt();
59
60private:
61
62  ~CachedFile();
63
64  enum ChunkState {
65    chunkStateNew = 0,
66    chunkStateLoaded
67  };
68
69  typedef struct {
70    ChunkState state;
71    char data[CachedFileChunkSize];
72  } Chunk;
73
74  int cache(size_t offset, size_t length);
75
76  CachedFileLoader *loader;
77  GooString *uri;
78
79  size_t length;
80  size_t streamPos;
81
82  GooVector<Chunk> *chunks;
83
84  int refCnt;  // reference count
85
86};
87
88//------------------------------------------------------------------------
89// CachedFileWriter
90//
91// CachedFileWriter handles sequential writes to a CachedFile.
92// On construction, you specify the CachedFile and the chunks of it to which data
93// should be written.
94//------------------------------------------------------------------------
95
96class CachedFileWriter {
97
98public:
99
100  // Construct a CachedFile Writer.
101  // The caller is responsible for deleting the cachedFile and chunksA.
102  CachedFileWriter(CachedFile *cachedFile, GooVector<int> *chunksA);
103
104  ~CachedFileWriter();
105
106  // Writes size bytes from ptr to cachedFile, returns number of bytes written.
107  size_t write(const char *ptr, size_t size);
108
109private:
110
111  CachedFile *cachedFile;
112  GooVector<int> *chunks;
113  GooVector<int>::iterator it;
114  size_t offset;
115
116};
117
118//------------------------------------------------------------------------
119// CachedFileLoader
120//
121// CachedFileLoader is an abstact class that specifies the interface for
122// loadng data from an URI into a CachedFile.
123//------------------------------------------------------------------------
124
125class CachedFileLoader {
126
127public:
128
129  virtual ~CachedFileLoader() {};
130
131  // Initializes the file load.
132  // Returns the length of the file.
133  // The caller is responsible for deleting uri and cachedFile.
134  virtual size_t init(GooString *uri, CachedFile *cachedFile) = 0;
135
136  // Loads speficified byte ranges and passes it to the writer to store them.
137  // Returns 0 on success, Anything but 0 on failure.
138  // The caller is responsible for deleting the writer.
139  virtual int load(const GooVector<ByteRange> &ranges, CachedFileWriter *writer) = 0;
140
141};
142
143//------------------------------------------------------------------------
144
145#endif
Note: See TracBrowser for help on using the repository browser.