// optional_primitives.test-mojom.h is auto generated by mojom_bindings_generator.py, do not edit

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

#ifndef OPTIONAL_PRIMITIVES_TEST_MOJOM_H_
#define OPTIONAL_PRIMITIVES_TEST_MOJOM_H_

#include <stdint.h>

#include <limits>
#include <optional>
#include <type_traits>
#include <utility>
#include "mojo/public/cpp/bindings/clone_traits.h"
#include "mojo/public/cpp/bindings/equals_traits.h"
#include "mojo/public/cpp/bindings/struct_ptr.h"
#include "mojo/public/cpp/bindings/struct_traits.h"
#include "mojo/public/cpp/bindings/union_traits.h"
#include "mojo/public/cpp/bindings/lib/serialization.h"

#include "third_party/perfetto/include/perfetto/tracing/traced_value_forward.h"

#include "optional_primitives.test-mojom-features.h"  // IWYU pragma: export
#include "optional_primitives.test-mojom-shared.h"  // IWYU pragma: export
#include "optional_primitives.test-mojom-forward.h"  // IWYU pragma: export
#include <string>
#include <vector>








namespace golden {








class  OptionalPrimitives {
 public:
  template <typename T>
  using EnableIfSame = std::enable_if_t<std::is_same<OptionalPrimitives, T>::value>;
  using DataView = OptionalPrimitivesDataView;
  using Data_ = internal::OptionalPrimitives_Data;

  template <typename... Args>
  static OptionalPrimitivesPtr New(Args&&... args) {
    return OptionalPrimitivesPtr(
        std::in_place, std::forward<Args>(args)...);
  }

  template <typename U>
  static OptionalPrimitivesPtr From(const U& u) {
    return mojo::TypeConverter<OptionalPrimitivesPtr, U>::Convert(u);
  }

  template <typename U>
  U To() const {
    return mojo::TypeConverter<U, OptionalPrimitives>::Convert(*this);
  }


  OptionalPrimitives();

  OptionalPrimitives(
      std::optional<int32_t> int,
      std::optional<int64_t> long,
      std::vector<std::optional<uint32_t>> uints,
      std::vector<std::optional<bool>> boolarray,
      const base::flat_map<bool, std::optional<bool>>& bitmap,
      std::optional<int32_t> int_with_default,
      std::optional<int64_t> long_with_default,
      std::optional<bool> bool_with_default);


  ~OptionalPrimitives();

  // Clone() is a template so it is only instantiated if it is used. Thus, the
  // bindings generator does not need to know whether Clone() or copy
  // constructor/assignment are available for members.
  template <typename StructPtrType = OptionalPrimitivesPtr>
  OptionalPrimitivesPtr Clone() const;

  // Equals() is a template so it is only instantiated if it is used. Thus, the
  // bindings generator does not need to know whether Equals() or == operator
  // are available for members.
  template <typename T, OptionalPrimitives::EnableIfSame<T>* = nullptr>
  bool Equals(const T& other) const;

  template <typename T, OptionalPrimitives::EnableIfSame<T>* = nullptr>
  bool operator==(const T& rhs) const { return Equals(rhs); }

  template <typename T, OptionalPrimitives::EnableIfSame<T>* = nullptr>
  bool operator!=(const T& rhs) const { return !operator==(rhs); }

  template <mojo::internal::SendValidation send_validation, typename UserType>
  static std::vector<uint8_t> Serialize(UserType* input) {
    return mojo::internal::SerializeImpl<
        OptionalPrimitives::DataView, std::vector<uint8_t>, send_validation>(input);
  }

  template <typename UserType>
  static std::vector<uint8_t> Serialize(UserType* input) {
    return mojo::internal::SerializeImpl<
        OptionalPrimitives::DataView, std::vector<uint8_t>>(input);
  }

  template <typename UserType>
  static mojo::Message SerializeAsMessage(UserType* input) {
    return mojo::internal::SerializeAsMessageImpl<
        OptionalPrimitives::DataView>(input);
  }

  // The returned Message is serialized only if the message is moved
  // cross-process or cross-language. Otherwise if the message is Deserialized
  // as the same UserType |input| will just be moved to |output| in
  // DeserializeFromMessage.
  template <typename UserType>
  static mojo::Message WrapAsMessage(UserType input) {
    return mojo::Message(std::make_unique<
        internal::OptionalPrimitives_UnserializedMessageContext<
            UserType, OptionalPrimitives::DataView>>(0, 0, std::move(input)),
        MOJO_CREATE_MESSAGE_FLAG_NONE);
  }

  template <typename UserType>
  static bool Deserialize(const void* data,
                          size_t data_num_bytes,
                          UserType* output) {
    mojo::Message message;
    return mojo::internal::DeserializeImpl<OptionalPrimitives::DataView>(
        message, data, data_num_bytes, output, Validate);
  }

  template <typename UserType>
  static bool Deserialize(base::span<const uint8_t> input,
                          UserType* output) {
    return OptionalPrimitives::Deserialize(
        input.empty() ? nullptr : input.data(), input.size(), output);
  }

  template <typename UserType>
  static bool DeserializeFromMessage(mojo::Message input,
                                     UserType* output) {
    auto context = input.TakeUnserializedContext<
        internal::OptionalPrimitives_UnserializedMessageContext<
            UserType, OptionalPrimitives::DataView>>();
    if (context) {
      *output = std::move(context->TakeData());
      return true;
    }
    input.SerializeIfNecessary();
    return mojo::internal::DeserializeImpl<OptionalPrimitives::DataView>(
        input, input.payload(), input.payload_num_bytes(), output, Validate);
  }

  
  std::optional<int32_t> int;
  
  std::optional<int64_t> long;
  
  std::vector<std::optional<uint32_t>> uints;
  
  std::vector<std::optional<bool>> boolarray;
  
  base::flat_map<bool, std::optional<bool>> bitmap;
  
  std::optional<int32_t> int_with_default;
  
  std::optional<int64_t> long_with_default;
  
  std::optional<bool> bool_with_default;

  // Serialise this struct into a trace.
  void WriteIntoTrace(perfetto::TracedValue traced_context) const;

 private:
  static bool Validate(const void* data,
                       mojo::internal::ValidationContext* validation_context);
};

// The comparison operators are templates, so they are only instantiated if they
// are used. Thus, the bindings generator does not need to know whether
// comparison operators are available for members.
template <typename T, OptionalPrimitives::EnableIfSame<T>* = nullptr>
bool operator<(const T& lhs, const T& rhs);

template <typename T, OptionalPrimitives::EnableIfSame<T>* = nullptr>
bool operator<=(const T& lhs, const T& rhs) {
  return !(rhs < lhs);
}

template <typename T, OptionalPrimitives::EnableIfSame<T>* = nullptr>
bool operator>(const T& lhs, const T& rhs) {
  return rhs < lhs;
}

template <typename T, OptionalPrimitives::EnableIfSame<T>* = nullptr>
bool operator>=(const T& lhs, const T& rhs) {
  return !(lhs < rhs);
}

template <typename StructPtrType>
OptionalPrimitivesPtr OptionalPrimitives::Clone() const {
  return New(
      mojo::Clone(int),
      mojo::Clone(long),
      mojo::Clone(uints),
      mojo::Clone(boolarray),
      mojo::Clone(bitmap),
      mojo::Clone(int_with_default),
      mojo::Clone(long_with_default),
      mojo::Clone(bool_with_default)
  );
}

template <typename T, OptionalPrimitives::EnableIfSame<T>*>
bool OptionalPrimitives::Equals(const T& other_struct) const {
  if (!mojo::Equals(this->int, other_struct.int))
    return false;
  if (!mojo::Equals(this->long, other_struct.long))
    return false;
  if (!mojo::Equals(this->uints, other_struct.uints))
    return false;
  if (!mojo::Equals(this->boolarray, other_struct.boolarray))
    return false;
  if (!mojo::Equals(this->bitmap, other_struct.bitmap))
    return false;
  if (!mojo::Equals(this->int_with_default, other_struct.int_with_default))
    return false;
  if (!mojo::Equals(this->long_with_default, other_struct.long_with_default))
    return false;
  if (!mojo::Equals(this->bool_with_default, other_struct.bool_with_default))
    return false;
  return true;
}

template <typename T, OptionalPrimitives::EnableIfSame<T>*>
bool operator<(const T& lhs, const T& rhs) {
  if (lhs.int < rhs.int)
    return true;
  if (rhs.int < lhs.int)
    return false;
  if (lhs.long < rhs.long)
    return true;
  if (rhs.long < lhs.long)
    return false;
  if (lhs.uints < rhs.uints)
    return true;
  if (rhs.uints < lhs.uints)
    return false;
  if (lhs.boolarray < rhs.boolarray)
    return true;
  if (rhs.boolarray < lhs.boolarray)
    return false;
  if (lhs.bitmap < rhs.bitmap)
    return true;
  if (rhs.bitmap < lhs.bitmap)
    return false;
  if (lhs.int_with_default < rhs.int_with_default)
    return true;
  if (rhs.int_with_default < lhs.int_with_default)
    return false;
  if (lhs.long_with_default < rhs.long_with_default)
    return true;
  if (rhs.long_with_default < lhs.long_with_default)
    return false;
  if (lhs.bool_with_default < rhs.bool_with_default)
    return true;
  if (rhs.bool_with_default < lhs.bool_with_default)
    return false;
  return false;
}


}  // golden

namespace mojo {


template <>
struct  StructTraits<::golden::OptionalPrimitives::DataView,
                                         ::golden::OptionalPrimitivesPtr> {
  static bool IsNull(const ::golden::OptionalPrimitivesPtr& input) { return !input; }
  static void SetToNull(::golden::OptionalPrimitivesPtr* output) { output->reset(); }

  static decltype(::golden::OptionalPrimitives::int) int(
      const ::golden::OptionalPrimitivesPtr& input) {
    return input->int;
  }

  static decltype(::golden::OptionalPrimitives::long) long(
      const ::golden::OptionalPrimitivesPtr& input) {
    return input->long;
  }

  static const decltype(::golden::OptionalPrimitives::uints)& uints(
      const ::golden::OptionalPrimitivesPtr& input) {
    return input->uints;
  }

  static const decltype(::golden::OptionalPrimitives::boolarray)& boolarray(
      const ::golden::OptionalPrimitivesPtr& input) {
    return input->boolarray;
  }

  static const decltype(::golden::OptionalPrimitives::bitmap)& bitmap(
      const ::golden::OptionalPrimitivesPtr& input) {
    return input->bitmap;
  }

  static decltype(::golden::OptionalPrimitives::int_with_default) int_with_default(
      const ::golden::OptionalPrimitivesPtr& input) {
    return input->int_with_default;
  }

  static decltype(::golden::OptionalPrimitives::long_with_default) long_with_default(
      const ::golden::OptionalPrimitivesPtr& input) {
    return input->long_with_default;
  }

  static decltype(::golden::OptionalPrimitives::bool_with_default) bool_with_default(
      const ::golden::OptionalPrimitivesPtr& input) {
    return input->bool_with_default;
  }

  static bool Read(::golden::OptionalPrimitives::DataView input, ::golden::OptionalPrimitivesPtr* output);
};

}  // namespace mojo

#endif  // OPTIONAL_PRIMITIVES_TEST_MOJOM_H_