Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

EMAN::Factory< T > Class Template Reference

Factory is used to store objects to create new instances. More...

#include <emobject.h>

List of all members.

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<>
Symmetry3Dget (const string &instancename)
template<>
 Factory ()

Static Public Member Functions

template<class ClassType>
void add ()
T * get (const string &instance_name)
T * get (const string &instance_name, const Dict &params)
vector< string > get_list ()

Private Member Functions

 Factory ()
 Factory (const Factory< T > &)
 ~Factory ()
template<class ClassType>
void force_add ()

Static Private Member Functions

void init ()

Private Attributes

map< string, InstanceTypemy_dict

Static Private Attributes

Factory< T > * my_instance = 0


Detailed Description

template<class T>
class EMAN::Factory< T >

Factory is used to store objects to create new instances.

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("filter.lowpass.gauss", Dict("cufoff_freq", EMObject(12));

Author:
Liwei Peng

Definition at line 708 of file emobject.h.


Member Typedef Documentation

template<class T>
typedef T*(* EMAN::Factory< T >::InstanceType)()
 

Definition at line 711 of file emobject.h.


Constructor & Destructor Documentation

template<class T>
EMAN::Factory< T >::Factory  )  [private]
 

template<class T>
EMAN::Factory< T >::Factory const Factory< T > &   )  [private]
 

template<class T>
EMAN::Factory< T >::~Factory  )  [private]
 

template<>
EMAN::Factory< Aligner >::Factory  ) 
 

template<>
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         }

template<>
EMAN::Factory< Analyzer >::Factory  ) 
 

template<>
EMAN::Factory< Averager >::Factory  ) 
 

template<>
EMAN::Factory< Cmp >::Factory  ) 
 

template<>
EMAN::Factory< Processor >::Factory  ) 
 

template<>
EMAN::Factory< Projector >::Factory  ) 
 

template<>
EMAN::Factory< Reconstructor >::Factory  ) 
 

template<>
EMAN::Factory< FourierPixelInserter3D >::Factory  ) 
 

template<>
EMAN::Factory< Symmetry3D >::Factory  ) 
 

template<>
EMAN::Factory< OrientationGenerator >::Factory  ) 
 


Member Function Documentation

template<class T>
template<class ClassType>
void EMAN::Factory< T >::add  )  [static]
 

Definition at line 749 of file emobject.h.

00750         {
00751                 init();
00752 
00753                 string name = ClassType::NAME;
00754                 typename map < string, InstanceType >::iterator fi =
00755                         my_instance->my_dict.find(name);
00756 
00757                 if (fi == my_instance->my_dict.end()) {
00758                         my_instance->my_dict[name] = &ClassType::NEW;
00759                 }
00760         }

template<class T>
template<class ClassType>
void EMAN::Factory< T >::force_add  )  [private]
 

Definition at line 740 of file emobject.h.

00741         {
00742                 string name = ClassType::NAME;
00743                 my_dict[name] = &ClassType::NEW;
00744         }

template<>
Symmetry3D * EMAN::Factory< Symmetry3D >::get const string &  instancename  ) 
 

template<class T>
T * EMAN::Factory< T >::get const string &  instance_name,
const Dict params
[static]
 

Definition at line 782 of file emobject.h.

References InvalidParameterException, EMAN::TypeDict::keys(), 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         }

template<class T>
T * EMAN::Factory< T >::get const string &  instance_name  )  [static]
 

Definition at line 762 of file emobject.h.

References NotExistingObjectException.

Referenced by ali3d_d(), EMAN::SymAlignProcessor::align(), EMAN::BackProjectionReconstructor::finish(), EMAN::Transform::get_nsym(), EMAN::Transform::get_sym(), EMAN::Transform::get_sym_proj(), EMAN::Symmetry3D::get_symmetries(), EMAN::group_processors(), EMAN::FourierReconstructor::load_inserter(), EMAN::ApplySymProcessor::process(), EMAN::AutoMaskAsymUnit::process_inplace(), recons3d_4nn(), and EMAN::RT3DSphereAligner::xform_align_nbest().

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         }

template<class T>
vector< string > EMAN::Factory< T >::get_list  )  [static]
 

Definition at line 818 of file emobject.h.

Referenced by EMAN::group_processors().

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         }

template<class T>
void EMAN::Factory< T >::init  )  [static, private]
 

Definition at line 731 of file emobject.h.

00732         {
00733                 if (!my_instance) {
00734                         my_instance = new Factory < T > ();
00735                 }
00736         }


Member Data Documentation

template<class T>
map< string, InstanceType > EMAN::Factory< T >::my_dict [private]
 

Definition at line 726 of file emobject.h.

template<class T>
Factory< T > * EMAN::Factory< T >::my_instance = 0 [static, private]
 

Definition at line 729 of file emobject.h.


The documentation for this class was generated from the following file:
Generated on Thu Nov 17 12:45:31 2011 for EMAN2 by  doxygen 1.3.9.1