[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 | //è¤æ°é¨ä½ãããªãåºåç¨ã¹ããªã¼ã ã®ã¯ã©ã¹
|
---|
| 76 | class MultipartStream : public Event<ShutdownEvent>::Handler
|
---|
| 77 | {
|
---|
| 78 | public:
|
---|
| 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 |
|
---|
| 140 | protected:
|
---|
| 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 |
|
---|
| 150 | public:
|
---|
| 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 |
|
---|