CompositeFactory.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 "CompositeFactory.hpp"
00023 #include "Composite.hpp"
00024 #include "ComponentFactory.hpp"
00025 #include "util/type/String.hpp"
00026 #include "util/error/Log.hpp"
00027 #include <cstring>
00028 #include <cstdio>
00029 
00030 namespace se_core {
00031     CompositeFactory::Generic& CompositeFactory::gen() {
00032         static CompositeFactory::Generic g;
00033         return g;
00034     }
00035 
00036     CompositeFactory
00037     ::CompositeFactory(CompositeType type, String* name)
00038         : name_(name), type_(type), tag_(0), componentCount_(0) {
00039     }
00040 
00041 
00042     CompositeFactory
00043     ::~CompositeFactory() {
00044         while(componentCount_ > 0) {
00045             --componentCount_;
00046             if(components_[ componentCount_ ]->doDestroy()) {
00047                 delete components_[ componentCount_ ];
00048             }
00049         }
00050         delete name_;
00051     }
00052 
00053 
00054     Composite* CompositeFactory
00055     ::create() const {
00056         Composite* c = new Composite(this);
00057         createComponents(c);
00058         createGenericComponents(c);
00059         return c;
00060     }
00061 
00062 
00063     void CompositeFactory
00064     ::release(Composite* t) const {
00065         delete t;
00066     }
00067 
00068 
00069     const char* CompositeFactory
00070     ::name() const {
00071         return name_->get();
00072     }
00073 
00074 
00075     void CompositeFactory
00076     ::addComponent(ComponentFactory* f) {
00077         Assert(componentCount_ < MAX_COMPONENTS);
00078         components_[ componentCount_++ ] = f;
00079     }
00080 
00081 
00082     void CompositeFactory
00083     ::createComponents(Composite* owner) const {
00084         for(int i = 0; i < componentCount_; ++i) {
00085             components_[ i ]->create(owner);
00086         }
00087     }
00088 
00089 
00090     void CompositeFactory
00091     ::createGenericComponents(Composite* owner) const {
00092         gen().createComponents(type_, owner);
00093     }
00094 
00095 }

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