#include <OSGLog.h>
Public Types | |
| typedef void(*) | Callback (const Char8 *data, Int32 size, void *clientData) |
Public Member Functions | |
Constructors | |
| LogBuf (UInt32 bufferSize=1024) | |
| LogBuf (const LogBuf &) | |
Destructors | |
| virtual | ~LogBuf () |
Class Specific | |
| bool | getEnabled (void) |
| void | setEnabled (bool value=true) |
| void | clearChunkBag (void) |
| clear the chunk bag | |
Callback handling | |
| void | setCallback (Callback cb, void *clientData=0, bool flushData=false) |
| void | removeCallback (void) |
Private Member Functions | |
| const LogBuf & | operator= (const LogBuf &) |
| void | write (const Char8 *buffer, std::streamsize size) |
Callback handling | |
| virtual Int32 | overflow (Int32 c) |
| virtual Int32 | sync (void) |
| virtual std::streamsize | xsputn (const Char8 *buffer, std::streamsize size) |
Private Attributes | |
| bool | _enabled |
| std::list< Chunk * > | _chunkBag |
| Callback | _callback |
| void * | _clientData |
Classes | |
| struct | Chunk |
Definition at line 147 of file OSGLog.h.
| typedef void(*) OSG::LogBuf::Callback(const Char8 *data, Int32 size, void *clientData) |
| LogBuf::LogBuf | ( | UInt32 | bufferSize = 1024 |
) |
Definition at line 64 of file OSGLog.cpp.
00064 : 00065 std::streambuf( ), 00066 _enabled (true), 00067 _chunkBag ( ), 00068 _callback (NULL), 00069 _clientData (NULL) 00070 { 00071 setg(0, 0, 0); 00072 00073 if(bufferSize > 0) 00074 { 00075 Char8 *buffer = new Char8[bufferSize]; 00076 00077 setp(buffer, buffer + bufferSize - 1); 00078 } 00079 else 00080 { 00081 setp(0, 0); 00082 } 00083 }
| OSG::LogBuf::LogBuf | ( | const LogBuf & | ) |
| LogBuf::~LogBuf | ( | ) | [virtual] |
Definition at line 85 of file OSGLog.cpp.
References _callback.
00086 { 00087 delete [] pbase(); 00088 00089 _callback = NULL; 00090 }
| bool OSG::LogBuf::getEnabled | ( | void | ) | [inline] |
Definition at line 91 of file OSGLog.inl.
References _enabled.
00092 { 00093 return _enabled; 00094 }
| void OSG::LogBuf::setEnabled | ( | bool | value = true |
) | [inline] |
| void LogBuf::clearChunkBag | ( | void | ) |
| void LogBuf::setCallback | ( | Callback | cb, | |
| void * | clientData = 0, |
|||
| bool | flushData = false | |||
| ) |
Definition at line 106 of file OSGLog.cpp.
References _callback, _chunkBag, _clientData, OSG::LogBuf::Chunk::data, and OSG::LogBuf::Chunk::size.
00108 { 00109 std::list<LogBuf::Chunk*>::iterator cI; 00110 LogBuf::Chunk *chunk; 00111 00112 if(cb) 00113 { 00114 if(flushData) 00115 { 00116 for(cI = _chunkBag.begin(); cI != _chunkBag.end(); cI++) 00117 { 00118 if((chunk = *cI)) 00119 cb(chunk->data,chunk->size,clientData); 00120 } 00121 } 00122 00123 _callback = cb; 00124 _clientData = clientData; 00125 } 00126 }
| void LogBuf::removeCallback | ( | void | ) |
Definition at line 129 of file OSGLog.cpp.
References _callback.
00130 { 00131 _callback = 0; 00132 }
| void LogBuf::write | ( | const Char8 * | buffer, | |
| std::streamsize | size | |||
| ) | [private] |
Definition at line 135 of file OSGLog.cpp.
References _callback, _chunkBag, _clientData, _enabled, OSG::LogBuf::Chunk::data, and OSG::LogBuf::Chunk::size.
Referenced by overflow(), sync(), and xsputn().
00136 { 00137 Chunk *chunk = 0; 00138 Callback cb = NULL; 00139 00140 if(_enabled) 00141 { 00142 chunk = new Chunk; 00143 00144 chunk->size = size; 00145 chunk->data = new Char8[size]; 00146 00147 memcpy(chunk->data, buffer, size); 00148 00149 _chunkBag.push_back(chunk); 00150 } 00151 00152 if ((cb = _callback)) 00153 cb(buffer,size, _clientData); 00154 }
| int LogBuf::overflow | ( | Int32 | c | ) | [private, virtual] |
Definition at line 156 of file OSGLog.cpp.
00157 { 00158 if(!pptr()) 00159 return EOF; 00160 00161 if(c != EOF) 00162 { 00163 // Put character into write buffer 00164 *pptr() = c; 00165 00166 pbump(1); 00167 00168 // Flush write buffer 00169 std::streamsize size = pptr() - pbase(); 00170 00171 if(size > 0) 00172 { 00173 write(pbase(), size); 00174 pbump(-size); 00175 } 00176 } 00177 00178 return 0; 00179 }
| int LogBuf::sync | ( | void | ) | [private, virtual] |
Definition at line 181 of file OSGLog.cpp.
00182 { 00183 if(!pptr()) 00184 return EOF; 00185 00186 // Flush write buffer 00187 std::streamsize size = pptr() - pbase(); 00188 00189 if(size > 0) 00190 { 00191 write(pbase(), size); 00192 pbump(-size); 00193 } 00194 00195 return 0; 00196 }
| std::streamsize LogBuf::xsputn | ( | const Char8 * | buffer, | |
| std::streamsize | size | |||
| ) | [private, virtual] |
Definition at line 198 of file OSGLog.cpp.
References write().
00199 { 00200 if(size > 0) 00201 { 00202 if(!pptr()) 00203 return 0; 00204 00205 std::streamsize s = epptr() - pptr(); 00206 00207 if(s >= size) 00208 { 00209 // Put it into the write buffer 00210 memcpy(pptr(), buffer, size); 00211 pbump(size); 00212 } 00213 else 00214 { 00215 // Flush write buffer 00216 s = pptr() - pbase(); 00217 00218 if (s > 0) 00219 { 00220 write(pbase(), s); 00221 pbump(-s); 00222 } 00223 00224 // Write data 00225 write(buffer, size); 00226 } 00227 } 00228 00229 return size; 00230 }
bool OSG::LogBuf::_enabled [private] |
std::list<Chunk*> OSG::LogBuf::_chunkBag [private] |
Callback OSG::LogBuf::_callback [private] |
Definition at line 213 of file OSGLog.h.
Referenced by removeCallback(), setCallback(), write(), and ~LogBuf().
void* OSG::LogBuf::_clientData [private] |