21 #include <boost/bind.hpp>
33 OutStringStream::OutStringStream()
34 : std::ostringstream(), buffer(0), index(0), bufferSize(0), full(false) {
52 buffer =
new char[
static_cast<size_t>(size)];
59 std::streamsize towrite =
static_cast<std::streamsize
>(size);
89 :
Tracer(n), bufferSize(BUFFER_SIZE_DEFAULT) {
96 "Trash the current content of the buffers, without saving it.");
116 const std::string &givenname) {
119 if (givenname.length()) {
122 signame =
sig.shortName();
126 dgDEBUG(5) <<
"Sig <" <<
sig.getName() <<
">: new file " << filename << endl;
127 std::ofstream *newfile =
new std::ofstream(filename.c_str());
128 if (!newfile->good()) {
132 "Could not open file " + filename +
" for signal " + signame,
"");
134 dgDEBUG(5) <<
"Newfile:" << (
void *)newfile << endl;
136 dgDEBUG(5) <<
"Creating Outstringstream" << endl;
142 files.push_back(newbuffer);
149 std::lock_guard<std::mutex> files_lock(
files_mtx);
151 FileList::iterator iter =
files.begin();
152 HardFileList::iterator hardIter =
hardFiles.begin();
154 while (
files.end() != iter) {
155 dgDEBUG(25) <<
"Close the files." << endl;
157 std::stringstream *file =
dynamic_cast<stringstream *
>(*iter);
158 std::ofstream *hardFile = *hardIter;
160 (*hardFile) << flush;
169 dgDEBUG(25) <<
"Clear the lists." << endl;
179 FileList::iterator iter =
files.begin();
180 HardFileList::iterator hardIter =
hardFiles.begin();
182 while (
files.end() != iter) {
184 std::ostream *os = *iter;
193 "The buffer is not open",
"");
196 std::ofstream &hardFile = **hardIter;
197 if (!hardFile.good()) {
199 "The file is not open",
"");
202 if ((hardFile.good()) && (NULL != file)) {
203 file->
dump(hardFile);
217 for (FileList::iterator iter =
files.begin();
files.end() != iter; ++iter) {
225 "The buffer is not open",
"");
238 dgDEBUG(45) <<
"Empty file [" << file.tellp() <<
"] <" << file.str().c_str()
242 file.
addData(file.str().c_str(), file.tellp());
243 dgDEBUG(35) <<
"Write data [" << file.tellp() <<
"] <" << file.str().c_str()
250 "The buffer is not open",
"");
262 os << CLASS_NAME <<
" " <<
name <<
" [mode=" << (
play ?
"play" :
"pause")
264 <<
" - Dep list: " << endl;
266 FileList::const_iterator iterFile =
files.begin();
271 os <<
" -> " << (*iter)->getName();
275 const std::streamsize PRECISION = os.precision();
276 const std::streamsize SIZE = file->
index;
277 const std::streamsize MSIZE = file->
bufferSize;
278 unsigned int dec = 0;
279 std::string unit =
"";
280 if ((SIZE >> 30) || (MSIZE >> 30)) {
283 }
else if ((SIZE >> 20) || (MSIZE >> 20)) {
286 }
else if ((SIZE >> 10) || (MSIZE >> 10)) {
290 os <<
"[" << std::setw(1) << std::setprecision(1)
291 << (((double)SIZE + 0.0) / (1 << dec)) << unit <<
"/"
292 << std::setprecision(2) << (((double)MSIZE + 0.0) / (1 << dec)) << unit
294 if (file->
full) os <<
"(FULL)";
295 os.precision(PRECISION);