LeechCraft 0.6.70-14794-g33744ae6ce
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
introspectable.cpp
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#include "introspectable.h"
10#include <string>
11#include <QtDebug>
12
13namespace LC::Util
14{
16 {
17 static Introspectable inst;
18 return inst;
19 }
20
21 QVariantMap Introspectable::operator() (const QVariant& variant) const
22 {
23 if (!variant.isValid ())
24 throw std::runtime_error { "Invalid variant." };
25
26 const auto type = variant.userType ();
27
28 if (type < static_cast<int> (QVariant::UserType))
29 return { { "data", variant } };
30
31 if (Intros_.contains (type))
32 return Intros_ [type] (variant);
33
34 qWarning () << Q_FUNC_INFO
35 << "unregistered type"
36 << type
37 << variant;
38 throw std::runtime_error { "Unregistered type: " + std::to_string (type) };
39 }
40}
QVariantMap operator()(const T &t) const
static Introspectable & Instance()