Ignore:
Timestamp:
Feb 12, 2016, 11:15:23 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:
65c323
Parents:
98c35c
git-author:
Frederik Heber <heber@…> (10/29/15 09:52:10)
git-committer:
Frederik Heber <heber@…> (02/12/16 23:15:23)
Message:

Extracted functions handling refcounting of ObservedValues into ObservedValuesContainer.

  • this avoids a lot of code duplication.
Location:
src/UIElements/Qt4/InstanceBoard
Files:
2 added
4 edited

Legend:

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

    r98c35c r41e287  
    2323
    2424#include "UIElements/Qt4/InstanceBoard/ObservedValue_types.hpp"
     25#include "UIElements/Qt4/InstanceBoard/ObservedValuesContainer.hpp"
    2526#include "types.hpp"
    2627
     
    4142  Q_OBJECT
    4243
     44  //!> ObservedValuesContainer needs to access private cstor and dstor
     45  friend class ObservedValuesContainer<QtObservedAtom, atomId_t>;
    4346  //!> QtObservedInstanceBoard needs to access private cstor and dstor
    4447  friend class QtObservedInstanceBoard;
  • src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.cpp

    r98c35c r41e287  
    4747#include "Descriptors/MoleculeIdDescriptor.hpp"
    4848#include "molecule.hpp"
     49#include "UIElements/Qt4/InstanceBoard/ObservedValuesContainer_impl.hpp"
    4950#include "World.hpp"
    5051
     
    5354  Observer("QtObservedInstanceBoard"),
    5455  WorldSignedOn(false),
     56  atomObservedValues("atom"),
     57  moleculeObservedValues("molecule"),
    5558  atomSubjectKilled(
    5659      boost::bind(&QtObservedInstanceBoard::atomcountsubjectKilled, this, _1)),
     
    139142              moleculeSubjectKilled);
    140143#ifndef NDEBUG
    141           std::pair<moleculeObservedValues_t::iterator, bool> inserter =
     144          bool status =
    142145#endif
    143               moleculeObservedValues.insert(
    144                   std::make_pair( _id, std::make_pair(ObservedValues,0) ));
    145           ASSERT( inserter.second,
     146              moleculeObservedValues.insert(_id, ObservedValues);
     147          ASSERT( status,
    146148              "QtObservedInstanceBoard::recieveNotification() - could not insert ObservedValues for"
    147149              +toString(_id)+".");
     
    187189              atomSubjectKilled);
    188190#ifndef NDEBUG
    189           std::pair<atomObservedValues_t::iterator, bool> inserter =
     191          bool status =
    190192#endif
    191               atomObservedValues.insert(
    192                   std::make_pair( _id, std::make_pair(ObservedValues,0) ));
    193           ASSERT( inserter.second,
     193              atomObservedValues.insert(_id, ObservedValues);
     194          ASSERT( status,
    194195              "QtObservedInstanceBoard::recieveNotification() - could not insert ObservedValues for"
    195196              +toString(_id)+".");
     
    227228              << atomid << " from molecule " << molid);
    228229          // check whether atom's observedvalues are present
    229           ASSERT( atomObservedValues.find(atomid) != atomObservedValues.end(),
     230          ASSERT( atomObservedValues.isPresent(atomid),
    230231              "QtObservedInstanceBoard::recieveNotification() - ObservedValues for atom "
    231232              +toString(atomid)+" are not present yet.");
     
    255256        const moleculeId_t newmoleculeId = dynamic_cast<molecule *>(publisher)->getId();
    256257        LOG(3, "DEBUG: InformationBoard got IndexChanged from molecule " << molid << " to " << newmoleculeId);
    257         {
    258           moleculeObservedValues_t::iterator iter = moleculeObservedValues.find(molid);
    259           // change id here only if still present
    260           if (iter != moleculeObservedValues.end()) {
    261             RefCountedObservedValues_t obsvalues = iter->second;
    262             moleculeObservedValues.erase(iter);
    263             ASSERT( moleculeObservedValues.find(newmoleculeId) == moleculeObservedValues.end(),
    264                 "QtObservedInstanceBoard::recieveNotification() - ObservedValues for atom "
    265                 +toString(newmoleculeId)+" already present.");
    266             moleculeObservedValues.insert( std::make_pair(newmoleculeId, obsvalues) );
    267         //    if (!inserter.second)
    268         //      ELOG(1, "QtInformationBoard could not insert molecule id change "
    269         //          << molid << "->" << newmoleculeId);
    270           }
    271         }
     258#ifndef NDEBUG
     259        bool status =
     260#endif
     261        moleculeObservedValues.changeIdentifier(molid, newmoleculeId);
     262        ASSERT( status,
     263            "QtObservedInstanceBoard::recieveNotification() - cannot change molecule's id "
     264            +toString(molid)+" "+toString(newmoleculeId)+" in moleculeObservedValues.");
    272265        // no need update SignedOn, ref does not change
    273266        emit moleculeIndexChanged(molid, newmoleculeId);
     
    285278        const atomId_t newatomId = dynamic_cast<atom *>(publisher)->getId();
    286279        LOG(3, "DEBUG: InformationBoard got IndexChanged from atom " << oldatomId << " to " << newatomId);
    287         // update atomObservedValues
    288         {
    289           atomObservedValues_t::iterator iter = atomObservedValues.find(oldatomId);
    290           // change id here only if still present
    291           if (iter != atomObservedValues.end()) {
    292             RefCountedObservedValues_t obsvalues = iter->second;
    293             atomObservedValues.erase(iter);
    294             ASSERT( atomObservedValues.find(newatomId) == atomObservedValues.end(),
    295                 "QtObservedInstanceBoard::recieveNotification() - ObservedValues for atom "
    296                 +toString(newatomId)+" already present.");
    297             atomObservedValues.insert( std::make_pair(newatomId, obsvalues) );
    298       //    if (!inserter.second)
    299       //      ELOG(1, "QtInformationBoard could not insert atom id change "
    300       //          << oldatomId << "->" << newatomId);
    301           }
    302         }
     280        atomObservedValues.changeIdentifier(oldatomId, newatomId);
    303281        // no need update SignedOn, ref does not change
    304282        emit atomIndexChanged(oldatomId, newatomId);
     
    326304
    327305  if (iter->second > GLMoleculeObject_atom::MAX_ObservedTypes) {
    328     ASSERT( atomObservedValues[_atomid].second == 0,
     306    ASSERT( atomObservedValues.getRefCount(_atomid) == 0,
    329307        "QtObservedInstanceBoard::atomcountsubjectKilled() - observed Values for atom "
    330308        +toString(_atomid)+" are still being held somewhere.");
     
    350328
    351329  if (iter->second > GLMoleculeObject_molecule::MAX_ObservedTypes) {
    352     ASSERT( moleculeObservedValues[_molid].second == 0,
     330    ASSERT( moleculeObservedValues.getRefCount(_molid) == 0,
    353331        "QtObservedInstanceBoard::moleculecountsubjectKilled() - observed Values for molecule "
    354332        +toString(_molid)+" are still being held somewhere.");
     
    359337}
    360338
    361 ObservedValues_t
    362 QtObservedInstanceBoard::getAtomObservedValues(const atomId_t _id)
    363 {
    364   ObservedValues_t returnvalues;
    365   const atomObservedValues_t::iterator iter = atomObservedValues.find(_id);
    366   ASSERT(iter != atomObservedValues.end(),
    367       "QtObservedInstanceBoard::getAtomObservedValues() - atom values not present for id"
    368       +toString(_id));
    369   if (iter->first == _id) {
    370     returnvalues = iter->second.first;
    371     atomObservedValues.erase(iter);
    372   }
    373   return returnvalues;
    374 }
    375 
    376 ObservedValues_t
    377 QtObservedInstanceBoard::getMoleculeObservedValues(const moleculeId_t _id)
    378 {
    379   ObservedValues_t returnvalues;
    380   const moleculeObservedValues_t::iterator iter = moleculeObservedValues.find(_id);
    381   ASSERT(iter != moleculeObservedValues.end(),
    382       "getMoleculeObservedValues::getAtomObservedValues() - molecule values not present for id"
    383       +toString(_id));
    384   if (iter->first == _id) {
    385     returnvalues = iter->second.first;
    386     moleculeObservedValues.erase(iter);
    387   }
    388   return returnvalues;
     339QtObservedAtom::ptr QtObservedInstanceBoard::getObservedAtom(const atomId_t _id)
     340{
     341  return atomObservedValues.get(_id);
     342}
     343
     344QtObservedMolecule::ptr QtObservedInstanceBoard::getObservedMolecule(const moleculeId_t _id)
     345{
     346  return moleculeObservedValues.get(_id);
     347}
     348
     349void QtObservedInstanceBoard::returnObservedAtom(const atomId_t _id)
     350{
     351  atomObservedValues.yield(_id);
     352}
     353
     354void QtObservedInstanceBoard::returnObservedMolecule(const moleculeId_t _id)
     355{
     356  moleculeObservedValues.yield(_id);
     357}
     358
     359ObservedValues_t QtObservedInstanceBoard::getAtomObservedValues(const atomId_t _id)
     360{
     361  return atomObservedValues.getObservedValues(_id);
     362}
     363ObservedValues_t QtObservedInstanceBoard::getMoleculeObservedValues(const moleculeId_t _id)
     364{
     365  return moleculeObservedValues.getObservedValues(_id);
    389366}
    390367
     
    394371{
    395372  if (lastremovedatom != _id) {
    396 #ifndef NDEBUG
    397     std::pair<atomObservedValues_t::iterator, bool> inserter =
    398 #endif
    399         atomObservedValues.insert(
    400             std::make_pair( _id, std::make_pair(_observedvalues,0) ) );
    401     ASSERT( inserter.second,
    402         "QtObservedInstanceBoard::returnAtomObservedValues() - could not insert ObservedValues for"
    403         +toString(_id)+".");
    404   } else
     373    atomObservedValues.returnObservedValues(_id, _observedvalues);
     374  } else {
    405375    lastremovedatom = (atomId_t)-1;
     376    atomObservedValues.erase(_id);
     377  }
    406378}
    407379
     
    411383{
    412384  if (lastremovedmolecule != _id) {
    413 #ifndef NDEBUG
    414       std::pair<moleculeObservedValues_t::iterator, bool> inserter =
    415 #endif
    416           moleculeObservedValues.insert(
    417               std::make_pair( _id, std::make_pair(_observedvalues,0) ) );
    418       ASSERT( inserter.second,
    419           "QtObservedInstanceBoard::returnMoleculeObservedValues() - could not insert ObservedValues for"
    420           +toString(_id)+".");
    421   } else
     385    moleculeObservedValues.returnObservedValues(_id, _observedvalues);
     386  } else {
    422387    lastremovedmolecule = (moleculeId_t)-1;
    423 }
    424 
    425 QtObservedAtom::ptr QtObservedInstanceBoard::getObservedAtom(const atomId_t _id)
    426 {
    427   atomObservedValues_t::iterator iter = atomObservedValues.find(_id);
    428   ASSERT( iter != atomObservedValues.end(),
    429       "QtObservedInstanceBoard::getObservedAtom() - no observed values present for atom "
    430       +toString(_id));
    431   const ObservedValues_t &obsvalues = iter->second.first;
    432   // increase refcount
    433   ++(iter->second.second);
    434   QtObservedAtom::ptr _atom(new QtObservedAtom(obsvalues));
    435 
    436   return _atom;
    437 }
    438 
    439 QtObservedMolecule::ptr QtObservedInstanceBoard::getObservedMolecule(const moleculeId_t _id)
    440 {
    441   moleculeObservedValues_t::iterator iter = moleculeObservedValues.find(_id);
    442   ASSERT( iter != moleculeObservedValues.end(),
    443       "QtObservedInstanceBoard::getObservedMolecule() - no observed values present for molecule "
    444       +toString(_id));
    445   const ObservedValues_t &obsvalues = iter->second.first;
    446   // increase refcount
    447   ++(iter->second.second);
    448   QtObservedMolecule::ptr _molecule(new QtObservedMolecule(obsvalues));
    449 
    450   return _molecule;
    451 }
    452 
    453 void QtObservedInstanceBoard::returnObservedAtom(const atomId_t _id)
    454 {
    455   atomObservedValues_t::iterator iter = atomObservedValues.find(_id);
    456   ASSERT( iter != atomObservedValues.end(),
    457       "QtObservedInstanceBoard::returnObservedAtom() - no observed values present for atom "
    458       +toString(_id));
    459   ASSERT( iter->second.second != 0,
    460       "QtObservedInstanceBoard::returnObservedAtom() - all ObservedAtoms for atom "
    461       +toString(_id)+" have already been returned.");
    462   // decrease refcount
    463   --(iter->second.second);
    464   if (iter->second.second == 0) {
    465     // free instance
    466   }
    467 }
    468 
    469 void QtObservedInstanceBoard::returnObservedMolecule(const moleculeId_t _id)
    470 {
    471   moleculeObservedValues_t::iterator iter = moleculeObservedValues.find(_id);
    472   ASSERT( iter != moleculeObservedValues.end(),
    473       "QtObservedInstanceBoard::returnObservedMolecule() - no observed values present for molecule "
    474       +toString(_id));
    475   ASSERT( iter->second.second != 0,
    476       "QtObservedInstanceBoard::returnObservedMolecule() - all ObservedMolecules for molecule "
    477       +toString(_id)+" have already been returned.");
    478   // decrease refcount
    479   --(iter->second.second);
    480   if (iter->second.second == 0) {
    481     // free instance
    482   }
    483 }
    484 
     388    moleculeObservedValues.erase(_id);
     389  }
     390}
     391
  • src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp

    r98c35c r41e287  
    2626
    2727#include "UIElements/Qt4/InstanceBoard/ObservedValue_types.hpp"
     28#include "UIElements/Qt4/InstanceBoard/ObservedValuesContainer.hpp"
    2829#include "types.hpp"
    2930
     
    8182  QtObservedAtom::ptr getObservedAtom(const atomId_t _id);
    8283  QtObservedMolecule::ptr getObservedMolecule(const moleculeId_t _id);
     84  void returnObservedAtom(const atomId_t _id);
     85  void returnObservedMolecule(const moleculeId_t _id);
    8386
    8487  ObservedValues_t getAtomObservedValues(const atomId_t _id);
    8588  ObservedValues_t getMoleculeObservedValues(const moleculeId_t _id);
    86 
    87   void returnObservedAtom(const atomId_t _id);
    88   void returnObservedMolecule(const moleculeId_t _id);
    8989
    9090  void returnAtomObservedValues(const atomId_t _id, ObservedValues_t &_observedvalues);
     
    146146  moleculesubjectKilledCount_t moleculesubjectKilledCount;
    147147
    148   typedef std::pair<ObservedValues_t, size_t> RefCountedObservedValues_t;
    149 
    150   //!> typedef for the map of id to each one's ObservedValues
    151   typedef typename std::map<atomId_t, RefCountedObservedValues_t> atomObservedValues_t;
    152   //!> map containing all ObservedValues for each atom, associated by id
    153   atomObservedValues_t atomObservedValues;
    154 
    155   //!> typedef for the map of id to each one's ObservedValues
    156   typedef typename std::map<moleculeId_t, RefCountedObservedValues_t> moleculeObservedValues_t;
    157   //!> map containing all ObservedValues for each molecule, associated by id
    158   moleculeObservedValues_t moleculeObservedValues;
     148  //!> container with all ObservedValues for each atom, associated by id
     149  ObservedValuesContainer<QtObservedAtom, atomId_t> atomObservedValues;
     150  //!> container with all ObservedValues for each molecule, associated by id
     151  ObservedValuesContainer<QtObservedMolecule, moleculeId_t> moleculeObservedValues;
    159152
    160153  //!> stored callback function for notifying QtObservedInstanceBoard about subjectKilled in atom
  • src/UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp

    r98c35c r41e287  
    2222
    2323#include "UIElements/Qt4/InstanceBoard/ObservedValue_types.hpp"
     24#include "UIElements/Qt4/InstanceBoard/ObservedValuesContainer.hpp"
    2425#include "types.hpp"
    2526
     
    4041  Q_OBJECT
    4142
     43  //!> ObservedValuesContainer needs to access private cstor and dstor
     44  friend class ObservedValuesContainer<QtObservedMolecule, moleculeId_t>;
    4245  //!> QtObservedInstanceBoard needs to access private cstor and dstor
    4346  friend class QtObservedInstanceBoard;
Note: See TracChangeset for help on using the changeset viewer.