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");
|
E2D_ASSERT(action && "AddAction failed, NULL pointer exception");
|
||||||
|
|
||||||
|
|
@ -49,6 +49,7 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
actions_.PushBack(action);
|
actions_.PushBack(action);
|
||||||
}
|
}
|
||||||
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
ActionPtr ActionManager::GetAction(String const & name)
|
ActionPtr ActionManager::GetAction(String const & name)
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,8 @@ namespace easy2d
|
||||||
using Actions = IntrusiveList<ActionPtr>;
|
using Actions = IntrusiveList<ActionPtr>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// 执行动作
|
// 添加动作
|
||||||
void AddAction(
|
ActionPtr AddAction(
|
||||||
ActionPtr const& action
|
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");
|
E2D_ASSERT(listener && "AddListener failed, NULL pointer exception");
|
||||||
|
|
||||||
|
|
@ -48,6 +48,7 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
listeners_.PushBack(listener);
|
listeners_.PushBack(listener);
|
||||||
}
|
}
|
||||||
|
return listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventDispatcher::AddListener(UINT type, EventCallback callback, String const& name)
|
void EventDispatcher::AddListener(UINT type, EventCallback callback, String const& name)
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ namespace easy2d
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// 添加监听器
|
// 添加监听器
|
||||||
void AddListener(
|
EventListenerPtr AddListener(
|
||||||
EventListenerPtr const& listener
|
EventListenerPtr const& listener
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,19 +19,24 @@
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
#include "Object.h"
|
#include "Object.h"
|
||||||
|
#include "logs.h"
|
||||||
|
#include <typeinfo>
|
||||||
|
|
||||||
namespace easy2d
|
namespace easy2d
|
||||||
{
|
{
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
bool tracing_leaks = true;
|
bool tracing_leaks = false;
|
||||||
Array<Object*> tracing_objects;
|
Array<Object*> tracing_objects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int Object::last_object_id = 0;
|
||||||
|
|
||||||
Object::Object()
|
Object::Object()
|
||||||
: tracing_leak_(false)
|
: tracing_leak_(false)
|
||||||
, user_data_(nullptr)
|
, user_data_(nullptr)
|
||||||
, name_(nullptr)
|
, name_(nullptr)
|
||||||
|
, id_(++last_object_id)
|
||||||
{
|
{
|
||||||
#ifdef E2D_DEBUG
|
#ifdef E2D_DEBUG
|
||||||
|
|
||||||
|
|
@ -83,6 +88,13 @@ namespace easy2d
|
||||||
*name_ = name;
|
*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()
|
void Object::StartTracingLeaks()
|
||||||
{
|
{
|
||||||
tracing_leaks = true;
|
tracing_leaks = true;
|
||||||
|
|
@ -93,7 +105,17 @@ namespace easy2d
|
||||||
tracing_leaks = false;
|
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;
|
return tracing_objects;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,17 +43,24 @@ namespace easy2d
|
||||||
|
|
||||||
void SetName(String const& name);
|
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 StartTracingLeaks();
|
||||||
|
|
||||||
static void StopTracingLeaks();
|
static void StopTracingLeaks();
|
||||||
|
|
||||||
static Array<Object*> const& __GetTracingObjects();
|
static void DumpTracingObjects();
|
||||||
|
|
||||||
|
public:
|
||||||
|
static Array<Object*>& __GetTracingObjects();
|
||||||
|
|
||||||
protected:
|
|
||||||
static void __AddObjectToTracingList(Object*);
|
static void __AddObjectToTracingList(Object*);
|
||||||
|
|
||||||
static void __RemoveObjectFromTracingList(Object*);
|
static void __RemoveObjectFromTracingList(Object*);
|
||||||
|
|
@ -62,5 +69,8 @@ namespace easy2d
|
||||||
bool tracing_leak_;
|
bool tracing_leak_;
|
||||||
void* user_data_;
|
void* user_data_;
|
||||||
String* name_;
|
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
|
inline void Print(const wchar_t* format, _Args&&... args) const
|
||||||
{
|
{
|
||||||
using namespace __console_colors;
|
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>
|
template <typename ..._Args>
|
||||||
inline void Println(const wchar_t* format, _Args&&... args) const
|
inline void Println(const wchar_t* format, _Args&&... args) const
|
||||||
{
|
{
|
||||||
using namespace __console_colors;
|
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>
|
template <typename ..._Args>
|
||||||
inline void Message(const wchar_t * format, _Args&&... args) const
|
inline void Message(const wchar_t * format, _Args&&... args) const
|
||||||
{
|
{
|
||||||
using namespace __console_colors;
|
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>
|
template <typename ..._Args>
|
||||||
inline void Messageln(const wchar_t * format, _Args&&... args) const
|
inline void Messageln(const wchar_t * format, _Args&&... args) const
|
||||||
{
|
{
|
||||||
using namespace __console_colors;
|
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>
|
template <typename ..._Args>
|
||||||
inline void Warning(const wchar_t* format, _Args&&... args) const
|
inline void Warning(const wchar_t* format, _Args&&... args) const
|
||||||
{
|
{
|
||||||
using namespace __console_colors;
|
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>
|
template <typename ..._Args>
|
||||||
inline void Warningln(const wchar_t* format, _Args&&... args) const
|
inline void Warningln(const wchar_t* format, _Args&&... args) const
|
||||||
{
|
{
|
||||||
using namespace __console_colors;
|
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>
|
template <typename ..._Args>
|
||||||
inline void Error(const wchar_t* format, _Args&&... args) const
|
inline void Error(const wchar_t* format, _Args&&... args) const
|
||||||
{
|
{
|
||||||
using namespace __console_colors;
|
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>
|
template <typename ..._Args>
|
||||||
inline void Errorln(const wchar_t* format, _Args&&... args) const
|
inline void Errorln(const wchar_t* format, _Args&&... args) const
|
||||||
{
|
{
|
||||||
using namespace __console_colors;
|
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:
|
private:
|
||||||
|
|
@ -154,7 +154,7 @@ namespace easy2d
|
||||||
if (!enabled_)
|
if (!enabled_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Output(os, color, prompt, format, std::forward<_Args&&>(args)...);
|
Output(os, color, prompt, format, std::forward<_Args>(args)...);
|
||||||
|
|
||||||
os << std::endl;
|
os << std::endl;
|
||||||
::OutputDebugStringW(L"\r\n");
|
::OutputDebugStringW(L"\r\n");
|
||||||
|
|
@ -166,7 +166,7 @@ namespace easy2d
|
||||||
if (!enabled_)
|
if (!enabled_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::wstring output = MakeOutputString(prompt, format, std::forward<_Args&&>(args)...);
|
std::wstring output = MakeOutputString(prompt, format, std::forward<_Args>(args)...);
|
||||||
|
|
||||||
os << color << output;
|
os << color << output;
|
||||||
::OutputDebugStringW(output.c_str());
|
::OutputDebugStringW(output.c_str());
|
||||||
|
|
@ -179,8 +179,8 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
static wchar_t temp_buffer[1024 * 3 + 1];
|
static wchar_t temp_buffer[1024 * 3 + 1];
|
||||||
|
|
||||||
const auto len = ::_scwprintf(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)...);
|
::swprintf_s(temp_buffer, len + 1, format, std::forward<_Args>(args)...);
|
||||||
|
|
||||||
std::wstringstream ss;
|
std::wstringstream ss;
|
||||||
ss << Logger::OutPrefix;
|
ss << Logger::OutPrefix;
|
||||||
|
|
|
||||||
|
|
@ -337,7 +337,7 @@ namespace easy2d
|
||||||
|
|
||||||
inline JsonValue& operator=(JsonValue && other)
|
inline JsonValue& operator=(JsonValue && other)
|
||||||
{
|
{
|
||||||
JsonValue{ std::forward<JsonValue &&>(other) }.swap(*this);
|
JsonValue{ std::forward<JsonValue>(other) }.swap(*this);
|
||||||
return (*this);
|
return (*this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -355,8 +355,7 @@ namespace easy2d
|
||||||
|
|
||||||
template <
|
template <
|
||||||
typename _CompatibleTy,
|
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)
|
basic_json(const _CompatibleTy& value)
|
||||||
{
|
{
|
||||||
value_.type = JsonType::String;
|
value_.type = JsonType::String;
|
||||||
|
|
@ -461,37 +460,6 @@ namespace easy2d
|
||||||
return string_type();
|
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_); }
|
inline void swap(basic_json& rhs) { value_.swap(rhs.value_); }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
@ -693,9 +661,9 @@ namespace easy2d
|
||||||
public:
|
public:
|
||||||
// operator= functions
|
// 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);
|
return (*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -770,7 +738,7 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
throw json_invalid_key();
|
throw json_invalid_key();
|
||||||
}
|
}
|
||||||
return iter.second;
|
return iter->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename _CharT>
|
template <typename _CharT>
|
||||||
|
|
@ -801,7 +769,7 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
throw json_invalid_key();
|
throw json_invalid_key();
|
||||||
}
|
}
|
||||||
return iter.second;
|
return iter->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
@ -862,6 +830,8 @@ namespace easy2d
|
||||||
template <typename _Ty>
|
template <typename _Ty>
|
||||||
struct iterator_impl
|
struct iterator_impl
|
||||||
{
|
{
|
||||||
|
friend _Ty;
|
||||||
|
|
||||||
using value_type = _Ty;
|
using value_type = _Ty;
|
||||||
using difference_type = std::ptrdiff_t;
|
using difference_type = std::ptrdiff_t;
|
||||||
using iterator_category = std::bidirectional_iterator_tag;
|
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 rend() const { return const_reverse_iterator(begin()); }
|
||||||
inline const_reverse_iterator crend() const { return rend(); }
|
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:
|
public:
|
||||||
// compare functions
|
// compare functions
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -190,6 +190,20 @@ namespace easy2d
|
||||||
void swap(String& rhs);
|
void swap(String& rhs);
|
||||||
size_t hash() const;
|
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:
|
public:
|
||||||
inline iterator begin() { check_operability(); return iterator(str_); }
|
inline iterator begin() { check_operability(); return iterator(str_); }
|
||||||
inline const_iterator begin() const { return const_iterator(const_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 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 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:
|
public:
|
||||||
static const String::size_type npos = static_cast<size_type>(-1);
|
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==(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==(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
|
// operator+ for String
|
||||||
|
|
@ -343,7 +366,7 @@ namespace easy2d
|
||||||
//
|
//
|
||||||
|
|
||||||
template<typename ..._Args>
|
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
|
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<<>>
|
// details of operator<<>>
|
||||||
//
|
//
|
||||||
|
|
@ -1151,11 +1194,11 @@ namespace easy2d
|
||||||
template<typename ..._Args>
|
template<typename ..._Args>
|
||||||
inline String format_wstring(const wchar_t* const fmt, _Args&&... 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)
|
if (len)
|
||||||
{
|
{
|
||||||
String str(len, L'\0');
|
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 str;
|
||||||
}
|
}
|
||||||
return String{};
|
return String{};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue