• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javaandroidc++linuxc#objective-ccocoa誰得qtrubybathyscaphegamephpguicwindows翻訳pythonomegattwitterframeworkbtronarduinovb.net計画中(planning stage)directxpreviewertestゲームエンジンdom

Small footprint UI library for hardware accelerated games & applications


コミットメタ情報

リビジョンebb7c955c2d581db5a417b76f2b1b89d6e4298bf (tree)
日時2017-09-18 23:33:28
作者Starg <starg@user...>
コミッターStarg

ログメッセージ

Make use of TBUniquePointer

変更サマリ

差分

--- a/Demo/demo01/Demo01.cpp
+++ b/Demo/demo01/Demo01.cpp
@@ -396,10 +396,10 @@ bool ScrollContainerWindow::OnEvent(const TBWidgetEvent &ev)
396396 {
397397 for(int i = 0; i < ev.target->data.GetInt(); i++)
398398 {
399- TBMessageData *data = new TBMessageData();
399+ TBUniquePointer<TBMessageData> data(new TBMessageData());
400400 data->id1 = ev.target->GetParent()->GetID();
401401 data->v1.SetInt(i);
402- PostMessageDelayed(TBIDC("new button"), data, 100 + i * 500);
402+ PostMessageDelayed(TBIDC("new button"), TBMove(data), 100 + i * 500);
403403 }
404404 return true;
405405 }
--- a/src/tb/tb_msg.cpp
+++ b/src/tb/tb_msg.cpp
@@ -17,16 +17,11 @@ TBLinkListOf<TBMessageLink> g_all_normal_messages;
1717
1818 // == TBMessage =========================================================================
1919
20-TBMessage::TBMessage(TBID message, TBMessageData *data, double fire_time_ms, TBMessageHandler *mh)
21- : message(message), data(data), fire_time_ms(fire_time_ms), mh(mh)
20+TBMessage::TBMessage(TBID message, TBUniquePointer<TBMessageData> data, double fire_time_ms, TBMessageHandler *mh)
21+ : message(message), data(TBMove(data)), fire_time_ms(fire_time_ms), mh(mh)
2222 {
2323 }
2424
25-TBMessage::~TBMessage()
26-{
27- delete data;
28-}
29-
3025 // == TBMessageHandler ==================================================================
3126
3227 TBMessageHandler::TBMessageHandler()
@@ -38,14 +33,14 @@ TBMessageHandler::~TBMessageHandler()
3833 DeleteAllMessages();
3934 }
4035
41-bool TBMessageHandler::PostMessageDelayed(TBID message, TBMessageData *data, uint32 delay_in_ms)
36+bool TBMessageHandler::PostMessageDelayed(TBID message, TBUniquePointer<TBMessageData> data, uint32 delay_in_ms)
4237 {
43- return PostMessageOnTime(message, data, TBSystem::GetTimeMS() + (double)delay_in_ms);
38+ return PostMessageOnTime(message, TBMove(data), TBSystem::GetTimeMS() + (double)delay_in_ms);
4439 }
4540
46-bool TBMessageHandler::PostMessageOnTime(TBID message, TBMessageData *data, double fire_time)
41+bool TBMessageHandler::PostMessageOnTime(TBID message, TBUniquePointer<TBMessageData> data, double fire_time)
4742 {
48- if (TBMessage *msg = new TBMessage(message, data, fire_time, this))
43+ if (TBMessage *msg = new TBMessage(message, TBMove(data), fire_time, this))
4944 {
5045 // Find the message that is already in the list that should fire later, so we can
5146 // insert msg just before that. (Always keep the list ordered after fire time)
@@ -85,9 +80,9 @@ bool TBMessageHandler::PostMessageOnTime(TBID message, TBMessageData *data, doub
8580 return false;
8681 }
8782
88-bool TBMessageHandler::PostMessage(TBID message, TBMessageData *data)
83+bool TBMessageHandler::PostMessage(TBID message, TBUniquePointer<TBMessageData> data)
8984 {
90- if (TBMessage *msg = new TBMessage(message, data, 0, this))
85+ if (TBMessage *msg = new TBMessage(message, TBMove(data), 0, this))
9186 {
9287 g_all_normal_messages.AddLast(msg);
9388 m_messages.AddLast(msg);
@@ -144,14 +139,14 @@ void TBMessageHandler::ProcessMessages()
144139 {
145140 if (TBSystem::GetTimeMS() >= msg->fire_time_ms)
146141 {
142+ TBUniquePointer<TBMessage> umsg(msg);
143+
147144 // Remove from global list
148145 g_all_delayed_messages.Remove(msg);
149146 // Remove from local list
150147 msg->mh->m_messages.Remove(msg);
151148
152149 msg->mh->OnMessageReceived(msg);
153-
154- delete msg;
155150 }
156151 else
157152 break; // Since the list is sorted, all remaining messages should fire later
@@ -159,16 +154,14 @@ void TBMessageHandler::ProcessMessages()
159154
160155 // Handle normal messages
161156 iter = g_all_normal_messages.IterateForward();
162- while (TBMessage *msg = static_cast<TBMessage*>(iter.GetAndStep()))
157+ while (TBUniquePointer<TBMessage> msg = TBUniquePointer<TBMessage>(static_cast<TBMessage*>(iter.GetAndStep())))
163158 {
164159 // Remove from global list
165- g_all_normal_messages.Remove(msg);
160+ g_all_normal_messages.Remove(msg.Get());
166161 // Remove from local list
167- msg->mh->m_messages.Remove(msg);
168-
169- msg->mh->OnMessageReceived(msg);
162+ msg->mh->m_messages.Remove(msg.Get());
170163
171- delete msg;
164+ msg->mh->OnMessageReceived(msg.Get());
172165 }
173166 }
174167
--- a/src/tb/tb_msg.h
+++ b/src/tb/tb_msg.h
@@ -8,6 +8,7 @@
88
99 #include "tb_core.h"
1010 #include "tb_linklist.h"
11+#include "tb_memory.h"
1112 #include "tb_value.h"
1213 #include "tb_object.h"
1314 #include "tb_id.h"
@@ -47,12 +48,11 @@ class TBMessageLink : public TBLinkOf<TBMessageLink> { };
4748 class TBMessage : public TBLinkOf<TBMessage>, public TBMessageLink
4849 {
4950 private:
50- TBMessage(TBID message, TBMessageData *data, double fire_time_ms, TBMessageHandler *mh);
51- ~TBMessage();
51+ TBMessage(TBID message, TBUniquePointer<TBMessageData> data, double fire_time_ms, TBMessageHandler *mh);
5252
5353 public:
5454 TBID message; ///< The message id
55- TBMessageData *data; ///< The message data, or nullptr if no data is set
55+ TBUniquePointer<TBMessageData> data; ///< The message data, or nullptr if no data is set
5656
5757 /** The time which a delayed message should have fired (0 for non delayed messages) */
5858 double GetFireTime() { return fire_time_ms; }
@@ -78,17 +78,17 @@ public:
7878 /** Posts a message to the target after a delay.
7979 data may be nullptr if no extra data need to be sent. It will be deleted
8080 automatically when the message is deleted. */
81- bool PostMessageDelayed(TBID message, TBMessageData *data, uint32 delay_in_ms);
81+ bool PostMessageDelayed(TBID message, TBUniquePointer<TBMessageData> data, uint32 delay_in_ms);
8282
8383 /** Posts a message to the target at the given time (relative to TBSystem::GetTimeMS()).
8484 data may be nullptr if no extra data need to be sent. It will be deleted
8585 automatically when the message is deleted. */
86- bool PostMessageOnTime(TBID message, TBMessageData *data, double fire_time);
86+ bool PostMessageOnTime(TBID message, TBUniquePointer<TBMessageData> data, double fire_time);
8787
8888 /** Posts a message to the target.
8989 data may be nullptr if no extra data need to be sent. It will be deleted
9090 automatically when the message is deleted. */
91- bool PostMessage(TBID message, TBMessageData *data);
91+ bool PostMessage(TBID message, TBUniquePointer<TBMessageData> data);
9292
9393 /** Check if this messagehandler has a pending message with the given id.
9494 Returns the message if found, or nullptr.