source: src/Fragmentation/Summation/SetValueMap.hpp@ e0ae58d

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 e0ae58d was 07266b, checked in by Frederik Heber <heber@…>, 12 years ago

Added SetValueMap::getConstValue() for getting const reference to SetValue.

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 * SetValueMap.hpp
3 *
4 * Created on: Jul 4, 2012
5 * Author: heber
6 */
7
8#ifndef SETVALUEMAP_HPP_
9#define SETVALUEMAP_HPP_
10
11
12// include config.h
13#ifdef HAVE_CONFIG_H
14#include <config.h>
15#endif
16
17#include <map>
18
19#include "IndexSet.hpp"
20#include "SetValue.hpp"
21
22#include "CodePatterns/Assert.hpp"
23
24class SetValueMapTest;
25
26/** This class represents a map from IndexSet to SetValue<T>.
27 *
28 * Each SetValue knows its IndexSet but we also need the inverse
29 * association from IndexSet to SetValue.
30 *
31 */
32template <typename T>
33class SetValueMap
34{
35 //!> grant unit access
36 friend class SetValueMapTest;
37public:
38 /** Either adds a new SetValue<T> to the map or changes the value the present
39 * instance.
40 *
41 * @param ptr associated IndexSet
42 * @param _value new value of the SetValue
43 */
44 void addValue(const IndexSet::ptr& ptr, const T &_value) {
45 typename Lookup_t::iterator iter = Lookup.find(ptr);
46 if (iter != Lookup.end()) {
47 iter->second->setValue(_value);
48 } else {
49 Lookup.insert( std::make_pair( ptr, typename SetValue<T>::ptr(new SetValue<T>(ptr, _value)) ) );
50 }
51 }
52
53 /** Getter for the SetValue to a specific IndexSet.
54 *
55 * @param ptr IndexSet
56 * @return SetValue associated with this IndexSet
57 */
58 typename SetValue<T>::ptr & getValue(const IndexSet::ptr &ptr) {
59 ASSERT( isIndexSetPresent(ptr),
60 "SetValueMap<T>::getValue() - IndexSet "+toString(*ptr)+" is unknown.");
61 typename Lookup_t::iterator iter = Lookup.find(ptr);
62 ASSERT( *iter->second->getIndexSet() == *ptr,
63 "SetValueMap<T>::getValue() - returned SetValue associated to set "+
64 toString(*iter->second->getIndexSet())+"does not match with desired set "
65 +toString(*ptr)+".");
66 return iter->second;
67 }
68
69 /** Getter for the SetValue to a specific IndexSet.
70 *
71 * @param ptr IndexSet
72 * @return SetValue associated with this IndexSet
73 */
74 const typename SetValue<T>::ptr & getConstValue(const IndexSet::ptr &ptr) const {
75 ASSERT( isIndexSetPresent(ptr),
76 "SetValueMap<T>::getValue() - IndexSet "+toString(*ptr)+" is unknown.");
77 typename Lookup_t::const_iterator iter = Lookup.find(ptr);
78 ASSERT( *iter->second->getIndexSet() == *ptr,
79 "SetValueMap<T>::getValue() - returned SetValue associated to set "+
80 toString(*iter->second->getIndexSet())+"does not match with desired set "
81 +toString(*ptr)+".");
82 return iter->second;
83 }
84
85 bool removeValue(const IndexSet::ptr &ptr) {
86 if (isIndexSetPresent(ptr)) {
87 Lookup.erase(ptr);
88 return true;
89 } else {
90 return false;
91 }
92 }
93
94 /** Checks whether a given IndexSet \a ptr is known.
95 *
96 * @param ptr IndexSet to check
97 * @return true - set present, false - else
98 */
99 bool isIndexSetPresent(const IndexSet::ptr& ptr) const {
100 typename Lookup_t::const_iterator iter = Lookup.find(ptr);
101 return (iter != Lookup.end());
102 }
103
104private:
105 //!> typedef for the internal lookup
106 typedef std::map< IndexSet::ptr, typename SetValue<T>::ptr, IndexSetContainer::Comparator_t > Lookup_t;
107 //!> internal map to provide the lookup
108 Lookup_t Lookup;
109
110public:
111 //!> typedef to const iterator of internal map such that easy const traversal is possible
112 typedef typename Lookup_t::const_iterator const_iterator;
113
114 /** Getter for first node of iternal map.
115 *
116 * @return Lookup::begin()
117 */
118 const_iterator begin() const {
119 return Lookup.begin();
120 }
121
122 /** Getter for last and one node of iternal map.
123 *
124 * @return Lookup::end()
125 */
126 const_iterator end() const {
127 return Lookup.end();
128 }
129};
130
131#endif /* SETVALUEMAP_HPP_ */
Note: See TracBrowser for help on using the repository browser.