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