Accelerated Computation Engine
edebug.h
1 #ifndef EDEBUG_H
2 #define EDEBUG_H
3 #include <QObject>
4 #include <QAtomicInteger>
5 #include <QVector>
6 #include "eabstractanalytic.h"
7 #include "eabstractanalytic_input.h"
8 #include "ace_analytic_abstractmpi.h"
9 #ifdef QT_DEBUG
10 #define EDEBUG_FUNC(...) EDebug debug(__PRETTY_FUNCTION__,#__VA_ARGS__); debug.setArguments(__VA_ARGS__);
11 #else
12 #define EDEBUG_FUNC(...)
13 #endif
14 //
15 
16 
17 
38 class EDebug
39 {
40 public:
45  enum Token
46  {
56  ,NoQuote
57  };
58 public:
59  static int threadId();
60 public:
61  EDebug& operator<<(Token token);
62  EDebug& operator<<(bool value);
63  EDebug& operator<<(qint8 value);
64  EDebug& operator<<(qint16 value);
65  EDebug& operator<<(qint32 value);
66  EDebug& operator<<(qint64 value);
67  EDebug& operator<<(quint8 value);
68  EDebug& operator<<(quint16 value);
69  EDebug& operator<<(quint32 value);
70  EDebug& operator<<(quint64 value);
71  EDebug& operator<<(float value);
72  EDebug& operator<<(double value);
73  EDebug& operator<<(const char* value);
74  EDebug& operator<<(const void*const value);
75  EDebug& operator<<(const QByteArray& value);
76  EDebug& operator<<(const QString& value);
77  EDebug& operator<<(const QStringList& value);
78  EDebug& operator<<(const QObject*const value);
79  EDebug& operator<<(const QVariant& value);
83 public:
84  EDebug(const char* function, const char* argumentNames);
85  ~EDebug();
86  template<class... Args> void setArguments(Args... arguments);
87 protected:
88  template<class T> void setArgument(int depth, T last);
89  template<class T,class... Args> void setArgument(int depth, T next, Args... arguments);
90 private:
96  static QAtomicInteger<int> _counter;
100  static thread_local int _threadId;
105  static thread_local int _stackDepth;
110  static thread_local bool _active;
111 private:
112  void setArgument(int depth);
113  void setupArguments(const char* argumentNames);
114  void dumpArguments();
118  const char* _function;
123  char* _argumentNames {nullptr};
128  QVector<int> _argumentIndexes;
132  QVector<QByteArray> _argumentValues;
139  QByteArray _holder;
144  bool _quote {true};
145 };
146 
147 
148 
149 
150 
151 
161 template<class... Args> void EDebug::setArguments(Args... arguments)
162 {
163  // Signal this debug object is active, call the initial variadic template
164  // function, and then disable the active flag.
165  _active = true;
166  setArgument(0,arguments...);
167  _active = false;
168 }
169 
170 
171 
172 
173 
174 
184 template<class T> void EDebug::setArgument(int depth, T last)
185 {
186  // Reset this object's holder byte array for streaming.
187  _quote = true;
188  _holder.clear();
189 
190  // Stream the given argument's value using this object's stream operators.
191  *this << last;
192 
193  // Get the holder byte array string and set it as this object's tracked argument
194  // value for the given depth.
195  _argumentValues[depth] = _holder;
196 
197  // Dump all argument names and values to the logging server.
198  dumpArguments();
199 }
200 
201 
202 
203 
204 
205 
219 template<class T,class... Args> void EDebug::setArgument(int depth, T next, Args... arguments)
220 {
221  // Reset this object's holder byte array for streaming.
222  _quote = true;
223  _holder.clear();
224 
225  // Stream the given next argument's value using this object's stream operators.
226  *this << next;
227 
228  // Get the holder byte array string and set it as this object's tracked argument
229  // value for the given depth.
230  _argumentValues[depth] = _holder;
231 
232  // Call the next variadic function in this chain with one less argument in the
233  // list.
234  setArgument(depth + 1,arguments...);
235 }
236 
237 
238 
239 #endif
static int threadId()
Definition: edebug.cpp:46
~EDebug()
Definition: edebug.cpp:737
void setArguments(Args... arguments)
Definition: edebug.h:161
EDebug(const char *function, const char *argumentNames)
Definition: edebug.cpp:690
Type
Definition: eabstractanalytic_input.h:29
Token
Definition: edebug.h:45
Role
Definition: eabstractanalytic_input.h:72
void setArgument(int depth, T last)
Definition: edebug.h:184
Definition: edebug.h:38
EDebug & operator<<(Token token)
Definition: edebug.cpp:71
Type
Definition: ace_analytic_abstractmpi.h:29
Definition: edebug.h:51