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