]> git.stg.codes - stg.git/blobdiff - libs/ibpp/_tpb.cpp
Port to CMake, get rid of os_int.h.
[stg.git] / libs / ibpp / _tpb.cpp
diff --git a/libs/ibpp/_tpb.cpp b/libs/ibpp/_tpb.cpp
new file mode 100644 (file)
index 0000000..d27c2d5
--- /dev/null
@@ -0,0 +1,100 @@
+///////////////////////////////////////////////////////////////////////////////\r
+//\r
+//     File    : $Id: _tpb.cpp,v 1.2 2009/03/19 20:00:28 faust Exp $\r
+//     Subject : IBPP, internal TPB class implementation\r
+//\r
+///////////////////////////////////////////////////////////////////////////////\r
+//\r
+//     (C) Copyright 2000-2006 T.I.P. Group S.A. and the IBPP Team (www.ibpp.org)\r
+//\r
+//     The contents of this file are subject to the IBPP License (the "License");\r
+//     you may not use this file except in compliance with the License.  You may\r
+//     obtain a copy of the License at http://www.ibpp.org or in the 'license.txt'\r
+//     file which must have been distributed along with this file.\r
+//\r
+//     This software, distributed under the License, is distributed on an "AS IS"\r
+//     basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the\r
+//     License for the specific language governing rights and limitations\r
+//     under the License.\r
+//\r
+///////////////////////////////////////////////////////////////////////////////\r
+//\r
+//     COMMENTS\r
+//     * TPB == Transaction Parameter Block/Buffer, see Interbase 6.0 C-API\r
+//     * Tabulations should be set every four characters when editing this file.\r
+//\r
+///////////////////////////////////////////////////////////////////////////////\r
+\r
+#ifdef _MSC_VER\r
+#pragma warning(disable: 4786 4996)\r
+#ifndef _DEBUG\r
+#pragma warning(disable: 4702)\r
+#endif\r
+#endif\r
+\r
+#include "_ibpp.h"\r
+\r
+#ifdef HAS_HDRSTOP\r
+#pragma hdrstop\r
+#endif\r
+\r
+#include <cstring>\r
+\r
+using namespace ibpp_internals;\r
+\r
+const int TPB::BUFFERINCR = 128;\r
+\r
+void TPB::Grow(int needed)\r
+{\r
+       if (mBuffer == 0) ++needed;     // Initial alloc will require one more byte\r
+       if ((mSize + needed) > mAlloc)\r
+       {\r
+               // We need to grow the buffer. We use increments of BUFFERINCR bytes.\r
+               needed = (needed / BUFFERINCR + 1) * BUFFERINCR;\r
+               char* newbuffer = new char[mAlloc + needed];\r
+               if (mBuffer == 0)\r
+               {\r
+                       // Initial allocation, initialize the version tag\r
+                       newbuffer[0] = isc_tpb_version3;\r
+                       mSize = 1;\r
+               }\r
+               else\r
+               {\r
+                       // Move the old buffer content to the new one\r
+                       memcpy(newbuffer, mBuffer, mSize);\r
+                       delete [] mBuffer;\r
+               }\r
+               mBuffer = newbuffer;\r
+               mAlloc += needed;\r
+       }\r
+}\r
+\r
+void TPB::Insert(char item)\r
+{\r
+       Grow(1);\r
+       mBuffer[mSize++] = item;\r
+}\r
+\r
+void TPB::Insert(const std::string& data)\r
+{\r
+       int len = (int)data.length();\r
+       Grow(1 + len);\r
+       mBuffer[mSize++] = (char)len;\r
+       strncpy(&mBuffer[mSize], data.c_str(), len);\r
+       mSize += len;\r
+}\r
+\r
+void TPB::Reset()\r
+{\r
+       if (mSize != 0)\r
+       {\r
+               delete [] mBuffer;\r
+               mBuffer = 0;\r
+               mSize = 0;\r
+               mAlloc = 0;\r
+       }\r
+}\r
+\r
+//\r
+//     EOF\r
+//\r