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

📄 propertybuffer.cpp

📁 天之炼狱1服务器端源文件游戏服务端不完整
💻 CPP
字号:
////////////////////////////////////////////////////////////////////////////////// Filename    : PropertyBuffer.cpp// Written By  : // Description : ////////////////////////////////////////////////////////////////////////////////#include "PropertyBuffer.h"#include "Utility.h"			// trim(), getline()////////////////////////////////////////////////////////////////////////////////// static constant variables////////////////////////////////////////////////////////////////////////////////const char PropertyBuffer::Comment = '#';const char PropertyBuffer::Separator = ':';const char PropertyBuffer::EOL = '\n';const char * PropertyBuffer::WhiteSpaces = " \t\n";const char * PropertyBuffer::SpaceTab = " \t";	////////////////////////////////////////////////////////////////////////////////// constructor////////////////////////////////////////////////////////////////////////////////PropertyBuffer::PropertyBuffer (const string & buffer) 	throw (){	m_Index  = 0;	m_Buffer = buffer;}	////////////////////////////////////////////////////////////////////////////////// destructor////////////////////////////////////////////////////////////////////////////////PropertyBuffer::~PropertyBuffer () 	throw (){}string PropertyBuffer::getProperty (string key)	    throw (NoSuchElementException , Error){	__BEGIN_TRY	uint bufferLen = m_Buffer.size();	while (m_Index < bufferLen)	{		string line = trim(getline(m_Buffer , m_Index));		// 后 扼牢 肚绰 内膏飘 扼牢捞 酒囱 版快		if (line.size() != 0 && line[0] != Comment)		{			uint i = line.find(Separator);			if (i == string::npos)			{				throw Error("missing separator");			}			string paramName  = trim(line.substr(0 , i - 1));			if (paramName == key)			{				return trim(line.substr(i + 1));			}			else			{				throw NoSuchElementException(key);			}		}	}	cout << "PropertyBuffer::getProperty() : thers is no [" << key << "] element." << endl;	throw NoSuchElementException(key);	__END_CATCH}int PropertyBuffer::getPropertyInt (string key)	    throw (NoSuchElementException , Error){	__BEGIN_TRY	return atoi(getProperty(key).c_str());	__END_CATCH}bool PropertyBuffer::getProperty (string key, string& value)	throw (NoSuchElementException , Error){	__BEGIN_TRY	uint bufferLen = m_Buffer.size();    while (m_Index < bufferLen)    {        string line = trim(getline(m_Buffer , m_Index));        // 后 扼牢 肚绰 内膏飘 扼牢捞 酒囱 版快        if (line.size() != 0 && line[0] != Comment)        {            uint i = line.find(Separator);            if (i == string::npos)            {				return false;            }            string paramName  = trim(line.substr(0 , i - 1));            if (paramName == key)            {            	value = trim(line.substr(i + 1));				return true;            }            else            {				return false;            }        }    }	return false;	__END_CATCH}bool PropertyBuffer::getPropertyInt (string key, int& value)	throw (NoSuchElementException , Error){	__BEGIN_TRY	string rstring;		if (getProperty(key, rstring))	{		value = atoi(rstring.c_str());		return true;	}	return false;	__END_CATCH}////////////////////////////////////////////////////////////////////////////////// get debug string////////////////////////////////////////////////////////////////////////////////string PropertyBuffer::toString () const 	throw (){	__BEGIN_TRY	StringStream msg;	msg << "PropertyBuffer("			<< "Index:"   << m_Index			<< ",Buffer:" << m_Buffer			<< ")";	return msg.toString();		__END_CATCH}

⌨️ 快捷键说明

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