Composite.hpp

Go to the documentation of this file.
00001 /*
00002 SagaEngine library
00003 Copyright (c) 2002-2006 Skalden Studio AS
00004 
00005 This software is provided 'as-is', without any express or implied 
00006 warranty. In no event will the authors be held liable for any 
00007 damages arising from the use of this software.
00008 
00009 Permission is granted to distribute the library under the terms of the 
00010 Q Public License version 1.0. Be sure to read and understand the license
00011 before using the library. It should be included here, or you may read it
00012 at http://www.trolltech.com/products/qt/licenses/licensing/qpl
00013 
00014 The original version of this library can be located at:
00015 http://www.sagaengine.com/
00016 
00017 Rune Myrland
00018 rune@skalden.com
00019 */
00020 
00021 
00022 #ifndef Composite_hpp
00023 #define Composite_hpp
00024 
00025 #include "comp.hpp"
00026 #include "RefPtr.hpp"
00027 #include "comp/list/ComponentList.hpp"
00028 #include "comp/list/CompositeList.hpp"
00029 
00030 
00031 namespace se_core {
00032     class _SeCoreExport Composite {
00033     public:
00034         typedef RefPtr<Composite> RefPtr;
00035         typedef Composite* id_type;
00036 
00037         Composite(const CompositeFactory* factory);
00038         Composite(const CompositeFactory* factory, const char* name);
00039         virtual ~Composite();
00040 
00041         RefPtr& ref() { return ptr_; }
00042 
00043         const char* name() const;
00044         int type() const;
00045 
00046         id_type id() const { return (id_type)this; }
00047 
00048         void init(bool doTraverseChildren = true);
00049         void cleanup(bool doTraverseChildren = true);
00050 
00051         Component* component(int type);
00052         const Component* component(int type) const;
00053 
00054         const CompositeFactory* factory() { return factory_; }
00055         void setFactory(const CompositeFactory* f) { factory_ = f; }
00056 
00060         bool hasParent() const { return parent_ != 0; }
00061 
00065         Composite* parent() {
00066             return parent_;
00067         }
00068 
00072         void setParent(Composite& p);
00073 
00077         void resetParent();
00078 
00082         const CompositeList& children() const { return children_; }
00083 
00084 
00089         void setActive(bool state, bool doTraverseChildren = true);
00090 
00091 
00095         bool isActive() const { return isActive_; }
00096 
00097         void setTag(int t) { tag_ = t; }
00098         int tag() const { return tag_; }
00099 
00107         virtual void scheduleForDestruction();
00108 
00113         bool isDead() const { return isDead_; }
00114 
00118         void zoneChanged(int type, Composite* newZone, Composite* oldZone);
00119 
00123         void releaseComponents();
00124 
00125     private:
00126         friend class Component;
00127         // The Component adds and removes itself
00128         void addComponent(Component& c);
00129         void removeComponent(Component& c);
00130 
00131 
00132     protected:
00133 
00138         void addChild(Composite& node);
00139 
00144         void removeChild(Composite& node);
00145 
00146         const char* name_;
00147         const CompositeFactory* factory_;
00148         int tag_;
00149         bool isActive_;
00150         bool isDead_;
00151 
00152         ComponentList components_;
00153 
00154         Composite* parent_;
00155         CompositeList children_;
00156         enum { FAST_COMPONENT_COUNT = 16 };
00157         Component* fastComponents_[16];
00158 
00159 
00163         RefPtr ptr_;
00164 
00165     };
00166 
00167 }
00168 
00169 
00170 #endif

Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:10 2007 by Doxygen version 1.3.9.1.

SourceForge.net Logo