source: src/Patterns/Registry.hpp@ c66537

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since c66537 was b2d8d0, checked in by Frederik Heber <heber@…>, 15 years ago

Registry pattern split off of ActionRegistry, the latter converted to derive from Registry<Action>

  • new header files Registry.hpp and Registry_impl.hpp containing templated registry pattern.
  • ActionRegistry derives from Singleton and Registry<Action>
  • renamed ... to ActionRegistry::isActionPresentByName().
  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 * Registry.hpp
3 *
4 * Based on Registry<Action> by Till Crueger.
5 *
6 * The registry pattern is basically just a singleton map, wherein instantiations
7 * of a class can be registered, unregistered and retrieved.
8 *
9 * Created on: Jul 28, 2010
10 * Author: heber
11 */
12
13#ifndef REGISTRY_HPP_
14#define REGISTRY_HPP_
15
16#include <map>
17
18/**
19 * This template produces a generic registry pattern.
20 *
21 * <h1> Registry Howto </h1>
22 *
23 * The registry is a class where instances of other classes are stored and be retrieved
24 * when desired. For this purpose a registry should always be a singleton (i.e. use both
25 * this registry and the singleton pattern to declare a registry class). It basically
26 * is simply a singleton container of a map, where the pointers to the class instances are
27 * stored by a string key and can be retrieved thereby.
28 *
29 * The available functions are, if your class to be stored in registry is foo :
30 *
31 * - <code>foo* Registry<foo>::getByName()</code> : returns the instance of a specific
32 * class foo instance as a pointer associated with the given name
33 * - <code>bool Registry<foo>::isPresentByName()</code> : returns whether an instance
34 * of class foo is present under the given name.
35 * - <code>map<string,foo*>::iterator Registry<foo>::getBeginIter()</code> : returns an
36 * iterator to the beginning of the storage map (STL).
37 * - <code>map<string,foo*>::const_iterator Registry<foo>::getBeginIter()</code> : returns a
38 * constant iterator to the beginning of the storage map (STL).
39 * - <code>map<string,foo*>::const_iterator Registry<foo>::getEndIter()</code> : returns an
40 * iterator to the one step past the last element of the storage map (STL).
41 * - <code>map<string,foo*>::const_iterator Registry<foo>::getEndIter()</code> : returns a
42 * constant iterator to the one step past the last element of the storage map (STL).
43 *
44 * In order to use this pattern, additionally to the requirements of the Singleton pattern,
45 * do this:
46 * -# in the declaration derive your class from Registry<foo>, where foo is the class to be
47 * stored
48 * -# in the definition add CONSTRUCT_REGISTRY(foo) to the code such that the templated
49 * functions get instantiated there (otherwise you'll get undefined reference errors).
50 *
51 */
52
53template <class T>
54class Registry
55{
56public:
57 Registry();
58 ~Registry();
59
60 T* getByName(const std::string name);
61 bool isPresentByName(const std::string name);
62 void registerInstance(T*);
63 void unregisterInstance(T*);
64
65 typename std::map<const std::string,T*>::iterator getBeginIter();
66 typename std::map<const std::string,T*>::const_iterator getBeginIter() const;
67 typename std::map<const std::string,T*>::iterator getEndIter();
68 typename std::map<const std::string,T*>::const_iterator getEndIter() const;
69
70private:
71 typename std::map<const std::string,T*> InstanceMap;
72};
73
74template <class T> std::ostream& operator<<(std::ostream& ost, const Registry<T>& m);
75
76#endif /* REGISTRY_HPP_ */
Note: See TracBrowser for help on using the repository browser.