EMAN2
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
EMAN::Factory< T > Class Template Reference

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

#include <emobject.h>

Public Types

typedef T *(* InstanceType) ()
 

Public Member Functions

Symmetry3Dget (const string &instancename)
 A template specialization for get - so people can call get with strings like "c1","d4" etc - this avoids have to use Dicts to specify the nsym. More...
 

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 &params)
 
static vector< string > get_list ()
 

Private Member Functions

 Factory ()
 
 Factory (const Factory< T > &)
 
 ~Factory ()
 
template<class ClassType >
void force_add ()
 
 Factory ()
 
 Factory ()
 
 Factory ()
 
 Factory ()
 
 Factory ()
 
 Factory ()
 
 Factory ()
 
 Factory ()
 
 Factory ()
 
 Factory ()
 A template specialization for the Symmetry3D factory. Adds all of the symmetries. More...
 
 Factory ()
 Template specialization for the OrientationGenerator class. More...
 

Static Private Member Functions

static void init ()
 

Private Attributes

map< string, InstanceTypemy_dict
 

Static Private Attributes

static 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 724 of file emobject.h.

Member Typedef Documentation

◆ InstanceType

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

Definition at line 727 of file emobject.h.

Constructor & Destructor Documentation

◆ Factory() [1/13]

template<class T >
EMAN::Factory< T >::Factory ( )
private

◆ Factory() [2/13]

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

◆ ~Factory()

template<class T >
EMAN::Factory< T >::~Factory ( )
private

◆ Factory() [3/13]

EMAN::Factory< Aligner >::Factory ( )
private

◆ Factory() [4/13]

EMAN::Factory< Analyzer >::Factory ( )
private

Definition at line 55 of file analyzer.cpp.

56 {
57 force_add<PCAsmall>();
58 force_add<PCAlarge>();
59 force_add<varimax>();
60 force_add<InertiaMatrixAnalyzer>();
61 force_add<ShapeAnalyzer>();
62 force_add<KMeansAnalyzer>();
63 force_add<SVDAnalyzer>();
64 force_add<CircularAverageAnalyzer>();
65 }

◆ Factory() [5/13]

EMAN::Factory< Analyzer >::Factory ( )
private

◆ Factory() [6/13]

EMAN::Factory< Averager >::Factory ( )
private

◆ Factory() [7/13]

EMAN::Factory< Cmp >::Factory ( )
private

◆ Factory() [8/13]

EMAN::Factory< Processor >::Factory ( )
private

◆ Factory() [9/13]

EMAN::Factory< Projector >::Factory ( )
private

◆ Factory() [10/13]

◆ Factory() [11/13]

◆ Factory() [12/13]

EMAN::Factory< Symmetry3D >::Factory ( )
private

A template specialization for the Symmetry3D factory. Adds all of the symmetries.

◆ Factory() [13/13]

Template specialization for the OrientationGenerator class.

Member Function Documentation

◆ add()

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

Definition at line 767 of file emobject.h.

768 {
769 init();
770
771 string name = ClassType::NAME;
772 typename map < string, InstanceType >::iterator fi =
773 my_instance->my_dict.find(name);
774
775 if (fi == my_instance->my_dict.end()) {
776 my_instance->my_dict[name] = &ClassType::NEW;
777 }
778 }
static void init()
Definition: emobject.h:749
static Factory< T > * my_instance
Definition: emobject.h:741

◆ force_add()

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

Definition at line 758 of file emobject.h.

759 {
760 string name = ClassType::NAME;
761 my_dict[name] = &ClassType::NEW;
762 }
map< string, InstanceType > my_dict
Definition: emobject.h:742

◆ get() [1/3]

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

Definition at line 781 of file emobject.h.

782 {
783 init();
784 typename map < string, InstanceType >::iterator fi =
785 my_instance->my_dict.find(instancename);
786 if (fi != my_instance->my_dict.end()) {
787 return my_instance->my_dict[instancename] ();
788 }
789
790 string lower = instancename;
791 for (unsigned int i=0; i<lower.length(); i++) lower[i]=tolower(lower[i]);
792
793 fi = my_instance->my_dict.find(lower);
794 if (fi != my_instance->my_dict.end()) {
795 return my_instance->my_dict[lower] ();
796 }
797
798 throw NotExistingObjectException(instancename, "The named object doesn't exist");
799 }
#define NotExistingObjectException(objname, desc)
Definition: exception.h:130

References NotExistingObjectException.

Referenced by EMAN::dump_factory(), EMAN::dump_factory_list(), EMAN::BackProjectionReconstructor::finish(), EMAN::RealMedianReconstructor::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(), EMAN::SegmentSubunitProcessor::process_inplace(), EMAN::RT3DSphereAligner::xform_align_nbest(), EMAN::RT2Dto3DTreeAligner::xform_align_nbest(), EMAN::RT3DTreeAligner::xform_align_nbest(), and EMAN::RT3DLocalTreeAligner::xform_align_nbest().

◆ get() [2/3]

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

Definition at line 802 of file emobject.h.

803 {
804 init();
805
806 typename map<string, InstanceType>::iterator fi =
807 my_instance->my_dict.find(instancename);
808
809 string lower = instancename;
810 if (fi == my_instance->my_dict.end()) {
811 for (unsigned int i=0; i<lower.length(); i++)
812 lower[i]=tolower(lower[i]);
813 fi = my_instance->my_dict.find(lower);
814 }
815
816 if (fi != my_instance->my_dict.end()) {
817 T *i = my_instance->my_dict[lower] ();
818
819 const vector<string> para_keys = params.keys();
820// std::cout << "the number of keys is " << para_keys.size() << std::endl; // PRB May 19th
821 const vector<string> valid_keys = i->get_param_types().keys();
822 for(auto it=para_keys.begin(); it!=para_keys.end(); ++it) {
823// std::cout << "the iterator is " << *it << std::endl; // PRB May 19th
824 if( find(valid_keys.begin(), valid_keys.end(), *it) == valid_keys.end() ) {
825 throw InvalidParameterException(*it);
826 }
827 }
828
829 i->set_params(params);
830 return i;
831 }
832
833 throw NotExistingObjectException(instancename, "No such an instance existing");
834 }
#define InvalidParameterException(desc)
Definition: exception.h:361

References InvalidParameterException, EMAN::Dict::keys(), and NotExistingObjectException.

◆ get() [3/3]

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

A template specialization for get - so people can call get with strings like "c1","d4" etc - this avoids have to use Dicts to specify the nsym.

◆ get_list()

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

Definition at line 837 of file emobject.h.

837 {
838 init();
839 vector<string> result;
840 for (auto p = my_instance->my_dict.begin(); p != my_instance->my_dict.end(); p++) {
841 result.push_back(p->first);
842 }
843
844 return result;
845 }

Referenced by EMAN::dump_factory(), EMAN::dump_factory_list(), and EMAN::group_processors().

◆ init()

template<class T >
void EMAN::Factory< T >::init
staticprivate

Definition at line 749 of file emobject.h.

750 {
751 if (!my_instance) {
752 my_instance = new Factory<T>();
753 }
754 }

Member Data Documentation

◆ my_dict

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

Definition at line 742 of file emobject.h.

◆ my_instance

template<class T >
Factory< T > * EMAN::Factory< T >::my_instance = 0
staticprivate

Definition at line 741 of file emobject.h.


The documentation for this class was generated from the following file: