Changeset 23221f for src/UIElements


Ignore:
Timestamp:
Feb 14, 2016, 12:34:30 PM (9 years ago)
Author:
Frederik Heber <heber@…>
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)
Message:

Removed RefCounted... again.

Location:
src/UIElements/Qt4/InstanceBoard
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Qt4/InstanceBoard/ObservedValuesContainer.hpp

    r59f1bc r23221f  
    8787
    8888private:
    89   /** \note CountedObservedValues_t needs to contain a list in the second argument
    90    * as the ObservedValuesContainer may fall behind when a single atom is created
    91    * and destroyed a number of times in a row (e.g. in the undo/redo cases). This
    92    * problem is inherent because on the one hand we keep the QtObservedAtom alive
    93    * till the last moment, i.e. till the GUI does not need it anymore where the
    94    * original instance may long have been removed from the World. On the other hand
    95    * we instantiate the e.g. QtObservedAtom as soon as the observed atom is created.
    96    */
    9789
    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;
    18891  //!> internal vector of observed values
    18992  CountedObservedValues_t ObservedValues;
    19093
    19194  //!> typedef for the set with ids to be erase
    192   typedef std::set<id> MarkedForErase_t;
     95  typedef std::set<id> MarkedSet_t;
    19396
    19497  //!> 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;
    196102
    197103  //!> name used in describing the instance type
     
    214120   * \return true - no more signOn()s, false - else
    215121   */
    216   bool checkRefCount(const id _id) const;
     122  bool checkMarkedForConnected(const id _id) const;
    217123
    218124  /** Internal function to check whether the vector of ObservedValue's
  • src/UIElements/Qt4/InstanceBoard/ObservedValuesContainer_impl.hpp

    r59f1bc r23221f  
    3636  boost::recursive_mutex::scoped_lock lock(atomic_mutex);
    3737  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();
    4740}
    4841
     
    5346void ObservedValuesContainer<T,id>::checkRemoval(const id _id)
    5447{
    55   if (checkRefCount(_id) && checkMarkedForErase(_id))
     48  if (checkMarkedForConnected(_id) && checkMarkedForErase(_id))
    5649    removeObservedValues(_id);
    5750}
     
    6760    return typename T::ptr();
    6861  else
    69     return iter->second.getCurrentValue().first;
     62    return iter->second;
    7063}
    7164
     
    7770  LOG(3, "DEBUG: ObservedValuesContainer got markObservedValuesAsConnected() for an observed value of "
    7871      << NameOfType << " " << _id);
    79   typename CountedObservedValues_t::iterator iter = ObservedValues.find(_id);
    80   ASSERT (iter != ObservedValues.end(),
     72  ASSERT (MarkedForConnected.find(_id) == MarkedForConnected.end(),
    8173      "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>::checkRefCount(
     74      +NameOfType+" "+toString(_id)+" is already marked as connected.");
     75  MarkedForConnected.insert( _id );
     76}
     77
     78template <class T, typename id>
     79bool ObservedValuesContainer<T,id>::checkMarkedForConnected(
    8880    const id _id) const
    8981{
    9082  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();
    9385}
    9486
     
    10092  LOG(3, "DEBUG: ObservedValuesContainer got markObservedValuesAsDisconnected() for an observed value of "
    10193      << 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(),
    10496      "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);
    11099
    111100  checkRemoval(_id);
     
    117106  boost::recursive_mutex::scoped_lock lock(atomic_mutex);
    118107  LOG(3, "DEBUG: ObservedValuesContainer removes " << NameOfType << " " << _id);
     108  MarkedForConnected.erase(_id);
     109  MarkedForErase.erase(_id);
     110  ObservedValues.erase(_id);
    119111  // call callback function
    120112  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);
    126113}
    127114
     
    148135{
    149136  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();
    151139}
    152140
     
    155143{
    156144  boost::recursive_mutex::scoped_lock lock(atomic_mutex);
    157   typename ObservedValuesContainer<T,id>::RefCountedObserved::Value_t value(std::make_pair(_obsvalues,0));
    158145  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
    173156  _obsvalues->activateObserver();
    174157}
     
    180163  const typename CountedObservedValues_t::iterator Colditer = ObservedValues.find(_oldid);
    181164  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);
    184169  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()));
    186172  // change id here only if still present
    187173  if (status) {
     
    192178      // whether changing ids "there" is possible when the QtObserved... is under
    193179      // removal.
    194       ObservedValuesContainer<T,id>::RefCountedObserved obsvalues = Colditer->second;
     180      typename T::ptr obsvalues = Colditer->second;
    195181      ObservedValues.erase(Colditer);
    196182      ObservedValues.insert( std::make_pair(_newid, obsvalues) );
    197183    }
    198184    {
    199       MarkedForErase.erase(Eolditer);
     185      MarkedForErase.erase(MEolditer);
    200186      MarkedForErase.insert(_newid);
     187    }
     188    {
     189      MarkedForConnected.erase(MColditer);
     190      MarkedForConnected.insert(_newid);
    201191    }
    202192    return true;
Note: See TracChangeset for help on using the changeset viewer.