summaryrefslogtreecommitdiff
path: root/src/T2DLL/LAttachable.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/T2DLL/LAttachable.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/T2DLL/LAttachable.cpp b/src/T2DLL/LAttachable.cpp
new file mode 100644
index 0000000..9700c4d
--- /dev/null
+++ b/src/T2DLL/LAttachable.cpp
@@ -0,0 +1,86 @@
+#include "LArray.h"
+#include "LAttachable.h"
+#include "LAttachment.h"
+
+LAttachable::LAttachable() {
+ mAttachments = NULL;
+ SetDefaultAttachable(this);
+}
+
+LAttachable::LAttachable(const LAttachable& other) {
+ mAttachments = NULL;
+ SetDefaultAttachable(this);
+}
+
+/*virtual*/ LAttachable::~LAttachable() {
+ RemoveAllAttachments();
+}
+
+/*virtual*/ void LAttachable::AddAttachment(LAttachment* attachment, LAttachment* before, BOOL setAsOwner) {
+ if (!mAttachments)
+ mAttachments = new LArray;
+
+ if (!before) {
+ mAttachments->Add(&attachment);
+ } else {
+ int index = mAttachments->GetCount() + 1;
+ if (before) {
+ // bug? should this use &before?
+ index = mAttachments->FetchIndexOf(before);
+ if (index == 0)
+ index = mAttachments->GetCount() + 1;
+ }
+ mAttachments->InsertItemsAt(1, index, &attachment);
+ }
+
+ if (setAsOwner)
+ attachment->SetOwnerHost(this);
+}
+
+/*virtual*/ void LAttachable::RemoveAttachment(LAttachment* attachment) {
+ if (mAttachments) {
+ mAttachments->Remove(&attachment);
+ if (attachment->GetOwnerHost() == this)
+ attachment->SetOwnerHost(NULL);
+ }
+}
+
+/*virtual*/ void LAttachable::RemoveAllAttachments() {
+ if (mAttachments) {
+ LArrayIterator iter(*mAttachments);
+ LAttachment *attachment;
+
+ while (iter.Next(&attachment)) {
+ if (attachment->GetOwnerHost() == this) {
+ delete attachment;
+ iter.Reset();
+ }
+ }
+
+ delete mAttachments;
+ mAttachments = NULL;
+ }
+}
+
+/*virtual*/ BOOL LAttachable::ExecuteAttachments(unsigned int message, void* data) {
+ BOOL result = true;
+ if (mAttachments) {
+ LArrayIterator iter(*mAttachments);
+ LAttachment *attachment;
+
+ while (iter.Next(&attachment)) {
+ result = result & attachment->Execute(message, data);
+ }
+ }
+ return result;
+}
+
+/*static*/ LAttachable* LAttachable::sDefaultAttachable;
+
+/*static*/ LAttachable* LAttachable::GetDefaultAttachable() {
+ return sDefaultAttachable;
+}
+
+/*static*/ void LAttachable::SetDefaultAttachable(LAttachable* attachable) {
+ sDefaultAttachable = attachable;
+}