1 ///////////////////////////////////////////////////////////////////////////////
\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
6 ///////////////////////////////////////////////////////////////////////////////
\r
8 // (C) Copyright 2000-2006 T.I.P. Group S.A. and the IBPP Team (www.ibpp.org)
\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
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
20 ///////////////////////////////////////////////////////////////////////////////
\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
26 ///////////////////////////////////////////////////////////////////////////////
\r
29 #pragma warning(disable: 4786 4996)
\r
31 #pragma warning(disable: 4702)
\r
43 using namespace ibpp_internals;
\r
45 const int SPB::BUFFERINCR = 128;
\r
47 void SPB::Grow(int needed)
\r
49 if ((mSize + needed) > mAlloc)
\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
56 // Move the old buffer content to the new one
\r
57 memcpy(newbuffer, mBuffer, mSize);
\r
60 mBuffer = newbuffer;
\r
65 void SPB::Insert(char opcode)
\r
68 mBuffer[mSize++] = opcode;
\r
71 void SPB::InsertString(char type, int lenwidth, const char* data)
\r
73 int16_t len = (int16_t)strlen(data);
\r
75 Grow(1 + lenwidth + len);
\r
76 mBuffer[mSize++] = type;
\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
82 default : throw LogicExceptionImpl("IISPB::IISPB", _("Invalid length parameter"));
\r
84 strncpy(&mBuffer[mSize], data, len);
\r
88 void SPB::InsertByte(char type, char data)
\r
91 mBuffer[mSize++] = type;
\r
92 mBuffer[mSize++] = data;
\r
95 void SPB::InsertQuad(char type, int32_t data)
\r
98 mBuffer[mSize++] = type;
\r
99 *(int32_t*)&mBuffer[mSize] = int32_t((*gds.Call()->m_vax_integer)((char*)&data, 4));
\r
115 void SPB::Insert(char type, short data)
\r
118 mBuffer[mSize++] = type;
\r
119 mBuffer[mSize++] = char(2);
\r
120 *(short*)&mBuffer[mSize] = data;
\r
124 void SPB::Insert(char type, bool data)
\r
127 mBuffer[mSize++] = type;
\r
128 mBuffer[mSize++] = char(1);
\r
129 mBuffer[mSize++] = char(data ? 1 : 0);
\r