ParseManager.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 "ParseManager.hpp"
00023 #include "Parser.hpp"
00024 #include "component/ComponentParser.hpp"
00025 #include "util/error/Log.hpp"
00026 #include <cstdio>
00027 
00028 
00029 namespace se_core {
00030 
00031     ParseManager
00032     ::ParseManager()
00033         : moduleCount_(0), componentModuleCount_(0) {
00034     }
00035 
00036 
00037     ParseManager
00038     ::~ParseManager() {
00039     }
00040 
00041 
00042     void ParseManager
00043     ::add(Parser *module) {
00044         LogDetail("Added file parser for header code: " << module->headerCodeString());
00045         for(int i = 0; i < moduleCount_; ++i) {
00046             if(module->headerCode() == modules_[ i ]->headerCode()) {
00047                 LogFatal("Module with header code " << module->headerCodeString() << " already exists");
00048                 return;
00049             }
00050         }
00051         modules_[ moduleCount_++ ] = module;
00052     }
00053 
00054     void ParseManager
00055     ::add(ComponentParser *module) {
00056         LogDetail("Added file component parser for type code: " << module->type() << ", " << module->subtype());
00057         for(int i = 0; i < componentModuleCount_; ++i) {
00058             if(module->type() == componentModules_[ i ]->type()
00059                     && module->subtype() == componentModules_[ i ]->subtype()) {
00060                 LogFatal("Component module with header code " << module->type()  << ", " << module->subtype() << " already exists");
00061                 return;
00062             }
00063         }
00064         componentModules_[ componentModuleCount_++ ] = module;
00065     }
00066 
00067     bool ParseManager
00068     ::parse(InputStream& in) {
00069         //LogDetail("Loading file: " << in.name());
00070 
00071         int headerCode = in.readHeaderCode();
00072 
00073         for(int i = 0; i < moduleCount_; ++i) {
00074             if(modules_[i]->headerCode() == headerCode) {
00075                 modules_[i]->parse(in);
00076                 return true;
00077             }
00078         }
00079         LogWarning("The file '" << in.name() << "' had unsupported header name.");
00080         return false;
00081     }
00082 
00083     ComponentFactory* ParseManager
00084     ::parseComponent(InputStream& in, int type, int subtype) {
00085         //LogDetail("Loading component type " << type << ", " << subtype << " for " << in.name());
00086         LogWarning("Loading component type " << type << ", " << subtype << " for " << in.name());
00087 
00088         for(int i = 0; i < componentModuleCount_; ++i) {
00089             if(type == componentModules_[ i ]->type()
00090                     && subtype == componentModules_[ i ]->subtype()) {
00091                 ComponentFactory* f = componentModules_[i]->parse(in);
00092                 if(f) f->setDoDestroy(true);
00093                 return f;
00094             }
00095         }
00096         LogWarning("The file '" << in.name() << "' had unsupported component type: " << type << ", " << subtype << ".");
00097         return 0;
00098     }
00099 };

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