Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/util/debug_buffer.cc @ 9917

Last change on this file since 9917 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 3.1 KB
RevLine 
[4744]1/*
[1853]2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
[1855]10
11   ### File Specific:
[5246]12   main-programmer: Benjamin Grauer
[1855]13   co-programmer: ...
[1853]14*/
15
[9861]16#include "debug_buffer.h"
[1853]17
[7737]18#include <stdarg.h>
19
[5174]20#include "debug.h"
[9856]21#include "compiler.h"
[9861]22#include "threading.h"
[1853]23
[9861]24/**
25 * @brief standard constructor
26 */
27DebugBuffer::DebugBuffer ()
[7374]28{
[9861]29  DebugBuffer::singletonRef = this;
[1853]30
[9861]31  this->lineCount = 0;
32  this->bufferArray[0] = '\0';
[1856]33
[9861]34  this->setMaxBufferSize(100);
35}
[5175]36
[9861]37DebugBuffer* DebugBuffer::singletonRef = NULL;
38std::list<std::string> DebugBuffer::buffer;
39char DebugBuffer::bufferArray[DEBUG_BUFFER_SIZE] = "";
[4320]40
[8145]41
[9861]42/**
43 * @brief standard deconstructor
44 */
45DebugBuffer::~DebugBuffer ()
46{
47  DebugBuffer::singletonRef = NULL;
48}
[5174]49
[9861]50/**
51 * @brief deletes all the Buffers
52 */
53void DebugBuffer::flush()
54{
55  this->buffer.clear();
56}
[5206]57
[9861]58/**
59 * @brief adds a new Line to the List of Buffers
60 * @param line the Line as in the first argument in printf
61 */
62void DebugBuffer::addBufferLineStatic(const char* line, ...)
63{
64  static OrxThread::Mutex DebugBuffer__bufferMutex;
[8145]65
[9861]66  OrxThread::MutexLock bufferLock(&DebugBuffer__bufferMutex);
[8145]67
[9861]68  va_list arguments;
69  va_start(arguments, line);
70  vsnprintf(DebugBuffer::bufferArray, DEBUG_BUFFER_SIZE, line, arguments);
71  va_end(arguments);
[5206]72
[7729]73#if DEBUG_LEVEL < 3
[9861]74  if (DebugBuffer::singletonRef == NULL)
[5174]75#endif
[9861]76    printf(DebugBuffer::bufferArray);
[7729]77#if DEBUG_LEVEL < 3
[9861]78  else
[5174]79#else
[9861]80  if (DebugBuffer::singletonRef != NULL)
[5174]81#endif
[9861]82    DebugBuffer::singletonRef->addBufferLine(DebugBuffer::bufferArray);
83}
[5174]84
[9861]85/**
86 * @brief add a Line to the List of Buffers
87 * @param line
88 * @param arguments
89 *
90 * This function Adds one line to the buffer.
91 * and displays the line as the First Line of the display-buffer
92 */
93void DebugBuffer::addBufferLine(const char* line)
94{
95  std::string inputBuffer = this->keepBuffer + line;
96
97  unsigned int lineBegin = 0;
98  unsigned int lineEnd = 0;
99  // adding all the new Lines
100  while (lineEnd < inputBuffer.size())
[7375]101  {
[9861]102    lineBegin = lineEnd;
103    lineEnd = inputBuffer.find('\n', (lineBegin == 0) ? 0: ++lineBegin);
104    if (likely(lineEnd != std::string::npos ))
[7375]105    {
[9861]106      this->lineCount++;
107      this->buffer.push_front(inputBuffer.substr(lineBegin, lineEnd - lineBegin));
108    }
109    else      // No end of Line reached.
110    {
111      this->keepBuffer = inputBuffer.substr(lineBegin, inputBuffer.size() - lineBegin);
112      break;
113    }
[5174]114
[9861]115    if (inputBuffer[lineBegin] == '\n')
116      lineBegin++, lineEnd++;
[7764]117
[9861]118    if (this->buffer.size() > this->maxBufferSize)
119      this->buffer.pop_back();
[5174]120  }
[9861]121}
[5174]122
[9861]123/**
124 * @brief displays some nice output from the Debug
125 */
126void DebugBuffer::debug() const
127{
128  PRINT(3)("Debugging output to console (not this debug)\n");
[5177]129
[9861]130  std::list<std::string>::const_iterator bufferLine;
131  for (bufferLine = --this->buffer.end(); bufferLine != this->buffer.begin(); --bufferLine)
132    printf((*bufferLine).c_str());
[5177]133}
Note: See TracBrowser for help on using the repository browser.