• 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 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 class ASTRawDataType;
29 
30 class ASTNamespace : public ASTNode {
31 public:
32     explicit ASTNamespace(const std::string &nspaceStr);
33 
34     ~ASTNamespace() override = default;
35 
GetName()36     inline std::string GetName()
37     {
38         return name_;
39     }
40 
41     void AddNamespace(const AutoPtr<ASTNamespace> &innerNspace);
42 
43     AutoPtr<ASTNamespace> FindNamespace(const std::string &nspaceStr);
44 
45     AutoPtr<ASTNamespace> GetNamespace(size_t index);
46 
GetNamespaceNumber()47     inline size_t GetNamespaceNumber()
48     {
49         return innerNamespaces_.size();
50     }
51 
52     void AddInterface(const AutoPtr<ASTInterfaceType> &interface);
53 
54     AutoPtr<ASTInterfaceType> GetInterface(size_t index);
55 
GetInterfaceNumber()56     inline size_t GetInterfaceNumber()
57     {
58         return interfaces_.size();
59     }
60 
61     void AddSequenceable(const AutoPtr<ASTSequenceableType> &sequenceable);
62 
63     AutoPtr<ASTSequenceableType> GetSequenceable(size_t index);
64 
GetSequenceableNumber()65     inline size_t GetSequenceableNumber()
66     {
67         return sequenceables_.size();
68     }
69 
70     void AddRawData(const AutoPtr<ASTRawDataType> &rawdata);
71 
72     AutoPtr<ASTRawDataType> GetRawData(size_t index);
73 
GetRawDataNumber()74     inline size_t GetRawDataNumber()
75     {
76         return rawdatas_.size();
77     }
78 
ToShortString()79     inline std::string ToShortString()
80     {
81         return name_;
82     }
83 
84     std::string ToString() const override;
85 
86 private:
87     std::string name_;
88     ASTNamespace *outerNamespace_;
89     std::vector<AutoPtr<ASTNamespace>> innerNamespaces_;
90     std::vector<AutoPtr<ASTSequenceableType>> sequenceables_;
91     std::vector<AutoPtr<ASTRawDataType>> rawdatas_;
92     std::vector<AutoPtr<ASTInterfaceType>> interfaces_;
93 };
94 } // namespace Idl
95 } // namespace OHOS
96 
97 #endif // OHOS_IDL_ASTNAMESPACE_H