swift
jsonexception.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_MISC_JSONEXCEPTION_H
7 #define SWIFT_MISC_JSONEXCEPTION_H
8 
9 #include <stdexcept>
10 
11 #include <QString>
12 
13 #include "misc/swiftmiscexport.h"
14 
15 namespace swift::misc
16 {
17  class CStatusMessage;
18  class CLogCategoryList;
19 
23  class SWIFT_MISC_EXPORT CJsonException : public std::runtime_error
24  {
25  virtual void anchor();
26 
27  public:
29  explicit CJsonException(const QString &message) : std::runtime_error(message.toStdString()) {}
30 
32  const QString &getStackTrace() const { return m_stack; }
33 
35  QString toString(const QString &prefix) const;
36 
37  private:
38  static QString stackString();
39 
40  QString m_stack = stackString();
41  };
42 
50  {
51  public:
54  CJsonScope(const QString &name, int index = -1) noexcept : m_index(index), m_string(&name) { push(); }
55  CJsonScope(QLatin1String name, int index = -1) noexcept : m_index(index), m_latin1(name) { push(); }
56  template <size_t N>
57  CJsonScope(const char (&name)[N], int index = -1) noexcept : CJsonScope(QLatin1String(name, N), index)
58  {}
60 
62  CJsonScope(const QString &&, int = -1) = delete;
63 
66  CJsonScope(const CJsonScope &) = delete;
67  CJsonScope &operator=(const CJsonScope &) = delete;
69 
71  ~CJsonScope() { pop(); }
72 
73  private:
74  void push() const noexcept;
75  void pop() const noexcept;
76 
77  friend class CJsonException;
78  int m_index = -1;
79  const QString *m_string = nullptr;
80  QLatin1String m_latin1;
81  };
82 } // namespace swift::misc
83 
84 #endif // SWIFT_MISC_JSONEXCEPTION_H
Thrown when a convertFromJson method encounters an unrecoverable error in JSON data.
Definition: jsonexception.h:24
const QString & getStackTrace() const
Get a stack trace of where in the JSON object tree the error occurred.
Definition: jsonexception.h:32
CJsonException(const QString &message)
Constructor.
Definition: jsonexception.h:29
Pseudo-RAII pattern that tracks the current JSON value being converted.
Definition: jsonexception.h:50
CJsonScope(const CJsonScope &)=delete
Not copyable.
CJsonScope(const char(&name)[N], int index=-1) noexcept
Construct a scope with the given name and optional index subscript.
Definition: jsonexception.h:57
CJsonScope(QLatin1String name, int index=-1) noexcept
Construct a scope with the given name and optional index subscript.
Definition: jsonexception.h:55
CJsonScope & operator=(const CJsonScope &)=delete
Not copyable.
CJsonScope(const QString &name, int index=-1) noexcept
Construct a scope with the given name and optional index subscript.
Definition: jsonexception.h:54
~CJsonScope()
Destructor.
Definition: jsonexception.h:71
CJsonScope(const QString &&, int=-1)=delete
QString constructor argument must be an lvalue.
Free functions in swift::misc.
#define SWIFT_MISC_EXPORT
Export a class or function from the library.