📄 mpstrstream.h
字号:
/*
* TOPPERS/JSP Kernel
* Toyohashi Open Platform for Embedded Real-Time Systems/
* Just Standard Profile Kernel
*
* Copyright (C) 2003 by Embedded and Real-Time Systems Laboratory
* Toyohashi Univ. of Technology, JAPAN
*
* 忋婰挊嶌尃幰偼丆埲壓偺 (1)乣(4) 偺忦審偐丆Free Software Foundation
* 偵傛偭偰岞昞偝傟偰偄傞 GNU General Public License 偺 Version 2 偵婰
* 弎偝傟偰偄傞忦審傪枮偨偡応崌偵尷傝丆杮僜僼僩僂僃傾乮杮僜僼僩僂僃傾
* 傪夵曄偟偨傕偺傪娷傓丏埲壓摨偠乯傪巊梡丒暋惢丒夵曄丒嵞攝晍乮埲壓丆
* 棙梡偲屇傇乯偡傞偙偲傪柍彏偱嫋戻偡傞丏
* (1) 杮僜僼僩僂僃傾傪僜乕僗僐乕僪偺宍偱棙梡偡傞応崌偵偼丆忋婰偺挊嶌
* 尃昞帵丆偙偺棙梡忦審偍傛傃壓婰偺柍曐徹婯掕偑丆偦偺傑傑偺宍偱僜乕
* 僗僐乕僪拞偵娷傑傟偰偄傞偙偲丏
* (2) 杮僜僼僩僂僃傾傪丆儔僀僽儔儕宍幃側偳丆懠偺僜僼僩僂僃傾奐敪偵巊
* 梡偱偒傞宍偱嵞攝晍偡傞応崌偵偼丆嵞攝晍偵敽偆僪僉儏儊儞僩乮棙梡
* 幰儅僯儏傾儖側偳乯偵丆忋婰偺挊嶌尃昞帵丆偙偺棙梡忦審偍傛傃壓婰
* 偺柍曐徹婯掕傪宖嵹偡傞偙偲丏
* (3) 杮僜僼僩僂僃傾傪丆婡婍偵慻傒崬傓側偳丆懠偺僜僼僩僂僃傾奐敪偵巊
* 梡偱偒側偄宍偱嵞攝晍偡傞応崌偵偼丆師偺偄偢傟偐偺忦審傪枮偨偡偙
* 偲丏
* (a) 嵞攝晍偵敽偆僪僉儏儊儞僩乮棙梡幰儅僯儏傾儖側偳乯偵丆忋婰偺挊
* 嶌尃昞帵丆偙偺棙梡忦審偍傛傃壓婰偺柍曐徹婯掕傪宖嵹偡傞偙偲丏
* (b) 嵞攝晍偺宍懺傪丆暿偵掕傔傞曽朄偵傛偭偰丆TOPPERS僾儘僕僃僋僩偵
* 曬崘偡傞偙偲丏
* (4) 杮僜僼僩僂僃傾偺棙梡偵傛傝捈愙揑傑偨偼娫愙揑偵惗偠傞偄偐側傞懝
* 奞偐傜傕丆忋婰挊嶌尃幰偍傛傃TOPPERS僾儘僕僃僋僩傪柶愑偡傞偙偲丏
*
* 杮僜僼僩僂僃傾偼丆柍曐徹偱採嫙偝傟偰偄傞傕偺偱偁傞丏忋婰挊嶌尃幰偍
* 傛傃TOPPERS僾儘僕僃僋僩偼丆杮僜僼僩僂僃傾偵娭偟偰丆偦偺揔梡壜擻惈傕
* 娷傔偰丆偄偐側傞曐徹傕峴傢側偄丏傑偨丆杮僜僼僩僂僃傾偺棙梡偵傛傝捈
* 愙揑傑偨偼娫愙揑偵惗偠偨偄偐側傞懝奞偵娭偟偰傕丆偦偺愑擟傪晧傢側偄丏
*
* @(#) $Id: mpstrstream.h,v 1.1 2006/04/14 02:46:06 9564907 Exp $
*/
// $Header: J:\\SapporoSoft\\usb20\\S1R72V05\\Debug\\Repository/S1R72V05_Toppers/Toppers/cfg/base/mpstrstream.h,v 1.1 2006/04/14 02:46:06 9564907 Exp $
#ifndef MPSTRSTREAM_H
#define MPSTRSTREAM_H
#ifdef _MSC_VER
# pragma warning(disable:4290) //C++ 偺椺奜偺巜掕偼柍帇偝傟傑偡丅娭悢偑 __declspec(nothrow) 偱側偄偙偲偺傒昞帵偝傟傑偡丅
# pragma warning(disable:4786) //僨僶僢僌忣曬偱幆暿巕偑255暥帤偵愗傝幪偰傜傟傑偟偨丅
#endif
#include "testsuite.h"
#include "base/except.h"
#include "base/message.h"
#include "base/event.h"
#include <fstream>
#include <sstream>
#include <string>
#include <list>
//暋悢晹埵偐傜側傞弌椡梡僗僩儕乕儉偺僋儔僗
class MultipartStream : public Event<ShutdownEvent>::Handler
{
public:
//暋悢晹埵偐傜側傞弌椡梡僗僩儕乕儉偺堦晹埵偵憡摉偡傞僋儔僗
class Part
{
protected:
std::string name;
std::stringstream stream;
public:
//僐儞僗僩儔僋僞
Part(std::string name) throw();
Part(const Part & src) throw();
//惓摉惈敾掕
inline bool isValid(void) const throw()
{ return (this != 0) && !name.empty() && stream.good(); }
//僗僩儕乕儉傊偺彂崬傒
template<class T>
Part & operator << ( T src ) throw(Exception)
{
if(isValid())
stream << src;
else
ExceptionMessage("Operation was performed against an invalid stream.","柍岠側僗僩儕乕儉偵懳偟偰憖嶌偑峴傢傟傑偟偨").throwException();
return *this;
}
//僗僩儕乕儉偵彂偄偨撪梕傪庴偗庢傞
std::string getContents(void) const throw(Exception);
//僗僩儕乕儉偺撪梕傪捈愙愝掕偡傞
void setContents(std::string contents) throw(Exception);
//僗僩儕乕儉柤偺嶲徠
inline const std::string & getName(void) const throw(Exception)
{
if(!isValid())
ExceptionMessage("Operation was performed against an invalid stream.","柍岠側僗僩儕乕儉偵懳偟偰憖嶌偑峴傢傟傑偟偨").throwException();
return name;
}
//戙擖墘嶼巕
inline Part & operator = (const Part & src) throw()
{
name = src.name;
stream.clear();
stream << src.stream.str();
return *this;
}
TESTSUITE_PROTOTYPE(main)
};
protected:
std::string filename; //娭楢晅偗傜傟偨僼傽僀儖柤
std::list<Part> parts; //晹埵廤崌(弴彉偮偒)
Part * current; //崱尒偰偄傞晹埵
bool dirty; //僼傽僀儖偵弌椡偡傞梫偁傜偽true (壗偐彂偒崬傫偩傜... 偱偼側偔丄傑偩弌椡偟偰側偄偐偳偆偐)
bool output; //弌椡偟偰傕椙偄側傜true
virtual void handler(ShutdownEvent & evt)
{ serialize(); }
public:
//僐儞僗僩儔僋僞
MultipartStream(std::string filename = "") throw();
//僨僗僩儔僋僞
virtual ~MultipartStream(void) throw();
//惓摉惈敾掕
inline bool isValid(void) const throw()
{ return (this != 0) && !filename.empty(); }
//僼傽僀儖柤
std::string setFilename(std::string filename) throw(Exception);
std::string getFilename(void) const throw() { return filename; };
//僗僩儕乕儉偺撪梕傪僼傽僀儖偵弌椡
bool serialize(void) throw(Exception);
//晹埵偺惗惉
MultipartStream & createPart(std::string name, bool precedence = false) throw(Exception);
//晹埵偺慖戰
MultipartStream & movePart(std::string name) throw(Exception);
//弌椡偡傞偐偳偆偐偺愝掕
inline void enableOutput(void) throw()
{ if(isValid()) output = true; }
inline void disableOutput(void) throw()
{ if(isValid()) output = false; }
//僟乕僥傿價僢僩偺愝掕
inline void setDirty(bool _dirty = true) throw()
{ dirty = _dirty; }
//弌椡
template <class T>
inline MultipartStream & operator << ( T src ) throw(Exception)
{
if(this != 0 && current != 0) {
setDirty();
(*current) << src;
}
else
ExceptionMessage("Invalid operation against an invalid object","柍岠側僆僽僕僃僋僩偵懳偡傞梫媮").throwException();
return *this;
}
//晹埵偺慖戰 (Synonym)
inline MultipartStream & operator[] (std::string name) throw(Exception)
{ return movePart(name); }
TESTSUITE_PROTOTYPE(main)
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -