1 | // Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file |
2 | // for details. All rights reserved. Use of this source code is governed by a |
3 | // BSD-style license that can be found in the LICENSE file. |
4 | |
5 | #ifndef RUNTIME_BIN_TYPED_DATA_UTILS_H_ |
6 | #define RUNTIME_BIN_TYPED_DATA_UTILS_H_ |
7 | |
8 | #include "include/dart_api.h" |
9 | #include "platform/globals.h" |
10 | |
11 | namespace dart { |
12 | namespace bin { |
13 | |
14 | class TypedDataScope { |
15 | public: |
16 | explicit TypedDataScope(Dart_Handle data); |
17 | ~TypedDataScope() { Release(); } |
18 | |
19 | void Release(); |
20 | |
21 | const char* GetCString() const { |
22 | return reinterpret_cast<const char*>(data_); |
23 | } |
24 | |
25 | const char* GetScopedCString() const; |
26 | |
27 | void* data() const { return data_; } |
28 | intptr_t length() const { return length_; } |
29 | intptr_t size_in_bytes() const; |
30 | Dart_TypedData_Type type() const { return type_; } |
31 | |
32 | private: |
33 | Dart_Handle data_handle_; |
34 | void* data_; |
35 | intptr_t length_; |
36 | Dart_TypedData_Type type_; |
37 | |
38 | DISALLOW_ALLOCATION(); |
39 | DISALLOW_IMPLICIT_CONSTRUCTORS(TypedDataScope); |
40 | }; |
41 | |
42 | } // namespace bin |
43 | } // namespace dart |
44 | |
45 | #endif // RUNTIME_BIN_TYPED_DATA_UTILS_H_ |
46 | |