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_HDI_ENUMTYPE_EMITTER_H
17 #define OHOS_IDL_HDI_ENUMTYPE_EMITTER_H
18 
19 #include "codegen/HDI/hdi_type_emitter.h"
20 
21 namespace OHOS {
22 namespace Idl {
23 class HdiEnumValueEmitter : public HdiTypeEmitter {
24 public:
HdiEnumValueEmitter(const std::string & name,const std::string & value)25     explicit HdiEnumValueEmitter(const std::string &name, const std::string &value) : mName_(name), value_(value) {}
26 
~HdiEnumValueEmitter()27     inline ~HdiEnumValueEmitter() override {}
28 
GetValue()29     inline std::string GetValue()
30     {
31         return value_;
32     }
33 
GetValueName()34     inline std::string GetValueName()
35     {
36         return mName_;
37     }
38 
39 private:
40     std::string mName_;
41     std::string value_;
42 };
43 
44 class HdiEnumTypeEmitter : public HdiTypeEmitter {
45 public:
AddMember(const AutoPtr<HdiEnumValueEmitter> & member)46     inline void AddMember(const AutoPtr<HdiEnumValueEmitter> &member)
47     {
48         members_.push_back(member);
49     }
50 
51     void SetBaseTypeName(const std::string &name);
52 
53     TypeKind GetTypeKind() override;
54 
55     std::string EmitCType(TypeMode mode = TypeMode::NO_MODE) const override;
56 
57     std::string EmitCppType(TypeMode mode = TypeMode::NO_MODE) const override;
58 
59     std::string EmitJavaType(TypeMode mode, bool isInnerType = false) const override;
60 
61     std::string EmitCTypeDecl() const override;
62 
63     std::string EmitCppTypeDecl() const override;
64 
65     void EmitCWriteVar(TypeMode mode, const std::string &name, const std::string &gotoLabel,
66         StringBuilder &sb, const std::string &prefix) const override;
67 
68     void EmitCProxyReadVar(const std::string &name, bool isInnerType, const std::string &gotoLabel, StringBuilder &sb,
69         const std::string &prefix) const override;
70 
71     void EmitCStubReadVar(const std::string &name, const std::string &gotoLabel, StringBuilder &sb,
72         const std::string &prefix) const override;
73 
74     void EmitCppWriteVar(const std::string &parcelName, const std::string &name, StringBuilder &sb,
75         const std::string &prefix, unsigned int innerLevel = 0) const override;
76 
77     void EmitCppReadVar(const std::string &name, StringBuilder &sb, const std::string &prefix,
78         TypeMode mode, unsigned int innerLevel = 0) const override;
79 
80     void EmitCMarshalling(const std::string &name, StringBuilder &sb, const std::string &prefix) const override;
81 
82     void EmitCUnMarshalling(const std::string &name, const std::string &gotoLabel, StringBuilder &sb,
83         const std::string &prefix, std::vector<std::string> &freeObjStatements) const override;
84 
85     void EmitCppMarshalling(const std::string &parcelName, const std::string &name, StringBuilder &sb,
86         const std::string &prefix, unsigned int innerLevel = 0) const override;
87 
88     void EmitCppUnMarshalling(const std::string &parcelName, const std::string &name, StringBuilder &sb,
89         const std::string &prefix, unsigned int innerLevel = 0) const override;
90 private:
91     std::vector<AutoPtr<HdiEnumValueEmitter>> members_;
92     std::string baseTypeName_;
93 };
94 } // namespace Idl
95 } // namespace OHOS
96 
97 #endif // OHOS_IDL_HDI_ENUMTYPE_EMITTER_H