Public Member Functions | Private Attributes

CppSQLite3Binary Class Reference

#include <CppSQLite3.h>

List of all members.

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

Detailed Description

Definition at line 169 of file CppSQLite3.h.


Constructor & Destructor Documentation

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();

}

Here is the call graph for this function:


Member Function Documentation

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;

}

Here is the call graph for this function:

Here is the caller graph for this function:

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;

        }

}

Here is the caller graph for this function:

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;

}

Here is the call graph for this function:

Here is the caller graph for this function:

int CppSQLite3Binary::getBinaryLength (  ) 

Definition at line 513 of file CppSQLite3.cpp.

References getBinary(), and mnBinaryLen.

{

        getBinary();

        return mnBinaryLen;

}

Here is the call graph for this function:

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;

}

Here is the call graph for this function:

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);

}

Here is the call graph for this function:

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;

}

Here is the call graph for this function:


Member Data Documentation

Definition at line 221 of file CppSQLite3.h.

Referenced by allocBuffer(), getBinary(), getEncoded(), and setEncoded().

Definition at line 215 of file CppSQLite3.h.

Referenced by allocBuffer(), clear(), getBinary(), getBinaryLength(), and getEncoded().

Definition at line 217 of file CppSQLite3.h.

Referenced by allocBuffer(), clear(), and setEncoded().

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().


The documentation for this class was generated from the following files: