27 #ifndef _osaThreadedLogFile_h
28 #define _osaThreadedLogFile_h
45 template<
class _element,
class _trait = std::
char_traits<_element> >
58 typedef typename ChannelContainerType::iterator
iterator;
65 FilePrefix(filePrefix),
78 typedef typename std::basic_streambuf<_element, _trait>::int_type
int_type;
86 virtual std::streamsize
xsputn(
const _element *s, std::streamsize n);
97 std::string FilePrefix;
113 template<
class _element,
class _trait>
118 iterator it = FindChannel(threadId);
119 if (it != ChannelContainer.end()) {
121 return it->second->pubsync();
123 ChannelType * channel = AddChannelForThread(threadId);
125 return channel->pubsync();
129 template<
class _element,
class _trait>
135 const iterator it = FindChannel(threadId);
136 if (it != ChannelContainer.end()) {
138 return it->second->sputn(s, n);
140 ChannelType * channel = AddChannelForThread(threadId);
142 return channel->sputn(s, n);
146 template<
class _element,
class _trait>
151 if (_trait::eq_int_type(_trait::eof(), c))
152 return (_trait::not_eof(c));
156 const iterator it = FindChannel(threadId);
157 if (it != ChannelContainer.end()) {
159 return it->second->sputc( _trait::to_char_type(c) );
161 ChannelType * channel = AddChannelForThread(threadId);
163 return channel->sputc( _trait::to_char_type(c) );
167 template<
class _element,
class _trait>
171 iterator it = ChannelContainer.begin();
172 while (it != ChannelContainer.end()) {
173 if ((*it).first == threadId)
181 template<
class _element,
class _trait>
185 std::stringstream fileName;
186 fileName << this->FilePrefix << this->ChannelContainer.size() <<
".txt";
187 std::ofstream * newFile =
new std::ofstream(fileName.str().c_str());
188 ChannelContainer.push_back(
ElementType(threadId, newFile->rdbuf()));
189 return newFile->rdbuf();
202 std::ostream(&Streambuf),
203 Streambuf(filePrefix)
206 virtual std::basic_streambuf<char> *
rdbuf(
void) {
virtual int_type overflow(int_type c=_trait::eof())
Definition: osaThreadedLogFile.h:148
std::pair< osaThreadId, ChannelType * > ElementType
Definition: osaThreadedLogFile.h:54
Define a Mutex object.
Definition: osaMutex.h:48
Portability across compilers and operating systems tools.
Definition: osaThreadedLogFile.h:46
Definition: osaThreadedLogFile.h:195
ChannelContainerType::iterator iterator
Definition: osaThreadedLogFile.h:58
std::basic_streambuf< _element, _trait > ChannelType
Definition: osaThreadedLogFile.h:52
std::basic_streambuf< _element, _trait > BaseClassType
Definition: osaThreadedLogFile.h:50
std::basic_streambuf< _element, _trait >::int_type int_type
Definition: osaThreadedLogFile.h:78
osaThreadedLogFileStreambuf(const std::string &filePrefix)
Definition: osaThreadedLogFile.h:64
std::list< ElementType > ChannelContainerType
Definition: osaThreadedLogFile.h:57
Declaration of osaThread.
virtual int sync()
Definition: osaThreadedLogFile.h:114
osaThreadedLogFile(const std::string &filePrefix)
Definition: osaThreadedLogFile.h:201
CISST_EXPORT osaThreadId osaGetCurrentThreadId(void)
ChannelType * AddChannelForThread(const osaThreadId &threadId)
Definition: osaThreadedLogFile.h:183
ThreadId type.
Definition: osaThread.h:77
virtual std::streamsize xsputn(const _element *s, std::streamsize n)
Definition: osaThreadedLogFile.h:131
ChannelContainerType::const_iterator const_iterator
Definition: osaThreadedLogFile.h:59
virtual std::basic_streambuf< char > * rdbuf(void)
Definition: osaThreadedLogFile.h:206