| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

FormString.cc

Go to the documentation of this file.
00001 #include "FormString.hh" //hxt
00002 #include <stdarg.h>
00003 #include <iostream>
00004 
00005 using namespace Logging;
00006 
00007 std::string Logging::FormString(const char* fmt, ...)
00008 {
00009   static int sBufSize = 10;
00010   static char* sBuffer = new char[sBufSize];
00011   
00012   va_list ap;
00013   va_start(ap,fmt);
00014   int res = vsnprintf(sBuffer, sBufSize, fmt, ap);
00015   va_end(ap);
00016         if(res > sBufSize) {
00017           sBufSize = res+20;
00018     std::cerr << "Increasing buffer size to " << sBufSize << std::endl;
00019           delete [] sBuffer;
00020     sBuffer = new char[sBufSize];
00021     
00022     // And try again.
00023     va_list ap2;
00024     va_start(ap2,fmt);
00025     int res = vsnprintf(sBuffer, sBufSize, fmt, ap2);
00026     res = 0; // quell unused variable warnings
00027     va_end(ap2);    
00028   }
00029         
00030   return std::string(sBuffer);  
00031 }
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:06:22 2011 for Log by doxygen 1.4.7