aboutsummaryrefslogtreecommitdiff
path: root/mojo/public/cpp/bindings/native_struct.h
blob: ac27250bcc4221f493a487d25b7b3b0a2e84f2de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MOJO_PUBLIC_CPP_BINDINGS_NATIVE_STRUCT_H_
#define MOJO_PUBLIC_CPP_BINDINGS_NATIVE_STRUCT_H_

#include <vector>

#include "base/optional.h"
#include "mojo/public/cpp/bindings/bindings_export.h"
#include "mojo/public/cpp/bindings/lib/native_struct_data.h"
#include "mojo/public/cpp/bindings/struct_ptr.h"
#include "mojo/public/cpp/bindings/type_converter.h"

namespace mojo {

class NativeStruct;
using NativeStructPtr = StructPtr<NativeStruct>;

// Native-only structs correspond to "[Native] struct Foo;" definitions in
// mojom.
class MOJO_CPP_BINDINGS_EXPORT NativeStruct {
 public:
  using Data_ = internal::NativeStruct_Data;

  static NativeStructPtr New();

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

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

  NativeStruct();
  ~NativeStruct();

  NativeStructPtr Clone() const;
  bool Equals(const NativeStruct& other) const;
  size_t Hash(size_t seed) const;

  base::Optional<std::vector<uint8_t>> data;
};

}  // namespace mojo

#endif  // MOJO_PUBLIC_CPP_BINDINGS_NATIVE_STRUCT_H_