/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef META_SRC_METADATA_H
#define META_SRC_METADATA_H
#include
#include
#include
#include
#include
#include
#include
#include "container/flat_container.h"
META_BEGIN_NAMESPACE()
namespace Internal {
class Metadata : public IntroduceInterfaces {
public:
Metadata();
Metadata(const IMetadata& data);
~Metadata() override = default;
IMetadata::Ptr CloneMetadata() const override;
protected:
IContainer::Ptr GetPropertyContainer() override;
IContainer::ConstPtr GetPropertyContainer() const override;
void AddFunction(const IFunction::Ptr&) override;
void RemoveFunction(const IFunction::Ptr&) override;
void AddProperty(const IProperty::Ptr&) override;
void RemoveProperty(const IProperty::Ptr&) override;
void AddEvent(const IEvent::Ptr&) override;
void RemoveEvent(const IEvent::Ptr&) override;
void SetProperties(const BASE_NS::vector&) override;
void Merge(const IMetadata::Ptr&) override;
BASE_NS::vector GetAllProperties() override;
BASE_NS::vector GetAllProperties() const override;
BASE_NS::vector GetAllFunctions() override;
BASE_NS::vector GetAllFunctions() const override;
BASE_NS::vector GetAllEvents() override;
BASE_NS::vector GetAllEvents() const override;
IProperty::Ptr GetPropertyByName(BASE_NS::string_view name) override;
IProperty::ConstPtr GetPropertyByName(BASE_NS::string_view name) const override;
IFunction::Ptr GetFunctionByName(BASE_NS::string_view name) override;
IFunction::ConstPtr GetFunctionByName(BASE_NS::string_view name) const override;
IEvent::ConstPtr GetEventByName(BASE_NS::string_view name) const override;
IEvent::Ptr GetEventByName(BASE_NS::string_view name) override;
private:
BASE_NS::shared_ptr propertyContainer_;
IContainer::Ptr properties_;
BASE_NS::vector functionMetadata_;
BASE_NS::vector eventMetadata_;
};
class MetadataPropertyContainer
: public IntroduceInterfaces {
public:
MetadataPropertyContainer();
~MetadataPropertyContainer() override = default;
META_NO_COPY_MOVE(MetadataPropertyContainer);
BASE_NS::vector GetAll() const override;
IObject::Ptr GetAt(SizeType index) const override;
SizeType GetSize() const override;
BASE_NS::vector FindAll(const FindOptions& options) const override;
IObject::Ptr FindAny(const FindOptions& options) const override;
IObject::Ptr FindByName(BASE_NS::string_view name) const override;
bool Add(const IObject::Ptr& object) override;
bool Insert(SizeType index, const IObject::Ptr& object) override;
bool Remove(SizeType index) override;
bool Remove(const IObject::Ptr& child) override;
bool Move(SizeType fromIndex, SizeType toIndex) override;
bool Move(const IObject::Ptr& child, SizeType toIndex) override;
bool Replace(const IObject::Ptr& child, const IObject::Ptr& replaceWith, bool addAlways) override;
void RemoveAll() override;
bool SetRequiredInterfaces(const BASE_NS::vector& interfaces) override;
bool IsAncestorOf(const IObject::ConstPtr& object) const override;
BASE_NS::vector GetRequiredInterfaces() const override;
BASE_NS::shared_ptr EventOnAdded() const override;
BASE_NS::shared_ptr EventOnRemoved() const override;
BASE_NS::shared_ptr EventOnMoved() const override;
BASE_NS::shared_ptr EventOnAdding() const override;
BASE_NS::shared_ptr EventOnRemoving() const override;
IterationResult Iterate(const IterationParameters& params) override;
IterationResult Iterate(const IterationParameters& params) const override;
ObjectId GetClassId() const override
{
return {};
}
BASE_NS::string_view GetClassName() const override
{
return "MetadataPropertyContainer";
}
BASE_NS::string GetName() const override
{
return "";
}
BASE_NS::vector GetInterfaces() const override
{
return GetInterfacesVector();
}
private:
FlatContainer impl_;
mutable BASE_NS::shared_ptr> onAdded_ { CreateShared>(
"OnAdded") };
mutable BASE_NS::shared_ptr> onRemoved_ { CreateShared>(
"OnRemoved") };
mutable BASE_NS::shared_ptr> onMoved_ { CreateShared>(
"OnMoved") };
mutable BASE_NS::shared_ptr> onAdding_ { CreateShared>(
"OnAdding") };
mutable BASE_NS::shared_ptr> onRemoving_ { CreateShared>(
"OnRemoving") };
};
} // namespace Internal
META_END_NAMESPACE()
#endif