OSDN Git Service

OMakeを利用するように、OMakefileを再度作成。
[simplecms/utakata.git] / src / reader_interface.h
1 // 各種デバイスからバイナリデータを読みだすためのインターフェースを
2 // 定義します。
3 // ここで定義されたインターフェースでは、文字列には変換されず、
4 // バイナリだけを読出します。
5 #ifndef _UTAKATA_SRC_READER_INTERFACE_H_
6 #define _UTAKATA_SRC_READER_INTERFACE_H_
7
8 #include <string>
9 #include <vector>
10 #include "src/exception.h"
11 #include "src/unicode.h"
12
13 namespace utakata {
14
15 namespace unicode {
16 class UniString;
17 }
18
19 namespace reader {
20
21 class EndOfDeviceException : public exception::Exception {
22   // reader::IReaderインターフェースの派生クラスにおいて、
23   // 末尾に到達しているにも関わらず読み出しが行われた場合に送出されます。
24  public:
25   EndOfDeviceException(const unicode::UniString message,
26                        const utakata::exception::ExceptionInfo& info) :
27       Exception(message, info) {}
28
29   EndOfDeviceException(const utakata::exception::Exception& exception,
30                        const unicode::UniString message,
31                        const utakata::exception::ExceptionInfo& info) :
32       Exception(exception, message, info) {}
33
34   virtual const char* what() const throw() {return "EndOfDeviceException";}
35 };
36
37 class IOException : public exception::Exception {
38   // reader::IReaderインターフェースの派生クラスにおいて、
39   // 入出力に対して発生する例外です。
40  public:
41   IOException(const unicode::UniString message,
42               const utakata::exception::ExceptionInfo& info) :
43       Exception(message, info) {}
44
45   IOException(const utakata::exception::Exception& exception,
46               const unicode::UniString message,
47               const utakata::exception::ExceptionInfo& info) :
48       Exception(exception, message, info) {}
49
50   virtual const char* what() const throw() {return "IOException";}
51 };
52
53 // IReader::Seekの方向を制御します。
54 enum SeekDirection {
55   kForward, kBackward,
56 };
57
58 class IReader {
59   // 各種デバイスから読み出しを行うためのインターフェースです。
60   // このインターフェースを実装したクラスは、すべてのインターフェース
61   // を実装する必要があります。
62  public:
63
64   virtual ~IReader() {}
65
66   // 各種デバイスから一文字読出します。
67   // 末尾に到達してなお読み出しが行われた場合、reader::EndOfDeviceException
68   // 例外を投げなければなりません。
69   // readでは、読み出し位置を更新します。
70   virtual unsigned int Read() = 0;
71   virtual std::vector<unsigned int> Read(size_t num) = 0;
72
73   // デバイスから1バイトの読出しを行いますが、内部の読み出し位置は変化
74   // しません。
75   // peekした後、readを行うと、全く同一のバイトが得られます。
76   virtual unsigned int Peek() = 0;
77   virtual std::vector<unsigned int> Peek(size_t num) = 0;
78
79   // 読出したバイト数を返します。
80   virtual unsigned int GetPos() const = 0;
81
82   // 現在位置から、指定された方向に指定された量だけ読み出し位置を進めます。
83   // 移動に成功したらtrueを返します。
84   virtual bool Seek(int seekpos, SeekDirection direciton) = 0;
85
86   // 現在位置から、指定された方向に指定された量だけ読み出し位置を進め、
87   // 実際に進めた量を返します。
88   // 移動に成功したらtrueを返します。
89   // seek_differenceには、有効なsize_tのポインタを渡す必要があります。
90   virtual bool Seek(int seekpos, SeekDirection direciton,
91                     size_t* seek_difference) = 0;
92
93   // 読み出し位置を先頭に戻します。
94   virtual void Begin() = 0;
95
96   // 読み出し対象のサイズを返します。
97   virtual unsigned int GetSize() const = 0;
98
99   // 読み出し位置が末尾であるかどうかを返します。
100   virtual bool IsEof() const = 0;
101 };
102 };
103 };
104
105 #endif /* __HOME_DERUI_DEVELOP_UTAKATA_SRC_READER_INTERFACE_H_ */