CARVIEW |
Select Language
HTTP/2 200
date: Wed, 16 Jul 2025 16:36:19 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
etag: W/"ec4aa7a16b3ea71641dd8654531e5f1f"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=RWl0CjETAq2Zcb9Bt%2BtWSIXvT%2BV4w8BYhYhPSo7UC0%2Fx4DFMRkI%2FypxeYMlIU4txcN6b%2BXu5Po8YT%2FeszrmAknNxEUhsbeX39Rg4T6WGi%2FoXIEIRUsWDibRAEOvRYNe4di6qZsUO1y9Y5E45B4fxr7CI17qWKskQi0FwI0sXR2Fzo9hqpT50dpEgBirhzr8FNT4AaS%2B%2BYg6ArJEHoDh0mdGh%2FEP%2FZu%2F3Y%2F23M4EjuGLR5tr9%2FCrajc6kZ0%2Bo1fGvU639WumWDuQQFCoBb0fJCg%3D%3D--kY3bKQvmCi79AW3Z--Nw3QY%2B45R5whWqtrMwd4lQ%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.502606035.1752683779; Path=/; Domain=github.com; Expires=Thu, 16 Jul 2026 16:36:19 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Thu, 16 Jul 2026 16:36:19 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: C9F6:168DC7:62ECE:75113:6877D503
Qt Yaml support using yaml-cpp library · GitHub
Show Gist options
Save brcha/d392b2fe5f1e427cc8a6 to your computer and use it in GitHub Desktop.
{{ message }}
Instantly share code, notes, and snippets.
-
Star
20
(20)
You must be signed in to star a gist -
Fork
13
(13)
You must be signed in to fork a gist
-
Save brcha/d392b2fe5f1e427cc8a6 to your computer and use it in GitHub Desktop.
Qt Yaml support using yaml-cpp library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ***** BEGIN LICENSE BLOCK ***** | |
* Version: MPL 2.0 | |
* | |
* This Source Code Form is subject to the terms of the Mozilla Public | |
* License, v. 2.0. If a copy of the MPL was not distributed with this | |
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | |
* | |
* ***** END LICENSE BLOCK ***** */ | |
/* | |
* Copyright (c) 2014, Filip Brcic <brcha@gna.org>. All rights reserved. | |
* | |
* This file is part of lusim | |
*/ | |
#ifndef QTYAML_H | |
#define QTYAML_H | |
#include <yaml-cpp/yaml.h> | |
#include <QtCore/QString> | |
#include <QtCore/QMap> | |
#include <QtCore/QVector> | |
#include <QtCore/QList> | |
#include <QtCore/QPair> | |
namespace YAML { | |
// QString | |
template<> | |
struct convert<QString> | |
{ | |
static Node encode(const QString& rhs) | |
{ | |
return Node(rhs.toStdString()); | |
} | |
static bool decode(const Node& node, QString& rhs) | |
{ | |
if (!node.IsScalar()) | |
return false; | |
rhs = QString::fromStdString(node.Scalar()); | |
return true; | |
} | |
}; | |
// QMap | |
template<typename Key, typename Value> | |
struct convert<QMap<Key, Value> > | |
{ | |
static Node encode(const QMap<Key,Value>& rhs) | |
{ | |
Node node(NodeType::Map); | |
auto it = rhs.constBegin(); | |
while (it != rhs.constEnd()) | |
{ | |
node.force_insert(it.key(), it.value()); | |
++it; | |
} | |
return node; | |
} | |
static bool decode(const Node& node, QMap<Key, Value>& rhs) | |
{ | |
if (!node.IsMap()) | |
return false; | |
rhs.clear(); | |
const_iterator it = node.begin(); | |
while (it != node.end()) | |
{ | |
rhs[it->first.as<Key>()] = it->second.as<Value>(); | |
++it; | |
} | |
return true; | |
} | |
}; | |
// QVector | |
template<typename T> | |
struct convert<QVector<T> > | |
{ | |
static Node encode(const QVector<T>& rhs) | |
{ | |
Node node(NodeType::Sequence); | |
foreach (T value, rhs) { | |
node.push_back(value); | |
} | |
return node; | |
} | |
static bool decode(const Node& node, QVector<T>& rhs) | |
{ | |
if (!node.IsSequence()) | |
return false; | |
rhs.clear(); | |
const_iterator it = node.begin(); | |
while (it != node.end()) | |
{ | |
rhs.push_back(it->as<T>()); | |
++it; | |
} | |
return true; | |
} | |
}; | |
// QList | |
template<typename T> | |
struct convert<QList<T> > | |
{ | |
static Node encode(const QList<T>& rhs) | |
{ | |
Node node(NodeType::Sequence); | |
foreach (T value, rhs) { | |
node.push_back(value); | |
} | |
return node; | |
} | |
static bool decode(const Node& node, QList<T>& rhs) | |
{ | |
if (!node.IsSequence()) | |
return false; | |
rhs.clear(); | |
const_iterator it = node.begin(); | |
while (it != node.end()) | |
{ | |
rhs.push_back(it->as<T>()); | |
++it; | |
} | |
return true; | |
} | |
}; | |
// QPair | |
template<typename T, typename U> | |
struct convert<QPair<T,U> > | |
{ | |
static Node encode(const QPair<T,U>& rhs) | |
{ | |
Node node(NodeType::Sequence); | |
node.push_back(rhs.first); | |
node.push_back(rhs.second); | |
return node; | |
} | |
static bool decode(const Node& node, QPair<T,U>& rhs) | |
{ | |
if (!node.IsSequence()) | |
return false; | |
if (node.size() != 2) | |
return false; | |
rhs.first = node[0].as<T>(); | |
rhs.second = node[1].as<U>(); | |
return true; | |
} | |
}; | |
// TODO: Add the rest of the container classes | |
// QLinkedList, QStack, QQueue, QSet, QMultiMap, QHash, QMultiHash, QStringList, ... | |
} // end namespace YAML | |
#endif // QTYAML_H |
i would like to add something kind of
inline QString toString(const Node& node, const QString &defaultValue = QString())
{
if(node.IsNull() || !node.IsScalar())
return defaultValue;
return QString::fromStdString(node.Scalar());
}
template<typename T>
inline QList<T> toList(const Node& node)
{
if(node.IsNull())
return QList<T>();
return QList<T>::fromStdList(node.as<std::list<T>>());
}
template<typename Key, typename Value>
inline QMap<Key, Value> toMap(const Node& node)
{
if(node.IsNull())
return QMap<Key, Value>();
return QMap<Key, Value>(node.as<std::map<Key, Value>>());
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can’t perform that action at this time.
Add QStringList