• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "opaque_test.impl.hpp"
16 
17 #include <cstdint>
18 #include <iostream>
19 
20 #include "opaque_test.Union.proj.1.hpp"
21 #include "stdexcept"
22 #include "taihe/array.hpp"
23 #include "taihe/runtime.hpp"
24 // Please delete <stdexcept> include when you implement
25 using namespace taihe;
26 
27 namespace {
28 
is_string(uintptr_t a)29 bool is_string(uintptr_t a)
30 {
31     ani_boolean res;
32     ani_class cls;
33     ani_env *env = get_env();
34     env->FindClass("Lstd/core/String;", &cls);
35     env->Object_InstanceOf((ani_object)a, cls, &res);
36     return res;
37 }
38 
get_objects()39 array<uintptr_t> get_objects()
40 {
41     ani_env *env = get_env();
42     ani_string ani_arr_0;
43     int const stringLen = 3;
44     env->String_NewUTF8("AAA", stringLen, &ani_arr_0);
45     ani_ref ani_arr_1;
46     env->GetUndefined(&ani_arr_1);
47     return array<uintptr_t>({(uintptr_t)ani_arr_0, (uintptr_t)ani_arr_1});
48 }
49 
get_object()50 uintptr_t get_object()
51 {
52     ani_env *env = get_env();
53     ani_string ani_arr_0;
54     int const stringLen = 3;
55     env->String_NewUTF8("BBB", stringLen, &ani_arr_0);
56     return (uintptr_t)ani_arr_0;
57 }
58 
is_opaque(::opaque_test::Union const & s)59 bool is_opaque(::opaque_test::Union const &s)
60 {
61     ani_boolean res;
62     ani_class cls;
63     ani_env *env = get_env();
64     if (s.get_tag() == ::opaque_test::Union::tag_t::oValue) {
65         return (ani_boolean) true;
66     }
67     return (ani_boolean) false;
68 }
69 }  // namespace
70 
71 // because these macros are auto-generate, lint will cause false positive.
72 // NOLINTBEGIN
73 TH_EXPORT_CPP_API_is_string(is_string);
74 TH_EXPORT_CPP_API_get_object(get_object);
75 TH_EXPORT_CPP_API_get_objects(get_objects);
76 TH_EXPORT_CPP_API_is_opaque(is_opaque);
77 // NOLINTEND