18bf80f4bSopenharmony_ci/* 28bf80f4bSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 38bf80f4bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 48bf80f4bSopenharmony_ci * you may not use this file except in compliance with the License. 58bf80f4bSopenharmony_ci * You may obtain a copy of the License at 68bf80f4bSopenharmony_ci * 78bf80f4bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 88bf80f4bSopenharmony_ci * 98bf80f4bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 108bf80f4bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 118bf80f4bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 128bf80f4bSopenharmony_ci * See the License for the specific language governing permissions and 138bf80f4bSopenharmony_ci * limitations under the License. 148bf80f4bSopenharmony_ci */ 158bf80f4bSopenharmony_ci 168bf80f4bSopenharmony_ci#ifndef CORE__ECS_HELPER__PROPERTY_TOOLS__PROPERTY_DATA_H 178bf80f4bSopenharmony_ci#define CORE__ECS_HELPER__PROPERTY_TOOLS__PROPERTY_DATA_H 188bf80f4bSopenharmony_ci 198bf80f4bSopenharmony_ci#include <PropertyTools/property_value.h> 208bf80f4bSopenharmony_ci#include <cstddef> 218bf80f4bSopenharmony_ci#include <cstdint> 228bf80f4bSopenharmony_ci 238bf80f4bSopenharmony_ci#include <base/containers/array_view.h> 248bf80f4bSopenharmony_ci#include <base/containers/string.h> 258bf80f4bSopenharmony_ci#include <base/containers/string_view.h> 268bf80f4bSopenharmony_ci#include <base/namespace.h> 278bf80f4bSopenharmony_ci#include <core/namespace.h> 288bf80f4bSopenharmony_ci#include <core/property/intf_property_handle.h> 298bf80f4bSopenharmony_ci 308bf80f4bSopenharmony_ciCORE_BEGIN_NAMESPACE() 318bf80f4bSopenharmony_cistruct Property; 328bf80f4bSopenharmony_ciclass IPropertyApi; 338bf80f4bSopenharmony_ciclass PropertyData : public IPropertyHandle { 348bf80f4bSopenharmony_cipublic: 358bf80f4bSopenharmony_ci PropertyData(); 368bf80f4bSopenharmony_ci 378bf80f4bSopenharmony_ci PropertyData(const PropertyData& other) = delete; 388bf80f4bSopenharmony_ci PropertyData(PropertyData&& other) = delete; 398bf80f4bSopenharmony_ci PropertyData& operator=(const PropertyData& other) = delete; 408bf80f4bSopenharmony_ci PropertyData& operator=(PropertyData&& other) = delete; 418bf80f4bSopenharmony_ci 428bf80f4bSopenharmony_ci struct PropertyOffset { 438bf80f4bSopenharmony_ci constexpr explicit operator bool() const noexcept 448bf80f4bSopenharmony_ci { 458bf80f4bSopenharmony_ci return property != nullptr; 468bf80f4bSopenharmony_ci } 478bf80f4bSopenharmony_ci const Property* property { nullptr }; 488bf80f4bSopenharmony_ci uintptr_t offset { 0U }; 498bf80f4bSopenharmony_ci size_t index { 0 }; 508bf80f4bSopenharmony_ci BASE_NS::string propertyPath; 518bf80f4bSopenharmony_ci }; 528bf80f4bSopenharmony_ci 538bf80f4bSopenharmony_ci bool WLock(IPropertyHandle& handle); // no-copy direct-access (Locks the datahandle); 548bf80f4bSopenharmony_ci bool WUnlock(const IPropertyHandle& handle); // (releases the datahandle lock, and removes ref) 558bf80f4bSopenharmony_ci bool RLock(const IPropertyHandle& handle); // no-copy direct-access (Locks the datahandle); 568bf80f4bSopenharmony_ci bool RUnlock(const IPropertyHandle& handle); // (releases the datahandle lock, and removes ref) 578bf80f4bSopenharmony_ci 588bf80f4bSopenharmony_ci /** no-copy direct write access 598bf80f4bSopenharmony_ci * Searches for property and locks the handle 608bf80f4bSopenharmony_ci * if property was found, returns valid PropertyOffset and keeps it locked 618bf80f4bSopenharmony_ci * if not found, releases the lock immediately and returns null PropertyOffset 628bf80f4bSopenharmony_ci */ 638bf80f4bSopenharmony_ci PropertyOffset WLock(IPropertyHandle& handle, BASE_NS::string_view propertyPath); 648bf80f4bSopenharmony_ci 658bf80f4bSopenharmony_ci /** no-copy direct read access 668bf80f4bSopenharmony_ci * Searches for property and locks the handle 678bf80f4bSopenharmony_ci * if property was found, returns valid PropertyOffset and keeps it locked 688bf80f4bSopenharmony_ci * if not found, releases the lock immediately and returns null PropertyOffset 698bf80f4bSopenharmony_ci */ 708bf80f4bSopenharmony_ci PropertyOffset RLock(const IPropertyHandle& handle, BASE_NS::string_view propertyPath); 718bf80f4bSopenharmony_ci 728bf80f4bSopenharmony_ci /** Find offset and property type for a property. 738bf80f4bSopenharmony_ci * @param properties Property metadata to search from. 748bf80f4bSopenharmony_ci * @param propertyPath property path to search for. 758bf80f4bSopenharmony_ci * @param baseOffset offset to (already locked) property data. 768bf80f4bSopenharmony_ci * @return PropertyOffset-structure. If property was not found, returns null PropertyOffset. 778bf80f4bSopenharmony_ci */ 788bf80f4bSopenharmony_ci static PropertyOffset FindProperty( 798bf80f4bSopenharmony_ci BASE_NS::array_view<const Property> properties, BASE_NS::string_view propertyPath, uintptr_t baseOffset); 808bf80f4bSopenharmony_ci 818bf80f4bSopenharmony_ci /** Find offset and property type for a property. 828bf80f4bSopenharmony_ci * @param properties Property metadata to search from. 838bf80f4bSopenharmony_ci * @param propertyPath Property path to search for. 848bf80f4bSopenharmony_ci * @return PropertyOffset-structure. If property was not found, returns null PropertyOffset. 858bf80f4bSopenharmony_ci */ 868bf80f4bSopenharmony_ci static PropertyOffset FindProperty( 878bf80f4bSopenharmony_ci BASE_NS::array_view<const Property> properties, BASE_NS::string_view propertyPath); 888bf80f4bSopenharmony_ci 898bf80f4bSopenharmony_ci ~PropertyData() override; 908bf80f4bSopenharmony_ci size_t PropertyCount() const; 918bf80f4bSopenharmony_ci 928bf80f4bSopenharmony_ci BASE_NS::array_view<const Property> MetaData() const; 938bf80f4bSopenharmony_ci const Property* MetaData(size_t index) const; 948bf80f4bSopenharmony_ci 958bf80f4bSopenharmony_ci // deprecated accessors.. (PropertyValue is deprecated) 968bf80f4bSopenharmony_ci PropertyValue Get(size_t index); 978bf80f4bSopenharmony_ci PropertyValue Get(size_t index) const; 988bf80f4bSopenharmony_ci 998bf80f4bSopenharmony_ci PropertyValue Get(BASE_NS::string_view name); 1008bf80f4bSopenharmony_ci PropertyValue Get(BASE_NS::string_view name) const; 1018bf80f4bSopenharmony_ci 1028bf80f4bSopenharmony_ci PropertyValue operator[](size_t index); 1038bf80f4bSopenharmony_ci PropertyValue operator[](size_t index) const; 1048bf80f4bSopenharmony_ci 1058bf80f4bSopenharmony_ci PropertyValue operator[](const BASE_NS::string_view& name); 1068bf80f4bSopenharmony_ci PropertyValue operator[](const BASE_NS::string_view& name) const; 1078bf80f4bSopenharmony_ci 1088bf80f4bSopenharmony_ci // Implement the IPropertyHandle api. 1098bf80f4bSopenharmony_ci const IPropertyApi* Owner() const override; 1108bf80f4bSopenharmony_ci size_t Size() const override; 1118bf80f4bSopenharmony_ci const void* RLock() const override; 1128bf80f4bSopenharmony_ci void RUnlock() const override; 1138bf80f4bSopenharmony_ci void* WLock() override; 1148bf80f4bSopenharmony_ci void WUnlock() override; 1158bf80f4bSopenharmony_ci 1168bf80f4bSopenharmony_ciprotected: 1178bf80f4bSopenharmony_ci void Reset(); 1188bf80f4bSopenharmony_ci 1198bf80f4bSopenharmony_ciprivate: 1208bf80f4bSopenharmony_ci const IPropertyApi* owner_ = nullptr; 1218bf80f4bSopenharmony_ci size_t size_ = 0; 1228bf80f4bSopenharmony_ci const void* data_ = nullptr; 1238bf80f4bSopenharmony_ci uint8_t* dataW_ = nullptr; 1248bf80f4bSopenharmony_ci const IPropertyHandle* dataHandle_ = nullptr; 1258bf80f4bSopenharmony_ci IPropertyHandle* dataHandleW_ = nullptr; 1268bf80f4bSopenharmony_ci}; 1278bf80f4bSopenharmony_ciCORE_END_NAMESPACE() 1288bf80f4bSopenharmony_ci 1298bf80f4bSopenharmony_ci#endif // CORE__ECS_HELPER__PROPERTY_TOOLS__PROPERTY_DATA_H 130