File: GenericFile_Blob.h

package info (click to toggle)
snap-aligner 1.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,988 kB
  • sloc: cpp: 36,500; ansic: 5,239; python: 227; makefile: 85; sh: 28
file content (66 lines) | stat: -rw-r--r-- 1,478 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*++

Module Name:

    GenericFile_Blob.h

Abstract:

    Generic IO class for SNAP that can read from an in-memory blob.

Authors:

    Bill Bolosky, March, 2014

Environment:

    User mode service.

Revision History:


--*/

#pragma once

#include "GenericFile.h"

class GenericFile_Blob: public GenericFile
{
public:
    //
    // This object does not take ownership of the blob, so it's the caller's
    // responsibility to assure that it continues to exist as long as the
    // GenericFile_Blob object does, and to free the memory as necessary.
    // In addition, if anyone calls mapAndAdvance, the caller must
    // assure that the blob continues to exist until all uses of that
    // pointer are finished as well.
    //
	static GenericFile_Blob *open(void *i_blob, size_t i_blobSize);

	virtual size_t read(void *ptr, size_t count);
	virtual int getchar();
	virtual char *gets(char *buf, size_t count);
	virtual int advance(long long offset);
	virtual void close();
	virtual ~GenericFile_Blob();
    virtual size_t getAmountUsed();



    //
    // This gives a pointer into the blob rather than copying it.
    // It's the caller's responsibility to assure that the blob doesn't
    // go away while this pointer's still in use.
    //
    void *mapAndAdvance(size_t count, size_t *bytesReturned);

protected:
	GenericFile_Blob(void *i_blob, size_t i_blobSize);

private:
	char    *blob;
    char    *blobEnd;
    char    *readPointer;
    size_t   blobSize;
};