Home
FAQ
Player
Utilities
Stage
Gazebo
Contrib
Documentation
Publications
Contributors
Users

Project
Download
Bugs/Feedback
Mailing lists

Radish

Old news
Old stuff

ModelFactory.hh

Go to the documentation of this file.
00001 /*
00002  *  Gazebo - Outdoor Multi-Robot Simulator
00003  *  Copyright (C) 2003  
00004  *     Nate Koenig & Andrew Howard
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 /*
00022  * Desc: Factory for creating models
00023  * Author: Andrew Howard
00024  * Date: 18 May 2003
00025  * CVS info: $Id: ModelFactory.hh,v 1.3 2004/11/16 19:22:54 inspectorg Exp $
00026  */
00027 
00028 #ifndef MODELFACTORY_HH
00029 #define MODELFACTORY_HH
00030 
00031 // Forward declarations
00032 class World;
00033 class Model;
00034 
00035 
00036 // Prototype for model factory functions
00037 typedef Model* (*ModelFactoryFn) (World *);
00038 
00039 
00041 class ModelFactory
00042 {
00044   public: static void RegisterAll();
00045   
00047   public: static void RegisterModel(const char *type, const char *classname,
00048                                     ModelFactoryFn factoryfn);
00049 
00052   public: static Model *NewModel(World *world, const char *classname);
00053 
00054   // Class describing a model class
00055   private: class ModelClass
00056   {
00057     public: const char *classname;
00058     public: ModelFactoryFn factoryfn;
00059   };
00060 
00061   // A list of registered model classes
00062   private: static int modelCount, modelMaxCount;
00063   private: static ModelClass *models;
00064 };
00065 
00066 
00072 #define GZ_REGISTER_STATIC(name, classname) \
00073 Model *New##classname(World *world) \
00074 { \
00075   return new classname(world); \
00076 } \
00077 void Register##classname() \
00078 {\
00079   ModelFactory::RegisterModel("static", name, New##classname);\
00080 }
00081 
00082 
00088 #define GZ_REGISTER_PLUGIN(name, classname) \
00089 Model *New##classname(World *world) \
00090 { \
00091   return new classname(world); \
00092 } \
00093 extern "C" \
00094 { \
00095   int gazebo_plugin_init(void) \
00096   { \
00097     ModelFactory::RegisterModel("plugin", name, New##classname); \
00098     return 0;\
00099   }\
00100 }
00101 
00102 #endif


Last updated $Date: 2004/12/21 01:49:15 $
Generated on Sun May 22 18:39:08 2005 for Gazebo by doxygen 1.4.2