• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 
16 #ifndef CPP_ABCKIT_ARKTS_FUNCTION_H
17 #define CPP_ABCKIT_ARKTS_FUNCTION_H
18 
19 #include "../core/function.h"
20 #include "../base_concepts.h"
21 
22 namespace abckit::arkts {
23 
24 /**
25  * @brief Function
26  */
27 class Function final : public core::Function {
28     // We restrict constructors in order to prevent C/C++ API mix-up by user.
29     /// @brief to access private constructor
30     friend class Class;
31     /// @brief to access private constructor
32     friend class Namespace;
33     /// @brief abckit::DefaultHash<Function>
34     friend class abckit::DefaultHash<Function>;
35     /// @brief to access private TargetCast
36     friend class abckit::traits::TargetCheckCast<Function>;
37 
38 public:
39     /**
40      * @brief Constructor Arkts API Function from the Core API with compatibility check
41      * @param other - Core API Function
42      */
43     explicit Function(const core::Function &other);
44 
45     /**
46      * @brief Construct a new Function object
47      * @param other
48      */
49     Function(const Function &other) = default;
50 
51     /**
52      * @brief Constructor
53      * @param coreOther
54      * @return Function&
55      */
56     Function &operator=(const Function &coreOther) = default;
57 
58     /**
59      * @brief Construct a new Function object
60      * @param other
61      */
62     Function(Function &&other) = default;
63 
64     /**
65      * @brief Constructor
66      * @param other
67      * @return Function&
68      */
69     Function &operator=(Function &&other) = default;
70 
71     /**
72      * @brief Destroy the Function object
73      */
74     ~Function() override = default;
75 
76     /**
77      * @brief Check whether the Function is native.
78      * @return `true` if Function is native, `false` otherwise.
79      */
80     bool IsNative() const;
81 
82     /**
83      * @brief Function to add annotation to.
84      * @return Newly created annotation.
85      * @param [ in ] ai -  Annotation Interface that is used to create the annotation.
86      * @note Allocates
87      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if view itself is false.
88      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if `ai` is false.
89      * @note Set `ABCKIT_STATUS_UNSUPPORTED` error if function Function doesn't have `ABCKIT_TARGET_ARK_TS_V1` target.
90      */
91     Annotation AddAnnotation(AnnotationInterface ai) const;
92 
93     /**
94      * @brief Remove annotation from the function.
95      * @param [ in ] anno - Annotation to remove from the function `function`.
96      * @return New state of Function.
97      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if view itself is false.
98      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if `anno` is false.
99      * @note Set `ABCKIT_STATUS_UNSUPPORTED` error if Function doesn't have `ABCKIT_TARGET_ARK_TS_V1` target.
100      */
101     Function RemoveAnnotation(Annotation anno) const;
102 
103 private:
104     /**
105      * @brief Converts underlying function from Core to Arkts target
106      * @return AbckitArktsFunction* - converted function
107      * @note Set `ABCKIT_STATUS_WRONG_TARGET` error if `this` is does not have `ABCKIT_TARGET_ARK_TS_V1` or
108      * `ABCKIT_TARGET_ARK_TS_V2` target.
109      */
110     AbckitArktsFunction *TargetCast() const;
111 
112     ABCKIT_NO_UNIQUE_ADDRESS traits::TargetCheckCast<Function> targetChecker_;
113 };
114 
115 }  // namespace abckit::arkts
116 
117 #endif  // CPP_ABCKIT_ARKTS_FUNCTION_H
118