source: src/UIElements/Qt4/InstanceBoard/ObservedValuesContainer.hpp@ 04c3a3

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

QtObservedAtom, ..Molecule, and ObservedValue_wCallback have flag to indicate invalid callback.

  • due to Qt's signal/slot destruction, which follows no proper order, we need to invalidate callback when their owners are destroyed. Each has a note-function() that flips the boolean to show the callbacks invalidity.
  • TODO: So far this is not nice, especially w.r.t to ObservedValue_wCallback because of templatization. We cannot place them in a loop and this makes this very error-prone once more Values are added ...
  • Property mode set to 100644
File size: 4.7 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 <map>
20#include <string>
21
22#include <boost/function.hpp>
23
24class QtObservedInstanceBoard;
25
26/** This class contains ObservedValues of the class \b T each instance identified
27 * by the id type \b id.
28 *
29 * All the reference counting is done inside this container.
30 */
31template <class T, typename id>
32class ObservedValuesContainer
33{
34public:
35
36 //!> typedef for callback functions to be used on last SubjectKilled()
37 typedef boost::function<void (const id _id)> onDestroy_t;
38
39 /** Cstor of class ObservedValuesContainer.
40 *
41 * \param _name name used in debugging and prints
42 * \param _board ref to InstanceBoard
43 * \param _onDestroy function to call when last subjectKilled() was received and
44 * ObservedValues are destroyed
45 */
46 ObservedValuesContainer(
47 const std::string _name,
48 QtObservedInstanceBoard &_board,
49 const onDestroy_t _onDestroy);
50
51 /** Destor of class ObservedValuesContainer.
52 *
53 */
54 ~ObservedValuesContainer();
55
56 /** Delivers the set of Observed value for the instance identified by \a _id.
57 *
58 * \param _id identifier of the instance
59 * \return shared ptr to observed instance.
60 */
61 typename T::ptr get(const id _id);
62
63 /** Used by QtObserved.. instance to note that signOn() has been called.
64 *
65 * \param _id identifier of the instance who called signOn()
66 */
67 void markObservedValuesAsConnected(const id _id);
68
69 /** Used by QtObserved.. instance to note that signOff() has been called.
70 *
71 * \param _id identifier of the instance who called signOff()
72 */
73 void markObservedValuesAsDisconnected(const id _id);
74
75 /** Inform this container that subjectKilled() was received by one of the ObservedValues.
76 *
77 * \param _id identifier of the receiving instance
78 */
79 void countsubjectKilled(const id _id);
80
81 /** Erases a vector of observed values of an instance identified by \a _id.
82 *
83 * \param _id identifier of instance
84 */
85 void removeObservedValues(const id _id);
86
87private:
88 typedef std::pair<typename T::ptr, size_t> RefCountedObservedValues_t;
89 typedef std::map<id, RefCountedObservedValues_t> CountedObservedValues_t;
90 //!> internal vector of observed values
91 CountedObservedValues_t ObservedValues;
92
93 //!> typedef for map with subjectKilledCounts for each instance
94 typedef std::map<id, size_t> subjectKilledCount_t;
95
96 //!> counts how many ObservedValues have already been subjectKilled()
97 subjectKilledCount_t subjectKilledCount;
98
99 //!> name used in describing the instance type
100 const std::string NameOfType;
101
102 //!> reference to InstanceBoard for callbacks on subjectKilled()
103 QtObservedInstanceBoard &board;
104
105 //!> callback function when ObservedValues need to be destroyed
106 const onDestroy_t onDestroy;
107
108private:
109 /** Internal function to check whether an Observed instance identified by
110 * \a _id is still signOn() to its associated World instance.
111 *
112 * \param _id identifier of instance
113 * \return true - no more signOn()s, false - else
114 */
115 bool checkRefCount(const id _id) const;
116
117 /** Internal function to check whether any ObservedValue identified by
118 * \a _id is still signOn() to its associated World instance.
119 *
120 * \param _id identifier of instance
121 * \return true - no more signOn()s, false - else
122 */
123 bool checksubjectKilled(const id _id) const;
124
125private:
126 //!> QtObservedInstanceBoard may access anything
127 friend class QtObservedInstanceBoard;
128
129 /** Inserts a new ObservedValue vector into the container.
130 *
131 * \param _id identifier of instance associated with observed values
132 * \param _obsvalues vector of observed values of instance
133 * \return true - insertion successful, false - else
134 */
135 bool insert(const id _id, const typename T::ptr &_obsvalues);
136
137 /** Use to change the identifier associated with a vector of observed values.
138 *
139 * \param _oldid old identifier
140 * \param _newid new identifier
141 * \return true - change successful, false - else
142 */
143 bool changeIdentifier(const id _oldid, const id _newid);
144
145 /** Returns the number of reference delivered for this instance identified by \a _id.
146 *
147 * \param _id identifier of instance
148 * \return reference count
149 */
150 size_t getRefCount(const id _id) const;
151
152 /** Checks whether a vector of observed values of an instance identified by \a _id
153 * is present.
154 *
155 * \param _id identifier of instance
156 * \return true - present, false - else
157 */
158 bool isPresent(const id _id) const;
159};
160
161#endif /* OBSERVEDVALUESCONTAINER_HPP_ */
Note: See TracBrowser for help on using the repository browser.