1/*
2 * Copyright 2008, Haiku.
3 * Distributed under the terms of the MIT license.
4 *
5 * Authors:
6 *		Michael Pfeiffer <laplace@users.sourceforge.net>
7 */
8
9#ifndef _PPD_FILE_H
10#define _PPD_FILE_H
11
12#include <File.h>
13#include <String.h>
14
15class Position {
16public:
17	int x;
18	int y;
19	Position()             : x(0), y(0) {}
20	Position(int x, int y) : x(x), y(y) {}
21};
22
23#define kReadBufferSize 1024
24
25class FileBuffer {
26	BFile* fFile;
27
28	unsigned char fBuffer[kReadBufferSize];
29	int           fIndex;
30	int           fSize;
31
32public:
33	FileBuffer(BFile* file) : fFile(file), fIndex(0), fSize(0) {}
34	int Read();
35};
36
37class PPDFile {
38private:
39	BString  fFileName;
40	BFile    fFile;
41	PPDFile* fPreviousFile; // single linked list of PPD files (stack)
42	Position fCurrentPosition;
43	int      fCurrentChar;
44	FileBuffer fBuffer;
45
46public:
47	// Opens the file for reading. Use IsValid to check if the file could
48	// be opened successfully.
49	// PPDFile also maintance a single linked list. The parameter previousFile
50	// can be used to store a reference to a previous file.
51	PPDFile(const char* file, PPDFile* previousFile = NULL);
52	// Closes the file.
53	~PPDFile();
54
55	// Returns the status of the constructor.
56	status_t InitCheck();
57
58	// Returns the current character or -1 if on EOF.
59	int GetCurrentChar();
60	// Reads the next character. Use GetChar to read the current
61	void NextChar();
62	// Returns the position of the current character.
63	Position GetPosition();
64	// The previous file from the constructor.
65	PPDFile* GetPreviousFile();
66	// Returns the file name
67	const char* GetFileName();
68};
69
70#endif
71