Magic_Game/src/kiwano/base/ObjectBase.h

131 lines
3.3 KiB
C
Raw Normal View History

2019-04-11 14:40:54 +08:00
// Copyright (c) 2016-2018 Kiwano - Nomango
2020-01-21 10:09:55 +08:00
//
// 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:
2020-01-21 10:09:55 +08:00
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
2020-01-21 10:09:55 +08:00
//
// 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
2020-05-24 11:26:21 +08:00
#include <kiwano/macros.h>
2020-01-17 16:55:47 +08:00
#include <kiwano/core/Common.h>
2020-04-15 16:37:58 +08:00
#include <kiwano/core/Serializable.h>
2019-11-13 14:33:15 +08:00
#include <kiwano/core/SmartPtr.hpp>
2020-05-24 11:26:21 +08:00
#include <kiwano/base/RefCounter.h>
2019-04-11 14:40:54 +08:00
namespace kiwano
{
2020-01-21 10:09:55 +08:00
KGE_DECLARE_SMART_PTR(ObjectBase);
2020-01-21 10:09:55 +08:00
/**
* \~chinese
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2020-01-21 10:09:55 +08:00
*/
2020-04-15 16:37:58 +08:00
class KGE_API ObjectBase
: public RefCounter
, public Serializable
2020-01-21 10:09:55 +08:00
{
public:
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2020-01-21 10:09:55 +08:00
ObjectBase();
2020-01-21 10:09:55 +08:00
virtual ~ObjectBase();
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><><EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD><EFBFBD>
2020-02-19 12:09:50 +08:00
void SetName(const String& name);
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2020-01-21 10:09:55 +08:00
String GetName() const;
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20>ж϶<D0B6><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ͬ
/// @param name <20><>Ҫ<EFBFBD>жϵ<D0B6><CFB5><EFBFBD><EFBFBD><EFBFBD>
2020-02-19 12:09:50 +08:00
bool IsName(const String& name) const;
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><>ȡ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
2020-01-21 10:09:55 +08:00
const Any& GetUserData() const;
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
2020-02-19 12:09:50 +08:00
void SetUserData(const Any& data);
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ID
2020-01-21 10:09:55 +08:00
uint32_t GetObjectID() const;
2020-01-21 10:09:55 +08:00
/// \~chinese
2020-04-15 16:37:58 +08:00
/// @brief <20><><EFBFBD>л<EFBFBD>
void DoSerialize(Serializer* serializer) const override;
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>
void DoDeserialize(Deserializer* deserializer) override;
2020-01-21 10:09:55 +08:00
public:
/// \~chinese
/// @brief <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>й©׷<C2A9><D7B7>
2020-01-21 10:09:55 +08:00
static bool IsTracingLeaks();
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><>ʼ׷<CABC><D7B7><EFBFBD>ڴ<EFBFBD>й©
2020-01-21 10:09:55 +08:00
static void StartTracingLeaks();
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief ֹͣ׷<D6B9><D7B7><EFBFBD>ڴ<EFBFBD>й©
2020-01-21 10:09:55 +08:00
static void StopTracingLeaks();
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD>׷<EFBFBD><D7B7><EFBFBD>еĶ<D0B5><C4B6><EFBFBD><EFBFBD><EFBFBD>Ϣ
2020-01-21 10:09:55 +08:00
static void DumpTracingObjects();
2020-01-21 10:09:55 +08:00
/// \~chinese
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>׷<EFBFBD><D7B7><EFBFBD>еĶ<D0B5><C4B6><EFBFBD>
2020-01-21 10:09:55 +08:00
static Vector<ObjectBase*>& GetTracingObjects();
2020-01-21 10:09:55 +08:00
private:
static void AddObjectToTracingList(ObjectBase*);
2020-01-21 10:09:55 +08:00
static void RemoveObjectFromTracingList(ObjectBase*);
2020-01-21 10:09:55 +08:00
private:
const uint32_t id_;
2020-02-20 22:27:09 +08:00
2020-02-22 19:44:50 +08:00
bool tracing_leak_;
String* name_;
Any user_data_;
2020-01-21 10:09:55 +08:00
};
2019-12-25 18:07:57 +08:00
2020-01-21 10:09:55 +08:00
inline String ObjectBase::GetName() const
{
if (name_)
return *name_;
return String();
}
2019-12-25 18:07:57 +08:00
2020-02-19 12:09:50 +08:00
inline bool ObjectBase::IsName(const String& name) const
2020-01-21 10:09:55 +08:00
{
return name_ ? (*name_ == name) : name.empty();
}
2019-12-25 18:07:57 +08:00
2020-01-21 10:09:55 +08:00
inline uint32_t ObjectBase::GetObjectID() const
{
return id_;
}
2020-01-21 10:09:55 +08:00
} // namespace kiwano