Ignore:
Timestamp:
Apr 20, 2016, 7:17:41 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:
1a58ce
Parents:
bff202
git-author:
Frederik Heber <heber@…> (03/21/16 20:42:05)
git-committer:
Frederik Heber <heber@…> (04/20/16 07:17:41)
Message:

Introduced unique and permanent ObservedValue_Index_t.

  • this is currently the address of the observable which is not perfectly secure but might work for the moment.
  • QtObservedInstanceBoard uses the index internally and only has an additional map to serve instances on request for the their atomId_t, moleculeId_t, .... However, this id should nowhere else be used because it may change during the lifetime of the object.
  • this should prevent the hazzle with the possibly changing atomId_t, moleculeId_t, ... in all classes that work with QtObserved... instances.
Location:
src/UIElements/Qt4/InstanceBoard
Files:
7 edited

Legend:

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

    rbff202 r59eabc  
    1919#include <boost/any.hpp>
    2020
     21class Observable;
     22
    2123/** typedef for a vector of ObservedValue's (each is due to templating its
    2224 * own type. Therefore, we need to use boost::any).
     
    2426typedef std::vector<boost::any> ObservedValues_t;
    2527
     28/** typedef for the permanent and (for the lifetime of the object) never
     29 * changing index.
     30 *
     31 * Note that this is slightly dangerous because two objects may get the same
     32 * index if one is destroyed and another one instantiated at the same address.
     33 */
     34typedef const Observable * ObservedValue_Index_t;
    2635
    2736
  • src/UIElements/Qt4/InstanceBoard/QtObservedAtom.cpp

    rbff202 r59eabc  
    255255
    256256    if (!BoardIsGone) {
    257       board.markObservedAtomAsDisconnected(getAtomIndex());
    258       board.markObservedAtomForErase(getAtomIndex());
     257      board.markObservedAtomAsDisconnected(getIndex());
     258      board.markObservedAtomForErase(getIndex());
    259259    }
    260260  }
     
    308308      owner->signOn(this, *iter);
    309309    if (!BoardIsGone)
    310       board.markObservedAtomAsConnected(getAtomIndex());
     310      board.markObservedAtomAsConnected(getIndex());
    311311  } else
    312312    signedOffChannels = AllsignedOnChannels;
     
    324324    signedOffChannels = AllsignedOnChannels;
    325325    if (!BoardIsGone)
    326       board.markObservedAtomAsDisconnected(getAtomIndex());
     326      board.markObservedAtomAsDisconnected(getIndex());
    327327  }
    328328}
     
    440440}
    441441
     442ObservedValue_Index_t QtObservedAtom::getIndex() const
     443{
     444  ASSERT( owner != NULL,
     445      "QtObservedAtom::getIndex() - index is NULL");
     446  return owner;
     447}
     448
    442449const atomId_t& QtObservedAtom::getAtomIndex() const
    443450{
  • src/UIElements/Qt4/InstanceBoard/QtObservedAtom.hpp

    rbff202 r59eabc  
    6060private:
    6161  //!> ObservedValuesContainer needs to access private cstor and dstor
    62   friend class ObservedValuesContainer<QtObservedAtom, atomId_t>;
     62  friend class ObservedValuesContainer<QtObservedAtom, ObservedValue_Index_t>;
    6363  //!> QtObservedInstanceBoard needs to access private cstor and dstor
    6464  friend class QtObservedInstanceBoard;
     
    8888  void subjectKilled(Observable *publisher);
    8989  void recieveNotification(Observable *publisher, Notification_ptr notification);
     90
     91  /** Getter for a permanent and unique index of this instance.
     92   *
     93   * \note ALWAYS use this index if you need to store and identifier to this
     94   * instance which you might need to retrieve at some later date.
     95   *
     96   * \warning DO NOT STORE the QtObserved...:ptr directly. This will possibly
     97   * prevent their eventual destruction. Only store the ObservedValue_Index_t
     98   * as means to obtain the ptr from the QtObservedInstanceBoard.
     99   *
     100   * \return returns a unique and permanent index that can be used to retrieve this
     101   * instance from the QtObservedInstanceBoard as it must not be stored.
     102   */
     103  ObservedValue_Index_t getIndex() const;
    90104
    91105  /** Getter to atom index contained in \a ObservedValues.
  • src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.cpp

    rbff202 r59eabc  
    6767      boost::bind(&QtObservedInstanceBoard::moleculecountsubjectKilled, this, _1))
    6868{
     69  qRegisterMetaType<ObservedValue_Index_t>("ObservedValue_Index_t");
    6970  qRegisterMetaType<QtObservedAtom::ptr>("QtObservedAtom::ptr");
    7071  qRegisterMetaType<QtObservedMolecule::ptr>("QtObservedMolecule::ptr");
     
    141142                  *this));
    142143          observedmolecule->setSelfRef(observedmolecule);
    143           moleculeObservedValues.insert(_id, observedmolecule);
     144          const ObservedValue_Index_t index = static_cast<const Observable *>(_molecule);
     145          moleculeObservedValues.insert(index, observedmolecule);
     146          moleculeids_lookup.insert( std::make_pair(_id, index) );
    144147          // we need to check for index changes
    145148          LOG(3, "DEBUG: InformationBoard signOn()s to molecule " << _id);
     
    167170              new QtObservedAtom(_id, _atom, *this));
    168171          observedatom->setSelfRef(observedatom);
    169           atomObservedValues.insert(_id, observedatom);
     172          const ObservedValue_Index_t index = static_cast<const Observable *>(_atom);
     173          atomObservedValues.insert(index, observedatom);
     174          atomids_lookup.insert( std::make_pair(_id, index) );
    170175          // we need to check for index changes
    171176          LOG(3, "DEBUG: InformationBoard signOn()s to atom " << _id);
     
    190195        const moleculeId_t newmoleculeId = dynamic_cast<molecule *>(publisher)->getId();
    191196        LOG(3, "DEBUG: InformationBoard got IndexChanged from molecule " << molid << " to " << newmoleculeId);
    192 #ifndef NDEBUG
    193         bool status =
    194 #endif
    195         moleculeObservedValues.changeIdentifier(molid, newmoleculeId);
    196         ASSERT( status,
    197             "QtObservedInstanceBoard::recieveNotification() - cannot change molecule's id "
    198             +toString(molid)+" "+toString(newmoleculeId)+" in moleculeObservedValues.");
     197        {
     198          typename IdtoIndex_t<moleculeId_t>::iterator iter = moleculeids_lookup.find(molid);
     199          ASSERT( iter != moleculeids_lookup.end(),
     200              "QtObservedInstanceBoard::recieveNotification() - mol id "
     201              +toString(molid)+" unknown to lookup.");
     202          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) );
     205        }
    199206        // no need update SignedOn, ref does not change
    200207        emit moleculeIndexChanged(molid, newmoleculeId);
     
    212219        const atomId_t newatomId = dynamic_cast<atom *>(publisher)->getId();
    213220        LOG(3, "DEBUG: InformationBoard got IndexChanged from atom " << oldatomId << " to " << newatomId);
    214 #ifndef NDEBUG
    215         bool status =
    216 #endif
    217         atomObservedValues.changeIdentifier(oldatomId, newatomId);
    218         ASSERT( status,
    219             "QtObservedInstanceBoard::recieveNotification() - cannot change atom's id "
    220             +toString(oldatomId)+" "+toString(newatomId)+" in atomObservedValues.");
     221        {
     222          typename IdtoIndex_t<atomId_t>::iterator iter = atomids_lookup.find(oldatomId);
     223          ASSERT( iter != atomids_lookup.end(),
     224              "QtObservedInstanceBoard::recieveNotification() - atom id "
     225              +toString(oldatomId)+" unknown to lookup.");
     226          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) );
     229        }
    221230        // no need update SignedOn, ref does not change
    222231        emit atomIndexChanged(oldatomId, newatomId);
     
    232241}
    233242
    234 void QtObservedInstanceBoard::atomcountsubjectKilled(const atomId_t _atomid)
    235 {
    236   LOG(3, "DEBUG: InstanceBoard emits atomRemoved for " << _atomid);
    237   emit atomRemoved(_atomid);
    238 }
    239 
    240 void QtObservedInstanceBoard::moleculecountsubjectKilled(const moleculeId_t _molid)
    241 {
    242   LOG(3, "DEBUG: InstanceBoard emits moleculeRemoved for " << _molid);
    243   emit moleculeRemoved(_molid);
     243void QtObservedInstanceBoard::atomcountsubjectKilled(ObservedValue_Index_t _id)
     244{
     245  LOG(3, "DEBUG: InstanceBoard emits atomRemoved for " << _id);
     246  emit atomRemoved(_id);
     247}
     248
     249void QtObservedInstanceBoard::moleculecountsubjectKilled(ObservedValue_Index_t _id)
     250{
     251  LOG(3, "DEBUG: InstanceBoard emits moleculeRemoved for " << _id);
     252  emit moleculeRemoved(_id);
    244253}
    245254
    246255QtObservedAtom::ptr QtObservedInstanceBoard::getObservedAtom(const atomId_t _id)
    247256{
    248   return atomObservedValues.get(_id);
    249 }
    250 
    251 QtObservedAtom::ptr QtObservedInstanceBoard::getObservedAtom(const Observable * _obs)
    252 {
    253   const atom * walker = dynamic_cast<const atom *>(_obs);
    254   return atomObservedValues.get(walker->getId());
     257  return atomObservedValues.get(atomids_lookup[_id]);
    255258}
    256259
    257260QtObservedMolecule::ptr QtObservedInstanceBoard::getObservedMolecule(const moleculeId_t _id)
    258261{
    259   return moleculeObservedValues.get(_id);
    260 }
    261 
    262 QtObservedMolecule::ptr QtObservedInstanceBoard::getObservedMolecule(const Observable * _obs)
    263 {
    264   const molecule * mol = dynamic_cast<const molecule *>(_obs);
    265   return moleculeObservedValues.get(mol->getId());
    266 }
    267 
    268 void QtObservedInstanceBoard::markObservedAtomAsConnected(const atomId_t _id)
     262  return moleculeObservedValues.get(moleculeids_lookup[_id]);
     263}
     264
     265void QtObservedInstanceBoard::markObservedAtomAsConnected(ObservedValue_Index_t _id)
    269266{
    270267  atomObservedValues.markObservedValuesAsConnected(_id);
    271268}
    272269
    273 void QtObservedInstanceBoard::markObservedAtomAsDisconnected(const atomId_t _id)
     270void QtObservedInstanceBoard::markObservedAtomAsDisconnected(ObservedValue_Index_t _id)
    274271{
    275272  atomObservedValues.markObservedValuesAsDisconnected(_id);
    276273}
    277274
    278 void QtObservedInstanceBoard::markObservedAtomForErase(const atomId_t _id)
     275void QtObservedInstanceBoard::markObservedAtomForErase(ObservedValue_Index_t _id)
    279276{
    280277  atomObservedValues.eraseObservedValues(_id);
    281278}
    282279
    283 void QtObservedInstanceBoard::markObservedMoleculeAsConnected(const moleculeId_t _id)
     280void QtObservedInstanceBoard::markObservedMoleculeAsConnected(ObservedValue_Index_t _id)
    284281{
    285282  moleculeObservedValues.markObservedValuesAsConnected(_id);
    286283}
    287284
    288 void QtObservedInstanceBoard::markObservedMoleculeAsDisconnected(const moleculeId_t _id)
     285void QtObservedInstanceBoard::markObservedMoleculeAsDisconnected(ObservedValue_Index_t _id)
    289286{
    290287  moleculeObservedValues.markObservedValuesAsDisconnected(_id);
    291288}
    292289
    293 void QtObservedInstanceBoard::markObservedMoleculeForErase(const moleculeId_t _id)
     290void QtObservedInstanceBoard::markObservedMoleculeForErase(ObservedValue_Index_t _id)
    294291{
    295292  moleculeObservedValues.eraseObservedValues(_id);
  • src/UIElements/Qt4/InstanceBoard/QtObservedInstanceBoard.hpp

    rbff202 r59eabc  
    8080
    8181  QtObservedAtom::ptr getObservedAtom(const atomId_t _id);
    82   QtObservedAtom::ptr getObservedAtom(const Observable * _obs);
    8382  QtObservedMolecule::ptr getObservedMolecule(const moleculeId_t _id);
    84   QtObservedMolecule::ptr getObservedMolecule(const Observable * _obs);
    85   void markObservedAtomAsConnected(const atomId_t _id);
    86   void markObservedAtomAsDisconnected(const atomId_t _id);
    87   void markObservedAtomForErase(const atomId_t _id);
    88   void markObservedMoleculeAsConnected(const moleculeId_t _id);
    89   void markObservedMoleculeAsDisconnected(const moleculeId_t _id);
    90   void markObservedMoleculeForErase(const moleculeId_t _id);
     83  void markObservedAtomAsConnected(ObservedValue_Index_t _id);
     84  void markObservedAtomAsDisconnected(ObservedValue_Index_t _id);
     85  void markObservedAtomForErase(ObservedValue_Index_t _id);
     86  void markObservedMoleculeAsConnected(ObservedValue_Index_t _id);
     87  void markObservedMoleculeAsDisconnected(ObservedValue_Index_t _id);
     88  void markObservedMoleculeForErase(ObservedValue_Index_t _id);
    9189
    9290signals:
    9391  void atomInserted(QtObservedAtom::ptr _atom);
    94   void atomRemoved(const atomId_t _atomid);
     92  void atomRemoved(ObservedValue_Index_t _atomid);
    9593  void atomIndexChanged(const atomId_t _oldid, const atomId_t _newid);
    9694  void moleculeInserted(QtObservedMolecule::ptr _mol);
    97   void moleculeRemoved(const moleculeId_t _molid);
     95  void moleculeRemoved(ObservedValue_Index_t _molid);
    9896  void moleculeIndexChanged(const moleculeId_t _oldid, const moleculeId_t _newid);
    9997
     
    113111  SignedOn_t MoleculeSignedOn;
    114112
     113  //!> "templated typedef" for an id to index map.
     114  template <class id>
     115  struct IdtoIndex_t : std::map<id, ObservedValue_Index_t> {};
     116  IdtoIndex_t<atomId_t> atomids_lookup;
     117  IdtoIndex_t<moleculeId_t> moleculeids_lookup;
     118
    115119  /** Counts how many atom's ObservedValues got subjectKilled.
    116120   *
     
    119123   * monitored Observable. Only then can we safely remove the instance.
    120124   *
    121    * \param _atomid id of the atom
     125   * \param _id observable that received the subjectKilled()
    122126   */
    123   void atomcountsubjectKilled(const atomId_t _atomid);
     127  void atomcountsubjectKilled(ObservedValue_Index_t _id);
    124128
    125129  /** Counts how many molecule's ObservedValues got subjectKilled.
     
    129133   * monitored Observable. Only then can we safely remove the instance.
    130134   *
    131    * \param _molid id of the molecule
     135   * \param _id observable that received the subjectKilled()
    132136   */
    133   void moleculecountsubjectKilled(const moleculeId_t _molid);
     137  void moleculecountsubjectKilled(ObservedValue_Index_t _id);
    134138
    135139  //!> container with all ObservedValues for each atom, associated by id
    136   ObservedValuesContainer<QtObservedAtom, atomId_t> atomObservedValues;
     140  ObservedValuesContainer<QtObservedAtom, ObservedValue_Index_t> atomObservedValues;
    137141  //!> container with all ObservedValues for each molecule, associated by id
    138   ObservedValuesContainer<QtObservedMolecule, moleculeId_t> moleculeObservedValues;
     142  ObservedValuesContainer<QtObservedMolecule, ObservedValue_Index_t> moleculeObservedValues;
    139143};
    140144
  • src/UIElements/Qt4/InstanceBoard/QtObservedMolecule.cpp

    rbff202 r59eabc  
    151151    signedOffChannels = AllsignedOnChannels;
    152152    if (!BoardIsGone)
    153       board.markObservedMoleculeAsDisconnected(getMolIndex());
     153      board.markObservedMoleculeAsDisconnected(getIndex());
    154154  }
    155155}
     
    166166      owner->signOn(this, *iter);
    167167    if (!BoardIsGone)
    168       board.markObservedMoleculeAsConnected(getMolIndex());
     168      board.markObservedMoleculeAsConnected(getIndex());
    169169  } else
    170170    signedOffChannels = AllsignedOnChannels;
     
    204204
    205205    if (!BoardIsGone) {
    206       board.markObservedMoleculeAsDisconnected(getMolIndex());
    207       board.markObservedMoleculeForErase(getMolIndex());
     206      board.markObservedMoleculeAsDisconnected(getIndex());
     207      board.markObservedMoleculeForErase(getIndex());
    208208    }
    209209  }
     
    523523}
    524524
     525ObservedValue_Index_t QtObservedMolecule::getIndex() const
     526{
     527  ASSERT( owner != NULL,
     528      "QtObservedMolecule::getIndex() - index is NULL");
     529  return owner;
     530}
     531
    525532const int& QtObservedMolecule::getAtomCount() const
    526533{
  • src/UIElements/Qt4/InstanceBoard/QtObservedMolecule.hpp

    rbff202 r59eabc  
    5757private:
    5858  //!> ObservedValuesContainer needs to access private cstor and dstor
    59   friend class ObservedValuesContainer<QtObservedMolecule, moleculeId_t>;
     59  friend class ObservedValuesContainer<QtObservedMolecule, ObservedValue_Index_t>;
    6060  //!> QtObservedInstanceBoard needs to access private cstor and dstor
    6161  friend class QtObservedInstanceBoard;
     
    8585  void subjectKilled(Observable *publisher);
    8686  void recieveNotification(Observable *publisher, Notification_ptr notification);
     87
     88  /** Getter for a permanent and unique index of this instance.
     89   *
     90   * \note ALWAYS use this index if you need to store and identifier to this
     91   * instance which you might need to retrieve at some later date.
     92   *
     93   * \warning DO NOT STORE the QtObserved...:ptr directly. This will possibly
     94   * prevent their eventual destruction. Only store the ObservedValue_Index_t
     95   * as means to obtain the ptr from the QtObservedInstanceBoard.
     96   *
     97   * \return returns a unique and permanent index that can be used to retrieve this
     98   * instance from the QtObservedInstanceBoard as it must not be stored.
     99   */
     100  ObservedValue_Index_t getIndex() const;
    87101
    88102  /** Getter to molecule atom count contained in \a ObservedValues.
Note: See TracChangeset for help on using the changeset viewer.