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