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_TYPE_H 17 #define CPP_ABCKIT_TYPE_H 18 19 #include "base_classes.h" 20 #include "core/class.h" 21 22 namespace abckit { 23 24 /** 25 * @brief Type 26 */ 27 class Type : public ViewInResource<AbckitType *, const File *> { 28 /// @brief abckit::File 29 friend class abckit::File; 30 /// @brief abckit::File 31 friend class abckit::core::AnnotationInterfaceField; 32 /// @brief abckit::Value 33 friend class abckit::Value; 34 /// @brief arkts::AnnotationInterface 35 friend class arkts::AnnotationInterface; 36 /// @brief abckit::Instruction 37 friend class abckit::Instruction; 38 39 public: 40 /** 41 * @brief Construct a new Type object 42 * @param other 43 */ 44 Type(const Type &other) = default; 45 46 /** 47 * @brief Constructor 48 * @param other 49 * @return Type& 50 */ 51 Type &operator=(const Type &other) = default; 52 53 /** 54 * @brief Construct a new Type object 55 * @param other 56 */ 57 Type(Type &&other) = default; 58 59 /** 60 * @brief Constructor 61 * @param other 62 * @return Type& 63 */ 64 Type &operator=(Type &&other) = default; 65 66 /** 67 * @brief Destroy the Type object 68 */ 69 ~Type() override = default; 70 71 /** 72 * @brief Returns the Type Id of type 73 * @return Returns the AbckitTypeId 74 */ GetTypeId()75 inline enum AbckitTypeId GetTypeId() const 76 { 77 auto ret = GetApiConfig()->cIapi_->typeGetTypeId(GetView()); 78 CheckError(GetApiConfig()); 79 return ret; 80 } 81 82 /** 83 * @brief Returns instance of a `core::Class` that the type is reference to. 84 * @return Instance of a `core::Class` that the type references. 85 */ GetReferenceClass()86 inline core::Class GetReferenceClass() const 87 { 88 auto *ret = GetApiConfig()->cIapi_->typeGetReferenceClass(GetView()); 89 CheckError(GetApiConfig()); 90 return core::Class(ret, GetApiConfig(), GetResource()); 91 } 92 93 protected: 94 /** 95 * @brief Get the Api Config object 96 * @return const ApiConfig* 97 */ GetApiConfig()98 const ApiConfig *GetApiConfig() const override 99 { 100 return conf_; 101 } 102 103 private: Type(AbckitType * type,const ApiConfig * conf,const File * file)104 explicit Type(AbckitType *type, const ApiConfig *conf, const File *file) : ViewInResource(type), conf_(conf) 105 { 106 SetResource(file); 107 }; 108 const ApiConfig *conf_; 109 }; 110 111 } // namespace abckit 112 113 #endif // CPP_ABCKIT_TYPE_H 114