• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2025 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 ANI_SIGNATURE_BUILDER_H
17 #define ANI_SIGNATURE_BUILDER_H
18 
19 #include <initializer_list>
20 #include <string>
21 #include <string_view>
22 #include <memory>
23 
24 namespace arkts::ani_signature {
25 
26 class Module {
27 public:
28     class Impl;
29 
30     explicit Module(std::unique_ptr<Impl> impl);
31     ~Module();
32     Module(const Module & /*other*/);
33     Module &operator=(const Module & /*other*/);
34     Module(Module &&other);
35     Module &operator=(Module &&other);
36 
37     std::string Descriptor() const;
38     std::string Name() const;
39 
40 private:
41     std::unique_ptr<Impl> impl_;
42 };
43 
44 class Namespace {
45 public:
46     class Impl;
47 
48     explicit Namespace(std::unique_ptr<Impl> impl);
49     ~Namespace();
50     Namespace(const Namespace & /*other*/);
51     Namespace &operator=(const Namespace & /*other*/);
52     Namespace(Namespace &&other);
53     Namespace &operator=(Namespace &&other);
54 
55     std::string Descriptor() const;
56     std::string Name() const;
57 
58 private:
59     std::unique_ptr<Impl> impl_;
60 };
61 
62 class Type {
63 public:
64     class Impl;
65 
66     explicit Type(std::unique_ptr<Impl> impl);
67     ~Type();
68     Type(const Type & /*other*/);
69     Type &operator=(const Type & /*other*/);
70     Type(Type &&other);
71     Type &operator=(Type &&other);
72 
73     std::string Descriptor() const;
74 
75 private:
76     std::unique_ptr<Impl> impl_;
77 };
78 
79 class Builder {
80 public:
81     static Type BuildUndefined();
82     static Type BuildNull();
83 
84     static Type BuildBoolean();
85     static Type BuildChar();
86     static Type BuildByte();
87     static Type BuildShort();
88     static Type BuildInt();
89     static Type BuildLong();
90     static Type BuildFloat();
91     static Type BuildDouble();
92 
93     static Module BuildModule(std::string_view fullName);
94     static Namespace BuildNamespace(std::initializer_list<std::string_view> fullName);
95     static Namespace BuildNamespace(std::string_view fullName);
96     static Type BuildClass(std::initializer_list<std::string_view> fullName);
97     static Type BuildClass(std::string_view fullName);
98     static Type BuildEnum(std::initializer_list<std::string_view> fullName);
99     static Type BuildEnum(std::string_view fullName);
100     static Type BuildPartial(std::initializer_list<std::string_view> fullName);
101     static Type BuildPartial(std::string_view fullName);
102     static Type BuildRequired(std::initializer_list<std::string_view> fullName);
103     static Type BuildRequired(std::string_view fullName);
104     static Type BuildFunctionalObject(std::size_t nrRequiredArgs, bool hasResetArgs);
105     static Type BuildArray(Type const &type);
106 
107     static std::string BuildSignatureDescriptor(std::initializer_list<Type> args);
108     static std::string BuildSignatureDescriptor(std::initializer_list<Type> args, Type const &ret);
109 
110     static std::string BuildConstructorName();
111     static std::string BuildSetterName(std::string_view name);
112     static std::string BuildGetterName(std::string_view name);
113 };
114 
115 class SignatureBuilder {
116 public:
117     SignatureBuilder();
118     ~SignatureBuilder();
119 
120     SignatureBuilder(const SignatureBuilder &) = delete;
121     SignatureBuilder &operator=(const SignatureBuilder &) = delete;
122 
123     SignatureBuilder(SignatureBuilder &&other);
124     SignatureBuilder &operator=(SignatureBuilder &&other);
125 
126     SignatureBuilder &AddUndefined();
127     SignatureBuilder &AddNull();
128 
129     SignatureBuilder &AddBoolean();
130     SignatureBuilder &AddChar();
131     SignatureBuilder &AddByte();
132     SignatureBuilder &AddShort();
133     SignatureBuilder &AddInt();
134     SignatureBuilder &AddLong();
135     SignatureBuilder &AddFloat();
136     SignatureBuilder &AddDouble();
137 
138     SignatureBuilder &Add(Type const &type);
139 
140     SignatureBuilder &AddClass(std::string_view fullName);
141     SignatureBuilder &AddClass(std::initializer_list<std::string_view> fullName);
142     SignatureBuilder &AddEnum(std::string_view fullName);
143     SignatureBuilder &AddEnum(std::initializer_list<std::string_view> fullName);
144     SignatureBuilder &AddPartial(std::string_view fullName);
145     SignatureBuilder &AddPartial(std::initializer_list<std::string_view> fullName);
146     SignatureBuilder &AddRequired(std::string_view fullName);
147     SignatureBuilder &AddRequired(std::initializer_list<std::string_view> fullName);
148     SignatureBuilder &AddFunctionalObject(std::size_t nrRequiredArgs, bool hasResetArgs);
149 
150     SignatureBuilder &SetReturnUndefined();
151     SignatureBuilder &SetReturnNull();
152 
153     SignatureBuilder &SetReturnBoolean();
154     SignatureBuilder &SetReturnChar();
155     SignatureBuilder &SetReturnByte();
156     SignatureBuilder &SetReturnShort();
157     SignatureBuilder &SetReturnInt();
158     SignatureBuilder &SetReturnLong();
159     SignatureBuilder &SetReturnFloat();
160     SignatureBuilder &SetReturnDouble();
161 
162     SignatureBuilder &SetReturn(Type const &type);
163 
164     SignatureBuilder &SetReturnClass(std::string_view fullName);
165     SignatureBuilder &SetReturnClass(std::initializer_list<std::string_view> fullName);
166     SignatureBuilder &SetReturnEnum(std::string_view fullName);
167     SignatureBuilder &SetReturnEnum(std::initializer_list<std::string_view> fullName);
168     SignatureBuilder &SetReturnPartial(std::string_view fullName);
169     SignatureBuilder &SetReturnPartial(std::initializer_list<std::string_view> fullName);
170     SignatureBuilder &SetReturnRequired(std::string_view fullName);
171     SignatureBuilder &SetReturnRequired(std::initializer_list<std::string_view> fullName);
172     SignatureBuilder &SetReturnFunctionalObject(std::size_t nrRequiredArgs, bool hasResetArgs);
173 
174     std::string BuildSignatureDescriptor();
175 
176     class Impl;
177 
178 private:
179     std::unique_ptr<Impl> impl_;
180 };
181 
182 }  // namespace arkts::ani_signature
183 
184 #endif  // ANI_SIGNATURE_BUILDER_H
185