#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 137 of file OSGLog.h.
| typedef void(* osg::LogBuf::Callback)(const Char8 *data, Int32 size, void *clientData) |
| LogBuf::LogBuf | ( | UInt32 | bufferSize = 1024 |
) |
Definition at line 72 of file OSGLog.cpp.
00072 : 00073 std::streambuf( ), 00074 _enabled (true), 00075 _chunkBag ( ), 00076 _callback (NULL), 00077 _clientData (NULL) 00078 { 00079 setg(0, 0, 0); 00080 00081 if(bufferSize > 0) 00082 { 00083 Char8 *buffer = new Char8[bufferSize]; 00084 00085 setp(buffer, buffer + bufferSize - 1); 00086 } 00087 else 00088 { 00089 setp(0, 0); 00090 } 00091 }
| osg::LogBuf::LogBuf | ( | const LogBuf & | ) |
| LogBuf::~LogBuf | ( | void | ) | [virtual] |
Definition at line 93 of file OSGLog.cpp.
References _callback.
00094 { 00095 delete [] pbase(); 00096 00097 _callback = NULL; 00098 }
| bool osg::LogBuf::getEnabled | ( | void | ) | [inline] |
Definition at line 99 of file OSGLog.inl.
References _enabled.
00100 { 00101 return _enabled; 00102 }
| void osg::LogBuf::setEnabled | ( | bool | value = true |
) | [inline] |
| void LogBuf::clearChunkBag | ( | void | ) |
| void LogBuf::setCallback | ( | LogBuf::Callback | cb, | |
| void * | clientData = 0, |
|||
| bool | flushData = false | |||
| ) |
Definition at line 114 of file OSGLog.cpp.
References _callback, _chunkBag, _clientData, osg::LogBuf::Chunk::data, and osg::LogBuf::Chunk::size.
00116 { 00117 std::list<LogBuf::Chunk*>::iterator cI; 00118 LogBuf::Chunk *chunk; 00119 00120 if(cb) 00121 { 00122 if(flushData) 00123 { 00124 for(cI = _chunkBag.begin(); cI != _chunkBag.end(); cI++) 00125 { 00126 if((chunk = *cI)) 00127 cb(chunk->data,chunk->size,clientData); 00128 } 00129 } 00130 00131 _callback = cb; 00132 _clientData = clientData; 00133 } 00134 }
| void LogBuf::removeCallback | ( | void | ) |
Definition at line 137 of file OSGLog.cpp.
References _callback.
00138 { 00139 _callback = 0; 00140 }
| void LogBuf::write | ( | const Char8 * | buffer, | |
| std::streamsize | size | |||
| ) | [private] |
Definition at line 143 of file OSGLog.cpp.
References _callback, _chunkBag, _clientData, _enabled, osg::LogBuf::Chunk::data, and osg::LogBuf::Chunk::size.
Referenced by overflow(), sync(), and xsputn().
00144 { 00145 Chunk *chunk = 0; 00146 Callback cb = NULL; 00147 00148 if(_enabled) 00149 { 00150 chunk = new Chunk; 00151 00152 chunk->size = size; 00153 chunk->data = new Char8[size]; 00154 00155 memcpy(chunk->data, buffer, size); 00156 00157 _chunkBag.push_back(chunk); 00158 } 00159 00160 if ((cb = _callback)) 00161 cb(buffer,size, _clientData); 00162 }
| int LogBuf::overflow | ( | Int32 | c | ) | [private, virtual] |
Definition at line 164 of file OSGLog.cpp.
References write().
00165 { 00166 if(!pptr()) 00167 return EOF; 00168 00169 if(c != EOF) 00170 { 00171 // Put character into write buffer 00172 *pptr() = c; 00173 00174 pbump(1); 00175 00176 // Flush write buffer 00177 std::streamsize size = pptr() - pbase(); 00178 00179 if(size > 0) 00180 { 00181 write(pbase(), size); 00182 pbump(-size); 00183 } 00184 } 00185 00186 return 0; 00187 }
| int LogBuf::sync | ( | void | ) | [private, virtual] |
Definition at line 189 of file OSGLog.cpp.
References write().
00190 { 00191 if(!pptr()) 00192 return EOF; 00193 00194 // Flush write buffer 00195 std::streamsize size = pptr() - pbase(); 00196 00197 if(size > 0) 00198 { 00199 write(pbase(), size); 00200 pbump(-size); 00201 } 00202 00203 return 0; 00204 }
| std::streamsize LogBuf::xsputn | ( | const Char8 * | buffer, | |
| std::streamsize | size | |||
| ) | [private, virtual] |
Definition at line 206 of file OSGLog.cpp.
References write().
00207 { 00208 if(size > 0) 00209 { 00210 if(!pptr()) 00211 return 0; 00212 00213 std::streamsize s = epptr() - pptr(); 00214 00215 if(s >= size) 00216 { 00217 // Put it into the write buffer 00218 memcpy(pptr(), buffer, size); 00219 pbump(size); 00220 } 00221 else 00222 { 00223 // Flush write buffer 00224 s = pptr() - pbase(); 00225 00226 if (s > 0) 00227 { 00228 write(pbase(), s); 00229 pbump(-s); 00230 } 00231 00232 // Write data 00233 write(buffer, size); 00234 } 00235 } 00236 00237 return size; 00238 }
bool osg::LogBuf::_enabled [private] |
std::list<Chunk*> osg::LogBuf::_chunkBag [private] |
Callback osg::LogBuf::_callback [private] |
Definition at line 202 of file OSGLog.h.
Referenced by removeCallback(), setCallback(), write(), and ~LogBuf().
void* osg::LogBuf::_clientData [private] |
1.5.5