1 // Copyright 2016 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_NATIVE_STRUCT_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_NATIVE_STRUCT_H_ 7 8 #include "mojo/public/cpp/bindings/array.h" 9 #include "mojo/public/cpp/bindings/lib/native_struct_data.h" 10 #include "mojo/public/cpp/bindings/struct_ptr.h" 11 #include "mojo/public/cpp/bindings/type_converter.h" 12 13 namespace mojo { 14 15 class NativeStruct; 16 using NativeStructPtr = StructPtr<NativeStruct>; 17 18 // Native-only structs correspond to "[Native] struct Foo;" definitions in 19 // mojom. 20 class NativeStruct { 21 public: 22 using Data_ = internal::NativeStruct_Data; 23 24 static NativeStructPtr New(); 25 26 template <typename U> From(const U & u)27 static NativeStructPtr From(const U& u) { 28 return TypeConverter<NativeStructPtr, U>::Convert(u); 29 } 30 31 template <typename U> To()32 U To() const { 33 return TypeConverter<U, NativeStruct>::Convert(*this); 34 } 35 36 NativeStruct(); 37 ~NativeStruct(); 38 39 NativeStructPtr Clone() const; 40 bool Equals(const NativeStruct& other) const; 41 42 Array<uint8_t> data; 43 }; 44 45 } // namespace mojo 46 47 #endif // MOJO_PUBLIC_CPP_BINDINGS_NATIVE_STRUCT_H_ 48