add Object dumps functions
This commit is contained in:
parent
1a5c7b02cb
commit
bf11282ccd
|
|
@ -41,7 +41,7 @@ namespace easy2d
|
|||
}
|
||||
}
|
||||
|
||||
void ActionManager::AddAction(ActionPtr const& action)
|
||||
ActionPtr ActionManager::AddAction(ActionPtr const& action)
|
||||
{
|
||||
E2D_ASSERT(action && "AddAction failed, NULL pointer exception");
|
||||
|
||||
|
|
@ -49,6 +49,7 @@ namespace easy2d
|
|||
{
|
||||
actions_.PushBack(action);
|
||||
}
|
||||
return action;
|
||||
}
|
||||
|
||||
ActionPtr ActionManager::GetAction(String const & name)
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ namespace easy2d
|
|||
using Actions = IntrusiveList<ActionPtr>;
|
||||
|
||||
public:
|
||||
// 执行动作
|
||||
void AddAction(
|
||||
// 添加动作
|
||||
ActionPtr AddAction(
|
||||
ActionPtr const& action
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ namespace easy2d
|
|||
}
|
||||
}
|
||||
|
||||
void EventDispatcher::AddListener(EventListenerPtr const & listener)
|
||||
EventListenerPtr EventDispatcher::AddListener(EventListenerPtr const & listener)
|
||||
{
|
||||
E2D_ASSERT(listener && "AddListener failed, NULL pointer exception");
|
||||
|
||||
|
|
@ -48,6 +48,7 @@ namespace easy2d
|
|||
{
|
||||
listeners_.PushBack(listener);
|
||||
}
|
||||
return listener;
|
||||
}
|
||||
|
||||
void EventDispatcher::AddListener(UINT type, EventCallback callback, String const& name)
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ namespace easy2d
|
|||
|
||||
public:
|
||||
// 添加监听器
|
||||
void AddListener(
|
||||
EventListenerPtr AddListener(
|
||||
EventListenerPtr const& listener
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -19,19 +19,24 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#include "Object.h"
|
||||
#include "logs.h"
|
||||
#include <typeinfo>
|
||||
|
||||
namespace easy2d
|
||||
{
|
||||
namespace
|
||||
{
|
||||
bool tracing_leaks = true;
|
||||
bool tracing_leaks = false;
|
||||
Array<Object*> tracing_objects;
|
||||
}
|
||||
|
||||
unsigned int Object::last_object_id = 0;
|
||||
|
||||
Object::Object()
|
||||
: tracing_leak_(false)
|
||||
, user_data_(nullptr)
|
||||
, name_(nullptr)
|
||||
, id_(++last_object_id)
|
||||
{
|
||||
#ifdef E2D_DEBUG
|
||||
|
||||
|
|
@ -83,6 +88,13 @@ namespace easy2d
|
|||
*name_ = name;
|
||||
}
|
||||
|
||||
String Object::DumpObject()
|
||||
{
|
||||
String name = typeid(*this).name();
|
||||
return String::format(L"{ class=\"%s\" id=%d refcount=%d name=\"%s\" }",
|
||||
name.c_str(), GetObjectID(), GetRefCount(), GetName().c_str());
|
||||
}
|
||||
|
||||
void Object::StartTracingLeaks()
|
||||
{
|
||||
tracing_leaks = true;
|
||||
|
|
@ -93,7 +105,17 @@ namespace easy2d
|
|||
tracing_leaks = false;
|
||||
}
|
||||
|
||||
Array<Object*> const& easy2d::Object::__GetTracingObjects()
|
||||
void Object::DumpTracingObjects()
|
||||
{
|
||||
E2D_LOG(L"-------------------------- All Objects --------------------------");
|
||||
for (const auto object : tracing_objects)
|
||||
{
|
||||
E2D_LOG(object->DumpObject().c_str());
|
||||
}
|
||||
E2D_LOG(L"------------------------- Total size: %d -------------------------", tracing_objects.size());
|
||||
}
|
||||
|
||||
Array<Object*>& easy2d::Object::__GetTracingObjects()
|
||||
{
|
||||
return tracing_objects;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,17 +43,24 @@ namespace easy2d
|
|||
|
||||
void SetName(String const& name);
|
||||
|
||||
inline String GetName() const { if (name_) return *name_; return String(); }
|
||||
inline String GetName() const { if (name_) return *name_; return String(); }
|
||||
|
||||
inline bool IsName(String const& name) const { return (name_ && (*name_ == name)) || (name.empty() && !name_); }
|
||||
inline bool IsName(String const& name) const { return name_ ? (*name_ == name) : name.empty(); }
|
||||
|
||||
inline unsigned int GetObjectID() const { return id_; }
|
||||
|
||||
String DumpObject();
|
||||
|
||||
public:
|
||||
static void StartTracingLeaks();
|
||||
|
||||
static void StopTracingLeaks();
|
||||
|
||||
static Array<Object*> const& __GetTracingObjects();
|
||||
static void DumpTracingObjects();
|
||||
|
||||
public:
|
||||
static Array<Object*>& __GetTracingObjects();
|
||||
|
||||
protected:
|
||||
static void __AddObjectToTracingList(Object*);
|
||||
|
||||
static void __RemoveObjectFromTracingList(Object*);
|
||||
|
|
@ -62,5 +69,8 @@ namespace easy2d
|
|||
bool tracing_leak_;
|
||||
void* user_data_;
|
||||
String* name_;
|
||||
|
||||
const unsigned int id_;
|
||||
static unsigned int last_object_id;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,56 +93,56 @@ namespace easy2d
|
|||
inline void Print(const wchar_t* format, _Args&&... args) const
|
||||
{
|
||||
using namespace __console_colors;
|
||||
Output(std::wcout, stdout_white, nullptr, format, std::forward<_Args&&>(args)...);
|
||||
Output(std::wcout, stdout_white, nullptr, format, std::forward<_Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename ..._Args>
|
||||
inline void Println(const wchar_t* format, _Args&&... args) const
|
||||
{
|
||||
using namespace __console_colors;
|
||||
OutputLine(std::wcout, stdout_white, nullptr, format, std::forward<_Args&&>(args)...);
|
||||
OutputLine(std::wcout, stdout_white, nullptr, format, std::forward<_Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename ..._Args>
|
||||
inline void Message(const wchar_t * format, _Args&&... args) const
|
||||
{
|
||||
using namespace __console_colors;
|
||||
Output(std::wcout, stdout_blue, nullptr, format, std::forward<_Args&&>(args)...);
|
||||
Output(std::wcout, stdout_blue, nullptr, format, std::forward<_Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename ..._Args>
|
||||
inline void Messageln(const wchar_t * format, _Args&&... args) const
|
||||
{
|
||||
using namespace __console_colors;
|
||||
OutputLine(std::wcout, stdout_blue, nullptr, format, std::forward<_Args&&>(args)...);
|
||||
OutputLine(std::wcout, stdout_blue, nullptr, format, std::forward<_Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename ..._Args>
|
||||
inline void Warning(const wchar_t* format, _Args&&... args) const
|
||||
{
|
||||
using namespace __console_colors;
|
||||
Output(std::wcerr, stdout_yellow_bg, L"Warning: ", format, std::forward<_Args&&>(args)...);
|
||||
Output(std::wcerr, stdout_yellow_bg, L"Warning: ", format, std::forward<_Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename ..._Args>
|
||||
inline void Warningln(const wchar_t* format, _Args&&... args) const
|
||||
{
|
||||
using namespace __console_colors;
|
||||
OutputLine(std::wcerr, stdout_yellow_bg, L"Warning: ", format, std::forward<_Args&&>(args)...);
|
||||
OutputLine(std::wcerr, stdout_yellow_bg, L"Warning: ", format, std::forward<_Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename ..._Args>
|
||||
inline void Error(const wchar_t* format, _Args&&... args) const
|
||||
{
|
||||
using namespace __console_colors;
|
||||
Output(std::wcerr, stderr_red_bg, L"Error: ", format, std::forward<_Args&&>(args)...);
|
||||
Output(std::wcerr, stderr_red_bg, L"Error: ", format, std::forward<_Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename ..._Args>
|
||||
inline void Errorln(const wchar_t* format, _Args&&... args) const
|
||||
{
|
||||
using namespace __console_colors;
|
||||
OutputLine(std::wcerr, stderr_red_bg, L"Error: ", format, std::forward<_Args&&>(args)...);
|
||||
OutputLine(std::wcerr, stderr_red_bg, L"Error: ", format, std::forward<_Args>(args)...);
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
@ -154,7 +154,7 @@ namespace easy2d
|
|||
if (!enabled_)
|
||||
return;
|
||||
|
||||
Output(os, color, prompt, format, std::forward<_Args&&>(args)...);
|
||||
Output(os, color, prompt, format, std::forward<_Args>(args)...);
|
||||
|
||||
os << std::endl;
|
||||
::OutputDebugStringW(L"\r\n");
|
||||
|
|
@ -166,7 +166,7 @@ namespace easy2d
|
|||
if (!enabled_)
|
||||
return;
|
||||
|
||||
std::wstring output = MakeOutputString(prompt, format, std::forward<_Args&&>(args)...);
|
||||
std::wstring output = MakeOutputString(prompt, format, std::forward<_Args>(args)...);
|
||||
|
||||
os << color << output;
|
||||
::OutputDebugStringW(output.c_str());
|
||||
|
|
@ -179,8 +179,8 @@ namespace easy2d
|
|||
{
|
||||
static wchar_t temp_buffer[1024 * 3 + 1];
|
||||
|
||||
const auto len = ::_scwprintf(format, std::forward<_Args&&>(args)...);
|
||||
::swprintf_s(temp_buffer, len + 1, format, std::forward<_Args&&>(args)...);
|
||||
const auto len = ::_scwprintf(format, std::forward<_Args>(args)...);
|
||||
::swprintf_s(temp_buffer, len + 1, format, std::forward<_Args>(args)...);
|
||||
|
||||
std::wstringstream ss;
|
||||
ss << Logger::OutPrefix;
|
||||
|
|
|
|||
|
|
@ -337,7 +337,7 @@ namespace easy2d
|
|||
|
||||
inline JsonValue& operator=(JsonValue && other)
|
||||
{
|
||||
JsonValue{ std::forward<JsonValue &&>(other) }.swap(*this);
|
||||
JsonValue{ std::forward<JsonValue>(other) }.swap(*this);
|
||||
return (*this);
|
||||
}
|
||||
};
|
||||
|
|
@ -355,8 +355,7 @@ namespace easy2d
|
|||
|
||||
template <
|
||||
typename _CompatibleTy,
|
||||
enable_if_t<std::is_constructible<string_type, _CompatibleTy>::value, int> = 0
|
||||
>
|
||||
enable_if_t<std::is_constructible<string_type, _CompatibleTy>::value, int> = 0>
|
||||
basic_json(const _CompatibleTy& value)
|
||||
{
|
||||
value_.type = JsonType::String;
|
||||
|
|
@ -461,37 +460,6 @@ namespace easy2d
|
|||
return string_type();
|
||||
}
|
||||
|
||||
inline size_type size() const
|
||||
{
|
||||
switch (type())
|
||||
{
|
||||
case JsonType::Null:
|
||||
return 0;
|
||||
case JsonType::Array:
|
||||
return value_.data.vector->size();
|
||||
case JsonType::Object:
|
||||
return value_.data.object->size();
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool empty() const
|
||||
{
|
||||
if (is_null())
|
||||
return true;
|
||||
|
||||
if (is_object())
|
||||
return value_.data.object->empty();
|
||||
|
||||
if (is_array())
|
||||
return value_.data.vector->empty();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
inline void clear() { value_ = nullptr; }
|
||||
|
||||
inline void swap(basic_json& rhs) { value_.swap(rhs.value_); }
|
||||
|
||||
public:
|
||||
|
|
@ -693,9 +661,9 @@ namespace easy2d
|
|||
public:
|
||||
// operator= functions
|
||||
|
||||
inline basic_json& operator=(basic_json other)
|
||||
inline basic_json& operator=(basic_json const& other)
|
||||
{
|
||||
other.swap(*this);
|
||||
value_ = other.value_;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
|
|
@ -770,7 +738,7 @@ namespace easy2d
|
|||
{
|
||||
throw json_invalid_key();
|
||||
}
|
||||
return iter.second;
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
template <typename _CharT>
|
||||
|
|
@ -801,7 +769,7 @@ namespace easy2d
|
|||
{
|
||||
throw json_invalid_key();
|
||||
}
|
||||
return iter.second;
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
public:
|
||||
|
|
@ -862,6 +830,8 @@ namespace easy2d
|
|||
template <typename _Ty>
|
||||
struct iterator_impl
|
||||
{
|
||||
friend _Ty;
|
||||
|
||||
using value_type = _Ty;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using iterator_category = std::bidirectional_iterator_tag;
|
||||
|
|
@ -1147,6 +1117,56 @@ namespace easy2d
|
|||
inline const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
|
||||
inline const_reverse_iterator crend() const { return rend(); }
|
||||
|
||||
public:
|
||||
inline size_type size() const
|
||||
{
|
||||
switch (type())
|
||||
{
|
||||
case JsonType::Null:
|
||||
return 0;
|
||||
case JsonType::Array:
|
||||
return value_.data.vector->size();
|
||||
case JsonType::Object:
|
||||
return value_.data.object->size();
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool empty() const
|
||||
{
|
||||
if (is_null())
|
||||
return true;
|
||||
|
||||
if (is_object())
|
||||
return value_.data.object->empty();
|
||||
|
||||
if (is_array())
|
||||
return value_.data.vector->empty();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename _Kty>
|
||||
inline const_iterator find(_Kty && key) const
|
||||
{
|
||||
if (is_object())
|
||||
{
|
||||
const_iterator iter;
|
||||
iter.it_.object_iter = value_.data.object->find(std::forward<_Kty>(key));
|
||||
return iter;
|
||||
}
|
||||
return cend();
|
||||
}
|
||||
|
||||
template <typename _Kty>
|
||||
inline size_type count(_Kty && key) const
|
||||
{
|
||||
return is_object() ? value_.data.object->count(std::forward<_Kty>(key)) : 0;
|
||||
}
|
||||
|
||||
inline void clear() { value_ = nullptr; }
|
||||
|
||||
public:
|
||||
// compare functions
|
||||
|
||||
|
|
|
|||
|
|
@ -190,6 +190,20 @@ namespace easy2d
|
|||
void swap(String& rhs);
|
||||
size_t hash() const;
|
||||
|
||||
public:
|
||||
static String parse(int val);
|
||||
static String parse(unsigned int val);
|
||||
static String parse(long val);
|
||||
static String parse(unsigned long val);
|
||||
static String parse(long long val);
|
||||
static String parse(unsigned long long val);
|
||||
static String parse(float val);
|
||||
static String parse(double val);
|
||||
static String parse(long double val);
|
||||
|
||||
template<typename ..._Args>
|
||||
static String format(const wchar_t* const fmt, _Args&&... args);
|
||||
|
||||
public:
|
||||
inline iterator begin() { check_operability(); return iterator(str_); }
|
||||
inline const_iterator begin() const { return const_iterator(const_str_); }
|
||||
|
|
@ -229,9 +243,6 @@ namespace easy2d
|
|||
inline String& operator=(String const& rhs) { if (this != &rhs) String{ rhs }.swap(*this); return *this; }
|
||||
inline String& operator=(String && rhs) { if (this != &rhs) String{ rhs }.swap(*this); return *this; }
|
||||
|
||||
inline bool operator!=(String const& rhs) { return compare(rhs) != 0; }
|
||||
inline bool operator!=(const wchar_t* cstr) { return compare(cstr) != 0; }
|
||||
|
||||
public:
|
||||
static const String::size_type npos = static_cast<size_type>(-1);
|
||||
|
||||
|
|
@ -299,8 +310,20 @@ namespace easy2d
|
|||
//
|
||||
|
||||
inline bool operator==(String const& lhs, String const& rhs) { return lhs.compare(rhs) == 0; }
|
||||
inline bool operator==(const wchar_t* lhs, String const& rhs) { return rhs.compare(rhs) == 0; }
|
||||
inline bool operator==(const wchar_t* lhs, String const& rhs) { return rhs.compare(lhs) == 0; }
|
||||
inline bool operator==(String const& lhs, const wchar_t* rhs) { return lhs.compare(rhs) == 0; }
|
||||
inline bool operator==(const char* lhs, String const& rhs) { return rhs.compare(String(lhs)) == 0; }
|
||||
inline bool operator==(String const& lhs, const char* rhs) { return lhs.compare(String(rhs)) == 0; }
|
||||
|
||||
//
|
||||
// operator!= for String
|
||||
//
|
||||
|
||||
inline bool operator!=(String const& lhs, String const& rhs) { return lhs.compare(rhs) != 0; }
|
||||
inline bool operator!=(const wchar_t* lhs, String const& rhs) { return rhs.compare(lhs) != 0; }
|
||||
inline bool operator!=(String const& lhs, const wchar_t* rhs) { return lhs.compare(rhs) != 0; }
|
||||
inline bool operator!=(const char* lhs, String const& rhs) { return rhs.compare(String(lhs)) != 0; }
|
||||
inline bool operator!=(String const& lhs, const char* rhs) { return lhs.compare(String(rhs)) != 0; }
|
||||
|
||||
//
|
||||
// operator+ for String
|
||||
|
|
@ -343,7 +366,7 @@ namespace easy2d
|
|||
//
|
||||
|
||||
template<typename ..._Args>
|
||||
inline String format_wstring(const wchar_t* const fmt, _Args&&... args);
|
||||
String format_wstring(const wchar_t* const fmt, _Args&&... args);
|
||||
}
|
||||
|
||||
namespace easy2d
|
||||
|
|
@ -1030,6 +1053,26 @@ namespace easy2d
|
|||
}
|
||||
}
|
||||
|
||||
//
|
||||
// details of String::parese
|
||||
//
|
||||
|
||||
inline String String::parse(int val) { return ::easy2d::to_wstring(val); }
|
||||
inline String String::parse(unsigned int val) { return ::easy2d::to_wstring(val); }
|
||||
inline String String::parse(long val) { return ::easy2d::to_wstring(val); }
|
||||
inline String String::parse(unsigned long val) { return ::easy2d::to_wstring(val); }
|
||||
inline String String::parse(long long val) { return ::easy2d::to_wstring(val); }
|
||||
inline String String::parse(unsigned long long val) { return ::easy2d::to_wstring(val); }
|
||||
inline String String::parse(float val) { return ::easy2d::to_wstring(val); }
|
||||
inline String String::parse(double val) { return ::easy2d::to_wstring(val); }
|
||||
inline String String::parse(long double val) { return ::easy2d::to_wstring(val); }
|
||||
|
||||
template<typename ..._Args>
|
||||
inline String String::format(const wchar_t* const fmt, _Args&&... args)
|
||||
{
|
||||
return ::easy2d::format_wstring(fmt, std::forward<_Args>(args)...);
|
||||
}
|
||||
|
||||
//
|
||||
// details of operator<<>>
|
||||
//
|
||||
|
|
@ -1151,11 +1194,11 @@ namespace easy2d
|
|||
template<typename ..._Args>
|
||||
inline String format_wstring(const wchar_t* const fmt, _Args&&... args)
|
||||
{
|
||||
const auto len = static_cast<String::size_type>(::_scwprintf(fmt, std::forward<_Args&&>(args)...));
|
||||
const auto len = static_cast<String::size_type>(::_scwprintf(fmt, std::forward<_Args>(args)...));
|
||||
if (len)
|
||||
{
|
||||
String str(len, L'\0');
|
||||
::swprintf_s(&str[0], len + 1, fmt, std::forward<_Args&&>(args)...);
|
||||
::swprintf_s(&str[0], len + 1, fmt, std::forward<_Args>(args)...);
|
||||
return str;
|
||||
}
|
||||
return String{};
|
||||
|
|
|
|||
Loading…
Reference in New Issue