creaImageIO_lib
CppSQLite3Binary Class Reference

#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
 

Detailed Description

Definition at line 169 of file CppSQLite3.h.

Constructor & Destructor Documentation

CppSQLite3Binary::CppSQLite3Binary ( )

Definition at line 353 of file CppSQLite3.cpp.

354  :
355 
356  mpBuf(0),
357 
358  mnBinaryLen(0),
359 
360  mnBufferLen(0),
361 
362  mnEncodedLen(0),
363 
364  mbEncoded(false)
365 
366 {
367 
}
CppSQLite3Binary::~CppSQLite3Binary ( )

Definition at line 373 of file CppSQLite3.cpp.

References clear().

375 {
376 
377  clear();
378 
379 }

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

529 {
530 
531  clear();
532 
533 
534 
535  // Allow extra space for encoded binary as per comments in
536 
537  // SQLite encode.c See bottom of this file for implementation
538 
539  // of SQLite functions use 3 instead of 2 just to be sure ;-)
540 
541  mnBinaryLen = nLen;
542 
543  mnBufferLen = 3 + (257*nLen)/254;
544 
545 
546 
547  mpBuf = (unsigned char*)malloc(mnBufferLen);
548 
549 
550 
551  if (!mpBuf)
552 
553  {
554 
556 
557  "Cannot allocate memory",
558 
560 
561  }
562 
563 
564 
565  mbEncoded = false;
566 
567 
568 
569  return mpBuf;
570 
571 }

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

579 {
580 
581  if (mpBuf)
582 
583  {
584 
585  mnBinaryLen = 0;
586 
587  mnBufferLen = 0;
588 
589  free(mpBuf);
590 
591  mpBuf = 0;
592 
593  }
594 
595 }

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

473 {
474 
475  if (mbEncoded)
476 
477  {
478 
479  // in/out buffers can be the same
480 
482 
483 
484 
485  if (mnBinaryLen == -1)
486 
487  {
488 
490 
491  "Cannot decode binary",
492 
494 
495  }
496 
497 
498 
499  mbEncoded = false;
500 
501  }
502 
503 
504 
505  return mpBuf;
506 
507 }

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.

515 {
516 
517  getBinary();
518 
519  return mnBinaryLen;
520 
521 }

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

443 {
444 
445  if (!mbEncoded)
446 
447  {
448 
449  unsigned char* ptmp = (unsigned char*)malloc(mnBinaryLen);
450 
451  memcpy(ptmp, mpBuf, mnBinaryLen);
452 
454 
455  free(ptmp);
456 
457  mbEncoded = true;
458 
459  }
460 
461 
462 
463  return mpBuf;
464 
465 }

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.

387 {
388 
389  mpBuf = allocBuffer(nLen);
390 
391  memcpy(mpBuf, pBuf, nLen);
392 
393 }

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.

401 {
402 
403  clear();
404 
405 
406 
407  mnEncodedLen = strlen((const char*)pBuf);
408 
409  mnBufferLen = mnEncodedLen + 1; // Allow for NULL terminator
410 
411 
412 
413  mpBuf = (unsigned char*)malloc(mnBufferLen);
414 
415 
416 
417  if (!mpBuf)
418 
419  {
420 
422 
423  "Cannot allocate memory",
424 
426 
427  }
428 
429 
430 
431  memcpy(mpBuf, pBuf, mnBufferLen);
432 
433  mbEncoded = true;
434 
435 }

Here is the call graph for this function:

Member Data Documentation

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


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