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

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