Support unrar64.dll
[xy_vsfilter.git] / src / subtitles / libssf / Stream.h
blobabfcbf9d618e3a08a7a878204c1b51ee58333609
1 /*
2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 #pragma once
24 #include "Exception.h"
26 namespace ssf
28 class Stream
30 public:
31 enum {EOS = -1};
32 enum encoding_t {none, unknown, utf8, utf16le, utf16be, wchar};
34 protected:
35 int m_line, m_col;
36 encoding_t m_encoding;
38 public:
39 Stream();
40 virtual ~Stream();
42 static bool IsWhiteSpace(int c, LPCWSTR morechars = NULL);
44 void ThrowError(LPCTSTR fmt, ...);
47 class InputStream : public Stream
49 CAtlList<int> m_queue;
50 int PushChar(), PopChar();
52 int NextChar();
54 protected:
55 virtual int NextByte() = 0;
57 public:
58 InputStream();
59 ~InputStream();
61 int PeekChar(), GetChar();
63 int SkipWhiteSpace(LPCWSTR morechars = NULL);
66 class FileInputStream : public InputStream
68 FILE* m_file;
70 protected:
71 int NextByte();
73 public:
74 FileInputStream(const TCHAR* fn);
75 ~FileInputStream();
78 class MemoryInputStream : public InputStream
80 BYTE* m_pBytes;
81 int m_pos, m_len;
82 bool m_fFree;
84 protected:
85 int NextByte();
87 public:
88 MemoryInputStream(BYTE* pBytes, int len, bool fCopy, bool fFree);
89 ~MemoryInputStream();
92 class WCharInputStream : public InputStream
94 CStringW m_str;
95 int m_pos;
97 protected:
98 int NextByte();
100 public:
101 WCharInputStream(CStringW str);
104 class OutputStream : public Stream
106 bool m_bof;
108 protected:
109 virtual void NextByte(int b) = 0;
111 public:
112 OutputStream(encoding_t e);
113 virtual ~OutputStream();
115 void PutChar(WCHAR c);
116 void PutString(LPCWSTR fmt, ...);
119 class WCharOutputStream : public OutputStream
121 CStringW m_str;
123 protected:
124 void NextByte(int b);
126 public:
127 WCharOutputStream();
129 const CStringW& GetString() {return m_str;}
132 class DebugOutputStream : public OutputStream
134 CStringW m_str;
136 protected:
137 void NextByte(int b);
139 public:
140 DebugOutputStream();
141 ~DebugOutputStream();