2017-12-20 14:39:09 +01:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
2014-06-18 18:05:04 +02:00
|
|
|
*
|
|
|
|
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
2018-02-26 15:04:20 +01:00
|
|
|
* Copyright 2017-2018, Adriaan de Groot <groot@kde.org>
|
2014-06-18 18:05:04 +02:00
|
|
|
*
|
|
|
|
* Calamares is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Calamares is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-04-29 12:04:55 +02:00
|
|
|
#ifndef UTILS_YAML_H
|
|
|
|
#define UTILS_YAML_H
|
2014-06-18 18:05:04 +02:00
|
|
|
|
|
|
|
#include <QStringList>
|
2015-03-27 11:59:27 +01:00
|
|
|
#include <QVariant>
|
2014-06-18 18:05:04 +02:00
|
|
|
|
2017-09-06 13:51:22 +02:00
|
|
|
class QByteArray;
|
2018-02-26 15:04:20 +01:00
|
|
|
class QFileInfo;
|
2017-09-06 13:51:22 +02:00
|
|
|
|
2019-04-17 11:43:21 +02:00
|
|
|
// The yaml-cpp headers are not C++11 warning-proof, especially
|
|
|
|
// with picky compilers like Clang 8. Since we use Clang for the
|
|
|
|
// find-all-the-warnings case, switch those warnings off for
|
|
|
|
// the we-can't-change-them system headers.
|
|
|
|
#ifdef __clang__
|
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
|
|
|
|
#pragma clang diagnostic ignored "-Wshadow"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <yaml-cpp/yaml.h>
|
|
|
|
|
|
|
|
#ifdef __clang__
|
|
|
|
#pragma clang diagnostic pop
|
|
|
|
#endif
|
2014-06-18 18:05:04 +02:00
|
|
|
|
2019-03-18 22:38:44 +01:00
|
|
|
/// @brief Appends all te elements of @p node to the string list @p v
|
2014-06-18 18:05:04 +02:00
|
|
|
void operator>>( const YAML::Node& node, QStringList& v );
|
|
|
|
|
2014-07-14 18:10:24 +02:00
|
|
|
namespace CalamaresUtils
|
|
|
|
{
|
2018-02-26 15:04:20 +01:00
|
|
|
/**
|
|
|
|
* Loads a given @p filename and returns the YAML data
|
|
|
|
* as a QVariantMap. If filename doesn't exist, or is
|
|
|
|
* malformed in some way, returns an empty map and sets
|
|
|
|
* @p *ok to false. Otherwise sets @p *ok to true.
|
|
|
|
*/
|
|
|
|
QVariantMap loadYaml( const QString& filename, bool* ok = nullptr );
|
|
|
|
/** Convenience overload. */
|
|
|
|
QVariantMap loadYaml( const QFileInfo&, bool* ok = nullptr );
|
2014-07-14 18:10:24 +02:00
|
|
|
|
|
|
|
QVariant yamlToVariant( const YAML::Node& node );
|
|
|
|
QVariant yamlScalarToVariant( const YAML::Node& scalarNode );
|
|
|
|
QVariant yamlSequenceToVariant( const YAML::Node& sequenceNode );
|
|
|
|
QVariant yamlMapToVariant( const YAML::Node& mapNode );
|
|
|
|
|
2019-03-18 22:38:44 +01:00
|
|
|
/// @brief Returns all the elements of @p listNode in a StringList
|
|
|
|
QStringList yamlToStringList( const YAML::Node& listNode );
|
|
|
|
|
2019-01-28 13:50:30 +01:00
|
|
|
/// @brief Save a @p map to @p filename as YAML
|
|
|
|
bool saveYaml( const QString& filename, const QVariantMap& map );
|
|
|
|
|
2017-09-06 13:51:22 +02:00
|
|
|
/**
|
|
|
|
* Given an exception from the YAML parser library, explain
|
|
|
|
* what is going on in terms of the data passed to the parser.
|
|
|
|
* Uses @p label when labeling the data source (e.g. "netinstall data")
|
|
|
|
*/
|
|
|
|
void explainYamlException( const YAML::Exception& e, const QByteArray& data, const char *label );
|
2018-02-26 20:07:06 +01:00
|
|
|
void explainYamlException( const YAML::Exception& e, const QByteArray& data, const QString& label );
|
|
|
|
void explainYamlException( const YAML::Exception& e, const QByteArray& data );
|
2017-09-06 13:51:22 +02:00
|
|
|
|
2019-04-29 12:04:55 +02:00
|
|
|
} // namespace
|
2014-07-14 18:10:24 +02:00
|
|
|
|
2019-04-29 12:04:55 +02:00
|
|
|
#endif
|