chromium/components/dbus/properties/types.h

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_DBUS_PROPERTIES_TYPES_H_
#define COMPONENTS_DBUS_PROPERTIES_TYPES_H_

#include <stdint.h>

#include <map>
#include <memory>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>

#include "base/component_export.h"
#include "base/memory/scoped_refptr.h"
#include "dbus/message.h"

namespace base {
class RefCountedMemory;
}

namespace detail {

template <std::size_t i,
          typename... Ts,
          std::enable_if_t<i == sizeof...(Ts), int> = 0>
void WriteDbusTypeTuple(const std::tuple<Ts...>&, dbus::MessageWriter*) {}

template <std::size_t i,
          typename... Ts,
          std::enable_if_t<(i < sizeof...(Ts)), int> = 0>
void WriteDbusTypeTuple(const std::tuple<Ts...>& ts,
                        dbus::MessageWriter* writer) {}

template <typename... Ts>
void WriteDbusTypeTuple(const std::tuple<Ts...>& ts,
                        dbus::MessageWriter* writer) {}

template <std::size_t i,
          typename... Ts,
          std::enable_if_t<i == sizeof...(Ts), int> = 0>
std::string GetDbusTypeTupleSignature() {}

template <std::size_t i,
          typename... Ts,
          std::enable_if_t<(i < sizeof...(Ts)), int> = 0>
std::string GetDbusTypeTupleSignature() {}

template <typename... Ts>
std::string GetDbusTypeTupleSignature() {}

}  // namespace detail

class COMPONENT_EXPORT(DBUS) DbusType {};

template <typename T>
class DbusTypeImpl : public DbusType {};

class COMPONENT_EXPORT(DBUS) DbusBoolean : public DbusTypeImpl<DbusBoolean> {};

class COMPONENT_EXPORT(DBUS) DbusInt32 : public DbusTypeImpl<DbusInt32> {};

class COMPONENT_EXPORT(DBUS) DbusUint32 : public DbusTypeImpl<DbusUint32> {};

class COMPONENT_EXPORT(DBUS) DbusInt64 : public DbusTypeImpl<DbusInt64> {};

class COMPONENT_EXPORT(DBUS) DbusDouble : public DbusTypeImpl<DbusDouble> {};

class COMPONENT_EXPORT(DBUS) DbusString : public DbusTypeImpl<DbusString> {};

class COMPONENT_EXPORT(DBUS) DbusObjectPath
    : public DbusTypeImpl<DbusObjectPath> {};

class COMPONENT_EXPORT(DBUS) DbusVariant : public DbusTypeImpl<DbusVariant> {};

template <typename T>
DbusVariant MakeDbusVariant(T t) {}

template <typename T>
class COMPONENT_EXPORT(DBUS) DbusArray : public DbusTypeImpl<DbusArray<T>> {};

template <typename... Ts>
auto MakeDbusArray(Ts&&... ts) {}

// (If DbusByte was defined) this is the same as DbusArray<DbusByte>.  This
// class avoids having to create a bunch of heavy virtual objects just to wrap
// individual bytes.
class COMPONENT_EXPORT(DBUS) DbusByteArray
    : public DbusTypeImpl<DbusByteArray> {};

template <typename... Ts>
class COMPONENT_EXPORT(DBUS) DbusStruct
    : public DbusTypeImpl<DbusStruct<Ts...>> {};

template <typename... Ts>
auto MakeDbusStruct(Ts&&... ts) {}

template <typename K, typename V>
class COMPONENT_EXPORT(DBUS) DbusDictEntry
    : public DbusTypeImpl<DbusDictEntry<K, V>> {};

template <typename K, typename V>
auto MakeDbusDictEntry(K&& k, V&& v) {}

// A convenience class for DbusArray<DbusDictEntry<DbusString, DbusVariant>>,
// which is a common idiom for DBus APIs.  Except this class has some subtle
// differences:
//   1. Duplicate keys are not allowed.
//   2. You cannot control the ordering of keys.  They will always be in sorted
//      order.
class COMPONENT_EXPORT(DBUS) DbusDictionary
    : public DbusTypeImpl<DbusDictionary> {};

#endif  // COMPONENTS_DBUS_PROPERTIES_TYPES_H_