| 1 |
/****************************************************************************** |
| 2 |
This source file is part of the Avogadro project. |
| 3 |
This source code is released under the 3-Clause BSD License, (see "LICENSE"). |
| 4 |
******************************************************************************/ |
| 5 |
|
| 6 |
#ifndef AVOGADRO_QTGUI_TOMLPARSE_H |
| 7 |
#define AVOGADRO_QTGUI_TOMLPARSE_H |
| 8 |
|
| 9 |
#include "avogadroqtguiexport.h" |
| 10 |
|
| 11 |
#include <QtCore/QJsonObject> |
| 12 |
#include <QtCore/QVariantMap> |
| 13 |
|
| 14 |
#include <string_view> |
| 15 |
|
| 16 |
class QByteArray; |
| 17 |
class QString; |
| 18 |
|
| 19 |
namespace Avogadro { |
| 20 |
namespace QtGui { |
| 21 |
|
| 22 |
/** |
| 23 |
* @brief Parse a TOML document and return the top-level table as a |
| 24 |
* QVariantMap. |
| 25 |
* |
| 26 |
* TOML types are mapped to Qt types as follows: |
| 27 |
* string → QString |
| 28 |
* integer → qlonglong |
| 29 |
* float → double |
| 30 |
* boolean → bool |
| 31 |
* date → QDate |
| 32 |
* time → QTime |
| 33 |
* datetime → QDateTime |
| 34 |
* array → QVariantList |
| 35 |
* table → QVariantMap |
| 36 |
* |
| 37 |
* @param content UTF-8 encoded TOML text. |
| 38 |
* @param ok If non-null, set to true on success and false on error. |
| 39 |
* @return The top-level TOML table as a QVariantMap; empty on parse error. |
| 40 |
*/ |
| 41 |
AVOGADROQTGUI_EXPORT QVariantMap parseTomlString(std::string_view content, |
| 42 |
bool* ok = nullptr); |
| 43 |
|
| 44 |
/** |
| 45 |
* Overload accepting a QString (converted to UTF-8 internally). |
| 46 |
*/ |
| 47 |
AVOGADROQTGUI_EXPORT QVariantMap parseTomlString(const QString& content, |
| 48 |
bool* ok = nullptr); |
| 49 |
|
| 50 |
/** |
| 51 |
* @brief Parse TOML bytes and return the top-level table as a QJsonObject. |
| 52 |
* |
| 53 |
* Convenience wrapper around parseTomlString() that converts the resulting |
| 54 |
* QVariantMap to a QJsonObject via QJsonObject::fromVariantMap(). Useful |
| 55 |
* when the caller needs to work with Qt's JSON types directly. |
| 56 |
* |
| 57 |
* @param content Raw UTF-8 encoded TOML bytes. |
| 58 |
* @param ok If non-null, set to true on success and false on error. |
| 59 |
* @return The top-level TOML table as a QJsonObject; empty on parse error. |
| 60 |
*/ |
| 61 |
AVOGADROQTGUI_EXPORT QJsonObject parseTomlToJson(const QByteArray& content, |
| 62 |
bool* ok = nullptr); |
| 63 |
|
| 64 |
} // namespace QtGui |
| 65 |
} // namespace Avogadro |
| 66 |
|
| 67 |
#endif // AVOGADRO_QTGUI_TOMLPARSE_H |