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