step/stepcore
factory.cc
Go to the documentation of this file.00001 /* This file is part of StepCore library. 00002 Copyright (C) 2007 Vladimir Kuznetsov <ks.vladimir@gmail.com> 00003 00004 StepCore library is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or 00007 (at your option) any later version. 00008 00009 StepCore library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with StepCore; if not, write to the Free Software 00016 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00017 */ 00018 00019 #include "factory.h" 00020 #include "world.h" 00021 #include "solver.h" 00022 #include "collisionsolver.h" 00023 #include "constraintsolver.h" 00024 00025 namespace StepCore { 00026 00027 // XXX: locking 00028 void Factory::registerMetaObject(const MetaObject* metaObject) 00029 { 00030 _metaObjects.insert(metaObject->className(), metaObject); 00031 } 00032 00033 const MetaObject* Factory::metaObject(const QString& name) const 00034 { 00035 return _metaObjects.value(name, NULL); 00036 } 00037 00038 Object* Factory::newObject(const QString& name) const 00039 { 00040 const MetaObject* metaObject = this->metaObject(name); 00041 if(!metaObject) return NULL; 00042 return metaObject->newObject(); 00043 } 00044 00045 Item* Factory::newItem(const QString& name) const 00046 { 00047 const MetaObject* metaObject = this->metaObject(name); 00048 if(!metaObject || !metaObject->inherits<Item>()) return NULL; 00049 return static_cast<Item*>(metaObject->newObject()); 00050 } 00051 00052 Solver* Factory::newSolver(const QString& name) const 00053 { 00054 const MetaObject* metaObject = this->metaObject(name); 00055 if(!metaObject || !metaObject->inherits<Solver>()) return NULL; 00056 return static_cast<Solver*>(metaObject->newObject()); 00057 } 00058 00059 CollisionSolver* Factory::newCollisionSolver(const QString& name) const 00060 { 00061 const MetaObject* metaObject = this->metaObject(name); 00062 if(!metaObject || !metaObject->inherits<CollisionSolver>()) return NULL; 00063 return static_cast<CollisionSolver*>(metaObject->newObject()); 00064 } 00065 00066 ConstraintSolver* Factory::newConstraintSolver(const QString& name) const 00067 { 00068 const MetaObject* metaObject = this->metaObject(name); 00069 if(!metaObject || !metaObject->inherits<ConstraintSolver>()) return NULL; 00070 return static_cast<ConstraintSolver*>(metaObject->newObject()); 00071 } 00072 00073 } // namespace StepCore 00074
KDE 4.2 API Reference