NanoShaper
0.7.2
NanoShaper is a tool able to triangulate and inspect an arbitray triangulated surface or several types of molecular surfaces
|
00001 00002 #ifndef SurfaceFactory_h 00003 #define SurfaceFactory_h 00004 00005 #include <map> 00006 #include <string> 00007 #include <iostream> 00008 #include "ConfigFile.h" 00009 #include "globals.h" 00010 00011 class Surface; 00012 class DelPhiShared; 00013 using namespace std; 00014 00015 typedef Surface* (*surface_instantiator)(ConfigFile* conf,DelPhiShared* ds); 00016 00017 class SurfaceFactory{ 00018 00019 private: 00020 map<string,surface_instantiator> surfRegister; 00021 map<string,surface_instantiator>::iterator it; 00022 public: 00023 00024 void add(string surfaceName,surface_instantiator si) 00025 { 00026 surfRegister.insert(pair<string,surface_instantiator>(surfaceName,si)); 00027 } 00028 00029 Surface* create(ConfigFile* conf,DelPhiShared* ds) 00030 { 00031 string surfName = conf->read<string>("Surface"); 00032 if (!surfRegister.count(surfName)) 00033 { 00034 cout << endl << surfName << " type is not registered!"; 00035 return NULL; 00036 } 00037 return surfRegister[surfName](conf,ds); 00038 } 00039 00040 void print() 00041 { 00042 cout << endl << INFO << "Available surfaces:"; 00043 for (it=surfRegister.begin();it!=surfRegister.end();it++) 00044 { 00045 cout << endl << INFO << "\t" << (*it).first; 00046 } 00047 } 00048 }; 00049 00050 SurfaceFactory& surfaceFactory(); 00051 00052 template<class T> class SurfaceRecorder 00053 { 00054 00055 public: 00056 SurfaceRecorder(string surface) 00057 { 00058 surfaceFactory().add(surface,createSurface); 00059 } 00060 00061 static Surface* createSurface(ConfigFile* conf,DelPhiShared* ds) 00062 { 00063 return new T(conf,ds); 00064 } 00065 }; 00066 00067 #endif