modelfactory.cc

来自「机器人人3D仿真工具,可以加入到Simbad仿真环境下应用。」· CC 代码 · 共 93 行

CC
93
字号
/* *  Gazebo - Outdoor Multi-Robot Simulator *  Copyright (C) 2003   *     Nate Koenig & Andrew Howard * *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2 of the License, or *  (at your option) any later version. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program; if not, write to the Free Software *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA * *//* * Desc: Factory for creating models * Author: Andrew Howard * Date: 18 May 2003 * CVS info: $Id: ModelFactory.cc,v 1.27 2004/11/16 19:22:54 inspectorg Exp $ */#if HAVE_CONFIG_H  #include <config.h>#endif#include <string.h>#include "Error.hh"#include "Model.hh"#include "ModelFactory.hh"// Declare static models (macro generated by autoconf)FACTORY_DECLARE_STATIC// All static initializersint ModelFactory::modelCount;int ModelFactory::modelMaxCount;ModelFactory::ModelClass *ModelFactory::models;// Register all known models.void ModelFactory::RegisterAll(){  // Register static models (macro generated by autoconf)  FACTORY_REGISTER_STATIC}// Register a model class.  Use by dynamically loaded modulesvoid ModelFactory::RegisterModel(const char *type, const char *classname,                                 ModelFactoryFn factoryfn){  PRINT_MSG2(2, "registered %s (%s)", classname, type);    // Resize (or initialize) array as necessary  if (modelCount >= modelMaxCount)  {    modelMaxCount += 10;    models = (ModelClass*) realloc(models, modelMaxCount * sizeof(Model));  }  // Add model class to list  models[modelCount].classname = classname;  models[modelCount].factoryfn = factoryfn;  modelCount++;    return;}// Create a new instance of a model.  Used by the world when reading// the world file.Model *ModelFactory::NewModel(World *world, const char *classname){    // Check list of models for named model  int i;  for (i = 0; i < modelCount; i++)  {    if (strcmp(classname, models[i].classname) == 0)      return (*models[i].factoryfn) (world);  }    return NULL;} 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?