Ignore:
Timestamp:
Apr 20, 2016, 7:17:43 AM (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:
3054f4a
Parents:
59eabc
git-author:
Frederik Heber <heber@…> (03/21/16 21:42:14)
git-committer:
Frederik Heber <heber@…> (04/20/16 07:17:43)
Message:

Added convenience function to return current id for given index.

  • this is mainly for printing in asserts and logs.
  • required to convert IdtoIndex to bimap.
  • ...Observed wire through getIdtoIndex() function.
Location:
src/UIElements/Qt4/InstanceBoard
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.cpp

    r59eabc r1a58ce  
    144144          const ObservedValue_Index_t index = static_cast<const Observable *>(_molecule);
    145145          moleculeObservedValues.insert(index, observedmolecule);
    146           moleculeids_lookup.insert( std::make_pair(_id, index) );
     146          moleculeids_lookup.left.insert( std::make_pair(_id, index) );
    147147          // we need to check for index changes
    148148          LOG(3, "DEBUG: InformationBoard signOn()s to molecule " << _id);
     
    172172          const ObservedValue_Index_t index = static_cast<const Observable *>(_atom);
    173173          atomObservedValues.insert(index, observedatom);
    174           atomids_lookup.insert( std::make_pair(_id, index) );
     174          atomids_lookup.left.insert( std::make_pair(_id, index) );
    175175          // we need to check for index changes
    176176          LOG(3, "DEBUG: InformationBoard signOn()s to atom " << _id);
     
    196196        LOG(3, "DEBUG: InformationBoard got IndexChanged from molecule " << molid << " to " << newmoleculeId);
    197197        {
    198           typename IdtoIndex_t<moleculeId_t>::iterator iter = moleculeids_lookup.find(molid);
    199           ASSERT( iter != moleculeids_lookup.end(),
     198          typename IdtoIndex_t<moleculeId_t>::left_iterator iter = moleculeids_lookup.left.find(molid);
     199          ASSERT( iter != moleculeids_lookup.left.end(),
    200200              "QtObservedInstanceBoard::recieveNotification() - mol id "
    201201              +toString(molid)+" unknown to lookup.");
    202202          const ObservedValue_Index_t index = iter->second;
    203           moleculeids_lookup.erase(iter);
    204           moleculeids_lookup.insert( std::pair<moleculeId_t, ObservedValue_Index_t>(newmoleculeId, index) );
     203          moleculeids_lookup.left.erase(iter);
     204          moleculeids_lookup.left.insert( std::pair<moleculeId_t, ObservedValue_Index_t>(newmoleculeId, index) );
    205205        }
    206206        // no need update SignedOn, ref does not change
     
    220220        LOG(3, "DEBUG: InformationBoard got IndexChanged from atom " << oldatomId << " to " << newatomId);
    221221        {
    222           typename IdtoIndex_t<atomId_t>::iterator iter = atomids_lookup.find(oldatomId);
    223           ASSERT( iter != atomids_lookup.end(),
     222          typename IdtoIndex_t<atomId_t>::left_iterator iter = atomids_lookup.left.find(oldatomId);
     223          ASSERT( iter != atomids_lookup.left.end(),
    224224              "QtObservedInstanceBoard::recieveNotification() - atom id "
    225225              +toString(oldatomId)+" unknown to lookup.");
    226226          const ObservedValue_Index_t index = iter->second;
    227           atomids_lookup.erase(iter);
    228           atomids_lookup.insert( std::pair<atomId_t, ObservedValue_Index_t>(newatomId, index) );
     227          atomids_lookup.left.erase(iter);
     228          atomids_lookup.left.insert( std::pair<atomId_t, ObservedValue_Index_t>(newatomId, index) );
    229229        }
    230230        // no need update SignedOn, ref does not change
     
    253253}
    254254
     255const atomId_t QtObservedInstanceBoard::getAtomIdToIndex(ObservedValue_Index_t _id) const
     256{
     257  typename IdtoIndex_t<atomId_t>::right_const_iterator iter = atomids_lookup.right.find(_id);
     258  ASSERT( iter != atomids_lookup.right.end(),
     259      "QtObservedInstanceBoard::getAtomIdToIndex() - index "
     260      +toString(_id)+" is unknown.");
     261  return iter->second;
     262}
     263
     264const moleculeId_t QtObservedInstanceBoard::getMoleculeIdToIndex(ObservedValue_Index_t _id) const
     265{
     266  typename IdtoIndex_t<moleculeId_t>::right_const_iterator iter = moleculeids_lookup.right.find(_id);
     267  ASSERT( iter != moleculeids_lookup.right.end(),
     268      "QtObservedInstanceBoard::getMoleculeIdToIndex() - index "
     269      +toString(_id)+" is unknown.");
     270  return iter->second;
     271}
     272
    255273QtObservedAtom::ptr QtObservedInstanceBoard::getObservedAtom(const atomId_t _id)
    256274{
    257   return atomObservedValues.get(atomids_lookup[_id]);
     275  return atomObservedValues.get(atomids_lookup.left.at(_id));
    258276}
    259277
    260278QtObservedMolecule::ptr QtObservedInstanceBoard::getObservedMolecule(const moleculeId_t _id)
    261279{
    262   return moleculeObservedValues.get(moleculeids_lookup[_id]);
     280  return moleculeObservedValues.get(moleculeids_lookup.left.at(_id));
    263281}
    264282
     
    276294{
    277295  atomObservedValues.eraseObservedValues(_id);
     296  atomids_lookup.right.erase(_id);
    278297}
    279298
     
    291310{
    292311  moleculeObservedValues.eraseObservedValues(_id);
    293 }
     312  moleculeids_lookup.right.erase(_id);
     313}
  • src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp

    r59eabc r1a58ce  
    2121
    2222#include <map>
     23#include <boost/bimap.hpp>
    2324#include <boost/function.hpp>
    2425
     
    7980  void recieveNotification(Observable *publisher, Notification_ptr notification);
    8081
     82  const atomId_t getAtomIdToIndex(ObservedValue_Index_t _id) const;
     83  const moleculeId_t getMoleculeIdToIndex(ObservedValue_Index_t _id) const;
     84
    8185  QtObservedAtom::ptr getObservedAtom(const atomId_t _id);
    8286  QtObservedMolecule::ptr getObservedMolecule(const moleculeId_t _id);
     
    113117  //!> "templated typedef" for an id to index map.
    114118  template <class id>
    115   struct IdtoIndex_t : std::map<id, ObservedValue_Index_t> {};
     119  struct IdtoIndex_t : boost::bimap<id, ObservedValue_Index_t> {};
    116120  IdtoIndex_t<atomId_t> atomids_lookup;
    117121  IdtoIndex_t<moleculeId_t> moleculeids_lookup;
Note: See TracChangeset for help on using the changeset viewer.