NodeComponentList.cpp

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 #include "NodeComponentList.hpp"
00023 #include "comp/node/NodeComponent.hpp"
00024 #include "util/error/Log.hpp"
00025 
00026 
00027 namespace se_core {
00028 
00029     NodeComponentList
00030     ::NodeComponentList()
00031         : firstNode_(CompSchema::VoidList::end()) {
00032     }
00033 
00034 
00035     NodeComponentList
00036     ::~NodeComponentList() {
00037         CompSchema::voidList.removeChain(firstNode_);
00038         firstNode_ = CompSchema::VoidList::end();
00039     }
00040 
00041 
00042     void NodeComponentList
00043     ::add(NodeComponent& value) {
00044         Assert(&value);
00045         //LogWarning(value.owner()->name() << "(" << value.type() << ") added.");
00046         CompSchema::voidList.add(&value, firstNode_);
00047     }
00048 
00049 
00050     void NodeComponentList
00051     ::remove(NodeComponent& value) {
00052         //LogWarning(value.owner()->name() << "(" << value.type() << ") removed.");
00053         CompSchema::voidList.remove(&value, firstNode_);
00054     }
00055 
00056 
00057     bool NodeComponentList
00058     ::contains(NodeComponent& value) const {
00059         CompSchema::VoidList::iterator_type it = iterator();
00060         while(it != CompSchema::VoidList::end()) {
00061             if(CompSchema::voidList.next(it) == &value)
00062                 return true;
00063         }
00064         return false;
00065     }
00066 
00067 
00068     bool NodeComponentList
00069     ::contains(NodeComponentList& msc) const {
00070         CompSchema::VoidList::iterator_type it = msc.iterator();
00071         while(it != CompSchema::VoidList::end()) {
00072             if(!contains(*static_cast<NodeComponent*>(CompSchema::voidList.next(it))))
00073                 return false;
00074         }
00075         return true;
00076     }
00077 
00078 
00079     bool NodeComponentList
00080     ::sharesAny(NodeComponentList& msc) const {
00081         CompSchema::VoidList::iterator_type it = msc.iterator();
00082         while(it != CompSchema::VoidList::end()) {
00083             if(contains(*static_cast<NodeComponent*>(CompSchema::voidList.next(it)))) {
00084                 return true;
00085             }
00086         }
00087         return false;
00088     }
00089 
00090 
00091     void NodeComponentList
00092     ::add(NodeComponentList& msc) {
00093         Assert(&msc);
00094         CompSchema::VoidList::iterator_type it = msc.iterator();
00095         while(it != CompSchema::VoidList::end()) {
00096             add(*static_cast<NodeComponent*>(CompSchema::voidList.next(it)));
00097         }
00098     }
00099 
00100 
00101     void NodeComponentList
00102     ::destroyMembersAndClear() {
00103         CompSchema::VoidList::iterator_type it = iterator();
00104         while(it != CompSchema::VoidList::end()) {
00105             delete static_cast<NodeComponent*>(CompSchema::voidList.next(it));
00106         }
00107         clear();
00108     }
00109 
00110 
00111     void NodeComponentList
00112     ::initIterator(CompSchema::VoidList::iterator_type& iterator) const {
00113         iterator = firstNode_;
00114     }
00115 
00116 
00117     bool NodeComponentList
00118     ::isEmpty() const {
00119         return (firstNode_ == CompSchema::VoidList::end());
00120     }
00121 
00122 
00123     void NodeComponentList
00124     ::clear() {
00125         CompSchema::voidList.removeChain(firstNode_);
00126     }
00127 
00128 
00129     int NodeComponentList
00130     ::size() const {
00131         return CompSchema::voidList.size(firstNode_);
00132     }
00133 
00134 
00135     NodeComponentList::Iterator
00136     ::Iterator()
00137         : it_(CompSchema::VoidList::end()) {
00138     }
00139 
00140 
00141     NodeComponentList::Iterator
00142     ::Iterator(NodeComponentList& msc) {
00143         (*this).init(msc);
00144     }
00145 
00146 
00147     void NodeComponentList::Iterator
00148 	::init(NodeComponentList& msc) {
00149         msc.initIterator(it_);
00150     }
00151 
00152 
00153     void NodeComponentList::Iterator
00154 	::init(short firstNode) {
00155         it_ = firstNode;
00156     }
00157 
00158 
00160     NodeComponentList::TreeIterator
00161     ::TreeIterator()
00162         : stackPointer_(-1) {
00163     }
00164 
00165 
00166     NodeComponentList::TreeIterator
00167     ::TreeIterator(NodeComponentList& msc) {
00168         if(msc.isEmpty()) {
00169             stackPointer_ = -1;
00170             return;
00171         }
00172         itStack_[ 0 ].init(msc);
00173         stackPointer_ = 0;
00174     }
00175 
00176 
00177     void NodeComponentList::TreeIterator
00178 	::init(NodeComponentList& msc) {
00179         if(msc.isEmpty()) {
00180             stackPointer_ = -1;
00181             return;
00182         }
00183         itStack_[ 0 ].init(msc);
00184         stackPointer_ = 0;
00185     }
00186 
00187 
00188     bool NodeComponentList::TreeIterator
00189     ::hasNext() {
00190         return (stackPointer_ >= 0);
00191     }
00192 
00193 
00194     NodeComponent& NodeComponentList::TreeIterator
00195     ::next() {
00196         // Get next in chain
00197         NodeComponent& c = itStack_[ stackPointer_ ].next();
00198 
00199         // Stack overflowed?
00200         Assert(stackPointer_ < MAX_STACK_DEPTH - 1);
00201 
00202         // Push child chain as next chain on stack
00203         itStack_[ ++stackPointer_ ].init(c.children());
00204 
00205         // Pop all completed chains
00206         while(stackPointer_ >= 0 && !itStack_[ stackPointer_ ].hasNext()) {
00207             --stackPointer_;
00208         }
00209 
00210         return c;
00211     }
00212 
00213 
00214 }

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