source: src/UIElements/Qt4/InstanceBoard/ObservedValuesContainer_impl.hpp@ 68418e

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 68418e was 68418e, checked in by Frederik Heber <heber@…>, 9 years ago

ObservedValuesContainer now stores QtObserved.. instances directly.

  • we need this as QtObservedAtom and ..Molecule must signOn() to World's instance right away. If later requests to ObservedValuesContainer::get() cause new signOn()s, then these might fail.
  • we now work with QtObserved..::ptr directly everywhere.
  • Property mode set to 100644
File size: 5.7 KB
Line 
1/*
2 * ObservedValuesContainer_impl.hpp
3 *
4 * Created on: Oct 29, 2015
5 * Author: heber
6 */
7
8
9#ifndef OBSERVEDVALUESCONTAINER_IMPL_HPP_
10#define OBSERVEDVALUESCONTAINER_IMPL_HPP_
11
12// include config.h
13#ifdef HAVE_CONFIG_H
14#include <config.h>
15#endif
16
17#include "ObservedValuesContainer.hpp"
18
19#include "CodePatterns/Assert.hpp"
20
21template <class T, typename id>
22ObservedValuesContainer<T,id>::ObservedValuesContainer(
23 const std::string _name,
24 QtObservedInstanceBoard &_board,
25 const onDestroy_t _onDestroy) :
26 NameOfType(_name),
27 board(_board),
28 onDestroy(_onDestroy)
29{}
30
31template <class T, typename id>
32typename T::ptr ObservedValuesContainer<T,id>::get(const id _id)
33{
34 typename CountedObservedValues_t::iterator iter = ObservedValues.find(_id);
35 ASSERT( iter != ObservedValues.end(),
36 "ObservedValuesContainer::getObservedValues() - no observed values present for "
37 +NameOfType+" "+toString(_id));
38 const typename T::ptr &obsvalues = iter->second.first;
39
40 return obsvalues;
41}
42
43template <class T, typename id>
44void ObservedValuesContainer<T,id>::markObservedValuesAsConnected(
45 const id _id)
46{
47 typename CountedObservedValues_t::iterator iter = ObservedValues.find(_id);
48 ASSERT (iter != ObservedValues.end(),
49 "ObservedValuesContainer<T,id>::markObservedValuesAsConnected() - Observed value of "
50 +NameOfType+" "+toString(_id)+" is not present yet.");
51 ++(iter->second.second);
52}
53
54template <class T, typename id>
55bool ObservedValuesContainer<T,id>::checkRefCount(
56 const id _id) const
57{
58 typename CountedObservedValues_t::const_iterator iter = ObservedValues.find(_id);
59 return ((iter != ObservedValues.end()) && (iter->second.second == 0));
60}
61
62template <class T, typename id>
63void ObservedValuesContainer<T,id>::markObservedValuesAsDisconnected(
64 const id _id)
65{
66 typename CountedObservedValues_t::iterator iter = ObservedValues.find(_id);
67 ASSERT (iter != ObservedValues.end(),
68 "ObservedValuesContainer<T,id>::markObservedValuesAsDisconnected() - Observed value of "
69 +NameOfType+" "+toString(_id)+" is not present yet.");
70 ASSERT (iter->second.second != 0,
71 "ObservedValuesContainer<T,id>::markObservedValuesAsDisconnected() - Observed value of "
72 +NameOfType+" "+toString(_id)+" is already signOff() from all.");
73 --(iter->second.second);
74
75 if (checkRefCount(_id) && checksubjectKilled(_id))
76 removeObservedValues(_id);
77}
78
79template <class T, typename id>
80bool ObservedValuesContainer<T,id>::checksubjectKilled(
81 const id _id) const
82{
83 typename subjectKilledCount_t::const_iterator iter = subjectKilledCount.find(_id);
84 return ((iter != subjectKilledCount.end()) && (iter->second == T::MAX_ObservedTypes));
85}
86
87template <class T, typename id>
88void ObservedValuesContainer<T,id>::countsubjectKilled(const id _id)
89{
90 LOG(3, "DEBUG: ObservedValuesContainer got subjectKilled() for an observed value of "
91 << NameOfType << " " << _id);
92 typename subjectKilledCount_t::iterator iter = subjectKilledCount.find(_id);
93 if (iter == subjectKilledCount.end()) {
94 std::pair<typename subjectKilledCount_t::iterator, bool> inserter =
95 subjectKilledCount.insert( std::make_pair(_id, 0) );
96 iter = inserter.first;
97 }
98 ASSERT (iter->second < T::MAX_ObservedTypes,
99 "ObservedValuesContainer<T,id>::countsubjectKilled() - all subjectKilled() for "
100 +NameOfType+" "+toString(_id)+" for each observed channel came in already.");
101 ++(iter->second);
102
103 if (checkRefCount(_id) && checksubjectKilled(_id))
104 removeObservedValues(_id);
105}
106
107template <class T, typename id>
108void ObservedValuesContainer<T,id>::removeObservedValues(const id _id)
109{
110 LOG(3, "DEBUG: ObservedValuesContainer removes " << NameOfType << " " << _id);
111 // call callback function
112 onDestroy(_id);
113 subjectKilledCount.erase(_id);
114 ObservedValues.erase(_id);
115}
116
117template <class T, typename id>
118bool ObservedValuesContainer<T,id>::insert(const id _id, const typename T::ptr &_obsvalues)
119{
120 std::pair<typename CountedObservedValues_t::iterator, bool> inserter =
121 ObservedValues.insert(
122 std::make_pair( _id, std::make_pair(_obsvalues,0) ) );
123 _obsvalues->activateObserver();
124 return inserter.second;
125}
126
127template <class T, typename id>
128bool ObservedValuesContainer<T,id>::changeIdentifier(const id _oldid, const id _newid)
129{
130 const typename CountedObservedValues_t::iterator Colditer = ObservedValues.find(_oldid);
131 const typename CountedObservedValues_t::iterator Cnewiter = ObservedValues.find(_newid);
132 const typename subjectKilledCount_t::iterator Solditer = subjectKilledCount.find(_oldid);
133 const typename subjectKilledCount_t::iterator Snewiter = subjectKilledCount.find(_newid);
134 bool status = ((Colditer != ObservedValues.end()) && (Cnewiter == ObservedValues.end()));
135 status &= ((Solditer != subjectKilledCount.end()) && (Snewiter == subjectKilledCount.end()));
136 // change id here only if still present
137 if (status) {
138 {
139 RefCountedObservedValues_t obsvalues = Colditer->second;
140 ObservedValues.erase(Colditer);
141 ObservedValues.insert( std::make_pair(_newid, obsvalues) );
142 }
143 {
144 const size_t countvalue = Solditer->second;
145 subjectKilledCount.erase(Solditer);
146 subjectKilledCount.insert( std::make_pair(_newid, countvalue) );
147 }
148 return true;
149 } else
150 return false;
151}
152
153template <class T, typename id>
154size_t ObservedValuesContainer<T,id>::getRefCount(const id _id) const
155{
156 typename CountedObservedValues_t::const_iterator iter = ObservedValues.find(_id);
157 return iter->second.second;
158}
159
160template <class T, typename id>
161bool ObservedValuesContainer<T,id>::isPresent(const id _id) const
162{
163 typename CountedObservedValues_t::const_iterator iter = ObservedValues.find(_id);
164 return (iter != ObservedValues.end());
165}
166
167#endif /* OBSERVEDVALUESCONTAINER_IMPL_HPP_ */
Note: See TracBrowser for help on using the repository browser.