From eaae662b7d69eeedad5270c5286ccf04e348966e Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 10 Mar 2017 17:06:10 +0300 Subject: [PATCH] Use mapbox::util::variant in a submodule. While we don't have C++17 std::variant<> use a BSD licensed alternative from mapbox team in a base:: wrapper. --- .gitmodules | 3 +++ README.md | 1 + Telegram/SourceFiles/core/variant.h | 36 +++++++++++++++++++++++++++++ Telegram/gyp/Telegram.gyp | 2 ++ third_party/variant | 1 + 5 files changed, 43 insertions(+) create mode 100644 Telegram/SourceFiles/core/variant.h create mode 160000 third_party/variant diff --git a/.gitmodules b/.gitmodules index fd09b6bea6..570f29fe21 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "third_party/GSL"] path = third_party/GSL url = https://github.com/Microsoft/GSL.git +[submodule "third_party/variant"] + path = third_party/variant + url = https://github.com/mapbox/variant diff --git a/README.md b/README.md index 6d1803920b..9f33647ed6 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ The source code is published under GPLv3 with OpenSSL exception, the license is * Opus codec ([BSD license](http://www.opus-codec.org/license/)) * FFmpeg ([LGPL](https://www.ffmpeg.org/legal.html)) * Guideline Support Library ([MIT License](https://github.com/Microsoft/GSL/blob/master/LICENSE)) +* Mapbox Variant ([BSD license](https://github.com/mapbox/variant/blob/master/LICENSE)) * Open Sans font ([Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0.html)) ## Build instructions diff --git a/Telegram/SourceFiles/core/variant.h b/Telegram/SourceFiles/core/variant.h new file mode 100644 index 0000000000..4eb411c6d5 --- /dev/null +++ b/Telegram/SourceFiles/core/variant.h @@ -0,0 +1,36 @@ +/* +This file is part of Telegram Desktop, +the official desktop version of Telegram messaging app, see https://telegram.org + +Telegram Desktop 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. + +It 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. + +In addition, as a special exception, the copyright holders give permission +to link the code of portions of this program with the OpenSSL library. + +Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE +Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org +*/ +#pragma once + +#include + +// We use base::variant<> alias and base::get_if() helper while we don't have std::variant<>. +namespace base { + +template +using variant = mapbox::util::variant; + +template +inline T *get_if(variant *v) { + return (v && v->is()) ? &v->get_unchecked() : nullptr; +} + +} // namespace base diff --git a/Telegram/gyp/Telegram.gyp b/Telegram/gyp/Telegram.gyp index cbb9e047c7..313064f8ae 100644 --- a/Telegram/gyp/Telegram.gyp +++ b/Telegram/gyp/Telegram.gyp @@ -96,6 +96,7 @@ '<(minizip_loc)', '<(sp_media_key_tap_loc)', '<(submodules_loc)/GSL/include', + '<(submodules_loc)/variant/include', ], 'sources': [ '<@(qrc_files)', @@ -178,6 +179,7 @@ '<(src_loc)/core/type_traits.h', '<(src_loc)/core/utils.cpp', '<(src_loc)/core/utils.h', + '<(src_loc)/core/variant.h', '<(src_loc)/core/version.h', '<(src_loc)/core/virtual_method.h', '<(src_loc)/core/zlib_help.h', diff --git a/third_party/variant b/third_party/variant new file mode 160000 index 0000000000..916139a2e5 --- /dev/null +++ b/third_party/variant @@ -0,0 +1 @@ +Subproject commit 916139a2e51e125816efce6e19d428385601273f