瀏覽代碼

Move StringStack methods into the cpp file

Glenn Smith 7 年之前
父節點
當前提交
593680fb3f
共有 2 個文件被更改,包括 198 次插入153 次删除
  1. 179 0
      Engine/source/console/stringStack.cpp
  2. 19 153
      Engine/source/console/stringStack.h

+ 179 - 0
Engine/source/console/stringStack.cpp

@@ -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 */)
 {
 {

+ 19 - 153
Engine/source/console/stringStack.h

@@ -79,105 +79,31 @@ struct StringStack
    U32 mArgBufferSize;
    U32 mArgBufferSize;
    char *mArgBuffer;
    char *mArgBuffer;
 
 
-   void validateBufferSize(U32 size)
-   {
-      if(size > mBufferSize)
-      {
-         mBufferSize = size + 2048;
-         mBuffer = (char *) dRealloc(mBuffer, mBufferSize);
-      }
-   }
-
-   void validateArgBufferSize(U32 size)
-   {
-      if(size > mArgBufferSize)
-      {
-         mArgBufferSize = size + 2048;
-         mArgBuffer = (char *) dRealloc(mArgBuffer, mArgBufferSize);
-      }
-   }
+   void validateBufferSize(U32 size);
+   void validateArgBufferSize(U32 size);
 
 
-   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 );
-   }
+   StringStack();
+   ~StringStack();
 
 
    /// 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)
-   {
-      validateBufferSize(mStart + 32);
-      dSprintf(mBuffer + mStart, 32, "%d", i);
-      mLen = dStrlen(mBuffer + mStart);
-   }
+   void setIntValue(U32 i);
 
 
    /// 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)
-   {
-      validateBufferSize(mStart + 32);
-      dSprintf(mBuffer + mStart, 32, "%g", v);
-      mLen = dStrlen(mBuffer + mStart);
-   }
+   void setFloatValue(F64 v);
 
 
    /// Return a temporary buffer we can use to return data.
    /// Return a temporary buffer we can use to return data.
-   char* getReturnBuffer(U32 size)
-   {
-      AssertFatal(Con::isMainThread(), "Manipulating return buffer from a secondary thread!");
-      validateArgBufferSize(size);
-      return mArgBuffer;
-   }
+   char* getReturnBuffer(U32 size);
 
 
    /// 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)
-   {
-      AssertFatal(Con::isMainThread(), "Manipulating console arg buffer from a secondary thread!");
-      validateBufferSize(mStart + mFunctionOffset + size);
-      char *ret = mBuffer + mStart + mFunctionOffset;
-      mFunctionOffset += size;
-      return ret;
-   }
+   char *getArgBuffer(U32 size);
 
 
    /// Clear the function offset.
    /// Clear the function offset.
-   void clearFunctionOffset()
-   {
-      //Con::printf("StringStack mFunctionOffset = 0 (from %i)", mFunctionOffset);
-      mFunctionOffset = 0;
-   }
+   void clearFunctionOffset();
 
 
    /// 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)
-   {
-      if(!s)
-      {
-         mLen = 0;
-         mBuffer[mStart] = 0;
-         return;
-      }
-      mLen = dStrlen(s);
-
-      validateBufferSize(mStart + mLen + 2);
-      dStrcpy(mBuffer + mStart, s, mBufferSize - mStart);
-   }
+   void setStringValue(const char *s);
 
 
    /// 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()
-   {
-      mStartOffsets[mStartStackSize++] = mStart;
-      mStart += mLen;
-      mLen = 0;
-   }
+   void advance();
 
 
    /// 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)
-   {
-      mStartOffsets[mStartStackSize++] = mStart;
-      mStart += mLen;
-      mBuffer[mStart] = c;
-      mBuffer[mStart+1] = 0;
-      mStart += 1;
-      mLen = 0;
-   }
+   void advanceChar(char c);
 
 
    /// Push the stack, placing a zero-length string on the top.
    /// Push the stack, placing a zero-length string on the top.
-   void push()
-   {
-      advanceChar(0);
-   }
+   void push();
 
 
    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()
-   {
-      mStart = mStartOffsets[--mStartStackSize];
-      mLen = dStrlen(mBuffer + mStart);
-   }
+   void rewind();
 
 
    // Terminate the current string, and pop the start stack.
    // Terminate the current string, and pop the start stack.
-   void rewindTerminate()
-   {
-      mBuffer[mStart] = 0;
-      mStart = mStartOffsets[--mStartStackSize];
-      mLen   = dStrlen(mBuffer + mStart);
-   }
+   void rewindTerminate();
 
 
    /// 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()
-   {
-      // 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;
+   U32 compare();
 
 
-      return ret;
-   }
-
-   void pushFrame()
-   {
-      //Con::printf("StringStack pushFrame [frame=%i, start=%i]", mNumFrames, mStartStackSize);
-      mFrameOffsets[mNumFrames++] = mStartStackSize;
-      mStartOffsets[mStartStackSize++] = mStart;
-      mStart += ReturnBufferSpace;
-      validateBufferSize(0);
-   }
+   void pushFrame();
 
 
-   void popFrame()
-   {
-      //Con::printf("StringStack popFrame [frame=%i, start=%i]", mNumFrames, mStartStackSize);
-      mStartStackSize = mFrameOffsets[--mNumFrames];
-      mStart = mStartOffsets[mStartStackSize];
-      mLen = 0;
-   }
+   void popFrame();
 
 
-   void clearFrames()
-   {
-      //Con::printf("StringStack clearFrames");
-      mNumFrames = 0;
-      mStart = 0;
-      mLen = 0;
-      mStartStackSize = 0;
-      mFunctionOffset = 0;
-   }
+   void clearFrames();
 
 
    /// 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);