• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #ifndef OHOS_HDI_ASTMAPTYPE_H
10 #define OHOS_HDI_ASTMAPTYPE_H
11 
12 #include "ast/ast_type.h"
13 #include "util/autoptr.h"
14 
15 namespace OHOS {
16 namespace HDI {
17 class ASTMapType : public ASTType {
18 public:
ASTMapType()19     ASTMapType() : ASTType(TypeKind::TYPE_MAP, false), keyType_(), valueType_() {}
20 
SetKeyType(const AutoPtr<ASTType> & keyType)21     inline void SetKeyType(const AutoPtr<ASTType> &keyType)
22     {
23         keyType_ = keyType;
24     }
25 
GetKeyType()26     inline AutoPtr<ASTType> GetKeyType()
27     {
28         return keyType_;
29     }
30 
SetValueType(const AutoPtr<ASTType> & valueType)31     inline void SetValueType(const AutoPtr<ASTType> &valueType)
32     {
33         valueType_ = valueType;
34     }
35 
GetValueType()36     inline AutoPtr<ASTType> GetValueType()
37     {
38         return valueType_;
39     }
40 
41     bool IsMapType() override;
42 
43     bool HasInnerType(TypeKind innerTypeKind) const override;
44 
45     std::string ToString() const override;
46 
47     TypeKind GetTypeKind() override;
48 
49     std::string EmitCType(TypeMode mode = TypeMode::NO_MODE) const override;
50 
51     std::string EmitCppType(TypeMode mode = TypeMode::NO_MODE) const override;
52 
53     std::string EmitJavaType(TypeMode mode, bool isInnerType = false) const override;
54 
55     void EmitCppWriteVar(const std::string &parcelName, const std::string &name, StringBuilder &sb,
56         const std::string &prefix, unsigned int innerLevel = 0) const override;
57 
58     void EmitCppReadVar(const std::string &parcelName, const std::string &name, StringBuilder &sb,
59         const std::string &prefix, bool initVariable, unsigned int innerLevel = 0) const override;
60 
61     void EmitCppMarshalling(const std::string &parcelName, const std::string &name, StringBuilder &sb,
62         const std::string &prefix, unsigned int innerLevel = 0) const override;
63 
64     void EmitCppUnMarshalling(const std::string &parcelName, const std::string &name, StringBuilder &sb,
65         const std::string &prefix, bool emitType, unsigned int innerLevel = 0) const override;
66 
67     void EmitJavaWriteVar(const std::string &parcelName, const std::string &name, StringBuilder &sb,
68         const std::string &prefix) const override;
69 
70     void EmitJavaReadVar(const std::string &parcelName, const std::string &name, StringBuilder &sb,
71         const std::string &prefix) const override;
72 
73     void EmitJavaReadInnerVar(const std::string &parcelName, const std::string &name, bool isInner, StringBuilder &sb,
74         const std::string &prefix) const override;
75 
76     void RegisterWriteMethod(Language language, SerMode mode, UtilMethodMap &methods) const override;
77 
78     void RegisterReadMethod(Language language, SerMode mode, UtilMethodMap &methods) const override;
79 
80 private:
81     AutoPtr<ASTType> keyType_;
82     AutoPtr<ASTType> valueType_;
83 };
84 } // namespace HDI
85 } // namespace OHOS
86 
87 #endif // OHOS_HDI_ASTMAPTYPE_H