Changeset 23221f for src/UIElements
- Timestamp:
- Feb 14, 2016, 12:34:30 PM (9 years ago)
- Branches:
- 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
- Children:
- bcf9cd
- Parents:
- 59f1bc
- git-author:
- Frederik Heber <heber@…> (01/08/16 13:53:48)
- git-committer:
- Frederik Heber <heber@…> (02/14/16 12:34:30)
- Location:
- src/UIElements/Qt4/InstanceBoard
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/Qt4/InstanceBoard/ObservedValuesContainer.hpp
r59f1bc r23221f 87 87 88 88 private: 89 /** \note CountedObservedValues_t needs to contain a list in the second argument90 * as the ObservedValuesContainer may fall behind when a single atom is created91 * and destroyed a number of times in a row (e.g. in the undo/redo cases). This92 * problem is inherent because on the one hand we keep the QtObservedAtom alive93 * till the last moment, i.e. till the GUI does not need it anymore where the94 * original instance may long have been removed from the World. On the other hand95 * we instantiate the e.g. QtObservedAtom as soon as the observed atom is created.96 */97 89 98 /** Structure to contain the sequence of created observed memories. 99 * 100 * \note QtGUI may lag behind the creation/destruction of observed instances a 101 * lot but one after the other must be served. Here, we keep an additional 102 * iterator that indicates the current instance to be served. 103 */ 104 struct RefCountedObserved 105 { 106 typedef std::pair<typename T::ptr, size_t> Value_t; 107 typedef std::deque<Value_t> Values_t; 108 109 /** Default cstor of RefCountedObservedValues. 110 * 111 * Make sure that currentvalue has some sensible default value. 112 */ 113 RefCountedObserved() : 114 tobedestroyed(values.end()), 115 currentvalue(values.end()) 116 {} 117 118 /** Default copy cstor of RefCountedObservedValues. 119 * 120 * \param _instance instance to copy 121 */ 122 RefCountedObserved(const RefCountedObserved & _instance) : 123 values(_instance.values), 124 tobedestroyed(values.begin()), 125 currentvalue(values.begin()) 126 {} 127 128 /** Cstor of RefCountedObservedValues. 129 * 130 * Make sure that currentvalue has some sensible default value. 131 * 132 * \param _value initial value for the list 133 */ 134 RefCountedObserved(Value_t _value) : 135 values(1, _value), 136 tobedestroyed(values.begin()), 137 currentvalue(values.begin()) 138 {} 139 140 bool empty() const 141 { 142 return values.empty(); 143 } 144 145 void push_back(Value_t _value) 146 { 147 values.push_back(_value); 148 if (currentvalue == values.end()) 149 currentvalue = values.end()--; 150 if (tobedestroyed == values.end()) 151 tobedestroyed = currentvalue; 152 } 153 154 Value_t& getCurrentValue() const 155 { 156 ASSERT (currentvalue != values.end(), 157 "RefCountedObservedValues::getCurrentValue() - cannot get, no values present."); 158 return *currentvalue; 159 } 160 161 Value_t& getEraseCandidate() const 162 { 163 ASSERT (tobedestroyed != values.end(), 164 "RefCountedObservedValues::getCurrentValue() - cannot get, no values present."); 165 return *tobedestroyed; 166 } 167 168 void eraseCurrentValue() 169 { 170 ASSERT (tobedestroyed != values.end(), 171 "RefCountedObservedValues::eraseCurrentValue() - cannot erase, no values present."); 172 if (tobedestroyed == currentvalue) 173 ++currentvalue; 174 values.erase(tobedestroyed); 175 tobedestroyed = currentvalue; 176 // removal of this instance when both iterators point to end is done inside QtObservedInstanceBoard 177 } 178 179 //!> set of values 180 Values_t values; 181 //!> iterator on the value that is next gonna be destroyed 182 typename Values_t::iterator tobedestroyed; 183 //!> iterator on the current value that is served on get 184 typename Values_t::iterator currentvalue; 185 }; 186 187 typedef std::map<id, RefCountedObserved > CountedObservedValues_t; 90 typedef std::map<id, typename T::ptr > CountedObservedValues_t; 188 91 //!> internal vector of observed values 189 92 CountedObservedValues_t ObservedValues; 190 93 191 94 //!> typedef for the set with ids to be erase 192 typedef std::set<id> Marked ForErase_t;95 typedef std::set<id> MarkedSet_t; 193 96 194 97 //!> marks ids marked for erase (i.e. all subjectKilled() received) 195 MarkedForErase_t MarkedForErase; 98 MarkedSet_t MarkedForErase; 99 100 //!> marks ids marked as connected (i.e. for later subjectKilled() received) 101 MarkedSet_t MarkedForConnected; 196 102 197 103 //!> name used in describing the instance type … … 214 120 * \return true - no more signOn()s, false - else 215 121 */ 216 bool check RefCount(const id _id) const;122 bool checkMarkedForConnected(const id _id) const; 217 123 218 124 /** Internal function to check whether the vector of ObservedValue's -
src/UIElements/Qt4/InstanceBoard/ObservedValuesContainer_impl.hpp
r59f1bc r23221f 36 36 boost::recursive_mutex::scoped_lock lock(atomic_mutex); 37 37 for (typename CountedObservedValues_t::iterator iter = ObservedValues.begin(); 38 iter != ObservedValues.end(); ++iter) { 39 ASSERT( !iter->second.empty(), 40 "~ObservedValuesContainer() of "+NameOfType+" "+toString(iter->first) 41 +" has an empty list in ObservedValues."); 42 for (typename RefCountedObserved::Values_t::iterator listiter = iter->second.values.begin(); 43 listiter != iter->second.values.end(); ++listiter) { 44 listiter->first->noteBoardIsGone(); 45 } 46 } 38 iter != ObservedValues.end(); ++iter) 39 iter->second->noteBoardIsGone(); 47 40 } 48 41 … … 53 46 void ObservedValuesContainer<T,id>::checkRemoval(const id _id) 54 47 { 55 if (check RefCount(_id) && checkMarkedForErase(_id))48 if (checkMarkedForConnected(_id) && checkMarkedForErase(_id)) 56 49 removeObservedValues(_id); 57 50 } … … 67 60 return typename T::ptr(); 68 61 else 69 return iter->second .getCurrentValue().first;62 return iter->second; 70 63 } 71 64 … … 77 70 LOG(3, "DEBUG: ObservedValuesContainer got markObservedValuesAsConnected() for an observed value of " 78 71 << NameOfType << " " << _id); 79 typename CountedObservedValues_t::iterator iter = ObservedValues.find(_id); 80 ASSERT (iter != ObservedValues.end(), 72 ASSERT (MarkedForConnected.find(_id) == MarkedForConnected.end(), 81 73 "ObservedValuesContainer<T,id>::markObservedValuesAsConnected() - Observed value of " 82 +NameOfType+" "+toString(_id)+" is not present yet.");83 ++(iter->second.getCurrentValue().second);84 } 85 86 template <class T, typename id> 87 bool ObservedValuesContainer<T,id>::check RefCount(74 +NameOfType+" "+toString(_id)+" is already marked as connected."); 75 MarkedForConnected.insert( _id ); 76 } 77 78 template <class T, typename id> 79 bool ObservedValuesContainer<T,id>::checkMarkedForConnected( 88 80 const id _id) const 89 81 { 90 82 boost::recursive_mutex::scoped_lock lock(atomic_mutex); 91 typename CountedObservedValues_t::const_iterator iter = ObservedValues.find(_id);92 return ((iter != ObservedValues.end()) && (iter->second.getEraseCandidate().second == 0));83 typename MarkedSet_t::const_iterator const iter = MarkedForConnected.find(_id); 84 return iter == MarkedForConnected.end(); 93 85 } 94 86 … … 100 92 LOG(3, "DEBUG: ObservedValuesContainer got markObservedValuesAsDisconnected() for an observed value of " 101 93 << NameOfType << " " << _id); 102 typename CountedObservedValues_t::iterator iter = ObservedValues.find(_id);103 ASSERT (iter != ObservedValues.end(),94 typename MarkedSet_t::iterator const iter = MarkedForConnected.find(_id); 95 ASSERT (iter != MarkedForConnected.end(), 104 96 "ObservedValuesContainer<T,id>::markObservedValuesAsDisconnected() - Observed value of " 105 +NameOfType+" "+toString(_id)+" is not present yet."); 106 ASSERT (iter->second.getEraseCandidate().second != 0, 107 "ObservedValuesContainer<T,id>::markObservedValuesAsDisconnected() - Observed value of " 108 +NameOfType+" "+toString(_id)+" is already signOff() from all."); 109 --(iter->second.getEraseCandidate().second); 97 +NameOfType+" "+toString(_id)+" is not marked as connected."); 98 MarkedForConnected.erase(iter); 110 99 111 100 checkRemoval(_id); … … 117 106 boost::recursive_mutex::scoped_lock lock(atomic_mutex); 118 107 LOG(3, "DEBUG: ObservedValuesContainer removes " << NameOfType << " " << _id); 108 MarkedForConnected.erase(_id); 109 MarkedForErase.erase(_id); 110 ObservedValues.erase(_id); 119 111 // call callback function 120 112 onDestroy(_id); 121 typename CountedObservedValues_t::iterator iter = ObservedValues.find(_id);122 iter->second.eraseCurrentValue();123 if (iter->second.empty())124 ObservedValues.erase(iter);125 MarkedForErase.erase(_id);126 113 } 127 114 … … 148 135 { 149 136 boost::recursive_mutex::scoped_lock lock(atomic_mutex); 150 return MarkedForErase.count(_id); 137 typename MarkedSet_t::const_iterator const iter = MarkedForErase.find(_id); 138 return iter != MarkedForErase.end(); 151 139 } 152 140 … … 155 143 { 156 144 boost::recursive_mutex::scoped_lock lock(atomic_mutex); 157 typename ObservedValuesContainer<T,id>::RefCountedObserved::Value_t value(std::make_pair(_obsvalues,0));158 145 typename CountedObservedValues_t::iterator iter = ObservedValues.find(_id); 159 if (iter == ObservedValues.end()) { 160 std::pair<typename CountedObservedValues_t::iterator, bool> inserter = 161 ObservedValues.insert( 162 std::make_pair( _id, RefCountedObserved(value) ) ); 163 ASSERT( inserter.second, 164 "ObservedValuesContainer<T,id>::insert() of "+NameOfType 165 +" for "+toString(_id)+", insertion failed though empty?"); 166 } else { 167 ASSERT( !iter->second.empty(), 168 "ObservedValuesContainer<T,id>::insert() of "+NameOfType 169 +" for "+toString(_id)+" has an empty list in ObservedValues."); 170 // already an entry present? add to deque 171 iter->second.push_back( value ); 172 } 146 ASSERT (iter == ObservedValues.end(), 147 "ObservedValuesContainer<T,id>::insert() of "+NameOfType 148 +" for "+toString(_id)+" failed because "+toString(_id)+" already present."); 149 std::pair<typename CountedObservedValues_t::iterator, bool> inserter = 150 ObservedValues.insert( 151 std::make_pair( _id, _obsvalues ) ); 152 ASSERT( inserter.second, 153 "ObservedValuesContainer<T,id>::insert() of "+NameOfType 154 +" for "+toString(_id)+", insertion failed though empty?"); 155 173 156 _obsvalues->activateObserver(); 174 157 } … … 180 163 const typename CountedObservedValues_t::iterator Colditer = ObservedValues.find(_oldid); 181 164 const typename CountedObservedValues_t::iterator Cnewiter = ObservedValues.find(_newid); 182 const typename MarkedForErase_t::iterator Eolditer = MarkedForErase.find(_oldid); 183 const typename MarkedForErase_t::iterator Enewiter = MarkedForErase.find(_newid); 165 const typename MarkedSet_t::iterator MEolditer = MarkedForErase.find(_oldid); 166 const typename MarkedSet_t::iterator MEnewiter = MarkedForErase.find(_newid); 167 const typename MarkedSet_t::iterator MColditer = MarkedForConnected.find(_oldid); 168 const typename MarkedSet_t::iterator MCnewiter = MarkedForConnected.find(_newid); 184 169 bool status = ((Colditer != ObservedValues.end()) && (Cnewiter == ObservedValues.end())); 185 status &= ((Eolditer != MarkedForErase.end()) && (Enewiter == MarkedForErase.end())); 170 status &= ((MEolditer != MarkedForErase.end()) && (MEnewiter == MarkedForErase.end())); 171 status &= ((MColditer != MarkedForConnected.end()) && (MCnewiter == MarkedForConnected.end())); 186 172 // change id here only if still present 187 173 if (status) { … … 192 178 // whether changing ids "there" is possible when the QtObserved... is under 193 179 // removal. 194 ObservedValuesContainer<T,id>::RefCountedObservedobsvalues = Colditer->second;180 typename T::ptr obsvalues = Colditer->second; 195 181 ObservedValues.erase(Colditer); 196 182 ObservedValues.insert( std::make_pair(_newid, obsvalues) ); 197 183 } 198 184 { 199 MarkedForErase.erase( Eolditer);185 MarkedForErase.erase(MEolditer); 200 186 MarkedForErase.insert(_newid); 187 } 188 { 189 MarkedForConnected.erase(MColditer); 190 MarkedForConnected.insert(_newid); 201 191 } 202 192 return true;
Note:
See TracChangeset
for help on using the changeset viewer.