ComponentList.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 "ComponentList.hpp"
00023 #include "comp/Component.hpp"
00024 #include "../schema/CompSchema.hpp"
00025 #include "util/error/Log.hpp"
00026 #include <cstdio>
00027 #include <cstring>
00028 
00029 
00030 namespace se_core {
00031 
00032     ComponentList
00033     ::ComponentList()
00034         : firstNode_(CompSchema::VoidList::end()) {
00035     }
00036 
00037 
00038     ComponentList
00039     ::~ComponentList() {
00040         CompSchema::voidList.removeChain(firstNode_);
00041         firstNode_ = CompSchema::VoidList::end();
00042     }
00043 
00044 
00045     void ComponentList
00046     ::add(Component& value) {
00047         Assert(&value);
00048         //LogWarning(value.owner()->name() << "(" << value.type() << ") added.");
00049         /*
00050         CompSchema::VoidList::iterator_type it = iterator();
00051         while(it != CompSchema::VoidList::end()) {
00052             Component* c = static_cast<Component*>(CompSchema::voidList.next(it));
00053             if(c->type() == value.type() && strcmp(c->owner()->name(), value.owner()->name()) == 0) {
00054                 LogFatal(value.name());
00055             }
00056         }
00057         LogWarning("Capacity: " << CompSchema::voidList.capacity());
00058         */
00059 
00060         CompSchema::voidList.add(&value, firstNode_);
00061     }
00062 
00063 
00064     void ComponentList
00065     ::remove(Component& value) {
00066         //LogWarning(value.owner()->name() << "(" << value.type() << ") removed.");
00067         CompSchema::voidList.remove(&value, firstNode_);
00068     }
00069 
00070 
00071     bool ComponentList
00072     ::contains(Component& value) const {
00073         CompSchema::VoidList::iterator_type it = iterator();
00074         while(it != CompSchema::VoidList::end()) {
00075             if(CompSchema::voidList.next(it) == &value)
00076                 return true;
00077         }
00078         return false;
00079     }
00080 
00081 
00082     bool ComponentList
00083     ::contains(ComponentList& msc) const {
00084         CompSchema::VoidList::iterator_type it = msc.iterator();
00085         while(it != CompSchema::VoidList::end()) {
00086             if(!contains(*static_cast<Component*>(CompSchema::voidList.next(it))))
00087                 return false;
00088         }
00089         return true;
00090     }
00091 
00092 
00093     bool ComponentList
00094     ::sharesAny(ComponentList& msc) const {
00095         CompSchema::VoidList::iterator_type it = msc.iterator();
00096         while(it != CompSchema::VoidList::end()) {
00097             if(contains(*static_cast<Component*>(CompSchema::voidList.next(it)))) {
00098                 return true;
00099             }
00100         }
00101         return false;
00102     }
00103 
00104 
00105     void ComponentList
00106     ::add(ComponentList& msc) {
00107         Assert(&msc);
00108         CompSchema::VoidList::iterator_type it = msc.iterator();
00109         while(it != CompSchema::VoidList::end()) {
00110             add(*static_cast<Component*>(CompSchema::voidList.next(it)));
00111         }
00112     }
00113 
00114 
00115     void ComponentList
00116     ::destroyMembersAndClear() {
00117         CompSchema::VoidList::iterator_type it = iterator();
00118         while(it != CompSchema::VoidList::end()) {
00119             delete static_cast<Component*>(CompSchema::voidList.next(it));
00120         }
00121         clear();
00122     }
00123 
00124 
00125     void ComponentList
00126     ::initIterator(CompSchema::VoidList::iterator_type& iterator) const {
00127         iterator = firstNode_;
00128     }
00129 
00130 
00131     bool ComponentList
00132     ::isEmpty() const {
00133         return (firstNode_ == CompSchema::VoidList::end());
00134     }
00135 
00136 
00137     void ComponentList
00138     ::clear() {
00139         CompSchema::voidList.removeChain(firstNode_);
00140     }
00141 
00142 
00143     int ComponentList
00144     ::size() const {
00145         return CompSchema::voidList.size(firstNode_);
00146     }
00147 
00148 
00149 
00150     ComponentList::Iterator
00151     ::Iterator()
00152         : it_(CompSchema::VoidList::end()) {
00153     }
00154 
00155 
00156     ComponentList::Iterator
00157     ::Iterator(const ComponentList& msc) {
00158         (*this).init(msc);
00159     }
00160 
00161 
00162     void ComponentList::Iterator
00163 	::init(const ComponentList& msc) {
00164         msc.initIterator(it_);
00165     }
00166 
00167 
00168     void ComponentList::Iterator
00169 	::init(short firstNode) {
00170         it_ = firstNode;
00171     }
00172 
00173 
00174 }

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