#include <CppSQLite3.h>
Public Member Functions | |
| CppSQLite3Binary () | |
| ~CppSQLite3Binary () | |
| void | setBinary (const unsigned char *pBuf, int nLen) |
| void | setEncoded (const unsigned char *pBuf) |
| const unsigned char * | getEncoded () |
| const unsigned char * | getBinary () |
| int | getBinaryLength () |
| unsigned char * | allocBuffer (int nLen) |
| void | clear () |
Private Attributes | |
| unsigned char * | mpBuf |
| int | mnBinaryLen |
| int | mnBufferLen |
| int | mnEncodedLen |
| bool | mbEncoded |
Definition at line 169 of file CppSQLite3.h.
| CppSQLite3Binary::CppSQLite3Binary | ( | ) |
Definition at line 353 of file CppSQLite3.cpp.
:
mpBuf(0),
mnBinaryLen(0),
mnBufferLen(0),
mnEncodedLen(0),
mbEncoded(false)
{
}
| CppSQLite3Binary::~CppSQLite3Binary | ( | ) |
Definition at line 373 of file CppSQLite3.cpp.
References clear().
{
clear();
}

| unsigned char * CppSQLite3Binary::allocBuffer | ( | int | nLen | ) |
Definition at line 527 of file CppSQLite3.cpp.
References clear(), CPPSQLITE_ERROR, DONT_DELETE_MSG, mbEncoded, mnBinaryLen, mnBufferLen, and mpBuf.
Referenced by setBinary().
{
clear();
// Allow extra space for encoded binary as per comments in
// SQLite encode.c See bottom of this file for implementation
// of SQLite functions use 3 instead of 2 just to be sure ;-)
mnBinaryLen = nLen;
mnBufferLen = 3 + (257*nLen)/254;
mpBuf = (unsigned char*)malloc(mnBufferLen);
if (!mpBuf)
{
throw CppSQLite3Exception(CPPSQLITE_ERROR,
"Cannot allocate memory",
DONT_DELETE_MSG);
}
mbEncoded = false;
return mpBuf;
}


| void CppSQLite3Binary::clear | ( | ) |
Definition at line 577 of file CppSQLite3.cpp.
References mnBinaryLen, mnBufferLen, and mpBuf.
Referenced by allocBuffer(), setEncoded(), and ~CppSQLite3Binary().
{
if (mpBuf)
{
mnBinaryLen = 0;
mnBufferLen = 0;
free(mpBuf);
mpBuf = 0;
}
}

| const unsigned char * CppSQLite3Binary::getBinary | ( | ) |
Definition at line 471 of file CppSQLite3.cpp.
References CPPSQLITE_ERROR, DONT_DELETE_MSG, mbEncoded, mnBinaryLen, mpBuf, and sqlite3_decode_binary().
Referenced by getBinaryLength().
{
if (mbEncoded)
{
// in/out buffers can be the same
mnBinaryLen = sqlite3_decode_binary(mpBuf, mpBuf);
if (mnBinaryLen == -1)
{
throw CppSQLite3Exception(CPPSQLITE_ERROR,
"Cannot decode binary",
DONT_DELETE_MSG);
}
mbEncoded = false;
}
return mpBuf;
}


| int CppSQLite3Binary::getBinaryLength | ( | ) |
Definition at line 513 of file CppSQLite3.cpp.
References getBinary(), and mnBinaryLen.
{
getBinary();
return mnBinaryLen;
}

| const unsigned char * CppSQLite3Binary::getEncoded | ( | ) |
Definition at line 441 of file CppSQLite3.cpp.
References mbEncoded, mnBinaryLen, mnEncodedLen, mpBuf, and sqlite3_encode_binary().
{
if (!mbEncoded)
{
unsigned char* ptmp = (unsigned char*)malloc(mnBinaryLen);
memcpy(ptmp, mpBuf, mnBinaryLen);
mnEncodedLen = sqlite3_encode_binary(ptmp, mnBinaryLen, mpBuf);
free(ptmp);
mbEncoded = true;
}
return mpBuf;
}

| void CppSQLite3Binary::setBinary | ( | const unsigned char * | pBuf, | |
| int | nLen | |||
| ) |
Definition at line 385 of file CppSQLite3.cpp.
References allocBuffer(), and mpBuf.
{
mpBuf = allocBuffer(nLen);
memcpy(mpBuf, pBuf, nLen);
}

| void CppSQLite3Binary::setEncoded | ( | const unsigned char * | pBuf | ) |
Definition at line 399 of file CppSQLite3.cpp.
References clear(), CPPSQLITE_ERROR, DONT_DELETE_MSG, mbEncoded, mnBufferLen, mnEncodedLen, and mpBuf.
{
clear();
mnEncodedLen = strlen((const char*)pBuf);
mnBufferLen = mnEncodedLen + 1; // Allow for NULL terminator
mpBuf = (unsigned char*)malloc(mnBufferLen);
if (!mpBuf)
{
throw CppSQLite3Exception(CPPSQLITE_ERROR,
"Cannot allocate memory",
DONT_DELETE_MSG);
}
memcpy(mpBuf, pBuf, mnBufferLen);
mbEncoded = true;
}

bool CppSQLite3Binary::mbEncoded [private] |
Definition at line 221 of file CppSQLite3.h.
Referenced by allocBuffer(), getBinary(), getEncoded(), and setEncoded().
int CppSQLite3Binary::mnBinaryLen [private] |
Definition at line 215 of file CppSQLite3.h.
Referenced by allocBuffer(), clear(), getBinary(), getBinaryLength(), and getEncoded().
int CppSQLite3Binary::mnBufferLen [private] |
Definition at line 217 of file CppSQLite3.h.
Referenced by allocBuffer(), clear(), and setEncoded().
int CppSQLite3Binary::mnEncodedLen [private] |
Definition at line 219 of file CppSQLite3.h.
Referenced by getEncoded(), and setEncoded().
unsigned char* CppSQLite3Binary::mpBuf [private] |
Definition at line 213 of file CppSQLite3.h.
Referenced by allocBuffer(), clear(), getBinary(), getEncoded(), setBinary(), and setEncoded().
1.7.1