OSDN Git Service

s
[simplecms/utakata.git] / textarrayformat.h
1 #ifndef _TEXTARRAYFORMAT_H_
2 #define _TEXTARRAYFORMAT_H_
3
4 #include <iostream>
5 #include <string>
6 #include <vector>
7 #include <exception>
8
9
10 namespace textarrayformat {
11
12     class OutOfIndexException : public std::exception
13     {
14     public:
15         OutOfIndexException(const std::string& str);
16         virtual ~OutOfIndexException() throw() {}
17
18         virtual const char* what() const throw();
19
20     private:
21         const std::string str_;
22     };
23
24     class TextArrayReader
25     {
26     public:
27
28         TextArrayReader(std::istream& is);
29         virtual ~TextArrayReader() {}
30
31         // 指定したストリームの先頭からフォーマットに従ってブロック単位
32         // への切り出しを行う。
33         // この関数が成功した場合、以前のブロックなどは保存されない。
34         void open(std::istream& is);
35
36         // 指定したブロックを取得する。
37         // 番号を指定しない場合には、最初に取得したブロックが取得される。
38         std::string get(int = 0);
39
40         // ブロックのリストを取得する。
41         const std::vector<std::string>& getBlock() const {return blocks_;}
42
43     private:
44
45         // ファイル中のスプリッタを行ごと退避する。
46         std::string splitter_;
47
48         // テキストのブロックを退避しておくリスト
49         std::vector<std::string> blocks_;
50     };
51
52 };
53
54 #endif /* _TEXTARRAYFORMAT_H_ */