Changeset 160

Show
Ignore:
Timestamp:
07/17/08 15:47:23 (6 months ago)
Author:
zork
Message:

suport for stream debug flag

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dba/dba/stream.cpp

    r41 r160  
    1010#include "string_filter.h" 
    1111#include <algorithm> 
     12#include <iostream> 
     13 
     14extern "C" { 
     15  #include <stdio.h> 
     16  #include <stdlib.h> 
     17  #include <stdarg.h> 
     18}; 
    1219 
    1320namespace dba { 
     
    214221}; 
    215222 
    216  
    217223void 
    218224Stream::makeOk(Storeable* pObject) { 
    219225  pObject->mStoreState = Storeable::OK; 
    220226}; 
     227 
     228#ifdef _DEBUG 
     229void  
     230Stream::debug(const char* pFormat, ...) { 
     231  if (!mDebugFlag) 
     232    return; 
     233/* Guess we need no more than 100 bytes. */ 
     234  int n, size = 100; 
     235  char *p, *np; 
     236  va_list ap; 
     237 
     238  if ((p = (char*)malloc (size)) == NULL) 
     239    return; 
     240 
     241  while (1) { 
     242    /* Try to print in the allocated space. */ 
     243    va_start(ap, pFormat); 
     244    n = vsnprintf (p, size, pFormat, ap); 
     245    va_end(ap); 
     246    /* If that worked, return the string. */ 
     247    if (n > -1 && n < size) 
     248      break; 
     249    /* Else try again with more space. */ 
     250    if (n > -1)    /* glibc 2.1 */ 
     251      size = n+1; /* precisely what is needed */ 
     252    else           /* glibc 2.0 */ 
     253      size *= 2;  /* twice the old size */ 
     254    if ((np = (char*)realloc (p, size)) == NULL) { 
     255      free(p); 
     256      return; 
     257    } else { 
     258      p = np; 
     259    } 
     260  } 
     261  std::cerr << p << std::endl; 
     262  free(p); 
     263}; 
     264#endif 
    221265 
    222266Stream::~Stream()