• 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 META_INTERFACE_SERIALIZATION_ISER_NODE_H
17 #define META_INTERFACE_SERIALIZATION_ISER_NODE_H
18 
19 #include <core/plugin/intf_interface.h>
20 
21 #include <meta/base/interface_macros.h>
22 #include <meta/base/namespace.h>
23 #include <meta/base/ref_uri.h>
24 #include <meta/base/version.h>
25 
26 META_BEGIN_NAMESPACE()
27 
28 class ISerNodeVisitor;
29 
30 class ISerNode : public CORE_NS::IInterface {
31     META_INTERFACE(CORE_NS::IInterface, ISerNode, "eea35313-5add-4408-ae62-0dd7464b986c")
32 public:
33     virtual void Apply(ISerNodeVisitor&) = 0;
34 };
35 
36 class IRootNode : public ISerNode {
37     META_INTERFACE(ISerNode, IRootNode, "d42016dc-3941-463b-b332-b101ca2a9665")
38 public:
39     virtual Version GetVersion() const = 0;
40     virtual Version GetSerializerVersion() const = 0;
41     virtual ISerNode::Ptr GetObject() const = 0;
42 };
43 
44 class INilNode : public ISerNode {
45     META_INTERFACE(ISerNode, INilNode, "d2712b6e-5c3c-4355-8c63-e039b946afdb")
46 public:
47 };
48 
49 class IObjectNode : public ISerNode {
50     META_INTERFACE(ISerNode, IObjectNode, "9c702ee2-6943-4cba-97c8-ac4cf9549cd2")
51 public:
52     virtual BASE_NS::string GetObjectClassName() const = 0;
53     virtual BASE_NS::string GetObjectName() const = 0;
54     virtual ObjectId GetObjectId() const = 0;
55     virtual InstanceId GetInstanceId() const = 0;
56     virtual ISerNode::Ptr GetMembers() const = 0;
57 
58     virtual void SetObjectClassName(BASE_NS::string) = 0;
59     virtual void SetObjectName(BASE_NS::string) = 0;
60     virtual void SetObjectId(ObjectId) = 0;
61     virtual void SetInstanceId(InstanceId) = 0;
62     virtual void SetMembers(ISerNode::Ptr) = 0;
63 };
64 
65 class IArrayNode : public ISerNode {
66     META_INTERFACE(ISerNode, IArrayNode, "40230896-a813-45df-b342-892d5b80405d")
67 public:
68     virtual BASE_NS::vector<ISerNode::Ptr> GetMembers() const = 0;
69     virtual void AddNode(const ISerNode::Ptr& node) = 0;
70 };
71 
72 struct NamedNode {
73     BASE_NS::string name;
74     ISerNode::Ptr node;
75 };
76 
77 class IMapNode : public ISerNode {
78     META_INTERFACE(ISerNode, IMapNode, "2fecfa69-652e-41cc-9724-3145b43a9ec5")
79 public:
80     virtual BASE_NS::vector<NamedNode> GetMembers() const = 0;
81     virtual ISerNode::Ptr FindNode(BASE_NS::string_view name) const = 0;
82     virtual void AddNode(BASE_NS::string_view name, ISerNode::Ptr) = 0;
83 };
84 
85 template<typename Type>
86 class IBuiltinValueNode : public ISerNode {
87     META_INTERFACE(ISerNode, IBuiltinValueNode, MakeUid<Type>("SerNodes"))
88 public:
89     virtual Type GetValue() const = 0;
90     virtual void SetValue(const Type& value) = 0;
91 };
92 
93 using IBoolNode = IBuiltinValueNode<bool>;
94 using IDoubleNode = IBuiltinValueNode<double>;
95 using IIntNode = IBuiltinValueNode<int64_t>;
96 using IUIntNode = IBuiltinValueNode<uint64_t>;
97 using IStringNode = IBuiltinValueNode<BASE_NS::string>;
98 using IRefUriNode = IBuiltinValueNode<RefUri>;
99 
100 class ISerNodeVisitor : public CORE_NS::IInterface {
101     META_INTERFACE(CORE_NS::IInterface, ISerNodeVisitor, "147d085e-a0c3-480b-ad21-37cb8db0c120")
102 public:
103     virtual void Visit(const IRootNode&) = 0;
104     virtual void Visit(const INilNode&) = 0;
105     virtual void Visit(const IObjectNode&) = 0;
106     virtual void Visit(const IArrayNode&) = 0;
107     virtual void Visit(const IMapNode&) = 0;
108     virtual void Visit(const IBoolNode&) = 0;
109     virtual void Visit(const IDoubleNode&) = 0;
110     virtual void Visit(const IIntNode&) = 0;
111     virtual void Visit(const IUIntNode&) = 0;
112     virtual void Visit(const IStringNode&) = 0;
113     virtual void Visit(const IRefUriNode&) = 0;
114     virtual void Visit(const ISerNode&) = 0;
115 };
116 
117 META_INTERFACE_TYPE(ISerNode)
118 
119 META_END_NAMESPACE()
120 
121 #endif
122