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_ARKTS_NAMESPACE_H 17 #define CPP_ABCKIT_ARKTS_NAMESPACE_H 18 19 #include "../core/namespace.h" 20 #include "./function.h" 21 #include "../base_concepts.h" 22 23 namespace abckit::arkts { 24 25 /** 26 * @brief Namespace 27 */ 28 class Namespace final : public core::Namespace { 29 // We restrict constructors in order to prevent C/C++ API mix-up by user. 30 /// @brief to access private constructor 31 friend class Module; 32 /// @brief abckit::DefaultHash<Namespace> 33 friend class abckit::DefaultHash<Namespace>; 34 /// @brief to access private TargetCast 35 friend class abckit::traits::TargetCheckCast<Namespace>; 36 37 public: 38 /** 39 * @brief Constructor Arkts API Namespace from the Core API with compatibility check 40 * @param other - Core API Namespace 41 */ 42 explicit Namespace(const core::Namespace &other); 43 44 /** 45 * @brief Constructor 46 * @param other 47 */ 48 Namespace(const Namespace &other) = default; 49 /** 50 * @brief Consructor 51 * @param other 52 * @return Namespace& 53 */ 54 Namespace &operator=(const Namespace &other) = default; 55 56 /** 57 * @brief Construct a new Namespace object 58 * @param other 59 */ 60 Namespace(Namespace &&other) = default; 61 /** 62 * @brief Constructor 63 * @param other 64 * @return Namespace& 65 */ 66 Namespace &operator=(Namespace &&other) = default; 67 68 /** 69 * @brief Destroy the Namespace object 70 */ 71 ~Namespace() override = default; 72 73 /** 74 * @brief Returns constructor function for Namespace. 75 * @return Function that is invoked upon Namespace construction. 76 */ 77 Function GetConstructor() const; 78 79 private: 80 /** 81 * @brief Converts underlying namespace from Core to Arkts target 82 * @return AbckitArktsNamespace* - converted namespace 83 * @note Set `ABCKIT_STATUS_WRONG_TARGET` error if `this` does not have `ABCKIT_TARGET_ARK_TS_V1` or 84 * `ABCKIT_TARGET_ARK_TS_V2` target. 85 */ 86 AbckitArktsNamespace *TargetCast() const; 87 88 ABCKIT_NO_UNIQUE_ADDRESS traits::TargetCheckCast<Namespace> targetChecker_; 89 }; 90 91 } // namespace abckit::arkts 92 93 #endif // CPP_ABCKIT_ARKTS_NAMESPACE_H 94