⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mpstrstream.cpp

📁 JAPAN RTOS TOPPERS/JSP kernel 1.4 PreRelease simulation environment JSP kernel Windows simulation
💻 CPP
字号:
/*
 *  TOPPERS/JSP Kernel
 *      Toyohashi Open Platform for Embedded Real-Time Systems/
 *      Just Standard Profile Kernel
 * 
 *  Copyright (C) 2000-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.cpp,v 1.6 2003/06/30 12:50:32 takayuki Exp $
 */


// $Header: /home/CVS/configurator/base/mpstrstream.cpp,v 1.6 2003/06/30 12:50:32 takayuki Exp $

#ifdef _MSC_VER
	#pragma warning(push)
	#pragma warning(disable:4786)
	#pragma warning(disable:4290)
#endif

#include "base/mpstrstream.h"
#include <stdarg.h>

using namespace std;

typedef std::list<struct mpstrstream::tagStreamPartInfo *> List;

list<struct mpstrstream::tagStreamPartInfo *>::iterator mpstrstream::findpart(const char * partname) const
{
	List::const_iterator scope;

	scope = container.begin();
	while(scope != container.end())
	{
		if((*scope)->name.compare(partname) == 0)
			break;
		++ scope;
	}
	return *reinterpret_cast<List::iterator *>(&scope);
}

mpstrstream::~mpstrstream(void)
{
	if(fileoutput && !filename.empty())
	{
			/* 偙偙偱serialize()傪屇傇偲丄拞偱椺奜偑婲偙偭偨応崌偵丄屻懕偡傞僷乕僩偺攋婞偑峴傢傟側偄 */
		fstream file(filename.c_str(), ios::out);

		if(file.is_open())
		{
			serialize(file);
			file.close();
		}
	}

	while(!container.empty())
	{
		delete *(container.begin());
		container.pop_front();
	}
}

stringstream & mpstrstream::moveto(const char * partname) throw(Exception)
{
	List::iterator scope;

	scope = container.begin();
	while(scope != container.end())
	{
		if((*scope)->name.compare(partname) == 0)
		{
			current = scope;
			return (*current)->stream;
		}
		++ scope;
	}

	ExceptionMessage("mpstrstream : There is no part named [%].","mpstrstream : [%]側傞僷乕僩柤偼懚嵼偟側偄") << partname << throwException;
	return (*current)->stream;	//Never reachable
}

stringstream & mpstrstream::moveto(unsigned int pos)
{
	List::iterator scope;

	scope = container.begin();
	while(pos -- > 0)
		++ scope;

	current = scope;
	return (*current)->stream;
}

stringstream & mpstrstream::moveto(enum tagPosition pos)
{
	switch(pos)
	{
	case BEGIN:
		current = container.begin();
		break;
	case END:
		current = container.end();
		break;
	}
	return (*current)->stream;
}

stringstream & mpstrstream::createpart(const char * partname, const char * second, ... )
{
	struct tagStreamPartInfo * info;
	va_list vl;

	va_start(vl, second);
	vl = (char *)vl - sizeof(const char *);

	while(partname != 0)
	{
		info = new struct tagStreamPartInfo;
		info->name.assign(partname);
		info->flags = DEFAULT;
		container.insert(current, info);

		partname = va_arg(vl, const char *);
	}

	return (*current)->stream;
}

stringstream & mpstrstream::insertpart(const char * partname, const char * successor) throw(Exception)
{
	struct tagStreamPartInfo * info;
	List::iterator scope;

	scope = container.end();
	if(successor != 0)
		if((scope = findpart(successor)) == container.end())
			ExceptionMessage("Stream does not have the part (%).","僗僩儕乕儉偼嬫夋(%)傪帩偪傑偣傫") << successor << throwException;

	info = new struct tagStreamPartInfo;
	info->name.assign(partname);
	info->flags = DEFAULT;
	current = container.insert(scope, info);
	
	return (*current)->stream;
}

void mpstrstream::erasepart(const char * partname)
{
	List::iterator scope;

	if((scope = findpart(partname)) == container.end())
		return;

	if(scope == container.begin())
		current = ++ container.begin();
	else
	{
		current = scope;
		-- current;
	}

	delete (*scope);
	container.erase(scope);
}

void mpstrstream::movepart(const char * partname, const char * successor) throw(Exception)
{
	List::iterator src;
	List::iterator dest;

	if((src = findpart(partname)) == container.end())
		ExceptionMessage("Stream dones not have the part (%).","僗僩儕乕儉偼嬫夋(%)傪帩偪傑偣傫") << partname << throwException;
	if(successor != 0)
	{
		if((dest = findpart(successor)) == container.end())
			ExceptionMessage("Stream dones not have the part (%).","僗僩儕乕儉偼嬫夋(%)傪帩偪傑偣傫") << successor << throwException;
	}else
		dest = container.end();

	current = container.insert(dest, (*src));
	container.erase(src);
}

void mpstrstream::serialize(void) throw(Exception)
{
	fstream file(filename.c_str(), ios::out);

	if(!file.is_open())
		ExceptionMessage("File creation failure of %","僼傽僀儖(%)偑嶌傟傑偣傫") << filename << throwException;

	serialize(file);

	file.close();
}

ostream & mpstrstream::serialize(ostream & out)
{
	string buffer;
	List::iterator scope;

	scope = container.begin();
	while(scope != container.end())
	{
		if(((*scope)->flags & NO_SERIALIZE) == 0)
		{
			buffer = (*scope)->stream.str();
			out.write(buffer.c_str(), buffer.size());
		}
		++ scope;
	}

	return out;
}

int mpstrstream::setf(int flag)
{
	int old_flag;
	if(current == container.end())
		return -1;

	old_flag = (*current)->flags;
	(*current)->flags = flag;

	return old_flag;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -