27#ifndef _osaThreadedLogFile_h
28#define _osaThreadedLogFile_h
45template<
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;
113template<
class _element,
class _trait>
118 iterator it = FindChannel(threadId);
119 if (it != ChannelContainer.end()) {
121 return it->second->pubsync();
125 return channel->pubsync();
129template<
class _element,
class _trait>
135 const iterator it = FindChannel(threadId);
136 if (it != ChannelContainer.end()) {
138 return it->second->sputn(s, n);
142 return channel->sputn(s, n);
146template<
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) );
163 return channel->sputc( _trait::to_char_type(c) );
167template<
class _element,
class _trait>
169osaThreadedLogFileStreambuf<_element, _trait>::FindChannel(
const osaThreadId & threadId)
171 iterator it = ChannelContainer.begin();
172 while (it != ChannelContainer.end()) {
173 if ((*it).first == threadId)
181template<
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) {
Define a Mutex object.
Definition osaMutex.h:48
ThreadId type.
Definition osaThread.h:77
virtual std::basic_streambuf< char > * rdbuf(void)
Definition osaThreadedLogFile.h:206
osaThreadedLogFile(const std::string &filePrefix)
Definition osaThreadedLogFile.h:201
Definition osaThreadedLogFile.h:47
ChannelType * AddChannelForThread(const osaThreadId &threadId)
Definition osaThreadedLogFile.h:183
std::basic_streambuf< _element, _trait > ChannelType
Definition osaThreadedLogFile.h:52
ChannelContainerType::iterator iterator
Definition osaThreadedLogFile.h:58
osaThreadedLogFileStreambuf(const std::string &filePrefix)
Definition osaThreadedLogFile.h:64
virtual std::streamsize xsputn(const _element *s, std::streamsize n)
Definition osaThreadedLogFile.h:131
std::basic_streambuf< _element, _trait > BaseClassType
Definition osaThreadedLogFile.h:50
std::list< ElementType > ChannelContainerType
Definition osaThreadedLogFile.h:57
virtual int sync()
Definition osaThreadedLogFile.h:114
std::basic_streambuf< _element, _trait >::int_type int_type
Definition osaThreadedLogFile.h:78
ChannelContainerType::const_iterator const_iterator
Definition osaThreadedLogFile.h:59
virtual int_type overflow(int_type c=_trait::eof())
Definition osaThreadedLogFile.h:148
std::pair< osaThreadId, ChannelType * > ElementType
Definition osaThreadedLogFile.h:54
Portability across compilers and operating systems tools.
Declaration of osaThread.
CISST_EXPORT osaThreadId osaGetCurrentThreadId(void)
OwnerType::iterator iterator
Definition vctDynamicConstMatrixBase.h:92