1 #pragma once 2 // Description: 3 // Model Manager. 4 // 5 // Copyright (C) 2001 Frank Becker 6 // 7 // This program is free software; you can redistribute it and/or modify it under 8 // the terms of the GNU General Public License as published by the Free Software 9 // Foundation; either version 2 of the License, or (at your option) any later 10 // version. 11 // 12 // This program is distributed in the hope that it will be useful, but WITHOUT 13 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details 15 // 16 17 #include <string> 18 19 #include "hashMap.hpp" 20 #include "HashString.hpp" 21 #include "FindHash.hpp" 22 23 #include "Trace.hpp" 24 #include "Model.hpp" 25 #include "Singleton.hpp" 26 27 class ModelManager 28 { 29 friend class Singleton<ModelManager>; 30 public: getModel(std::string modelName)31 Model *getModel( std::string modelName) 32 { 33 Model *model = findHash( modelName, _modelMap); 34 if( !model) 35 { 36 model = load( modelName); 37 if( !model) 38 { 39 LOG_ERROR << "Unable to find model " << modelName << "\n"; 40 return 0; 41 } 42 _modelMap[ modelName] = model; 43 } 44 return model; 45 } 46 47 void reload( void); 48 49 private: 50 ~ModelManager(); 51 ModelManager( void); 52 ModelManager( const ModelManager&); 53 ModelManager &operator=(const ModelManager&); 54 55 Model *load( const std::string &model); 56 57 hash_map< std::string, Model*, hash<std::string>, std::equal_to<std::string> > _modelMap; 58 }; 59 60 typedef Singleton<ModelManager> ModelManagerS; 61