]> git.stg.codes - stg.git/blob - libs/ibpp/_spb.cpp
Use std::lock_guard instead of STG_LOCKER.
[stg.git] / libs / ibpp / _spb.cpp
1 ///////////////////////////////////////////////////////////////////////////////\r
2 //\r
3 //      File    : $Id: _spb.cpp,v 1.2 2009/03/19 20:00:27 faust Exp $\r
4 //      Subject : IBPP, internal SPB 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 //      * SPB == Service 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 SPB::BUFFERINCR = 128;\r
46 \r
47 void SPB::Grow(int needed)\r
48 {\r
49         if ((mSize + needed) > mAlloc)\r
50         {\r
51                 // We need to grow the buffer. We use increments of BUFFERINCR bytes.\r
52                 needed = (needed / BUFFERINCR + 1) * BUFFERINCR;\r
53                 char* newbuffer = new char[mAlloc + needed];\r
54                 if (mBuffer != 0)\r
55                 {\r
56                         // Move the old buffer content to the new one\r
57                         memcpy(newbuffer, mBuffer, mSize);\r
58                         delete [] mBuffer;\r
59                 }\r
60                 mBuffer = newbuffer;\r
61                 mAlloc += needed;\r
62         }\r
63 }\r
64 \r
65 void SPB::Insert(char opcode)\r
66 {\r
67         Grow(1);\r
68         mBuffer[mSize++] = opcode;\r
69 }\r
70 \r
71 void SPB::InsertString(char type, int lenwidth, const char* data)\r
72 {\r
73         int16_t len = (int16_t)strlen(data);\r
74 \r
75         Grow(1 + lenwidth + len);\r
76         mBuffer[mSize++] = type;\r
77         switch (lenwidth)\r
78         {\r
79                 case 1 :        mBuffer[mSize] = char(len); mSize++; break;\r
80                 case 2 :        *(int16_t*)&mBuffer[mSize] = int16_t((*gds.Call()->m_vax_integer)((char*)&len, 2));\r
81                                         mSize += 2; break;\r
82                 default :       throw LogicExceptionImpl("IISPB::IISPB", _("Invalid length parameter"));\r
83         }\r
84         strncpy(&mBuffer[mSize], data, len);\r
85         mSize += len;\r
86 }\r
87 \r
88 void SPB::InsertByte(char type, char data)\r
89 {\r
90         Grow(1 + 1);\r
91         mBuffer[mSize++] = type;\r
92         mBuffer[mSize++] = data;\r
93 }\r
94 \r
95 void SPB::InsertQuad(char type, int32_t data)\r
96 {\r
97         Grow(1 + 4);\r
98         mBuffer[mSize++] = type;\r
99         *(int32_t*)&mBuffer[mSize] = int32_t((*gds.Call()->m_vax_integer)((char*)&data, 4));\r
100         mSize += 4;\r
101 }\r
102 \r
103 void SPB::Reset()\r
104 {\r
105         if (mBuffer != 0)\r
106         {\r
107                 delete [] mBuffer;\r
108                 mBuffer = 0;\r
109                 mSize = 0;\r
110                 mAlloc = 0;\r
111     }\r
112 }\r
113 \r
114 /*\r
115 void SPB::Insert(char type, short data)\r
116 {\r
117         Grow(1 + 3);\r
118         mBuffer[mSize++] = type;\r
119         mBuffer[mSize++] = char(2);\r
120         *(short*)&mBuffer[mSize] = data;\r
121         mSize += 2;\r
122 }\r
123 \r
124 void SPB::Insert(char type, bool data)\r
125 {\r
126         Grow(1 + 2);\r
127         mBuffer[mSize++] = type;\r
128         mBuffer[mSize++] = char(1);\r
129         mBuffer[mSize++] = char(data ? 1 : 0);\r
130 }\r
131 */\r
132 \r
133 //\r
134 //      EOF\r
135 //\r