-
Notifications
You must be signed in to change notification settings - Fork 66
/
GenericFile.h
executable file
·72 lines (49 loc) · 1.5 KB
/
GenericFile.h
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
/*++
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
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 ben 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();
protected:
char *_gets_impl(char *buf, size_t count);
GenericFile();
Mode _mode;
char *_filename;
};