Magic_Game/src/kiwano/base/ObjectBase.h

78 lines
2.2 KiB
C
Raw Normal View History

2019-04-11 14:40:54 +08:00
// Copyright (c) 2016-2018 Kiwano - Nomango
//
// 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
2019-10-11 21:55:29 +08:00
#include <kiwano/macros.h>
#include <kiwano/core/core.h>
#include <kiwano/base/RefCounter.hpp>
#include <kiwano/base/SmartPtr.hpp>
2019-04-11 14:40:54 +08:00
namespace kiwano
{
2019-08-18 10:23:54 +08:00
KGE_DECLARE_SMART_PTR(ObjectBase);
2019-08-18 10:23:54 +08:00
class KGE_API ObjectBase
2019-10-30 23:12:18 +08:00
: public virtual RefCounter
{
public:
2019-08-18 10:23:54 +08:00
ObjectBase();
2019-08-18 10:23:54 +08:00
virtual ~ObjectBase();
2019-10-13 17:45:58 +08:00
const Any& GetUserData() const;
2019-10-13 17:45:58 +08:00
void SetUserData(Any const& data);
2019-10-13 17:45:58 +08:00
void SetName(String const& name);
2019-10-13 17:45:58 +08:00
String DumpObject();
2019-10-12 11:26:41 +08:00
inline String GetName() const { if (name_) return *name_; return String(); }
2019-10-12 11:26:41 +08:00
inline bool IsName(String const& name) const { return name_ ? (*name_ == name) : name.empty(); }
2019-10-12 11:26:41 +08:00
inline uint32_t GetObjectID() const { return id_; }
public:
static bool IsTracingLeaks();
static void StartTracingLeaks();
static void StopTracingLeaks();
static void DumpTracingObjects();
public:
2019-08-18 10:23:54 +08:00
static Vector<ObjectBase*>& __GetTracingObjects();
2019-08-18 10:23:54 +08:00
static void __AddObjectToTracingList(ObjectBase*);
2019-08-18 10:23:54 +08:00
static void __RemoveObjectFromTracingList(ObjectBase*);
private:
2019-10-12 11:26:41 +08:00
bool tracing_leak_;
2019-10-13 17:45:58 +08:00
Any user_data_;
2019-10-12 11:26:41 +08:00
String* name_;
2019-10-12 11:26:41 +08:00
const uint32_t id_;
static uint32_t last_object_id;
};
}