libdrmconf 0.13.3
A library to program DMR radios.
Loading...
Searching...
No Matches
errorstack.hh
1#ifndef ERRORSTACK_HH
2#define ERRORSTACK_HH
3
4#include <QList>
5#include <QString>
6#include <QTextStream>
7
43{
44public:
45 class Stack;
46
48 class Message
49 {
50 public:
52 Message();
54 Message(const QString &file, unsigned line, const QString &message);
55
57 const QString &file() const;
59 unsigned line() const;
61 const QString &message() const;
63 QString format() const;
64
65 protected:
67 QString _file;
69 unsigned _line;
71 QString _message;
72 };
73
75 class MessageStream: public QTextStream
76 {
77 public:
79 MessageStream(const ErrorStack &stack, const QString &file, unsigned line);
81 virtual ~MessageStream();
82
83 protected:
87 QString _file;
89 unsigned _line;
91 QString _message;
92 };
93
95 class Stack
96 {
97 public:
99 Stack() noexcept;
100
101 public:
103 bool isEmpty() const;
105 unsigned count() const;
107 const Message &message(unsigned i) const;
109 QString format(const QString &indent=" ") const;
110
112 void push(const Message &msg);
114 void push(const Stack &other);
115
117 void clear();
118
120 Stack *ref();
123 void unref();
124
125 private:
127 unsigned _refcount;
129 QList<Message> _errorMessageStack;
130 };
131
132public:
134 ErrorStack() noexcept;
136 ErrorStack(const ErrorStack &other);
138 ~ErrorStack();
139
141 ErrorStack &operator= (const ErrorStack &other);
142
144 bool isEmpty() const;
146 unsigned count() const;
148 const Message &message(unsigned i) const;
149
151 void push(const Message &msg) const;
153 void take(const ErrorStack &other) const;
155 QString format(const QString &indent=" ") const;
156
157protected:
160};
161
162
164#define errMsg(stack) (ErrorStack::MessageStream(stack, __FILE__, __LINE__))
165
166#endif // ERRORSTACK_HH
const ErrorStack & _stack
Holds a weak reference to the error stack to put the message on.
Definition errorstack.hh:85
unsigned _line
The line number.
Definition errorstack.hh:89
QString _message
The message buffer.
Definition errorstack.hh:91
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:87
Represents a single error message.
Definition errorstack.hh:49
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:69
QString _message
Holds the error message.
Definition errorstack.hh:71
QString _file
Holds the file path.
Definition errorstack.hh:67
The actual error message stack.
Definition errorstack.hh:96
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
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:159
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