diff options
author | Jürgen Gehring <juergen.gehring@bmw.de> | 2015-06-01 07:57:07 -0700 |
---|---|---|
committer | Jürgen Gehring <juergen.gehring@bmw.de> | 2015-06-01 07:57:07 -0700 |
commit | 54982071a99484488207ad3bd5e9391a15bffe02 (patch) | |
tree | 479c178ee629947cf0df65fc0e38f986f6ccdbc9 /include/CommonAPI/DBus/DBusFreedesktopVariant.hpp | |
parent | 45a6f65628a142bb8d37a3b72cb210b1f8c24a5f (diff) | |
download | genivi-common-api-dbus-runtime-54982071a99484488207ad3bd5e9391a15bffe02.tar.gz |
CommonAPI-D-Bus 3.1.13.1.1
Diffstat (limited to 'include/CommonAPI/DBus/DBusFreedesktopVariant.hpp')
-rw-r--r-- | include/CommonAPI/DBus/DBusFreedesktopVariant.hpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/include/CommonAPI/DBus/DBusFreedesktopVariant.hpp b/include/CommonAPI/DBus/DBusFreedesktopVariant.hpp new file mode 100644 index 0000000..31490d2 --- /dev/null +++ b/include/CommonAPI/DBus/DBusFreedesktopVariant.hpp @@ -0,0 +1,74 @@ +// Copyright (C) 2014-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// 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 http://mozilla.org/MPL/2.0/. + +#if !defined (COMMONAPI_INTERNAL_COMPILATION) +#error "Only <CommonAPI/CommonAPI.h> can be included directly, this file may disappear or change contents." +#endif + +#include <CommonAPI/DBus/DBusTypeOutputStream.hpp> + +#ifndef COMMONAPI_DBUS_FREEDESKTOPVARIANT_HPP_ +#define COMMONAPI_DBUS_FREEDESKTOPVARIANT_HPP_ + +namespace CommonAPI { +namespace DBus { + +template<class Visitor, class Variant, typename ... _Types> +struct ApplyTypeCompareVisitor; + +template<class Visitor, class Variant> +struct ApplyTypeCompareVisitor<Visitor, Variant> { + static const uint8_t index = 0; + + static uint8_t visit(Visitor&, const Variant&) { + // won't be called if the variant contains the requested type + assert(false); + return 0; + } +}; + +template<class Visitor, class Variant, typename _Type, typename ... _Types> +struct ApplyTypeCompareVisitor<Visitor, Variant, _Type, _Types...> { + static const uint8_t index + = ApplyTypeCompareVisitor<Visitor, Variant, _Types...>::index + 1; + + static uint8_t visit(Visitor &_visitor, const Variant &_variant) { + DBusTypeOutputStream output; + _Type current; + output.writeType(current); +#ifdef WIN32 + if (_visitor.operator()<_Type>(output.getSignature())) { +#else + if (_visitor.template operator()<_Type>(output.getSignature())) { +#endif + return index; + } else { + return ApplyTypeCompareVisitor< + Visitor, Variant, _Types... + >::visit(_visitor, _variant); + } + } +}; + +template<typename ... _Types> +struct TypeCompareVisitor { +public: + TypeCompareVisitor(const std::string &_type) + : type_(_type) { + } + + template<typename _Type> + bool operator()(const std::string &_type) const { + return (_type == type_); + } + +private: + const std::string type_; +}; + +} // namespace DBus +} // namespace CommonAPI + +#endif // COMMONAPI_DBUS_FREEDESKTOPVARIANT_HPP_ |