#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<> | |
Symmetry3D * | get (const string &instancename) |
template<> | |
Factory () | |
Static Public Member Functions | |
template<class ClassType> | |
static void | add () |
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 () | |
template<class ClassType> | |
void | force_add () |
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 704 of file emobject.h.
typedef T*(*) EMAN::Factory< T >::InstanceType() |
Definition at line 707 of file emobject.h.
EMAN::Factory< T >::Factory | ( | ) | [private] |
EMAN::Factory< T >::Factory | ( | const Factory< T > & | ) | [private] |
EMAN::Factory< T >::~Factory | ( | ) | [private] |
EMAN::Factory< Aligner >::Factory | ( | ) |
EMAN::Factory< Analyzer >::Factory | ( | ) |
Definition at line 57 of file analyzer.cpp.
00058 { 00059 force_add<PCAsmall>(); 00060 force_add<PCAlarge>(); 00061 force_add<varimax>(); 00062 force_add<KMeansAnalyzer>(); 00063 force_add<SVDAnalyzer>(); 00064 }
EMAN::Factory< Analyzer >::Factory | ( | ) |
EMAN::Factory< Averager >::Factory | ( | ) |
EMAN::Factory< Cmp >::Factory | ( | ) |
EMAN::Factory< Processor >::Factory | ( | ) |
EMAN::Factory< Projector >::Factory | ( | ) |
EMAN::Factory< Reconstructor >::Factory | ( | ) |
EMAN::Factory< FourierPixelInserter3D >::Factory | ( | ) |
EMAN::Factory< Symmetry3D >::Factory | ( | ) |
EMAN::Factory< OrientationGenerator >::Factory | ( | ) |
Definition at line 745 of file emobject.h.
00746 { 00747 init(); 00748 00749 string name = ClassType::NAME; 00750 typename map < string, InstanceType >::iterator fi = 00751 my_instance->my_dict.find(name); 00752 00753 if (fi == my_instance->my_dict.end()) { 00754 my_instance->my_dict[name] = &ClassType::NEW; 00755 } 00756 }
Definition at line 736 of file emobject.h.
00737 { 00738 string name = ClassType::NAME; 00739 my_dict[name] = &ClassType::NEW; 00740 }
Symmetry3D * EMAN::Factory< Symmetry3D >::get | ( | const string & | instancename | ) |
T * EMAN::Factory< T >::get | ( | const string & | instance_name, | |
const Dict & | params | |||
) | [static] |
Definition at line 778 of file emobject.h.
References InvalidParameterException, and NotExistingObjectException.
00780 { 00781 init(); 00782 00783 typename map < string, InstanceType >::iterator fi = 00784 my_instance->my_dict.find(instancename); 00785 00786 string lower = instancename; 00787 if (fi == my_instance->my_dict.end()) { 00788 for (unsigned int i=0; i<lower.length(); i++) lower[i]=tolower(lower[i]); 00789 fi = my_instance->my_dict.find(lower); 00790 } 00791 00792 if (fi != my_instance->my_dict.end()) { 00793 T *i = my_instance->my_dict[lower] (); 00794 00795 const vector<string> para_keys = params.keys(); 00796 // std::cout << "the number of keys is " << para_keys.size() << std::endl; // PRB May 19th 00797 const vector<string> valid_keys = i->get_param_types().keys(); 00798 typename vector<string>::const_iterator it; 00799 for(it=para_keys.begin(); it!=para_keys.end(); ++it) { 00800 // std::cout << "the iterator is " << *it << std::endl; // PRB May 19th 00801 if( find(valid_keys.begin(), valid_keys.end(), *it) == valid_keys.end() ) { 00802 throw InvalidParameterException(*it); 00803 } 00804 } 00805 00806 i->set_params(params); 00807 return i; 00808 } 00809 00810 00811 throw NotExistingObjectException(instancename, "No such an instance existing"); 00812 }
T * EMAN::Factory< T >::get | ( | const string & | instance_name | ) | [static] |
Definition at line 758 of file emobject.h.
References NotExistingObjectException.
00759 { 00760 init(); 00761 typename map < string, InstanceType >::iterator fi = 00762 my_instance->my_dict.find(instancename); 00763 if (fi != my_instance->my_dict.end()) { 00764 return my_instance->my_dict[instancename] (); 00765 } 00766 00767 string lower = instancename; 00768 for (unsigned int i=0; i<lower.length(); i++) lower[i]=tolower(lower[i]); 00769 00770 fi = my_instance->my_dict.find(lower); 00771 if (fi != my_instance->my_dict.end()) { 00772 return my_instance->my_dict[lower] (); 00773 } 00774 00775 throw NotExistingObjectException(instancename, "The named object doesn't exist"); 00776 }
vector< string > EMAN::Factory< T >::get_list | ( | ) | [static] |
Definition at line 814 of file emobject.h.
00814 { 00815 init(); 00816 vector < string > result; 00817 typename map < string, InstanceType >::const_iterator p; 00818 for (p = my_instance->my_dict.begin(); p != my_instance->my_dict.end(); p++) { 00819 result.push_back(p->first); 00820 } 00821 00822 return result; 00823 }
void EMAN::Factory< T >::init | ( | ) | [static, private] |
Definition at line 727 of file emobject.h.
00728 { 00729 if (!my_instance) { 00730 my_instance = new Factory < T > (); 00731 } 00732 }
map< string, InstanceType > EMAN::Factory< T >::my_dict [private] |
Definition at line 722 of file emobject.h.
Factory< T > * EMAN::Factory< T >::my_instance = 0 [static, private] |
Definition at line 721 of file emobject.h.