source: anotherchoice/tags/jsp-1.4.4-full-UTF8/cfg/base/mpstrstream.h@ 26

Last change on this file since 26 was 26, checked in by ykominami, 12 years ago

initial

File size: 7.2 KB
RevLine 
[26]1/*
2 * TOPPERS/JSP Kernel
3 * Toyohashi Open Platform for Embedded Real-Time Systems/
4 * Just Standard Profile Kernel
5 *
6 * Copyright (C) 2003 by Embedded and Real-Time Systems Laboratory
7 * Toyohashi Univ. of Technology, JAPAN
8 *
9 * 上記著作権者
10は,以下の (1)〜(4) の条件か,Free Software Foundation
11 * によってå…
12¬è¡¨ã•ã‚Œã¦ã„ã‚‹ GNU General Public License の Version 2 に記
13 * 述されている条件を満たす場合に限り,本ソフトウェア(本ソフトウェア
14 * を改変したものを含む.以下同じ)を使用・複製・改変・再é…
15å¸ƒï¼ˆä»¥ä¸‹ï¼Œ
16 * 利用と呼ぶ)することを無償で許諾する.
17 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
18 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
19 * スコード中に含まれていること.
20 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
21 * 用できる形で再é…
22å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œå†é…
23å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨
24 * 者
25マニュアルなど)に,上記の著作権表示,この利用条件および下記
26 * の無保証規定を掲載すること.
27 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
28 * 用できない形で再é…
29å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œæ¬¡ã®ã„ずれかの条件を満たすこ
30 * と.
31 * (a) 再é…
32å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨è€…
33マニュアルなど)に,上記の著
34 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
35 * (b) 再é…
36å¸ƒã®å½¢æ…
37‹ã‚’,別に定める方法によって,TOPPERSプロジェクトに
38 * 報告すること.
39 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
40 * 害からも,上記著作権者
41およびTOPPERSプロジェクトをå…
42è²¬ã™ã‚‹ã“と.
43 *
44 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者
45お
46 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,その適用可能性も
47 * 含めて,いかなる保証も行わない.また,本ソフトウェアの利用により直
48 * 接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
49 *
50 * @(#) $Id: mpstrstream.h,v 1.9 2003/12/20 06:51:58 takayuki Exp $
51 */
52
53// $Header: /home/CVS/configurator/base/mpstrstream.h,v 1.9 2003/12/20 06:51:58 takayuki Exp $
54
55#ifndef MPSTRSTREAM_H
56#define MPSTRSTREAM_H
57
58#ifdef _MSC_VER
59# pragma warning(disable:4290) //C++ の例外の指定は無視されます。関数が __declspec(nothrow) でないことのみ表示されます。
60# pragma warning(disable:4786) //デバッグ情
61報で識別子が255文字に切り捨てられました。
62#endif
63
64#include "testsuite.h"
65#include "base/except.h"
66#include "base/message.h"
67#include "base/event.h"
68
69#include <fstream>
70#include <sstream>
71#include <string>
72#include <list>
73
74
75 //複数部位からなる出力用ストリームのクラス
76class MultipartStream : public Event<ShutdownEvent>::Handler
77{
78public:
79
80 //複数部位からなる出力用ストリームの一部位に相当するクラス
81 class Part
82 {
83 protected:
84 std::string name;
85 std::stringstream stream;
86
87 public:
88 //コンストラクタ
89 Part(std::string name) throw();
90 Part(const Part & src) throw();
91
92 //正当性判定
93 inline bool isValid(void) const throw()
94 { return (this != 0) && !name.empty() && stream.good(); }
95
96 //ストリームへの書込み
97 template<class T>
98 Part & operator << ( T src ) throw(Exception)
99 {
100 if(isValid())
101 stream << src;
102 else
103 ExceptionMessage("Operation was performed against an invalid stream.","無効なストリームに対して操作が行われました").throwException();
104
105 return *this;
106 }
107
108 //ストリームに書いた内
109容を受け取る
110 std::string getContents(void) const throw(Exception);
111
112 //ストリームの内
113容を直接設定する
114 void setContents(std::string contents) throw(Exception);
115
116 //ストリーム名の参ç…
117§
118 inline const std::string & getName(void) const throw(Exception)
119 {
120 if(!isValid())
121 ExceptionMessage("Operation was performed against an invalid stream.","無効なストリームに対して操作が行われました").throwException();
122 return name;
123 }
124
125 //代å…
126¥æ¼”算子
127 inline Part & operator = (const Part & src) throw()
128 {
129 name = src.name;
130 stream.clear();
131 stream << src.stream.str();
132
133 return *this;
134 }
135
136 TESTSUITE_PROTOTYPE(main)
137 };
138
139
140protected:
141 std::string filename; //関連付けられたファイル名
142 std::list<Part> parts; //部位集合(順序つき)
143 Part * current; //今見ている部位
144 bool dirty; //ファイルに出力する要あらばtrue (何か書き込んだら... ではなく、まだ出力してないかどうか)
145 bool output; //出力しても良いならtrue
146
147 virtual void handler(ShutdownEvent & evt)
148 { serialize(); }
149
150public:
151 //コンストラクタ
152 MultipartStream(std::string filename = "") throw();
153
154 //デストラクタ
155 virtual ~MultipartStream(void) throw();
156
157 //正当性判定
158 inline bool isValid(void) const throw()
159 { return (this != 0) && !filename.empty(); }
160
161 //ファイル名
162 std::string setFilename(std::string filename) throw(Exception);
163 std::string getFilename(void) const throw() { return filename; };
164
165 //ストリームの内
166容をファイルに出力
167 bool serialize(void) throw(Exception);
168
169 //部位の生成
170 MultipartStream & createPart(std::string name, bool precedence = false) throw(Exception);
171
172 //部位の選択
173 MultipartStream & movePart(std::string name) throw(Exception);
174
175 //出力するかどうかの設定
176 inline void enableOutput(void) throw()
177 { if(isValid()) output = true; }
178 inline void disableOutput(void) throw()
179 { if(isValid()) output = false; }
180
181 //ダーティビットの設定
182 inline void setDirty(bool _dirty = true) throw()
183 { dirty = _dirty; }
184
185 //出力
186 template <class T>
187 inline MultipartStream & operator << ( T src ) throw(Exception)
188 {
189 if(this != 0 && current != 0) {
190 setDirty();
191 (*current) << src;
192 }
193 else
194 ExceptionMessage("Invalid operation against an invalid object","無効なオブジェクトに対する要求").throwException();
195 return *this;
196 }
197
198 //部位の選択 (Synonym)
199 inline MultipartStream & operator[] (std::string name) throw(Exception)
200 { return movePart(name); }
201
202 TESTSUITE_PROTOTYPE(main)
203};
204
205#endif
206
207
Note: See TracBrowser for help on using the repository browser.