本文整理汇总了C++中StringStream类的典型用法代码示例。如果您正苦于以下问题:C++ StringStream类的具体用法?C++ StringStream怎么用?C++ StringStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StringStream类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: r
Exec::Variable Exec::eval(const String &value) {
CharReaderBase r(value);
if (r.is('$')) {
++ r;
return getVariable(r);
} else if (r.is<Group<GroupId::Numbers>>()) {
auto tmp = r;
r.skipUntil<Chars<'e', 'E', '.'>>();
if (!r.empty()) {
return Variable{new data::Value(tmp.readFloat())};
} else {
return Variable{new data::Value(tmp.readInteger())};
}
} else if (r.is('\'')) {
++ r;
StringStream str;
while (!r.empty() && !r.is('\'')) {
str << r.readUntil<Chars<'\'', '\\'>>();
if (r.is('\\')) {
++ r;
if (r.is('r')) {
str << "\r";
} else if (r.is('n')) {
str << "\n";
} else if (r.is('t')) {
str << "\t";
} else {
str << r.front();
}
++ r;
}
}
return Variable{new data::Value(str.str())};
} else if (r.is('"')) {
++ r;
StringStream str;
while (!r.empty() && !r.is('"')) {
str << r.readUntil<Chars<'"', '\\'>>();
if (r.is('\\')) {
++ r;
if (r.is('r')) {
str << "\r";
} else if (r.is('n')) {
str << "\n";
} else if (r.is('t')) {
str << "\t";
} else {
str << r.front();
}
++ r;
}
}
return Variable{new data::Value(str.str())};
} else {
if (r.is("true")) {
return Variable{new data::Value(true)};
} else if (r.is("false")) {
return Variable{new data::Value(false)};
} else if (r.is("null")) {
return Variable{new data::Value()};
} else if (r.is("inf")) {
return Variable{new data::Value(std::numeric_limits<double>::infinity())};
} else if (r.is("nan")) {
return Variable{new data::Value(nan())};
}
}
return Variable();
}
示例2: OGRE_EXCEPT
void GLFrameBufferObject::initialise()
{
// Release depth and stencil, if they were bound
mManager->releaseRenderBuffer(mDepth);
mManager->releaseRenderBuffer(mStencil);
mManager->releaseRenderBuffer(mMultisampleColourBuffer);
/// First buffer must be bound
if(!mColour[0].buffer)
{
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
"Attachment 0 must have surface attached",
"GLFrameBufferObject::initialise");
}
// If we're doing multisampling, then we need another FBO which contains a
// renderbuffer which is set up to multisample, and we'll blit it to the final
// FBO afterwards to perform the multisample resolve. In that case, the
// mMultisampleFB is bound during rendering and is the one with a depth/stencil
/// Store basic stats
size_t width = mColour[0].buffer->getWidth();
size_t height = mColour[0].buffer->getHeight();
GLuint format = mColour[0].buffer->getGLFormat();
PixelFormat ogreFormat = mColour[0].buffer->getFormat();
// Bind simple buffer to add colour attachments
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mFB);
/// Bind all attachment points to frame buffer
for(size_t x=0; x<OGRE_MAX_MULTIPLE_RENDER_TARGETS; ++x)
{
if(mColour[x].buffer)
{
if(mColour[x].buffer->getWidth() != width || mColour[x].buffer->getHeight() != height)
{
StringStream ss;
ss << "Attachment " << x << " has incompatible size ";
ss << mColour[x].buffer->getWidth() << "x" << mColour[x].buffer->getHeight();
ss << ". It must be of the same as the size of surface 0, ";
ss << width << "x" << height;
ss << ".";
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, ss.str(), "GLFrameBufferObject::initialise");
}
if(mColour[x].buffer->getGLFormat() != format)
{
StringStream ss;
ss << "Attachment " << x << " has incompatible format.";
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, ss.str(), "GLFrameBufferObject::initialise");
}
mColour[x].buffer->bindToFramebuffer(GL_COLOR_ATTACHMENT0_EXT+x, mColour[x].zoffset);
}
else
{
// Detach
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT+x,
GL_RENDERBUFFER_EXT, 0);
}
}
// Now deal with depth / stencil
if (mMultisampleFB)
{
// Bind multisample buffer
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mMultisampleFB);
// Create AA render buffer (colour)
// note, this can be shared too because we blit it to the final FBO
// right after the render is finished
mMultisampleColourBuffer = mManager->requestRenderBuffer(format, width, height, mNumSamples);
// Attach it, because we won't be attaching below and non-multisample has
// actually been attached to other FBO
mMultisampleColourBuffer.buffer->bindToFramebuffer(GL_COLOR_ATTACHMENT0_EXT,
mMultisampleColourBuffer.zoffset);
// depth & stencil will be dealt with below
}
/// Find suitable depth and stencil format that is compatible with colour format
GLenum depthFormat, stencilFormat;
mManager->getBestDepthStencil(ogreFormat, &depthFormat, &stencilFormat);
/// Request surfaces
mDepth = mManager->requestRenderBuffer(depthFormat, width, height, mNumSamples);
if (depthFormat == GL_DEPTH24_STENCIL8_EXT)
{
// bind same buffer to depth and stencil attachments
mManager->requestRenderBuffer(mDepth);
mStencil = mDepth;
}
else
{
// separate stencil
mStencil = mManager->requestRenderBuffer(stencilFormat, width, height, mNumSamples);
}
/// Attach/detach surfaces
if(mDepth.buffer)
{
//.........这里部分代码省略.........
示例3: throw
//.........这里部分代码省略.........
LCRegisterPlayerOK lcRegisterPlayerOK;
lcRegisterPlayerOK.setGroupName(g_pGameServerGroupInfoManager->getGameServerGroupInfo(ServerGroupID, WorldID)->getGroupName());
string SSN = pPacket->getSSN();
string preSSN;
bool isChina = false;
// 한국
if (strstr(SSN.c_str(), "-") != NULL )
{
preSSN = SSN.substr(0, 6);
}
// 중국
else
{
isChina = true;
if (SSN.size() == 15)
{
preSSN = SSN.substr(6, 12);
}
else if (SSN.size() == 18)
{
preSSN = SSN.substr(8, 14);
}
else
{
// 이런 경우는 없다고 하지만 -_- 머 암튼
preSSN = SSN.substr(0, 6);
}
}
// string preSSN = pPacket->getSSN().substr(0, 6).c_str();
StringStream AdultSSN;
time_t daytime = time(0);
tm Timec;
localtime_r(&daytime, &Timec);
AdultSSN << Timec.tm_year - 20 << Timec.tm_mon << Timec.tm_mday;
// 성인인지 아닌지 주민등록 번호 체크
if (atoi(preSSN.c_str()) <= atoi(AdultSSN.toString().c_str())) {
lcRegisterPlayerOK.setAdult(true);
} else {
lcRegisterPlayerOK.setAdult(false);
}
// 중국이면 무조건 성인
if (isChina )
{
lcRegisterPlayerOK.setAdult(true);
}
pLoginPlayer->sendPacket(&lcRegisterPlayerOK);
// 이름을 변경해줘야 한다.
pLoginPlayer->setID(pPacket->getID());
// 등록에 성공했을 경우, CLGetPCList 패킷을 기다린다.
pLoginPlayer->setPlayerStatus(LPS_WAITING_FOR_CL_GET_PC_LIST);
SAFE_DELETE(pStmt);
}
catch (DuplicatedException & de)
{
SAFE_DELETE(pStmt);
示例4: throw
void EventMorph::activate ()
throw(Error)
{
__BEGIN_TRY
__BEGIN_DEBUG
Assert(m_pGamePlayer != NULL);
Creature* pFromCreature = m_pGamePlayer->getCreature();
Assert(pFromCreature->isSlayer());
if (m_pGamePlayer->getPlayerStatus() != GPS_NORMAL)
{
// 플레이어의 상태가 WAITING_FOR_CG_READY인데, morph가
// activate되어 밑의 존에서 크리쳐를 지우는 부분에서 에러가 throw되어
// 서버가 죽는 버그가 있었다. 정확히 어떻게 해서 CG_READY상태에서
// 이벤트가 activate되는지는 모르겠으나, GamePlayer의
// EventManager 자체를 GPS_NORMAL일 때만 돌아가게 하면,
// Resurrect가 되지 않으니 주의하길 바란다. 결국 GamePlayer 내부에서
// 체크를 하기가 곤란하기 때문에 이 부분에서, 처리한다.
StringStream msg;
msg << "EventMorph::activate() : GamePlayer의 상태가 GPS_NORMAL이 아닙니다."
<< "PlayerID[" << m_pGamePlayer->getID() << "]"
<< "CreatureName[" << pFromCreature->getName() << "]";
filelog("EventMorphError.log", "%s", msg.toString().c_str());
return;
}
pFromCreature->removeFlag(Effect::EFFECT_CLASS_BLOOD_DRAIN);
Zone* pZone = pFromCreature->getZone();
// 만일 Restore 이펙트가 걸려있다면 변신이 되지 않는다.
if (pFromCreature->isFlag(Effect::EFFECT_CLASS_RESTORE))
{
return;
}
dropRelicToZone(pFromCreature);
dropFlagToZone(pFromCreature);
dropSweeperToZone(pFromCreature);
//////////////////////////////////////////////////////////////////////
// 각종 존 레벨 정보를 삭제해야 한다.
//////////////////////////////////////////////////////////////////////
// 파티 초대 중이라면 정보를 삭제해 준다.
PartyInviteInfoManager* pPIIM = pZone->getPartyInviteInfoManager();
Assert(pPIIM != NULL);
pPIIM->cancelInvite(pFromCreature);
// 파티 관련 정보를 삭제해 준다.
uint PartyID = pFromCreature->getPartyID();
if (PartyID != 0)
{
// 먼저 로컬에서 삭제하고...
LocalPartyManager* pLPM = pZone->getLocalPartyManager();
Assert(pLPM != NULL);
pLPM->deletePartyMember(PartyID, pFromCreature);
// 글로벌에서도 삭제해 준다.
deleteAllPartyInfo(pFromCreature);
}
// 트레이드 중이었다면 트레이드 관련 정보를 삭제해준다.
TradeManager* pTM = pZone->getTradeManager();
Assert(pTM != NULL);
pTM->cancelTrade(pFromCreature);
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
Vampire* pVampire = new Vampire();
GCMorph1 gcEventMorph1; // 변신 당사자에게..
GCMorphVampire2 gcEventMorphVampire2; // 변신 구경꾼들에게..
pVampire->setName(pFromCreature->getName());
ObjectID_t fromObjectID = pFromCreature->getObjectID();
pVampire->setObjectID(fromObjectID);
Player* pPlayer = pFromCreature->getPlayer();
dynamic_cast<GamePlayer*>(pPlayer)->setCreature(pVampire);
pVampire->setPlayer(pPlayer);
pVampire->setZone(pZone);
pVampire->load();
Coord_t x = pFromCreature->getX(), y = pFromCreature->getY();
Dir_t dir = pFromCreature->getDir();
pVampire->setXYDir(x, y, dir);
pVampire->setMoveMode(pFromCreature->getMoveMode());
// slayer to vampire
Slayer* pSlayer = dynamic_cast<Slayer*>(pFromCreature);
// 뱀파이어로 변신할때 Creature Pointer가 달라지므로...
// 원래 등록 되어있던 포인터는 개가 된다...
// 따라서 새로운 Creature Pointer를 등록해줘야 한다.
g_pPCFinder->deleteCreature(pFromCreature->getName());
//.........这里部分代码省略.........
示例5: replaceGlobalFunctions
/*
* Scaning all text
* Skip the "string"
* Why do finds the function name:
* function call:
* foo(arg1, arg2, ...)
* a = foo(arg1, arg2, ...)
* when function send to other function
* trycall(foo)
* ---------------------
* therefore function name is near '(' and ')'
*/
ptrdiff_t replaceGlobalFunctions(const char *szFileName, FakeFunctions &globalFunctions,
const StringList &excludeFunctions)
{
if (!szFileName || !szFileName[0])
return 0;
FILE *file = fopen(szFileName, "rt");
if (!file)
return 0;
fseek(file, 0, SEEK_END);
int size = ftell(file);
rewind(file);
char *pDataInSource = new char[size + 20]; // + 20 for additional 10_"data"_10
memset(pDataInSource, 0, 10);
char *pDataIn = pDataInSource + 10; // for delete/clear data
size_t realSize = fread(pDataIn, 1, size, file);
memset(pDataIn + realSize, 0, 10);
fclose(file);
StringStream stream;
char *p = pDataIn;
while (*p) {
if (isStringStart(p)) {
size_t size = skipStringAndMove(&p, NULL);
stream.write(p - size, size);
continue;
}
if (!strncmp(p, "tostring", sizeof("tostring") - 1))
*p = *p;
char *pStart = p;
while (isAlphaFun(*p)) {
++p;
}
size_t wordSize = p - pStart;
if (wordSize) {
if (isFunctionNameInCode(pStart, p)) {
std::string str(pStart, wordSize);
StringMapConstIter iter = globalFunctions.find(str);
if (iter != globalFunctions.end()) {
StringListConstIter IterFunExclude = std::find(excludeFunctions.begin(), excludeFunctions.end(), str);
if (IterFunExclude == excludeFunctions.end()) {
// replace
stream.write(iter->second.c_str(), FAKE_FUNCTION_LEN);
continue;
}
}
}
stream.write(pStart, wordSize);
if (!p[0]) {
break;
}
}
stream << *p;
++p;
}
file = fopen(szFileName, "wt");
const std::string& str = stream.str();
size_t obfuscateSize = str.length();
if (file) {
fwrite(str.c_str(), 1, obfuscateSize, file);
fclose(file);
}
delete[] pDataInSource;
print("%8d %s\n", obfuscateSize - realSize, szFileName);
return obfuscateSize - realSize;
}
示例6: obfuscateLocalVarsInBlock
/*
* Recurcive function
* Obfuscated all local variables in code
* Example:
* local varName = 123
* local abrakadabra = 123
*/
ptrdiff_t LuaObfuscator::obfuscateLocalVarsAndParameters(const char *szLuaCode, StringStream &obfuscatedLuaCode) {
LocalVarsStack localVarsStackBlock;
LocalVarsStack localModuleVars;
int level = 0;
char *p = const_cast<char*>(szLuaCode);
obfuscatedLuaCode.str("");
obfuscateLocalVarsInBlock(obfuscatedLuaCode, p, localVarsStackBlock, localModuleVars, level);
return obfuscatedLuaCode.str().size() - strlen(szLuaCode);
/* StringStream &stream = obfuscatedLuaCode;
stream.str("");
while (*p) {
if (isStringStart(p)) {
size_t size = skipStringAndMove(&p, NULL);
stream.write(p - size, size);
continue;
}
const int FUNCTION_LEN = sizeof("function") - 1;
if (*((unsigned long*)p) == 0x636E7566) { // 'cnuf' backview 'func'
if (!strncmp(p, "function", FUNCTION_LEN) && !isalnum(*(p + FUNCTION_LEN)))
{
//if (p > szLuaCode && !isalnum(*(p + FUNCTION_LEN))) {
char *pFunStart = p;
char *pFunEnd = p + FUNCTION_LEN;
char *pFunNameStart = pFunEnd;
stream << "function";
if (isSpace(*pFunNameStart)) {
++pFunNameStart;
stream << " ";
}
p = pFunNameStart;
// find function name
while (*p && *p != '(')
++p;
size_t nameSize = p - pFunNameStart;
//if (pFunEnd == p - 1 )
// continue;
if (*p != '(') {
print("Syntax error. '(' not found near \"function\"\n");
return -1;
}
if (nameSize)
stream.write(pFunNameStart, nameSize);
stream << "(";
++p;
LocalVars vars;
char *pParamStart = p; // + Formal parameters space
p = readAndObfuscateFunctionArguments(pParamStart, vars, stream);
//char *pBodyEnd = findFunctionEnd(p);
//p = obfuscateLocalVars(pParamStart, pBodyEnd, stream);
p = obfuscateLocalVarsInBlock(p, vars, stream);
//p = pBodyEnd + 1;
continue;
//}
}
}
stream << *p;
++p;
}
return stream.str().size() - strlen(szLuaCode);
*/
}
示例7: DoGetMySqlConnection
EErrorType CDatabaseStatementMySql::DoInitialise()
{
DatabaseConnectionMySqlSPtr connection = DoGetMySqlConnection();
if ( !connection )
{
DB_EXCEPT( EDatabaseExceptionCodes_StatementError, ERROR_MYSQL_LOST_CONNECTION );
}
EErrorType eReturn = EErrorType_ERROR;
if ( !_query.empty() )
{
_paramsCount = uint32_t( std::count( _query.begin(), _query.end(), STR( '?' ) ) );
_arrayQueries = StringUtils::Split( _query, STR( "?" ), _paramsCount + 1 );
}
CLogger::LogDebug( ( Format( DEBUG_MYSQL_PREPARING_STATEMENT ) % this ).str() );
assert( _paramsCount == GetParametersCount() );
StringStream query;
unsigned short i = 0;
auto && itQueries = _arrayQueries.begin();
auto && itParams = DoGetParameters().begin();
auto && itParamsEnd = DoGetParameters().end();
_outInitialisers.clear();
_arrayOutParams.clear();
_outInitialisers.reserve( GetParametersCount() );
_arrayOutParams.reserve( GetParametersCount() );
_bindings.reserve( GetParametersCount() );
while ( itQueries != _arrayQueries.end() && itParams != itParamsEnd )
{
query << ( *itQueries );
DatabaseParameterMySqlSPtr parameter = std::static_pointer_cast< CDatabaseParameterMySql >( *itParams );
if ( parameter->GetParamType() == EParameterType_OUT )
{
query << MYSQL_SQL_PARAM + parameter->GetName();
DatabaseStatementSPtr stmt = connection->CreateStatement( MYSQL_SQL_SET + parameter->GetName() + MYSQL_SQL_NULL );
stmt->Initialise();
_outInitialisers.push_back( stmt );
_arrayOutParams.push_back( parameter );
}
else if ( parameter->GetParamType() == EParameterType_IN )
{
MYSQL_BIND bind = { 0 };
_bindings.push_back( bind );
query << MYSQL_SQL_DELIM;
}
else
{
query << MYSQL_SQL_PARAM + parameter->GetName();
DatabaseStatementSPtr stmt = connection->CreateStatement( MYSQL_SQL_SET + parameter->GetName() + STR( " = " ) + MYSQL_SQL_DELIM );
stmt->CreateParameter( parameter->GetName(), parameter->GetType(), parameter->GetLimits(), EParameterType_IN );
stmt->Initialise();
_inOutInitialisers.push_back( std::make_pair( stmt, parameter ) );
_arrayOutParams.push_back( parameter );
}
++i;
++itQueries;
++itParams;
}
while ( itQueries != _arrayQueries.end() )
{
query << ( *itQueries );
++itQueries;
}
_query = query.str();
if ( !_arrayOutParams.empty() )
{
String sep;
StringStream queryInOutParam;
queryInOutParam << MYSQL_SQL_SELECT;
for ( auto && parameter : _arrayOutParams )
{
queryInOutParam << sep << MYSQL_SQL_PARAM << parameter.lock()->GetName() << MYSQL_SQL_AS << parameter.lock()->GetName();
sep = MYSQL_SQL_COMMA;
}
_stmtOutParams = connection->CreateStatement( queryInOutParam.str() );
_stmtOutParams->Initialise();
}
_statement = mysql_stmt_init( connection->GetConnection() );
if ( _statement )
{
eReturn = EErrorType_NONE;
}
else
{
DB_EXCEPT( EDatabaseExceptionCodes_StatementError, ERROR_MYSQL_CANT_CREATE_STATEMENT );
//.........这里部分代码省略.........
示例8: str
std::string str() const
{
return buffer.str();
}