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