/
Mr.Stalin
/
FOnline-Engine
Обзор
Документация
Войти
/
Mr.Stalin
/
FOnline-Engine
Код
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Source/Scripting/AngelScript/AngelScriptDict.h
207 строк
7 KB
cvet
Code coverage (#203)
10 авг 2026, 15:25
Не верифицирован
10 авг 2026, 15:25
d73ed92
Код
Авторство
О чём код?
// __________ ___ ______ _ // / ____/ __ \____ / (_)___ ___ / ____/___ ____ _(_)___ ___ // / /_ / / / / __ \/ / / __ \/ _ \ / __/ / __ \/ __ `/ / __ \/ _ ` // / __/ / /_/ / / / / / / / / / __/ / /___/ / / / /_/ / / / / / __/ // /_/ \____/_/ /_/_/_/_/ /_/\___/ /_____/_/ /_/\__, /_/_/ /_/\___/ // /____/ // FOnline Engine // https://fonline.ru // https://github.com/cvet/fonline // // MIT License // // Copyright (c) 2006 - 2026, Anton Tsvetinskiy aka cvet <cvet@tut.by> // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // #pragma once #include "Common.h" #if FO_ANGELSCRIPT_SCRIPTING #include "ScriptSystem.h" namespace AngelScript { class asIScriptEngine; class asITypeInfo; } FO_BEGIN_NAMESPACE class ScriptArray; struct ScriptDictTypeData; class ScriptDict { friend class SafeAlloc; template<typename T> static constexpr bool IsHandleAsType = std::is_same_v<T, void> || std::is_same_v<std::remove_cv_t<T>, Entity> || // std::is_same_v<std::remove_cv_t<T>, DynamicRefTypeInstance> || std::is_same_v<std::remove_cv_t<T>, ScriptArray> || std::is_same_v<std::remove_cv_t<T>, ScriptDict>; public: struct ScriptDictComparator { explicit ScriptDictComparator(ptr<ScriptDict> owner); auto operator()(ptr<void> a, ptr<void> b) const -> bool; ptr<ScriptDict> Owner; }; static auto Create(ptr<AngelScript::asITypeInfo> ti) -> refcount_ptr<ScriptDict>; static auto Create(ptr<AngelScript::asITypeInfo> ti, ptr<void> init_list) -> refcount_ptr<ScriptDict>; ScriptDict(ScriptDict&&) noexcept = delete; auto operator=(ScriptDict&&) noexcept -> ScriptDict& = delete; auto operator=(const ScriptDict& other) -> ScriptDict&; auto operator==(const ScriptDict& other) const -> bool; void AddRef() const; void Release() const; auto GetDictObjectType() -> ptr<AngelScript::asITypeInfo> { return _typeInfo; } auto GetDictObjectType() const -> ptr<const AngelScript::asITypeInfo> { return _typeInfo; } auto GetDictTypeId() const -> int32_t; auto GetMap() const -> ptr<const map<void*, void*, ScriptDictComparator>> { return &_data; } auto IsEmpty() const -> bool; auto GetSize() const -> int32_t; auto Get(ptr<void> key) const -> ptr<void>; auto GetOrCreate(ptr<void> key) -> ptr<void>; auto GetDefault(ptr<void> key, ptr<void> def_val) const -> ptr<void>; auto GetKey(int32_t index) const -> ptr<void>; auto GetValue(int32_t index) const -> ptr<void>; auto GetKeys() const -> refcount_ptr<ScriptArray>; auto GetValues() const -> refcount_ptr<ScriptArray>; auto Exists(ptr<void> key) const -> bool; void Set(ptr<void> key, ptr<void> value); void SetIfNotExist(ptr<void> key, ptr<void> value); auto Remove(ptr<void> key) -> bool; auto RemoveValues(ptr<void> value) -> int32_t; void Clear(); auto GetRefCount() const -> int32_t; void SetFlag() const; auto GetFlag() const -> bool; void EnumReferences(ptr<AngelScript::asIScriptEngine> engine) const; void ReleaseAllHandles(); template<typename T> requires(IsHandleAsType<T>) [[nodiscard]] auto KeyAs(void* key) const { if constexpr (std::is_same_v<T, void>) { return NativeDataProvider::ReadHandleSlot(KeyAs<const void>(key)); } else { return NativeDataProvider::ReadConstTypedHandleSlot<std::remove_const_t<T>>(KeyAs<const void>(key)); } } template<typename T> requires(!IsHandleAsType<T>) [[nodiscard]] auto KeyAs(void* key) const -> ptr<T> { if constexpr (std::is_void_v<std::remove_cv_t<T>>) { return static_cast<T*>(key); } else { return cast_from_void<T*>(key); } } template<typename T> requires(IsHandleAsType<T>) [[nodiscard]] auto ValueAs(void* value) const { if constexpr (std::is_same_v<T, void>) { return NativeDataProvider::ReadHandleSlot(ValueAs<const void>(value)); } else { return NativeDataProvider::ReadConstTypedHandleSlot<std::remove_const_t<T>>(ValueAs<const void>(value)); } } template<typename T> requires(!IsHandleAsType<T>) [[nodiscard]] auto ValueAs(void* value) const -> ptr<T> { if constexpr (std::is_void_v<std::remove_cv_t<T>>) { return static_cast<T*>(value); } else { return cast_from_void<T*>(value); } } template<typename T, typename Index> requires(IsHandleAsType<T>) [[nodiscard]] auto KeyAtAs(Index index) const { return KeyAs<T>(GetKey(numeric_cast<int32_t>(index)).get()); } template<typename T, typename Index> requires(!IsHandleAsType<T>) [[nodiscard]] auto KeyAtAs(Index index) const -> ptr<T> { return KeyAs<T>(GetKey(numeric_cast<int32_t>(index)).get()); } template<typename T, typename Index> requires(IsHandleAsType<T>) [[nodiscard]] auto ValueAtAs(Index index) const { return ValueAs<T>(GetValue(numeric_cast<int32_t>(index)).get()); } template<typename T, typename Index> requires(!IsHandleAsType<T>) [[nodiscard]] auto ValueAtAs(Index index) const -> ptr<T> { return ValueAs<T>(GetValue(numeric_cast<int32_t>(index)).get()); } private: explicit ScriptDict(ptr<AngelScript::asITypeInfo> ti); explicit ScriptDict(ptr<AngelScript::asITypeInfo> ti, ptr<void> init_list); explicit ScriptDict(const ScriptDict& other); ~ScriptDict(); auto PrecacheSubTypeData(int32_t type_id, nptr<AngelScript::asITypeInfo> ti) const -> nptr<ScriptDictTypeData>; auto MakeSubTypeArray(int32_t sub_type_id, const char* accessor_name) const -> refcount_ptr<ScriptArray>; refcount_ptr<AngelScript::asITypeInfo> _typeInfo; int32_t _keyTypeId; int32_t _valueTypeId; nptr<ScriptDictTypeData> _keyTypeData; nptr<ScriptDictTypeData> _valueTypeData; map<void*, void*, ScriptDictComparator> _data; mutable std::atomic<int32_t> _refCount {1}; mutable std::atomic<bool> _gcFlag {}; }; void RegisterAngelScriptDict(ptr<AngelScript::asIScriptEngine> as_engine); FO_END_NAMESPACE #endif