OSDN Git Service

・textarrayformat.*をsrc/commonに移動した。
[simplecms/utakata.git] / src / common / textarrayformat.h
1 // テキスト処理を行うテストのデバッグ用途に利用される、
2 // 簡単なテキストフォーマットであるTextArrayFormatの実装を提供します。
3 // TextArrayFormatは、TextArrayGeneratorにて文字列からの生成を行い
4 // TextArrayReaderによって、テキストブロックを取得することができます。
5 // 
6 // これらは柔軟に行うことができるため、テキストを扱うテストデータを
7 // 複数作成したい場合に有用です。
8 #ifndef _UTAKATA_SRC_COMMON_TEXTARRAYFORMAT_H_
9 #define _UTAKATA_SRC_COMMON_TEXTARRAYFORMAT_H_
10
11 #include <string>
12 #include <vector>
13 #include <exception>
14
15 namespace utility {
16
17 namespace textarrayformat {
18
19 class OutOfIndexException : public std::exception
20 {
21  public:
22   OutOfIndexException(const std::string& str);
23   virtual ~OutOfIndexException() throw() {}
24
25   virtual const char* what() const throw();
26
27  private:
28   const std::string str_;
29 };
30
31 class TextArrayReader
32 {
33  public:
34
35   explicit TextArrayReader(const TextArrayGenerator& is);
36   virtual ~TextArrayReader() {}
37
38   // 指定したストリームの先頭からフォーマットに従ってブロック単位
39   // への切り出しを行う。
40   // この関数が成功した場合、以前のブロックなどは保存されない。
41   void open(std::istream& is);
42
43   // 指定したブロックを取得する。
44   // 番号を指定しない場合には、最初に取得したブロックが取得される。
45   std::string get(int = 0);
46
47   // ブロックのリストを取得する。
48   const std::vector<std::string>& getBlock() const {return blocks_;}
49
50  private:
51
52   // ファイル中のスプリッタを行ごと退避する。
53   std::string splitter_;
54
55   // テキストのブロックを退避しておくリスト
56   std::vector<std::string> blocks_;
57 };
58
59 };
60 }; // end of namespace utility
61
62 #endif /* _C:_MEADOW_DEVELOP_UTAKATA_SRC_COMMON_TEXTARRAYFORMAT_H_ */