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_INTERFACE_H 17 #define CPP_ABCKIT_CORE_ANNOTATION_INTERFACE_H 18 19 #include "../base_classes.h" 20 #include "./annotation_interface_field.h" 21 #include "../config.h" 22 23 #include <vector> 24 #include <string> 25 26 namespace abckit::core { 27 28 /** 29 * @brief AnnotationInterface 30 */ 31 class AnnotationInterface : public ViewInResource<AbckitCoreAnnotationInterface *, const File *> { 32 /// @brief core::Annotation 33 friend class core::Annotation; 34 /// @brief arkts::AnnotationInterface 35 friend class arkts::Module; 36 /// @brief core::Module 37 friend class core::Module; 38 /// @brief core::AnnotationInterfaceField 39 friend class core::AnnotationInterfaceField; 40 /// @brief abckit::DefaultHash<AnnotationInterface> 41 friend class abckit::DefaultHash<AnnotationInterface>; 42 43 protected: 44 /// @brief Core API View type 45 using CoreViewT = AnnotationInterface; 46 47 public: 48 /** 49 * @brief Construct a new Annotation Interface object 50 * @param other 51 */ 52 AnnotationInterface(const AnnotationInterface &other) = default; // CC-OFF(G.CLS.07): design decision 53 54 /** 55 * @brief Constructor 56 * @param other 57 * @return AnnotationInterface& 58 */ 59 AnnotationInterface &operator=(const AnnotationInterface &other) = default; 60 61 /** 62 * @brief Construct a new Annotation Interface object 63 * @param other 64 */ 65 AnnotationInterface(AnnotationInterface &&other) = default; // CC-OFF(G.CLS.07): design decision 66 67 /** 68 * @brief Constructor 69 * @param other 70 * @return AnnotationInterface& 71 */ 72 AnnotationInterface &operator=(AnnotationInterface &&other) = default; 73 74 /** 75 * @brief Destroy the Annotation Interface object 76 */ 77 ~AnnotationInterface() override = default; 78 79 /** 80 * @brief Returns binary file that the given Annotation Interface is a part of. 81 * @return Pointer to the `File`. 82 * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if view itself is false. 83 */ 84 const File *GetFile() const; 85 86 /** 87 * @brief Returns name for annotation interface. 88 * @return `std::string`. 89 * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if view itself is false. 90 * @note Allocates 91 */ 92 std::string GetName() const; 93 94 /** 95 * @brief Get vector with Fields 96 * @return std::vector<AnnotationInterfaceField> 97 * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if view itself is false. 98 */ 99 std::vector<AnnotationInterfaceField> GetFields() const; 100 101 /** 102 * @brief Returns module for annotation interface. 103 * @return `core::Module`. 104 * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if view itself is false. 105 106 */ 107 core::Module GetModule() const; 108 109 /** 110 * @brief Enumerates fields of Annotation Interface, invoking callback `cb` for each field. 111 * @return `false` if was early exited. Otherwise - `true`. 112 * @param [ in ] cb - Callback that will be invoked. Should return `false` on early exit and `true` when iterations 113 * should continue. 114 * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if view itself is false. 115 * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if `cb` is false. 116 */ 117 bool EnumerateFields(const std::function<bool(core::AnnotationInterfaceField)> &cb) const; 118 119 private: 120 template <typename AnnotationPayload> GetFieldsInner(AnnotationPayload annPayload)121 inline bool GetFieldsInner(AnnotationPayload annPayload) 122 { 123 auto isNormalExit = GetApiConfig()->cIapi_->annotationInterfaceEnumerateFields( 124 GetView(), &annPayload, [](AbckitCoreAnnotationInterfaceField *func, void *data) { 125 const auto &payload = *static_cast<AnnotationPayload *>(data); 126 payload.vec->push_back(core::AnnotationInterfaceField(func, payload.config, payload.file)); 127 return true; 128 }); 129 return isNormalExit; 130 } 131 AnnotationInterface(AbckitCoreAnnotationInterface * anni,const ApiConfig * conf,const File * file)132 AnnotationInterface(AbckitCoreAnnotationInterface *anni, const ApiConfig *conf, const File *file) 133 : ViewInResource(anni), conf_(conf) 134 { 135 SetResource(file); 136 }; 137 const ApiConfig *conf_; 138 139 protected: 140 /** 141 * @brief Get the Api Config object 142 * @return const ApiConfig* 143 */ GetApiConfig()144 const ApiConfig *GetApiConfig() const override 145 { 146 return conf_; 147 } 148 }; 149 150 } // namespace abckit::core 151 152 #endif // CPP_ABCKIT_CORE_ANNOTATION_INTERFACE_H 153