mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 16:44:36 +00:00
Move StringStack methods into the cpp file
This commit is contained in:
parent
57a202db69
commit
3650e9afa9
2 changed files with 198 additions and 153 deletions
|
|
@ -24,6 +24,185 @@
|
||||||
#include "console/consoleInternal.h"
|
#include "console/consoleInternal.h"
|
||||||
#include "console/stringStack.h"
|
#include "console/stringStack.h"
|
||||||
|
|
||||||
|
StringStack::StringStack()
|
||||||
|
{
|
||||||
|
mBufferSize = 0;
|
||||||
|
mBuffer = NULL;
|
||||||
|
mArgBufferSize = 0;
|
||||||
|
mArgBuffer = NULL;
|
||||||
|
mNumFrames = 0;
|
||||||
|
mStart = 0;
|
||||||
|
mLen = 0;
|
||||||
|
mStartStackSize = 0;
|
||||||
|
mFunctionOffset = 0;
|
||||||
|
validateBufferSize(8192);
|
||||||
|
validateArgBufferSize(2048);
|
||||||
|
dMemset(mBuffer, '\0', mBufferSize);
|
||||||
|
dMemset(mArgBuffer, '\0', mArgBufferSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
StringStack::~StringStack()
|
||||||
|
{
|
||||||
|
if( mBuffer )
|
||||||
|
dFree( mBuffer );
|
||||||
|
if( mArgBuffer )
|
||||||
|
dFree( mArgBuffer );
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringStack::validateBufferSize(U32 size)
|
||||||
|
{
|
||||||
|
if(size > mBufferSize)
|
||||||
|
{
|
||||||
|
mBufferSize = size + 2048;
|
||||||
|
mBuffer = (char *) dRealloc(mBuffer, mBufferSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringStack::validateArgBufferSize(U32 size)
|
||||||
|
{
|
||||||
|
if(size > mArgBufferSize)
|
||||||
|
{
|
||||||
|
mArgBufferSize = size + 2048;
|
||||||
|
mArgBuffer = (char *) dRealloc(mArgBuffer, mArgBufferSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringStack::setIntValue(U32 i)
|
||||||
|
{
|
||||||
|
validateBufferSize(mStart + 32);
|
||||||
|
dSprintf(mBuffer + mStart, 32, "%d", i);
|
||||||
|
mLen = dStrlen(mBuffer + mStart);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringStack::setFloatValue(F64 v)
|
||||||
|
{
|
||||||
|
validateBufferSize(mStart + 32);
|
||||||
|
dSprintf(mBuffer + mStart, 32, "%g", v);
|
||||||
|
mLen = dStrlen(mBuffer + mStart);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *StringStack::getReturnBuffer(U32 size)
|
||||||
|
{
|
||||||
|
if(size > ReturnBufferSpace)
|
||||||
|
{
|
||||||
|
AssertFatal(Con::isMainThread(), "Manipulating return buffer from a secondary thread!");
|
||||||
|
validateArgBufferSize(size);
|
||||||
|
return mArgBuffer;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
validateBufferSize(mStart + size);
|
||||||
|
return mBuffer + mStart;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char *StringStack::getArgBuffer(U32 size)
|
||||||
|
{
|
||||||
|
AssertFatal(Con::isMainThread(), "Manipulating console arg buffer from a secondary thread!");
|
||||||
|
validateBufferSize(mStart + mFunctionOffset + size);
|
||||||
|
char *ret = mBuffer + mStart + mFunctionOffset;
|
||||||
|
mFunctionOffset += size;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringStack::clearFunctionOffset()
|
||||||
|
{
|
||||||
|
//Con::printf("StringStack mFunctionOffset = 0 (from %i)", mFunctionOffset);
|
||||||
|
mFunctionOffset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringStack::setStringValue(const char *s)
|
||||||
|
{
|
||||||
|
if(!s)
|
||||||
|
{
|
||||||
|
mLen = 0;
|
||||||
|
mBuffer[mStart] = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mLen = dStrlen(s);
|
||||||
|
|
||||||
|
validateBufferSize(mStart + mLen + 2);
|
||||||
|
dStrcpy(mBuffer + mStart, s, mBufferSize - mStart);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringStack::advance()
|
||||||
|
{
|
||||||
|
mStartOffsets[mStartStackSize++] = mStart;
|
||||||
|
mStart += mLen;
|
||||||
|
mLen = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringStack::advanceChar(char c)
|
||||||
|
{
|
||||||
|
mStartOffsets[mStartStackSize++] = mStart;
|
||||||
|
mStart += mLen;
|
||||||
|
mBuffer[mStart] = c;
|
||||||
|
mBuffer[mStart+1] = 0;
|
||||||
|
mStart += 1;
|
||||||
|
mLen = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringStack::push()
|
||||||
|
{
|
||||||
|
advanceChar(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringStack::rewind()
|
||||||
|
{
|
||||||
|
mStart = mStartOffsets[--mStartStackSize];
|
||||||
|
mLen = dStrlen(mBuffer + mStart);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringStack::rewindTerminate()
|
||||||
|
{
|
||||||
|
mBuffer[mStart] = 0;
|
||||||
|
mStart = mStartOffsets[--mStartStackSize];
|
||||||
|
mLen = dStrlen(mBuffer + mStart);
|
||||||
|
}
|
||||||
|
|
||||||
|
U32 StringStack::compare()
|
||||||
|
{
|
||||||
|
// Figure out the 1st and 2nd item offsets.
|
||||||
|
U32 oldStart = mStart;
|
||||||
|
mStart = mStartOffsets[--mStartStackSize];
|
||||||
|
|
||||||
|
// Compare current and previous strings.
|
||||||
|
U32 ret = !dStricmp(mBuffer + mStart, mBuffer + oldStart);
|
||||||
|
|
||||||
|
// Put an empty string on the top of the stack.
|
||||||
|
mLen = 0;
|
||||||
|
mBuffer[mStart] = 0;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringStack::pushFrame()
|
||||||
|
{
|
||||||
|
//Con::printf("StringStack pushFrame [frame=%i, start=%i]", mNumFrames, mStartStackSize);
|
||||||
|
mFrameOffsets[mNumFrames++] = mStartStackSize;
|
||||||
|
mStartOffsets[mStartStackSize++] = mStart;
|
||||||
|
mStart += ReturnBufferSpace;
|
||||||
|
validateBufferSize(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringStack::popFrame()
|
||||||
|
{
|
||||||
|
//Con::printf("StringStack popFrame [frame=%i, start=%i]", mNumFrames, mStartStackSize);
|
||||||
|
mStartStackSize = mFrameOffsets[--mNumFrames];
|
||||||
|
mStart = mStartOffsets[mStartStackSize];
|
||||||
|
mLen = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringStack::clearFrames()
|
||||||
|
{
|
||||||
|
//Con::printf("StringStack clearFrames");
|
||||||
|
mNumFrames = 0;
|
||||||
|
mStart = 0;
|
||||||
|
mLen = 0;
|
||||||
|
mStartStackSize = 0;
|
||||||
|
mFunctionOffset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ConsoleValueStack::getArgcArgv(StringTableEntry name, U32 *argc, ConsoleValueRef **in_argv, bool popStackFrame /* = false */)
|
void ConsoleValueStack::getArgcArgv(StringTableEntry name, U32 *argc, ConsoleValueRef **in_argv, bool popStackFrame /* = false */)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -79,105 +79,31 @@ struct StringStack
|
||||||
U32 mArgBufferSize;
|
U32 mArgBufferSize;
|
||||||
char *mArgBuffer;
|
char *mArgBuffer;
|
||||||
|
|
||||||
void validateBufferSize(U32 size)
|
void validateBufferSize(U32 size);
|
||||||
{
|
void validateArgBufferSize(U32 size);
|
||||||
if(size > mBufferSize)
|
|
||||||
{
|
|
||||||
mBufferSize = size + 2048;
|
|
||||||
mBuffer = (char *) dRealloc(mBuffer, mBufferSize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void validateArgBufferSize(U32 size)
|
StringStack();
|
||||||
{
|
~StringStack();
|
||||||
if(size > mArgBufferSize)
|
|
||||||
{
|
|
||||||
mArgBufferSize = size + 2048;
|
|
||||||
mArgBuffer = (char *) dRealloc(mArgBuffer, mArgBufferSize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
StringStack()
|
|
||||||
{
|
|
||||||
mBufferSize = 0;
|
|
||||||
mBuffer = NULL;
|
|
||||||
mArgBufferSize = 0;
|
|
||||||
mArgBuffer = NULL;
|
|
||||||
mNumFrames = 0;
|
|
||||||
mStart = 0;
|
|
||||||
mLen = 0;
|
|
||||||
mStartStackSize = 0;
|
|
||||||
mFunctionOffset = 0;
|
|
||||||
validateBufferSize(8192);
|
|
||||||
validateArgBufferSize(2048);
|
|
||||||
dMemset(mBuffer, '\0', mBufferSize);
|
|
||||||
dMemset(mArgBuffer, '\0', mArgBufferSize);
|
|
||||||
}
|
|
||||||
~StringStack()
|
|
||||||
{
|
|
||||||
if( mBuffer )
|
|
||||||
dFree( mBuffer );
|
|
||||||
if( mArgBuffer )
|
|
||||||
dFree( mArgBuffer );
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set the top of the stack to be an integer value.
|
/// Set the top of the stack to be an integer value.
|
||||||
void setIntValue(U32 i)
|
void setIntValue(U32 i);
|
||||||
{
|
|
||||||
validateBufferSize(mStart + 32);
|
|
||||||
dSprintf(mBuffer + mStart, 32, "%d", i);
|
|
||||||
mLen = dStrlen(mBuffer + mStart);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set the top of the stack to be a float value.
|
/// Set the top of the stack to be a float value.
|
||||||
void setFloatValue(F64 v)
|
void setFloatValue(F64 v);
|
||||||
{
|
|
||||||
validateBufferSize(mStart + 32);
|
|
||||||
dSprintf(mBuffer + mStart, 32, "%g", v);
|
|
||||||
mLen = dStrlen(mBuffer + mStart);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return a temporary buffer we can use to return data.
|
/// Return a temporary buffer we can use to return data.
|
||||||
char* getReturnBuffer(U32 size)
|
char* getReturnBuffer(U32 size);
|
||||||
{
|
|
||||||
AssertFatal(Con::isMainThread(), "Manipulating return buffer from a secondary thread!");
|
|
||||||
validateArgBufferSize(size);
|
|
||||||
return mArgBuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return a buffer we can use for arguments.
|
/// Return a buffer we can use for arguments.
|
||||||
///
|
///
|
||||||
/// This updates the function offset.
|
/// This updates the function offset.
|
||||||
char *getArgBuffer(U32 size)
|
char *getArgBuffer(U32 size);
|
||||||
{
|
|
||||||
AssertFatal(Con::isMainThread(), "Manipulating console arg buffer from a secondary thread!");
|
|
||||||
validateBufferSize(mStart + mFunctionOffset + size);
|
|
||||||
char *ret = mBuffer + mStart + mFunctionOffset;
|
|
||||||
mFunctionOffset += size;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Clear the function offset.
|
/// Clear the function offset.
|
||||||
void clearFunctionOffset()
|
void clearFunctionOffset();
|
||||||
{
|
|
||||||
//Con::printf("StringStack mFunctionOffset = 0 (from %i)", mFunctionOffset);
|
|
||||||
mFunctionOffset = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set a string value on the top of the stack.
|
/// Set a string value on the top of the stack.
|
||||||
void setStringValue(const char *s)
|
void setStringValue(const char *s);
|
||||||
{
|
|
||||||
if(!s)
|
|
||||||
{
|
|
||||||
mLen = 0;
|
|
||||||
mBuffer[mStart] = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mLen = dStrlen(s);
|
|
||||||
|
|
||||||
validateBufferSize(mStart + mLen + 2);
|
|
||||||
dStrcpy(mBuffer + mStart, s, mBufferSize - mStart);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the top of the stack, as a StringTableEntry.
|
/// Get the top of the stack, as a StringTableEntry.
|
||||||
///
|
///
|
||||||
|
|
@ -226,33 +152,17 @@ struct StringStack
|
||||||
///
|
///
|
||||||
/// @note You should use StringStack::push, not this, if you want to
|
/// @note You should use StringStack::push, not this, if you want to
|
||||||
/// properly push the stack.
|
/// properly push the stack.
|
||||||
void advance()
|
void advance();
|
||||||
{
|
|
||||||
mStartOffsets[mStartStackSize++] = mStart;
|
|
||||||
mStart += mLen;
|
|
||||||
mLen = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Advance the start stack, placing a single character, null-terminated strong
|
/// Advance the start stack, placing a single character, null-terminated strong
|
||||||
/// on the top.
|
/// on the top.
|
||||||
///
|
///
|
||||||
/// @note You should use StringStack::push, not this, if you want to
|
/// @note You should use StringStack::push, not this, if you want to
|
||||||
/// properly push the stack.
|
/// properly push the stack.
|
||||||
void advanceChar(char c)
|
void advanceChar(char c);
|
||||||
{
|
|
||||||
mStartOffsets[mStartStackSize++] = mStart;
|
|
||||||
mStart += mLen;
|
|
||||||
mBuffer[mStart] = c;
|
|
||||||
mBuffer[mStart+1] = 0;
|
|
||||||
mStart += 1;
|
|
||||||
mLen = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Push the stack, placing a zero-length string on the top.
|
/// Push the stack, placing a zero-length string on the top.
|
||||||
void push()
|
void push();
|
||||||
{
|
|
||||||
advanceChar(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void setLen(U32 newlen)
|
inline void setLen(U32 newlen)
|
||||||
{
|
{
|
||||||
|
|
@ -260,64 +170,20 @@ struct StringStack
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pop the start stack.
|
/// Pop the start stack.
|
||||||
void rewind()
|
void rewind();
|
||||||
{
|
|
||||||
mStart = mStartOffsets[--mStartStackSize];
|
|
||||||
mLen = dStrlen(mBuffer + mStart);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Terminate the current string, and pop the start stack.
|
// Terminate the current string, and pop the start stack.
|
||||||
void rewindTerminate()
|
void rewindTerminate();
|
||||||
{
|
|
||||||
mBuffer[mStart] = 0;
|
|
||||||
mStart = mStartOffsets[--mStartStackSize];
|
|
||||||
mLen = dStrlen(mBuffer + mStart);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Compare 1st and 2nd items on stack, consuming them in the process,
|
/// Compare 1st and 2nd items on stack, consuming them in the process,
|
||||||
/// and returning true if they matched, false if they didn't.
|
/// and returning true if they matched, false if they didn't.
|
||||||
U32 compare()
|
U32 compare();
|
||||||
{
|
|
||||||
// Figure out the 1st and 2nd item offsets.
|
|
||||||
U32 oldStart = mStart;
|
|
||||||
mStart = mStartOffsets[--mStartStackSize];
|
|
||||||
|
|
||||||
// Compare current and previous strings.
|
void pushFrame();
|
||||||
U32 ret = !dStricmp(mBuffer + mStart, mBuffer + oldStart);
|
|
||||||
|
|
||||||
// Put an empty string on the top of the stack.
|
void popFrame();
|
||||||
mLen = 0;
|
|
||||||
mBuffer[mStart] = 0;
|
|
||||||
|
|
||||||
return ret;
|
void clearFrames();
|
||||||
}
|
|
||||||
|
|
||||||
void pushFrame()
|
|
||||||
{
|
|
||||||
//Con::printf("StringStack pushFrame [frame=%i, start=%i]", mNumFrames, mStartStackSize);
|
|
||||||
mFrameOffsets[mNumFrames++] = mStartStackSize;
|
|
||||||
mStartOffsets[mStartStackSize++] = mStart;
|
|
||||||
mStart += ReturnBufferSpace;
|
|
||||||
validateBufferSize(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void popFrame()
|
|
||||||
{
|
|
||||||
//Con::printf("StringStack popFrame [frame=%i, start=%i]", mNumFrames, mStartStackSize);
|
|
||||||
mStartStackSize = mFrameOffsets[--mNumFrames];
|
|
||||||
mStart = mStartOffsets[mStartStackSize];
|
|
||||||
mLen = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void clearFrames()
|
|
||||||
{
|
|
||||||
//Con::printf("StringStack clearFrames");
|
|
||||||
mNumFrames = 0;
|
|
||||||
mStart = 0;
|
|
||||||
mLen = 0;
|
|
||||||
mStartStackSize = 0;
|
|
||||||
mFunctionOffset = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the arguments for a function call from the stack.
|
/// Get the arguments for a function call from the stack.
|
||||||
void getArgcArgv(StringTableEntry name, U32 *argc, const char ***in_argv, bool popStackFrame = false);
|
void getArgcArgv(StringTableEntry name, U32 *argc, const char ***in_argv, bool popStackFrame = false);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue