libdrmconf 0.12.1
A library to program DMR radios.
Loading...
Searching...
No Matches
errorstack.hh
1#ifndef ERRORSTACK_HH
2#define ERRORSTACK_HH
3
4#include <QTextStream>
5
41{
42public:
43 class Stack;
44
46 class Message
47 {
48 public:
50 Message();
52 Message(const QString &file, unsigned line, const QString &message);
53
55 const QString &file() const;
57 unsigned line() const;
59 const QString &message() const;
61 QString format() const;
62
63 protected:
65 QString _file;
67 unsigned _line;
69 QString _message;
70 };
71
73 class MessageStream: public QTextStream
74 {
75 public:
77 MessageStream(const ErrorStack &stack, const QString &file, unsigned line);
79 virtual ~MessageStream();
80
81 protected:
85 QString _file;
87 unsigned _line;
89 QString _message;
90 };
91
93 class Stack
94 {
95 public:
97 Stack() noexcept;
98
99 public:
101 bool isEmpty() const;
103 unsigned count() const;
105 const Message &message(unsigned i) const;
107 QString format(const QString &indent=" ") const;
108
110 void push(const Message &msg);
112 void push(const Stack &other);
113
115 void clear();
116
118 Stack *ref();
121 void unref();
122
123 private:
125 unsigned _refcount;
127 QList<Message> _errorMessageStack;
128 };
129
130public:
132 ErrorStack() noexcept;
134 ErrorStack(const ErrorStack &other);
136 ~ErrorStack();
137
139 ErrorStack &operator= (const ErrorStack &other);
140
142 bool isEmpty() const;
144 unsigned count() const;
146 const Message &message(unsigned i) const;
147
149 void push(const Message &msg) const;
151 void take(const ErrorStack &other) const;
153 QString format(const QString &indent=" ") const;
154
155protected:
158};
159
160
162#define errMsg(stack) (ErrorStack::MessageStream(stack, __FILE__, __LINE__))
163
164#endif // ERRORSTACK_HH
A helper class to assemble error messages as streams.
Definition errorstack.hh:74
const ErrorStack & _stack
Holds a weak reference to the error stack to put the message on.
Definition errorstack.hh:83
unsigned _line
The line number.
Definition errorstack.hh:87
QString _message
The message buffer.
Definition errorstack.hh:89
virtual ~MessageStream()
Destructor, puts the message on the stack.
Definition errorstack.cc:50
MessageStream(const ErrorStack &stack, const QString &file, unsigned line)
Constructor.
Definition errorstack.cc:44
QString _file
The file path.
Definition errorstack.hh:85
Represents a single error message.
Definition errorstack.hh:47
Message()
Empty constructor.
Definition errorstack.cc:8
const QString & message() const
Returns the error message.
Definition errorstack.cc:31
const QString & file() const
Returns the file name.
Definition errorstack.cc:21
unsigned line() const
Returns the line within the file.
Definition errorstack.cc:26
QString format() const
Formats the error messaege.
Definition errorstack.cc:36
unsigned _line
Holds the line.
Definition errorstack.hh:67
QString _message
Holds the error message.
Definition errorstack.hh:69
QString _file
Holds the file path.
Definition errorstack.hh:65
The actual error message stack.
Definition errorstack.hh:94
Stack() noexcept
Empty constructor.
Definition errorstack.cc:59
void clear()
Clears the error stack.
Definition errorstack.cc:106
const Message & message(unsigned i) const
Returns a specific error message.
Definition errorstack.cc:90
bool isEmpty() const
Returns true if there are any error messages.
Definition errorstack.cc:80
unsigned count() const
Returns the number of error messages.
Definition errorstack.cc:85
void unref()
Dereferences a stack, this decreases the ref count.
Definition errorstack.cc:117
void push(const Message &msg)
Adds an error message to the stack.
Definition errorstack.cc:66
Stack * ref()
Returns a new reference to the stack.
Definition errorstack.cc:111
QString format(const QString &indent=" ") const
Returns a formatted string of error messages.
Definition errorstack.cc:95
Implements a stack of error messages to provide a pretty formatted error traceback.
Definition errorstack.hh:41
ErrorStack() noexcept
Default constructor.
Definition errorstack.cc:127
void take(const ErrorStack &other) const
Takes all messages from the other stack.
Definition errorstack.cc:172
QString format(const QString &indent=" ") const
Returns a formatted string of error messages.
Definition errorstack.cc:178
Stack * _stack
A reference to the actual message stack.
Definition errorstack.hh:157
const Message & message(unsigned i) const
Returns the i-th message from the stack.
Definition errorstack.cc:162
void push(const Message &msg) const
Pushes a message on the stack.
Definition errorstack.cc:167
unsigned count() const
Returns the number of elements on the stack.
Definition errorstack.cc:157
bool isEmpty() const
Returns true, if the stack is empty.
Definition errorstack.cc:152