exceptioncontext.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "exceptioncontext_p.h"
  2. using namespace QtJsonSerializer;
  3. Q_LOGGING_CATEGORY(QtJsonSerializer::logExceptCtx, "qt.jsonserializer.private.exceptioncontext")
  4. QThreadStorage<SerializationException::PropertyTrace> ExceptionContext::contextStore;
  5. ExceptionContext::ExceptionContext(const QMetaProperty &property)
  6. {
  7. contextStore.localData().push({
  8. property.name(),
  9. property.isEnumType() ?
  10. property.enumerator().name() :
  11. property.typeName()
  12. });
  13. }
  14. ExceptionContext::ExceptionContext(int propertyType, const QByteArray &hint)
  15. {
  16. contextStore.localData().push({
  17. hint.isNull() ? QByteArray("<unnamed>") : hint,
  18. QMetaTypeName(propertyType)
  19. });
  20. }
  21. ExceptionContext::~ExceptionContext()
  22. {
  23. auto &context = contextStore.localData();
  24. if (context.isEmpty())
  25. qCWarning(logExceptCtx) << "Corrupted context store";
  26. else
  27. context.pop();
  28. }
  29. SerializationException::PropertyTrace ExceptionContext::currentContext()
  30. {
  31. return contextStore.localData();
  32. }
  33. int ExceptionContext::currentDepth()
  34. {
  35. return contextStore.localData().size();
  36. }