1 | // Copyright 2013 The Flutter 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 LIB_TONIC_DART_LIST_H_ |
6 | #define LIB_TONIC_DART_LIST_H_ |
7 | |
8 | #include <stddef.h> |
9 | |
10 | #include "third_party/dart/runtime/include/dart_api.h" |
11 | #include "tonic/converter/dart_converter.h" |
12 | |
13 | namespace tonic { |
14 | |
15 | class DartList { |
16 | public: |
17 | DartList(DartList&& other); |
18 | |
19 | void Set(size_t index, Dart_Handle value); |
20 | Dart_Handle Get(size_t index); |
21 | |
22 | template <class T> |
23 | void Set(size_t index, T value) { |
24 | Set(index, DartConverter<T>::ToDart(value)); |
25 | } |
26 | |
27 | template <class T> |
28 | T Get(size_t index) { |
29 | return DartConverter<T>::FromDart(Get(index)); |
30 | } |
31 | |
32 | Dart_Handle dart_handle() const { return dart_handle_; } |
33 | size_t size() const { return size_; } |
34 | bool is_valid() const { return is_valid_; } |
35 | |
36 | explicit operator bool() const { return is_valid_; } |
37 | |
38 | private: |
39 | explicit DartList(Dart_Handle list); |
40 | friend struct DartConverter<DartList>; |
41 | |
42 | DartList(); |
43 | Dart_Handle dart_handle_; |
44 | size_t size_; |
45 | bool is_valid_; |
46 | |
47 | DartList(const DartList& other) = delete; |
48 | }; |
49 | |
50 | template <> |
51 | struct DartConverter<DartList> { |
52 | static DartList FromArguments(Dart_NativeArguments args, |
53 | int index, |
54 | Dart_Handle& exception); |
55 | }; |
56 | |
57 | } // namespace tonic |
58 | |
59 | #endif // LIB_TONIC_DART_LIST_H_ |
60 |