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 OHOS_IDL_ASTNAMESPACE_H 17 #define OHOS_IDL_ASTNAMESPACE_H 18 19 #include <vector> 20 21 #include "ast/ast_node.h" 22 #include "util/autoptr.h" 23 24 namespace OHOS { 25 namespace Idl { 26 class ASTInterfaceType; 27 class ASTSequenceableType; 28 29 class ASTNamespace : public ASTNode { 30 public: 31 explicit ASTNamespace(const std::string &nspaceStr); 32 33 ~ASTNamespace() override = default; 34 GetName()35 inline std::string GetName() 36 { 37 return name_; 38 } 39 40 void AddNamespace(const AutoPtr<ASTNamespace> &innerNspace); 41 42 AutoPtr<ASTNamespace> FindNamespace(const std::string &nspaceStr); 43 44 AutoPtr<ASTNamespace> GetNamespace(size_t index); 45 GetNamespaceNumber()46 inline size_t GetNamespaceNumber() 47 { 48 return innerNamespaces_.size(); 49 } 50 51 void AddInterface(const AutoPtr<ASTInterfaceType> &interface); 52 53 AutoPtr<ASTInterfaceType> GetInterface(size_t index); 54 GetInterfaceNumber()55 inline size_t GetInterfaceNumber() 56 { 57 return interfaces_.size(); 58 } 59 60 void AddSequenceable(const AutoPtr<ASTSequenceableType> &sequenceable); 61 62 AutoPtr<ASTSequenceableType> GetSequenceable(size_t index); 63 GetSequenceableNumber()64 inline size_t GetSequenceableNumber() 65 { 66 return sequenceables_.size(); 67 } 68 ToShortString()69 inline std::string ToShortString() 70 { 71 return name_; 72 } 73 74 std::string ToString() const override; 75 76 private: 77 std::string name_; 78 ASTNamespace *outerNamespace_; 79 std::vector<AutoPtr<ASTNamespace>> innerNamespaces_; 80 std::vector<AutoPtr<ASTSequenceableType>> sequenceables_; 81 std::vector<AutoPtr<ASTInterfaceType>> interfaces_; 82 }; 83 } // namespace Idl 84 } // namespace OHOS 85 86 #endif // OHOS_IDL_ASTNAMESPACE_H