#include <emobject.h>
Public Types | |
| typedef T *(* | InstanceType )() |
Public Member Functions | |
| template<> | |
| Factory () | |
| template<> | |
| Factory () | |
| template<> | |
| Factory () | |
| template<> | |
| Factory () | |
| template<> | |
| Factory () | |
| template<> | |
| Factory () | |
| template<> | |
| Factory () | |
| template<> | |
| Factory () | |
| template<> | |
| Factory () | |
| template<> | |
| Factory () | |
| template<> | |
| Factory () | |
| template<> | |
| Symmetry3D * | get (const string &instancename) |
| template<> | |
| Factory () | |
Static Public Member Functions | |
| static void | add (InstanceType i) |
| static T * | get (const string &instance_name) |
| static T * | get (const string &instance_name, const Dict ¶ms) |
| static vector< string > | get_list () |
Private Member Functions | |
| Factory () | |
| Factory (const Factory< T > &) | |
| ~Factory () | |
| void | force_add (InstanceType i) |
Static Private Member Functions | |
| static void | init () |
Private Attributes | |
| map< string, InstanceType > | my_dict |
Static Private Attributes | |
| static Factory< T > * | my_instance = 0 |
It is a singleton template. Typical usages are as follows:
1. How to define a new factory (e.g. Processor Factory):
template<> Factory<Processor>::Factory() { force_add(&AbsoluateValueProcessor::NEW); force_add(&BooleanProcessor::NEW); }
2. How to use a Factory (e.g. Processor Factory):
Processor *f1 = Factory<Processor>::get("math.absvalue"); Processor *f2 = Factory<Processor>::get("eman1.filter.lowpass.gaussian", Dict("lowpass", EMObject(12));
Definition at line 700 of file emobject.h.
| typedef T*(* EMAN::Factory< T >::InstanceType)() |
| EMAN::Factory< T >::Factory | ( | ) | [private] |
| EMAN::Factory< T >::Factory | ( | const Factory< T > & | ) | [private] |
| EMAN::Factory< T >::~Factory | ( | ) | [private] |
| EMAN::Factory< Aligner >::Factory | ( | ) | [inline] |
| EMAN::Factory< Analyzer >::Factory | ( | ) | [inline] |
Definition at line 51 of file analyzer.cpp.
References EMAN::SVDAnalyzer::NEW(), EMAN::KMeansAnalyzer::NEW(), EMAN::varimax::NEW(), EMAN::PCAlarge::NEW(), and EMAN::PCAsmall::NEW().
00052 { 00053 force_add(&PCAsmall::NEW); 00054 force_add(&PCAlarge::NEW); 00055 force_add(&varimax::NEW); 00056 force_add(&KMeansAnalyzer::NEW); 00057 force_add(&SVDAnalyzer::NEW); 00058 }
| EMAN::Factory< Analyzer >::Factory | ( | ) | [inline] |
| EMAN::Factory< Averager >::Factory | ( | ) | [inline] |
| EMAN::Factory< Cmp >::Factory | ( | ) | [inline] |
| EMAN::Factory< Processor >::Factory | ( | ) | [inline] |
| EMAN::Factory< Projector >::Factory | ( | ) | [inline] |
| EMAN::Factory< Reconstructor >::Factory | ( | ) | [inline] |
| EMAN::Factory< FourierPixelInserter3D >::Factory | ( | ) | [inline] |
| EMAN::Factory< InterpolatedFRC >::Factory | ( | ) | [inline] |
| EMAN::Factory< Symmetry3D >::Factory | ( | ) | [inline] |
| EMAN::Factory< OrientationGenerator >::Factory | ( | ) | [inline] |
| void EMAN::Factory< T >::add | ( | InstanceType | i | ) | [inline, static] |
Definition at line 743 of file emobject.h.
00744 { 00745 init(); 00746 00747 T *i = new_instance(); 00748 string name = i->get_name(); 00749 typename map < string, InstanceType >::iterator fi = 00750 my_instance->my_dict.find(name); 00751 00752 if (fi == my_instance->my_dict.end()) { 00753 my_instance->my_dict[name] = new_instance; 00754 } 00755 if( i ) 00756 { 00757 delete i; 00758 i = 0; 00759 } 00760 }
| T * EMAN::Factory< T >::get | ( | const string & | instance_name | ) | [inline, static] |
Definition at line 762 of file emobject.h.
References NotExistingObjectException.
00763 { 00764 init(); 00765 typename map < string, InstanceType >::iterator fi = 00766 my_instance->my_dict.find(instancename); 00767 if (fi != my_instance->my_dict.end()) { 00768 return my_instance->my_dict[instancename] (); 00769 } 00770 00771 string lower = instancename; 00772 for (unsigned int i=0; i<lower.length(); i++) lower[i]=tolower(lower[i]); 00773 00774 fi = my_instance->my_dict.find(lower); 00775 if (fi != my_instance->my_dict.end()) { 00776 return my_instance->my_dict[lower] (); 00777 } 00778 00779 throw NotExistingObjectException(instancename, "The named object doesn't exist"); 00780 }
| T * EMAN::Factory< T >::get | ( | const string & | instance_name, | |
| const Dict & | params | |||
| ) | [inline, static] |
Definition at line 782 of file emobject.h.
References InvalidParameterException, and NotExistingObjectException.
00784 { 00785 init(); 00786 00787 typename map < string, InstanceType >::iterator fi = 00788 my_instance->my_dict.find(instancename); 00789 00790 string lower = instancename; 00791 if (fi == my_instance->my_dict.end()) { 00792 for (unsigned int i=0; i<lower.length(); i++) lower[i]=tolower(lower[i]); 00793 fi = my_instance->my_dict.find(lower); 00794 } 00795 00796 if (fi != my_instance->my_dict.end()) { 00797 T *i = my_instance->my_dict[lower] (); 00798 00799 const vector<string> para_keys = params.keys(); 00800 // std::cout << "the number of keys is " << para_keys.size() << std::endl; // PRB May 19th 00801 const vector<string> valid_keys = i->get_param_types().keys(); 00802 typename vector<string>::const_iterator it; 00803 for(it=para_keys.begin(); it!=para_keys.end(); ++it) { 00804 // std::cout << "the iterator is " << *it << std::endl; // PRB May 19th 00805 if( find(valid_keys.begin(), valid_keys.end(), *it) == valid_keys.end() ) { 00806 throw InvalidParameterException(*it); 00807 } 00808 } 00809 00810 i->set_params(params); 00811 return i; 00812 } 00813 00814 00815 throw NotExistingObjectException(instancename, "No such an instance existing"); 00816 }
| vector< string > EMAN::Factory< T >::get_list | ( | ) | [inline, static] |
Definition at line 818 of file emobject.h.
00818 { 00819 init(); 00820 vector < string > result; 00821 typename map < string, InstanceType >::const_iterator p; 00822 for (p = my_instance->my_dict.begin(); p != my_instance->my_dict.end(); p++) { 00823 result.push_back(p->first); 00824 } 00825 00826 return result; 00827 }
| void EMAN::Factory< T >::init | ( | ) | [inline, static, private] |
Definition at line 723 of file emobject.h.
00724 { 00725 if (!my_instance) { 00726 my_instance = new Factory < T > (); 00727 } 00728 }
| void EMAN::Factory< T >::force_add | ( | InstanceType | i | ) | [inline, private] |
Definition at line 730 of file emobject.h.
00731 { 00732 T *i = new_instance(); 00733 string name = i->get_name(); 00734 my_dict[name] = new_instance; 00735 if( i ) 00736 { 00737 delete i; 00738 i = 0; 00739 } 00740 }
| Symmetry3D * EMAN::Factory< Symmetry3D >::get | ( | const string & | instancename | ) | [inline] |
Factory< T > * EMAN::Factory< T >::my_instance = 0 [inline, static, private] |
Definition at line 717 of file emobject.h.
map< string, InstanceType > EMAN::Factory< T >::my_dict [private] |
Definition at line 718 of file emobject.h.
1.5.6