Changeset 393342 for src/UIElements


Ignore:
Timestamp:
Feb 14, 2016, 12:34:26 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:
6bce88
Parents:
0af22d
git-author:
Frederik Heber <heber@…> (12/30/15 18:42:38)
git-committer:
Frederik Heber <heber@…> (02/14/16 12:34:26)
Message:

FIX: ObservesValuesContainer uses internal struct for two iterators for observedvalues.

  • we need these two additional iterators (apart from the deque) in order to step through the created instances one-by-one as they are expected in this manner by the QtGUI which, though lacking behind, is trying to process all the seen events.
Location:
src/UIElements/Qt4/InstanceBoard
Files:
2 edited

Legend:

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

    r0af22d r393342  
    102102   */
    103103
    104   typedef std::deque<std::pair<typename T::ptr, size_t> > RefCountedObservedValues_t;
    105   typedef std::map<id, RefCountedObservedValues_t > CountedObservedValues_t;
     104  /** Structure to contain the sequence of created observed memories.
     105   *
     106   * \note QtGUI may lag behind the creation/destruction of observed instances a
     107   * lot but one after the other must be served. Here, we keep an additional
     108   * iterator that indicates the current instance to be served.
     109   */
     110  struct RefCountedObserved
     111  {
     112    typedef std::pair<typename T::ptr, size_t> Value_t;
     113    typedef std::deque<Value_t> Values_t;
     114
     115    /** Default cstor of RefCountedObservedValues.
     116     *
     117     * Make sure that currentvalue has some sensible default value.
     118     */
     119    RefCountedObserved() :
     120      tobedestroyed(values.end()),
     121      currentvalue(values.end())
     122    {}
     123
     124    /** Default copy cstor of RefCountedObservedValues.
     125     *
     126     * \param _instance instance to copy
     127     */
     128    RefCountedObserved(const RefCountedObserved & _instance) :
     129      values(_instance.values),
     130      tobedestroyed(values.begin()),
     131      currentvalue(values.begin())
     132    {}
     133
     134    /** Cstor of RefCountedObservedValues.
     135     *
     136     * Make sure that currentvalue has some sensible default value.
     137     *
     138     * \param _value initial value for the list
     139     */
     140    RefCountedObserved(Value_t _value) :
     141      values(1, _value),
     142      tobedestroyed(values.begin()),
     143      currentvalue(values.begin())
     144    {}
     145
     146    bool empty() const
     147    {
     148      return values.empty();
     149    }
     150
     151    void push_back(Value_t _value)
     152    {
     153      values.push_back(_value);
     154      if (currentvalue == values.end())
     155        currentvalue = values.end()--;
     156      if (tobedestroyed == values.end())
     157        tobedestroyed = currentvalue;
     158    }
     159
     160    Value_t& getCurrentValue() const
     161    {
     162      ASSERT (currentvalue != values.end(),
     163          "RefCountedObservedValues::getCurrentValue() - cannot get, no values present.");
     164      return *currentvalue;
     165    }
     166
     167    Value_t& getEraseCandidate() const
     168    {
     169      ASSERT (tobedestroyed != values.end(),
     170          "RefCountedObservedValues::getCurrentValue() - cannot get, no values present.");
     171      return *tobedestroyed;
     172    }
     173
     174    void eraseCurrentValue()
     175    {
     176      ASSERT (tobedestroyed != values.end(),
     177          "RefCountedObservedValues::eraseCurrentValue() - cannot erase, no values present.");
     178      if (tobedestroyed == currentvalue)
     179        ++currentvalue;
     180      values.erase(tobedestroyed);
     181      tobedestroyed = currentvalue;
     182      // removal of this instance when both iterators point to end is done inside QtObservedInstanceBoard
     183    }
     184
     185    //!> set of values
     186    Values_t values;
     187    //!> iterator on the value that is next gonna be destroyed
     188    typename Values_t::iterator tobedestroyed;
     189    //!> iterator on the current value that is served on get
     190    typename Values_t::iterator currentvalue;
     191  };
     192
     193  typedef std::map<id, RefCountedObserved > CountedObservedValues_t;
    106194  //!> internal vector of observed values
    107195  CountedObservedValues_t ObservedValues;
  • src/UIElements/Qt4/InstanceBoard/ObservedValuesContainer_impl.hpp

    r0af22d r393342  
    3737        "~ObservedValuesContainer() of "+NameOfType+" "+toString(iter->first)
    3838        +" has an empty list in ObservedValues.");
    39     for (typename RefCountedObservedValues_t::iterator listiter = iter->second.begin();
    40         listiter != iter->second.end(); ++listiter) {
     39    for (typename RefCountedObserved::Values_t::iterator listiter = iter->second.values.begin();
     40        listiter != iter->second.values.end(); ++listiter) {
    4141      listiter->first->noteBoardIsGone();
    4242    }
     
    5151      "ObservedValuesContainer::getObservedValues() - no observed values present for "
    5252      +NameOfType+" "+toString(_id));
    53   ASSERT( !iter->second.empty(),
    54       "ObservedValuesContainer<T,id>::get() of "+NameOfType+" "+toString(_id)
    55       +" has an empty list in ObservedValues.");
    56   const typename T::ptr &obsvalues = iter->second.back().first;
    57 
    58   return obsvalues;
     53  return iter->second.getCurrentValue().first;
    5954}
    6055
     
    6560  LOG(3, "DEBUG: ObservedValuesContainer got markObservedValuesAsConnected() for an observed value of "
    6661      << NameOfType << " " << _id);
    67  typename CountedObservedValues_t::iterator iter = ObservedValues.find(_id);
     62  typename CountedObservedValues_t::iterator iter = ObservedValues.find(_id);
    6863  ASSERT (iter != ObservedValues.end(),
    6964      "ObservedValuesContainer<T,id>::markObservedValuesAsConnected() - Observed value of "
    7065      +NameOfType+" "+toString(_id)+" is not present yet.");
    71   ASSERT( !iter->second.empty(),
    72       "ObservedValuesContainer<T,id>::markObservedValuesAsConnected() of "+NameOfType
    73       +" "+toString(_id)+" has an empty list in ObservedValues.");
    74   ++(iter->second.back().second);
     66  ++(iter->second.getCurrentValue().second);
    7567}
    7668
     
    8072{
    8173  typename CountedObservedValues_t::const_iterator iter = ObservedValues.find(_id);
    82   ASSERT( !iter->second.empty(),
    83       "ObservedValuesContainer<T,id>::checkRefCount() of "+NameOfType
    84       +" "+toString(_id)+" has an empty list in ObservedValues.");
    85   return ((iter != ObservedValues.end()) && (iter->second.front().second == 0));
     74  return ((iter != ObservedValues.end()) && (iter->second.getEraseCandidate().second == 0));
    8675}
    8776
     
    9685      "ObservedValuesContainer<T,id>::markObservedValuesAsDisconnected() - Observed value of "
    9786      +NameOfType+" "+toString(_id)+" is not present yet.");
    98   ASSERT( !iter->second.empty(),
    99       "ObservedValuesContainer<T,id>::markObservedValuesAsDisconnected() of "+NameOfType
    100       +" "+toString(_id)+" has an empty list in ObservedValues.");
    101   ASSERT (iter->second.front().second != 0,
     87  ASSERT (iter->second.getEraseCandidate().second != 0,
    10288      "ObservedValuesContainer<T,id>::markObservedValuesAsDisconnected() - Observed value of "
    10389      +NameOfType+" "+toString(_id)+" is already signOff() from all.");
    104   --(iter->second.front().second);
     90  --(iter->second.getEraseCandidate().second);
    10591
    10692  if (checkRefCount(_id) && checksubjectKilled(_id) && checkMarkedForErase(_id))
     
    144130  subjectKilledCount.erase(_id);
    145131  typename CountedObservedValues_t::iterator iter = ObservedValues.find(_id);
    146   ASSERT( !iter->second.empty(),
    147       "ObservedValuesContainer<T,id>::removeObservedValues() of "+NameOfType
    148       +" for "+toString(_id)+" has an empty list in ObservedValues.");
    149   if (iter->second.size() == 1)
     132  iter->second.eraseCurrentValue();
     133  if (iter->second.empty())
    150134    ObservedValues.erase(iter);
    151   else {
    152     //if more than one, erase always the first one
    153     iter->second.pop_front();
    154   }
    155135  MarkedForErase.erase(_id);
    156136}
     
    180160void ObservedValuesContainer<T,id>::insert(const id _id, const typename T::ptr &_obsvalues)
    181161{
    182   std::pair<typename CountedObservedValues_t::iterator, bool> inserter =
    183       ObservedValues.insert(
    184           std::make_pair( _id, RefCountedObservedValues_t(1,std::make_pair(_obsvalues,0)) ) );
    185   if (!inserter.second) {
     162  typename ObservedValuesContainer<T,id>::RefCountedObserved::Value_t value(std::make_pair(_obsvalues,0));
     163  typename CountedObservedValues_t::iterator iter = ObservedValues.find(_id);
     164  if (iter == ObservedValues.end()) {
     165    std::pair<typename CountedObservedValues_t::iterator, bool> inserter =
     166        ObservedValues.insert(
     167            std::make_pair( _id, RefCountedObserved(value) ) );
     168    ASSERT( inserter.second,
     169        "ObservedValuesContainer<T,id>::insert() of "+NameOfType
     170        +" for "+toString(_id)+", insertion failed though empty?");
     171  } else {
     172    ASSERT( !iter->second.empty(),
     173        "ObservedValuesContainer<T,id>::insert() of "+NameOfType
     174        +" for "+toString(_id)+" has an empty list in ObservedValues.");
    186175    // already an entry present? add to deque
    187     inserter.first->second.push_back( std::make_pair(_obsvalues,0) );
     176    iter->second.push_back( value );
    188177  }
    189178  _obsvalues->activateObserver();
     
    210199      // whether changing ids "there" is possible when the QtObserved... is under
    211200      // removal.
    212       RefCountedObservedValues_t obsvalues = Colditer->second;
     201      ObservedValuesContainer<T,id>::RefCountedObserved obsvalues = Colditer->second;
    213202      ObservedValues.erase(Colditer);
    214203      ObservedValues.insert( std::make_pair(_newid, obsvalues) );
Note: See TracChangeset for help on using the changeset viewer.