]> git.stg.codes - stg.git/blob - stglibs/ibpp.lib/_tpb.cpp
Merge branch 'stg-2.409-radius'
[stg.git] / stglibs / ibpp.lib / _tpb.cpp
1 ///////////////////////////////////////////////////////////////////////////////\r
2 //\r
3 //      File    : $Id: _tpb.cpp,v 1.2 2009/03/19 20:00:28 faust Exp $\r
4 //      Subject : IBPP, internal TPB class implementation\r
5 //\r
6 ///////////////////////////////////////////////////////////////////////////////\r
7 //\r
8 //      (C) Copyright 2000-2006 T.I.P. Group S.A. and the IBPP Team (www.ibpp.org)\r
9 //\r
10 //      The contents of this file are subject to the IBPP License (the "License");\r
11 //      you may not use this file except in compliance with the License.  You may\r
12 //      obtain a copy of the License at http://www.ibpp.org or in the 'license.txt'\r
13 //      file which must have been distributed along with this file.\r
14 //\r
15 //      This software, distributed under the License, is distributed on an "AS IS"\r
16 //      basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the\r
17 //      License for the specific language governing rights and limitations\r
18 //      under the License.\r
19 //\r
20 ///////////////////////////////////////////////////////////////////////////////\r
21 //\r
22 //      COMMENTS\r
23 //      * TPB == Transaction Parameter Block/Buffer, see Interbase 6.0 C-API\r
24 //      * Tabulations should be set every four characters when editing this file.\r
25 //\r
26 ///////////////////////////////////////////////////////////////////////////////\r
27 \r
28 #ifdef _MSC_VER\r
29 #pragma warning(disable: 4786 4996)\r
30 #ifndef _DEBUG\r
31 #pragma warning(disable: 4702)\r
32 #endif\r
33 #endif\r
34 \r
35 #include "_ibpp.h"\r
36 \r
37 #ifdef HAS_HDRSTOP\r
38 #pragma hdrstop\r
39 #endif\r
40 \r
41 #include <cstring>\r
42 \r
43 using namespace ibpp_internals;\r
44 \r
45 const int TPB::BUFFERINCR = 128;\r
46 \r
47 void TPB::Grow(int needed)\r
48 {\r
49         if (mBuffer == 0) ++needed;     // Initial alloc will require one more byte\r
50         if ((mSize + needed) > mAlloc)\r
51         {\r
52                 // We need to grow the buffer. We use increments of BUFFERINCR bytes.\r
53                 needed = (needed / BUFFERINCR + 1) * BUFFERINCR;\r
54                 char* newbuffer = new char[mAlloc + needed];\r
55                 if (mBuffer == 0)\r
56                 {\r
57                         // Initial allocation, initialize the version tag\r
58                         newbuffer[0] = isc_tpb_version3;\r
59                         mSize = 1;\r
60                 }\r
61                 else\r
62                 {\r
63                         // Move the old buffer content to the new one\r
64                         memcpy(newbuffer, mBuffer, mSize);\r
65                         delete [] mBuffer;\r
66                 }\r
67                 mBuffer = newbuffer;\r
68                 mAlloc += needed;\r
69         }\r
70 }\r
71 \r
72 void TPB::Insert(char item)\r
73 {\r
74         Grow(1);\r
75         mBuffer[mSize++] = item;\r
76 }\r
77 \r
78 void TPB::Insert(const std::string& data)\r
79 {\r
80         int len = (int)data.length();\r
81         Grow(1 + len);\r
82         mBuffer[mSize++] = (char)len;\r
83         strncpy(&mBuffer[mSize], data.c_str(), len);\r
84         mSize += len;\r
85 }\r
86 \r
87 void TPB::Reset()\r
88 {\r
89         if (mSize != 0)\r
90         {\r
91                 delete [] mBuffer;\r
92                 mBuffer = 0;\r
93                 mSize = 0;\r
94                 mAlloc = 0;\r
95         }\r
96 }\r
97 \r
98 //\r
99 //      EOF\r
100 //\r