00001 /* 00002 * factory.h 00003 * 00004 * Created on: Oct 22, 2009 00005 * Author: sturm 00006 */ 00007 00008 #ifndef FACTORY_H_ 00009 #define FACTORY_H_ 00010 00011 #include <boost/shared_ptr.hpp> 00012 #include <typeinfo> 00013 00014 #include "generic_model.h" 00015 #include "articulation_msgs/ModelMsg.h" 00016 00017 namespace articulation_models { 00018 00019 typedef boost::shared_ptr< GenericModel > GenericModelPtr; 00020 typedef std::vector< GenericModelPtr > GenericModelVector; 00021 00022 class GenericModelFactory { 00023 public: 00024 virtual GenericModelPtr createModel(articulation_msgs::TrackMsgConstPtr trackMsg) = 0; 00025 virtual GenericModelPtr createModel(const articulation_msgs::TrackMsg& trackMsg) = 0; 00026 virtual GenericModelPtr createModel(articulation_msgs::ModelMsgConstPtr modelMsg) = 0; 00027 virtual GenericModelPtr createModel(const articulation_msgs::ModelMsg& modelMsg) = 0; 00028 virtual std::string getLongName() = 0; 00029 virtual std::string getClassName() = 0; 00030 }; 00031 00032 template<class T> 00033 class SingleModelFactory: public GenericModelFactory { 00034 public: 00035 std::string longname; 00036 std::string classname; 00037 SingleModelFactory(std::string longname): longname(longname),classname(typeid(T).name()) {} 00038 GenericModelPtr createModel(articulation_msgs::TrackMsgConstPtr trackMsg) { 00039 GenericModelPtr model(new T()); 00040 model->setTrack( *trackMsg ); 00041 return model; 00042 } 00043 GenericModelPtr createModel(const articulation_msgs::TrackMsg& trackMsg) { 00044 GenericModelPtr model(new T()); 00045 model->setTrack( trackMsg ); 00046 return model; 00047 } 00048 GenericModelPtr createModel(articulation_msgs::ModelMsgConstPtr modelMsg) { 00049 GenericModelPtr model(new T()); 00050 model->setModel( *modelMsg ); 00051 return model; 00052 } 00053 GenericModelPtr createModel(const articulation_msgs::ModelMsg& modelMsg) { 00054 GenericModelPtr model(new T()); 00055 model->setModel( modelMsg ); 00056 return model; 00057 } 00058 std::string getLongName() { 00059 return longname; 00060 } 00061 std::string getClassName() { 00062 return classname; 00063 } 00064 }; 00065 00066 class MultiModelFactory { 00067 public: 00068 static MultiModelFactory instance; 00069 std::vector<GenericModelFactory*> all_factories; 00070 std::vector<GenericModelFactory*> factories; 00071 00072 MultiModelFactory(); 00073 GenericModelVector createModels(articulation_msgs::TrackMsgConstPtr trackMsg); 00074 GenericModelVector createModels(const articulation_msgs::TrackMsg& trackMsg); 00075 GenericModelVector createModels(articulation_msgs::ModelMsgConstPtr modelMsg); 00076 GenericModelVector createModels(const articulation_msgs::ModelMsg& modelMsg); 00077 GenericModelPtr restoreModel(articulation_msgs::ModelMsgConstPtr modelMsg); 00078 GenericModelPtr restoreModel(const articulation_msgs::ModelMsg& modelMsg); 00079 int getModelIndex(std::string name); 00080 int getFactoryCount(); 00081 void listModelFactories(); 00082 static std::string getLongName(GenericModel* model); 00083 void setFilter(std::string filter); 00084 }; 00085 00086 } 00087 #endif /* FACTORY_H_ */