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_CORE_ANNOTATION_H 17 #define CPP_ABCKIT_CORE_ANNOTATION_H 18 19 #include <functional> 20 21 #include "annotation_element.h" 22 #include "../base_classes.h" 23 24 namespace abckit::core { 25 26 /** 27 * @brief Annotation 28 */ 29 class Annotation : public ViewInResource<AbckitCoreAnnotation *, const File *> { 30 /// @brief core::Function 31 friend class core::Function; 32 /// @brief core::AnnotationElement 33 friend class core::AnnotationElement; 34 /// @brief arkts::Function 35 friend class arkts::Function; 36 /// @brief core::Class 37 friend class core::Class; 38 /// @brief arkts::Class 39 friend class arkts::Class; 40 /// @brief arkts::Function 41 friend class arkts::Function; 42 /// @brief abckit::DefaultHash<Annotation> 43 friend class abckit::DefaultHash<Annotation>; 44 45 protected: 46 /// @brief Core API View type 47 using CoreViewT = Annotation; 48 49 public: 50 /** 51 * @brief Construct a new Annotation object 52 * @param other 53 */ 54 Annotation(const Annotation &other) = default; // CC-OFF(G.CLS.07): design decision, detail: base_concepts.h 55 56 /** 57 * @brief Constructor 58 * @param other 59 * @return Annotation& 60 */ 61 Annotation &operator=(const Annotation &other) = default; 62 63 /** 64 * @brief Construct a new Annotation object 65 * @param other 66 */ 67 Annotation(Annotation &&other) = default; // CC-OFF(G.CLS.07): design decision, detail: base_concepts.h 68 69 /** 70 * @brief Constructor 71 * @param other 72 * @return Annotation& 73 */ 74 Annotation &operator=(Annotation &&other) = default; 75 76 /** 77 * @brief Destroy the Annotation object 78 */ 79 ~Annotation() override = default; 80 81 /** 82 * @brief Get the Interface of Annotation 83 * @return core::AnnotationInterface 84 * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if view itself is false. 85 */ 86 core::AnnotationInterface GetInterface() const; 87 88 /** 89 * @brief Enumerates elements of the Annotation, invoking the callback for each element. 90 * @return `false` if was early exited. Otherwise - `true`. 91 * @param [ in ] cb - Callback that will be invoked. Should return `false` on early exit and `true` when iterations 92 * should continue. 93 * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if `cb` is false. 94 * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if view itself is false. 95 */ 96 bool EnumerateElements(const std::function<bool(core::AnnotationElement)> &cb) const; 97 98 private: Annotation(AbckitCoreAnnotation * ann,const ApiConfig * conf,const File * file)99 Annotation(AbckitCoreAnnotation *ann, const ApiConfig *conf, const File *file) : ViewInResource(ann), conf_(conf) 100 { 101 SetResource(file); 102 }; 103 const ApiConfig *conf_; 104 105 protected: 106 /** 107 * @brief Get the Api Config object 108 * @return const ApiConfig* 109 */ GetApiConfig()110 const ApiConfig *GetApiConfig() const override 111 { 112 return conf_; 113 } 114 }; 115 116 } // namespace abckit::core 117 118 #endif // CPP_ABCKIT_CORE_ANNOTATION_H 119