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 #include "object_context.h"
17 
18 META_BEGIN_NAMESPACE()
19 
20 namespace Internal {
21 
SetSuperInstance(const IObject::Ptr & aggr,const IObject::Ptr & super)22 void ObjectContext::SetSuperInstance(const IObject::Ptr& aggr, const IObject::Ptr& super)
23 {
24     ObjectFwd::SetSuperInstance(aggr, super);
25     proxy_ = interface_cast<IProxyObject>(super);
26     assert(proxy_);
27     metadata_ = interface_cast<IMetadata>(super);
28     assert(metadata_);
29 }
30 
GetObjectRegistry()31 IObjectRegistry& ObjectContext::GetObjectRegistry()
32 {
33     // If we are shadowing another context, get object registry from the shadowed object
34     if (auto target = GetTarget()) {
35         return interface_cast<IObjectContext>(target)->GetObjectRegistry();
36     }
37     // By default return the global one.
38     return META_NS::GetObjectRegistry();
39 }
40 
GetTarget() const41 const IObject::Ptr ObjectContext::GetTarget() const
42 {
43     return proxy_->GetTarget();
44 }
45 
SetTarget(const IObject::Ptr & target)46 bool ObjectContext::SetTarget(const IObject::Ptr& target)
47 {
48     if (target && !interface_cast<META_NS::IObjectContext>(target)) {
49         CORE_LOG_E("ObjectContext shadow targets must implement IObjectContext");
50         return false;
51     }
52     return proxy_->SetTarget(target);
53 }
54 
GetOverrides() const55 BASE_NS::vector<IProperty::ConstPtr> ObjectContext::GetOverrides() const
56 {
57     return proxy_->GetOverrides();
58 }
59 
GetOverride(BASE_NS::string_view name) const60 IProperty::ConstPtr ObjectContext::GetOverride(BASE_NS::string_view name) const
61 {
62     return proxy_->GetOverride(name);
63 }
64 
SetPropertyTarget(const IProperty::Ptr & property)65 IProperty::Ptr ObjectContext::SetPropertyTarget(const IProperty::Ptr& property)
66 {
67     return proxy_->SetPropertyTarget(property);
68 }
69 
GetProxyProperty(BASE_NS::string_view name) const70 IProperty::ConstPtr ObjectContext::GetProxyProperty(BASE_NS::string_view name) const
71 {
72     return proxy_->GetProxyProperty(name);
73 }
74 
GetPropertyByName(BASE_NS::string_view name)75 IProperty::Ptr ObjectContext::GetPropertyByName(BASE_NS::string_view name)
76 {
77     return metadata_->GetPropertyByName(name);
78 }
79 
GetPropertyByName(BASE_NS::string_view name) const80 IProperty::ConstPtr ObjectContext::GetPropertyByName(BASE_NS::string_view name) const
81 {
82     return metadata_->GetPropertyByName(name);
83 }
84 
GetAllProperties()85 BASE_NS::vector<IProperty::Ptr> ObjectContext::GetAllProperties()
86 {
87     return metadata_->GetAllProperties();
88 }
89 
GetAllProperties() const90 BASE_NS::vector<IProperty::ConstPtr> ObjectContext::GetAllProperties() const
91 {
92     const IMetadata* p = metadata_;
93     return p->GetAllProperties();
94 }
95 
96 } // namespace Internal
97 
98 META_END_NAMESPACE()
99