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_EXPORT_DESCRIPTOR_H 17 #define CPP_ABCKIT_CORE_EXPORT_DESCRIPTOR_H 18 19 #include "../base_classes.h" 20 21 #include <string> 22 23 namespace abckit::core { 24 25 /** 26 * @brief ExportDescriptor 27 */ 28 class ExportDescriptor : public ViewInResource<AbckitCoreExportDescriptor *, const File *> { 29 // We restrict constructors in order to prevent C/C++ API mix-up by user. 30 /// @brief to access private constructor 31 friend class abckit::File; 32 /// @brief to access private constructor 33 friend class abckit::core::Module; 34 /// @brief to access private constructor 35 friend class abckit::arkts::Module; 36 /// @brief to access private constructor 37 friend class abckit::js::Module; 38 /// @brief to access private constructor 39 friend class abckit::Instruction; 40 /// @brief abckit::DefaultHash<ExportDescriptor> 41 friend class abckit::DefaultHash<ExportDescriptor>; 42 /// @brief abckit::DynamicIsa 43 friend class abckit::DynamicIsa; 44 45 protected: 46 /// @brief Core API View type 47 using CoreViewT = ExportDescriptor; 48 49 public: 50 /** 51 * @brief Construct a new Export Descriptor object 52 * @param other 53 */ 54 ExportDescriptor(const ExportDescriptor &other) = default; 55 56 /** 57 * @brief Constructor 58 * @param other 59 * @return ExportDescriptor& 60 */ 61 ExportDescriptor &operator=(const ExportDescriptor &other) = default; 62 63 /** 64 * @brief Construct a new Export Descriptor object 65 * @param other 66 */ 67 ExportDescriptor(ExportDescriptor &&other) = default; // CC-OFF(G.CLS.07): design decision, detail: base_concepts.h 68 69 /** 70 * @brief Constructor 71 * @param other 72 * @return ExportDescriptor& 73 */ 74 ExportDescriptor &operator=(ExportDescriptor &&other) = default; 75 76 /** 77 * @brief Destroy the Export Descriptor object 78 */ 79 ~ExportDescriptor() override = default; 80 81 /** 82 * @brief Returns binary file that the export descriptor is a part of. 83 * @return Pointer to the `File` that the export is a part of. 84 * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if view itself is false. 85 */ 86 const File *GetFile() const; 87 88 /** 89 * @brief Get the Name object 90 * @return std::string 91 * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if view itself is false. 92 */ 93 std::string GetName() const; 94 95 /** 96 * @brief Returns exporting module. 97 * @return `core::Module` that the export `e` is a part of. 98 * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if view itself is false. 99 */ 100 Module GetExportingModule() const; 101 102 /** 103 * @brief Returns exported module. 104 * @return `core::Module` that the export `e` exports from. For local 105 * entity export equals to the exporting module. For re-exports may be different. 106 * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if view itself is false. 107 */ 108 Module GetExportedModule() const; 109 110 /** 111 * @brief Returns alias for export descriptor. 112 * @return `std::string` - alias of the exported entity. 113 * @note Allocates 114 * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if view itself is false. 115 */ 116 std::string GetAlias() const; 117 118 private: ExportDescriptor(AbckitCoreExportDescriptor * module,const ApiConfig * conf,const File * file)119 ExportDescriptor(AbckitCoreExportDescriptor *module, const ApiConfig *conf, const File *file) 120 : ViewInResource(module), conf_(conf) 121 { 122 SetResource(file); 123 }; 124 const ApiConfig *conf_; 125 126 protected: 127 /** 128 * @brief Get the Api Config object 129 * @return const ApiConfig* 130 */ GetApiConfig()131 const ApiConfig *GetApiConfig() const override 132 { 133 return conf_; 134 } 135 }; 136 137 } // namespace abckit::core 138 139 #endif // CPP_ABCKIT_CORE_EXPORT_DESCRIPTOR_H 140