From 15740faf9fe9fe4be08965098bbf2947e096aeeb Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 14 Aug 2019 22:50:43 +0800 Subject: +Unity Runtime code --- Runtime/Misc/UserList.h | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Runtime/Misc/UserList.h (limited to 'Runtime/Misc/UserList.h') diff --git a/Runtime/Misc/UserList.h b/Runtime/Misc/UserList.h new file mode 100644 index 0000000..7999ba9 --- /dev/null +++ b/Runtime/Misc/UserList.h @@ -0,0 +1,63 @@ +#pragma once + +#include "Runtime/Utilities/dynamic_array.h" +#include "Runtime/Utilities/NonCopyable.h" +#include "Runtime/Modules/ExportModules.h" + +class MessageIdentifier; + +// A UserList can be connected to other UserLists or UserListNodes. +// A UserListNode is simply the optimized case of a single-element list. +// The connected lists are symmetrical and can send messages in both directions. +// Deleting a node or list will disconnect it from the graph. + +class EXPORT_COREMODULE UserListBase : public NonCopyable +{ +public: + Object* GetTarget () { return m_Target; } + +protected: + UserListBase (Object* target) : m_Target(target) {} + struct Entry + { + Entry() : other(NULL), indexInOther(-1) {} + UserListBase* other; + int indexInOther; + }; + Object* m_Target; +}; + +class UserListNode : public UserListBase +{ +public: + UserListNode (Object* target) : UserListBase(target) {} + ~UserListNode () { Clear(); } + + void Clear (); + bool IsConnected () const { return m_Entry.other != NULL; } + +private: + friend class UserList; + Entry m_Entry; +}; + +class EXPORT_COREMODULE UserList : public UserListBase +{ +public: + UserList (Object* target) : UserListBase(target) {} + ~UserList () { Clear(); } + + void Clear (); + void Reserve (size_t size); + void AddUser (UserListNode& other); + void AddUser (UserList& other); + void SendMessage (const MessageIdentifier& msg); + size_t GetSize () const { return m_Entries.size(); } + +private: + friend class UserListNode; + Entry& GetEntryInOther (int index); + void RemoveIndex (int index); + + dynamic_array m_Entries; +}; -- cgit v1.1-26-g67d0