Warning: include(php/utility.php): Failed to open stream: No such file or directory in /home/argos/argos3/doc/api/embedded/a00862_source.php on line 2

Warning: include(): Failed opening 'php/utility.php' for inclusion (include_path='.:/usr/lib64/php') in /home/argos/argos3/doc/api/embedded/a00862_source.php on line 2
The ARGoS Website

qtopengl_log_stream.h
Go to the documentation of this file.
1 
7 #ifndef QTOPENGL_LOG_STREAM_H
8 #define QTOPENGL_LOG_STREAM_H
9 
10 namespace argos {
11  class CQTOpenGLLogStream;
12 }
13 
14 #include <QTextEdit>
15 #include <argos3/core/simulator/simulator.h>
16 #include <argos3/core/simulator/space/space.h>
17 #include <argos3/core/utility/string_utilities.h>
18 
19 namespace argos {
20 
21  class CQTOpenGLLogStream : public std::basic_streambuf<char> {
22 
23  public:
24 
25  CQTOpenGLLogStream(std::ostream& c_stream,
26  QTextEdit* c_textedit) :
27  m_cStream(c_stream),
28  m_pcTextEdit(c_textedit),
29  m_cSpace(CSimulator::GetInstance().GetSpace()) {
30  /* Copy the original stream buffer */
31  m_pcOldStream = m_cStream.rdbuf();
32  /* Replace the streambuffer */
33  m_cStream.rdbuf(this);
34  }
35 
36  virtual ~CQTOpenGLLogStream() {
37  /* Replace old buffer */
38  m_cStream.rdbuf(m_pcOldStream);
39  }
40 
41  virtual int_type overflow(int_type t_value) {
42  if (t_value == '\n') {
43  std::string strTmp(m_strBuffer);
44  Replace(strTmp, "<", "&lt;");
45  Replace(strTmp, ">", "&gt;");
46  strTmp = "<b>[t=" + ToString(m_cSpace.GetSimulationClock()) + "]</b> " + strTmp;
47  m_pcTextEdit->append(strTmp.c_str());
48  m_strBuffer.erase(m_strBuffer.begin(), m_strBuffer.end());
49  }
50  else {
51  m_strBuffer += t_value;
52  }
53  return t_value;
54  }
55 
56  virtual std::streamsize xsputn(const char* pc_message,
57  std::streamsize un_size) {
58  /* Add the message to text stream */
59  m_strBuffer.append(pc_message, pc_message + un_size);
60  size_t nPos = 0;
61  do {
62  /* Look for a newline */
63  nPos = m_strBuffer.find('\n');
64  if (nPos != std::string::npos) {
65  /* Newline found: display text from the beginning of the stream till the newline */
66  /* Get the portion to display */
67  std::string strTmp(m_strBuffer.begin(), m_strBuffer.begin() + nPos);
68  /* Format the text to display */
69  Replace(strTmp, "<", "&lt;");
70  Replace(strTmp, ">", "&gt;");
71  strTmp = "<b>[t=" + ToString(m_cSpace.GetSimulationClock()) + "]</b> " + strTmp;
72  /* Append it to the text windoe */
73  m_pcTextEdit->append(strTmp.c_str());
74  /* Erase the displayed portion from the text stream */
75  m_strBuffer.erase(m_strBuffer.begin(), m_strBuffer.begin() + nPos + 1);
76  }
77  } while (nPos != std::string::npos);
78  /* No more newlines found, return */
79  return un_size;
80  }
81 
82  private:
83 
84  std::ostream& m_cStream;
85  std::streambuf* m_pcOldStream;
86  std::string m_strBuffer;
87  QTextEdit* m_pcTextEdit;
88  CSpace& m_cSpace;
89  };
90 
91 }
92 
93 #endif
virtual std::streamsize xsputn(const char *pc_message, std::streamsize un_size)
virtual int_type overflow(int_type t_value)
std::string ToString(const T &t_value)
Converts the given parameter to a std::string.
void Replace(std::string &str_buffer, const std::string &str_original, const std::string &str_new)
Searches into str_buffer for occurrences of str_original and substitutes them with str_new...
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
UInt32 GetSimulationClock() const
Returns the current value of the simulation clock.
Definition: space.h:324
The core class of ARGOS.
Definition: simulator.h:62
CQTOpenGLLogStream(std::ostream &c_stream, QTextEdit *c_textedit)