Ignore:
Timestamp:
Feb 12, 2016, 11:15:24 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:
68418e
Parents:
494478
git-author:
Frederik Heber <heber@…> (01/25/16 14:07:59)
git-committer:
Frederik Heber <heber@…> (02/12/16 23:15:24)
Message:

Moved countSubjectKilled related code from QtObservedInstanceBoard into ObservedValuesContainer.

  • this avoids some more duplicated code.
Location:
src/UIElements/Qt4/InstanceBoard
Files:
6 edited

Legend:

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

    r494478 r90821d  
    1919#include <map>
    2020#include <string>
     21
     22#include <boost/function.hpp>
    2123
    2224class QtObservedInstanceBoard;
     
    5658  void returnObservedValues(const id _id, ObservedValues_t &_observedvalues);
    5759
     60  /** Inform this container that subjectKilled() was received by one of the ObservedValues.
     61   *
     62   * \param _id identifier of the receiving instance
     63   * \param _onDestroy function to call when last subjectKilled() was received and
     64   *        ObservedValues are destroyed
     65   */
     66  void countsubjectKilled(
     67      const id _id,
     68      boost::function<void (const id _id)> _onDestroy);
     69
    5870private:
    5971  typedef std::pair<ObservedValues_t, size_t> RefCountedObservedValues_t;
     
    6173  //!> internal vector of observed values
    6274  CountedObservedValues_t ObservedValues;
     75
     76  //!> typedef for map with subjectKilledCounts for each instance
     77  typedef std::map<id, size_t> subjectKilledCount_t;
     78
     79  //!> counts how many ObservedValues have already been subjectKilled()
     80  subjectKilledCount_t subjectKilledCount;
    6381
    6482  //!> name used in describing the instance type
  • src/UIElements/Qt4/InstanceBoard/ObservedValuesContainer_impl.hpp

    r494478 r90821d  
    9090
    9191template <class T, typename id>
     92void ObservedValuesContainer<T,id>::countsubjectKilled(
     93    const id _id,
     94    boost::function<void (const id _id)> _onDestroy)
     95{
     96  LOG(3, "DEBUG: ObservedValuesContainer got subjectKilled() for an observed value of "
     97      << NameOfType << " " << _id);
     98  typename subjectKilledCount_t::iterator iter = subjectKilledCount.find(_id);
     99  if (iter == subjectKilledCount.end()) {
     100    std::pair<typename subjectKilledCount_t::iterator, bool> inserter =
     101        subjectKilledCount.insert( std::make_pair(_id, 0) );
     102    iter = inserter.first;
     103  }
     104  ++(iter->second);
     105
     106  if (iter->second > T::MAX_ObservedTypes) {
     107    ASSERT( getRefCount(_id) == 0,
     108        "ObservedValuesContainer::countsubjectKilled() - observed Values for "
     109        +NameOfType+" "+toString(_id)+" are still being held somewhere.");
     110    _onDestroy(_id);
     111    subjectKilledCount.erase(iter);
     112  }
     113}
     114
     115template <class T, typename id>
    92116bool ObservedValuesContainer<T,id>::insert(const id _id, ObservedValues_t &_obsvalues)
    93117{
     
    103127  const typename CountedObservedValues_t::iterator Colditer = ObservedValues.find(_oldid);
    104128  const typename CountedObservedValues_t::iterator Cnewiter = ObservedValues.find(_newid);
     129  const typename subjectKilledCount_t::iterator Solditer = subjectKilledCount.find(_oldid);
     130  const typename subjectKilledCount_t::iterator Snewiter = subjectKilledCount.find(_newid);
    105131  bool status = ((Colditer != ObservedValues.end()) && (Cnewiter == ObservedValues.end()));
     132  status &= ((Solditer != subjectKilledCount.end()) && (Snewiter == subjectKilledCount.end()));
    106133  // change id here only if still present
    107134  if (status) {
     
    110137      ObservedValues.erase(Colditer);
    111138      ObservedValues.insert( std::make_pair(_newid, obsvalues) );
     139    }
     140    {
     141      const size_t countvalue = Solditer->second;
     142      subjectKilledCount.erase(Solditer);
     143      subjectKilledCount.insert( std::make_pair(_newid, countvalue) );
    112144    }
    113145    return true;
  • src/UIElements/Qt4/InstanceBoard/QtObservedAtom.cpp

    r494478 r90821d  
    173173    owner = NULL;
    174174
    175     board.atomcountsubjectKilled(getAtomIndex());
     175    board.returnObservedAtom(getAtomIndex());
    176176  }
    177177}
  • src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.cpp

    r494478 r90821d  
    5656  atomObservedValues("atom", *this),
    5757  moleculeObservedValues("molecule", *this),
    58   atomSubjectKilled(
    59       boost::bind(&QtObservedInstanceBoard::atomcountsubjectKilled, this, _1)),
    60   moleculeSubjectKilled(
    61       boost::bind(&QtObservedInstanceBoard::moleculecountsubjectKilled, this, _1)),
    6258  lastremovedatom((atomId_t)-1),
    6359  lastremovedatomsmolecule( std::make_pair((moleculeId_t)-1,(atomId_t)-1) ),
    6460  lastremovedmolecule((moleculeId_t)-1)
    6561{
     62  boost::function<void (const atomId_t _id)> atomfctor =
     63      boost::bind(&QtObservedInstanceBoard::atomcountsubjectKilled, this, _1);
     64  atomSubjectKilled =
     65      boost::bind(&ObservedValuesContainer<QtObservedAtom, atomId_t>::countsubjectKilled,
     66          boost::ref(atomObservedValues),
     67          _1,
     68          atomfctor
     69          );
     70  boost::function<void (const moleculeId_t _id)> molfctor =
     71      boost::bind(&QtObservedInstanceBoard::moleculecountsubjectKilled, this, _1);
     72  moleculeSubjectKilled =
     73      boost::bind(&ObservedValuesContainer<QtObservedMolecule, moleculeId_t>::countsubjectKilled,
     74          boost::ref(moleculeObservedValues),
     75          _1,
     76          molfctor
     77          );
     78
    6679  // be first (besides ObservedValues to know about new insertions)
    6780  World::getInstance().signOn(this, World::AtomInserted, GlobalObservableInfo::PriorityLevel(int(-10)));
     
    294307void QtObservedInstanceBoard::atomcountsubjectKilled(const atomId_t _atomid)
    295308{
    296   LOG(3, "DEBUG: InformationBoard got subjectKilled() for a value of atom " << _atomid);
    297   atomsubjectKilledCount_t::iterator iter = atomsubjectKilledCount.find(_atomid);
    298   if (iter == atomsubjectKilledCount.end()) {
    299     std::pair<atomsubjectKilledCount_t::iterator, bool> inserter =
    300         atomsubjectKilledCount.insert( std::make_pair(_atomid, 0) );
    301     iter = inserter.first;
    302   }
    303   ++(iter->second);
    304 
    305   if (iter->second > QtObservedAtom::MAX_ObservedTypes) {
    306     ASSERT( atomObservedValues.getRefCount(_atomid) == 0,
    307         "QtObservedInstanceBoard::atomcountsubjectKilled() - observed Values for atom "
    308         +toString(_atomid)+" are still being held somewhere.");
    309     if (_atomid == lastremovedatomsmolecule.second)
    310       emit atomRemoved(lastremovedatomsmolecule.first, lastremovedatomsmolecule.second);
    311     else
    312       ELOG(2, "QtObservedInstanceBoard::atomcountsubjectKilled() - id " << _atomid
    313           << " not fitting with " << lastremovedatomsmolecule);
    314     atomsubjectKilledCount.erase(iter);
    315   }
     309  if (_atomid == lastremovedatomsmolecule.second)
     310    emit atomRemoved(lastremovedatomsmolecule.first, lastremovedatomsmolecule.second);
     311  else
     312    ELOG(2, "QtObservedInstanceBoard::atomcountsubjectKilled() - id " << _atomid
     313        << " not fitting with " << lastremovedatomsmolecule);
    316314}
    317315
    318316void QtObservedInstanceBoard::moleculecountsubjectKilled(const moleculeId_t _molid)
    319317{
    320   LOG(3, "DEBUG: InformationBoard got subjectKilled() for a value of molecule " << _molid);
    321   moleculesubjectKilledCount_t::iterator iter = moleculesubjectKilledCount.find(_molid);
    322   if (iter == moleculesubjectKilledCount.end()) {
    323     std::pair<moleculesubjectKilledCount_t::iterator, bool> inserter =
    324         moleculesubjectKilledCount.insert( std::make_pair(_molid, 0) );
    325     iter = inserter.first;
    326   }
    327   ++(iter->second);
    328 
    329   if (iter->second > QtObservedMolecule::MAX_ObservedTypes) {
    330     ASSERT( moleculeObservedValues.getRefCount(_molid) == 0,
    331         "QtObservedInstanceBoard::moleculecountsubjectKilled() - observed Values for molecule "
    332         +toString(_molid)+" are still being held somewhere.");
    333     // then free the instance
    334     emit moleculeRemoved(_molid);
    335     moleculesubjectKilledCount.erase(iter);
    336   }
     318  emit moleculeRemoved(_molid);
    337319}
    338320
  • src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp

    r494478 r90821d  
    133133  void moleculecountsubjectKilled(const moleculeId_t _molid);
    134134
    135   //!> typedef for map with subjectKilledCounts for each atom
    136   typedef typename std::map<atomId_t, size_t> atomsubjectKilledCount_t;
    137 
    138   //!> typedef for map with subjectKilledCounts for each molecule
    139   typedef typename std::map<moleculeId_t, size_t> moleculesubjectKilledCount_t;
    140 
    141   //!> counts how many ObservedValues have already been subjectKilled()
    142   atomsubjectKilledCount_t atomsubjectKilledCount;
    143 
    144   //!> counts how many ObservedValues have already been subjectKilled()
    145   moleculesubjectKilledCount_t moleculesubjectKilledCount;
    146 
    147135  //!> container with all ObservedValues for each atom, associated by id
    148136  ObservedValuesContainer<QtObservedAtom, atomId_t> atomObservedValues;
     
    151139
    152140  //!> stored callback function for notifying QtObservedInstanceBoard about subjectKilled in atom
    153   boost::function<void (atomId_t)> atomSubjectKilled;
     141  boost::function<void (const atomId_t)> atomSubjectKilled;
    154142  //!> stored callback function for notifying QtObservedInstanceBoard about subjectKilled in molecule
    155   boost::function<void (moleculeId_t)> moleculeSubjectKilled;
    156 
     143  boost::function<void (const moleculeId_t)> moleculeSubjectKilled;
    157144  //!> note down atom id of last removed atom to drop its ObservedValues
    158145  atomId_t lastremovedatom;
  • src/UIElements/Qt4/InstanceBoard/QtObservedMolecule.cpp

    r494478 r90821d  
    132132    owner = NULL;
    133133
    134     board.moleculecountsubjectKilled(getMolIndex());
     134    board.returnObservedMolecule(getMolIndex());
    135135  }
    136136}
Note: See TracChangeset for help on using the changeset viewer.