source: src/UIElements/Qt4/InstanceBoard/ObservedValuesContainer.hpp@ 0af22d

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

FIX: ObservedValuesContainer uses deque for internal observed values.

  • it may happen that an atom is created before the _visual representation_ got destroyed (and hence it's QtObserved... would be destroyed). In that case the QtObservedInstanceBoard fails with an assertion.
  • Now, we use a deque. At the front end, we have all the observedvalues that have not yet been deleted, on the back end we have the observedvalues to the currently active instance.
  • removed unused getRefCount().
  • Property mode set to 100644
File size: 5.8 KB
Line 
1/*
2 * ObservedValuesContainer.hpp
3 *
4 * Created on: Oct 29, 2015
5 * Author: heber
6 */
7
8
9#ifndef OBSERVEDVALUESCONTAINER_HPP_
10#define OBSERVEDVALUESCONTAINER_HPP_
11
12// include config.h
13#ifdef HAVE_CONFIG_H
14#include <config.h>
15#endif
16
17#include "ObservedValue_types.hpp"
18
19#include <deque>
20#include <map>
21#include <string>
22
23#include <boost/function.hpp>
24
25class QtObservedInstanceBoard;
26
27/** This class contains ObservedValues of the class \b T each instance identified
28 * by the id type \b id.
29 *
30 * All the reference counting is done inside this container.
31 */
32template <class T, typename id>
33class ObservedValuesContainer
34{
35public:
36
37 //!> typedef for callback functions to be used on last SubjectKilled()
38 typedef boost::function<void (const id _id)> onDestroy_t;
39
40 /** Cstor of class ObservedValuesContainer.
41 *
42 * \param _name name used in debugging and prints
43 * \param _board ref to InstanceBoard
44 * \param _onDestroy function to call when last subjectKilled() was received and
45 * ObservedValues are destroyed
46 */
47 ObservedValuesContainer(
48 const std::string _name,
49 QtObservedInstanceBoard &_board,
50 const onDestroy_t _onDestroy);
51
52 /** Destor of class ObservedValuesContainer.
53 *
54 */
55 ~ObservedValuesContainer();
56
57 /** Delivers the set of Observed value for the instance identified by \a _id.
58 *
59 * \param _id identifier of the instance
60 * \return shared ptr to observed instance.
61 */
62 typename T::ptr get(const id _id);
63
64 /** Used by QtObserved.. instance to note that signOn() has been called.
65 *
66 * \param _id identifier of the instance who called signOn()
67 */
68 void markObservedValuesAsConnected(const id _id);
69
70 /** Used by QtObserved.. instance to note that signOff() has been called.
71 *
72 * \param _id identifier of the instance who called signOff()
73 */
74 void markObservedValuesAsDisconnected(const id _id);
75
76 /** Inform this container that subjectKilled() was received by one of the ObservedValues.
77 *
78 * \param _id identifier of the receiving instance
79 */
80 void countsubjectKilled(const id _id);
81
82 /** Prepares removeal a vector of observed values of an instance identified by \a _id.
83 *
84 * \param _id identifier of instance
85 */
86 void removeObservedValues(const id _id);
87
88 /** Erases a vector of observed values of an instance identified by \a _id.
89 *
90 * \param _id identifier of instance
91 */
92 void eraseObservedValues(const id _id);
93
94private:
95 /** \note CountedObservedValues_t needs to contain a list in the second argument
96 * as the ObservedValuesContainer may fall behind when a single atom is created
97 * and destroyed a number of times in a row (e.g. in the undo/redo cases). This
98 * problem is inherent because on the one hand we keep the QtObservedAtom alive
99 * till the last moment, i.e. till the GUI does not need it anymore where the
100 * original instance may long have been removed from the World. On the other hand
101 * we instantiate the e.g. QtObservedAtom as soon as the observed atom is created.
102 */
103
104 typedef std::deque<std::pair<typename T::ptr, size_t> > RefCountedObservedValues_t;
105 typedef std::map<id, RefCountedObservedValues_t > CountedObservedValues_t;
106 //!> internal vector of observed values
107 CountedObservedValues_t ObservedValues;
108
109 //!> typedef for map with subjectKilledCounts for each instance
110 typedef std::map<id, size_t> subjectKilledCount_t;
111
112 //!> counts how many ObservedValues have already been subjectKilled()
113 subjectKilledCount_t subjectKilledCount;
114
115 //!> typedef for the set with ids to be erase
116 typedef std::set<id> MarkedForErase_t;
117
118 //!> marks ids marked for erase (i.e. all subjectKilled() received)
119 MarkedForErase_t MarkedForErase;
120
121 //!> name used in describing the instance type
122 const std::string NameOfType;
123
124 //!> reference to InstanceBoard for callbacks on subjectKilled()
125 QtObservedInstanceBoard &board;
126
127 //!> callback function when ObservedValues need to be destroyed
128 const onDestroy_t onDestroy;
129
130private:
131 /** Internal function to check whether an Observed instance identified by
132 * \a _id is still signOn() to its associated World instance.
133 *
134 * \param _id identifier of instance
135 * \return true - no more signOn()s, false - else
136 */
137 bool checkRefCount(const id _id) const;
138
139 /** Internal function to check whether any ObservedValue identified by
140 * \a _id is still signOn() to its associated World instance.
141 *
142 * \param _id identifier of instance
143 * \return true - no more signOn()s, false - else
144 */
145 bool checksubjectKilled(const id _id) const;
146
147 /** Internal function to check whether the vector of ObservedValue's
148 * identified by \a _id has been marked for erase.
149 *
150 * Marked for erase means that it has received all subjectKilled()
151 * (the container not the values themselves).
152 *
153 * \param _id identifier of instance
154 * \return true - marked for erase, false - else
155 */
156 bool checkMarkedForErase(const id _id) const;
157
158private:
159 //!> QtObservedInstanceBoard may access anything
160 friend class QtObservedInstanceBoard;
161
162 /** Inserts a new ObservedValue vector into the container.
163 *
164 * \param _id identifier of instance associated with observed values
165 * \param _obsvalues vector of observed values of instance
166 */
167 void insert(const id _id, const typename T::ptr &_obsvalues);
168
169 /** Use to change the identifier associated with a vector of observed values.
170 *
171 * \param _oldid old identifier
172 * \param _newid new identifier
173 * \return true - change successful, false - else
174 */
175 bool changeIdentifier(const id _oldid, const id _newid);
176
177 /** Checks whether a vector of observed values of an instance identified by \a _id
178 * is present.
179 *
180 * \param _id identifier of instance
181 * \return true - present, false - else
182 */
183 bool isPresent(const id _id) const;
184};
185
186#endif /* OBSERVEDVALUESCONTAINER_HPP_ */
Note: See TracBrowser for help on using the repository browser.