File: GenericFile.h

package info (click to toggle)
snap-aligner 2.0.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 6,652 kB
  • sloc: cpp: 41,051; ansic: 5,239; python: 227; makefile: 85; sh: 28
file content (75 lines) | stat: -rwxr-xr-x 1,678 bytes parent folder | download | duplicates (3)
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
67
68
69
70
71
72
73
74
75
/*++

Module Name:

    GenericFile.h

Abstract:

    Generic IO class for SNAP that can read from either stdlib or HDFS.

Authors:

    Jeremy Elson, February 2014

Environment:

    User mode service.

Revision History:


--*/

#pragma once
#include "Compat.h"

class GenericFile
{
public:
	enum Mode
	{
		ReadOnly,
		WriteOnly,
	};

	static const char *HDFS_PREFIX;

	// Factory that returns either:
    //   * a GenericFile_HDFS object if the filename starts with "hdfs://"
    //   * a GenericFile_stdio object otherwise
    static GenericFile *open(const char *fileName, Mode mode);

	// Read 'count' bytes into the memory pointed at by 'ptr'.
    // Returns the actual number of bytes read, or -1 on error.
	virtual size_t read(void *ptr, size_t count) = 0;

    // Gets a single character from the stream, like stdio getc.
    // On success, returns the char promoted to an int.	
    // On failure, returns EOF.
    virtual int getchar() = 0;

	// Gets a string from the file and store it as a c string in 'str' until (num-1)
	// characters have been read or either a newline or eod-of-file is reached,
	// whichever happens first.
	virtual char *gets(char *buf, size_t count) = 0;

	// Advance forward or back by byteOffset bytes in the file.
	virtual int advance(long long byteOffset) = 0;

    // Close the file.
	virtual void close() = 0;

	// Return the name of the file.
	char *getFilename() { return _filename; }

	virtual ~GenericFile();

	virtual _int64 prefetch();	// Ignore the return value, it's just to trick the compiler into not optimizing it away.

protected:
	char *_gets_impl(char *buf, size_t count);
	GenericFile();
	Mode _mode;
	char *_filename;
};