Changeset 7d82a5


Ignore:
Timestamp:
Feb 13, 2013, 3:47:38 PM (12 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:
b4b364
Parents:
c8302f3
git-author:
Frederik Heber <heber@…> (11/02/12 13:38:08)
git-committer:
Frederik Heber <heber@…> (02/13/13 15:47:38)
Message:

Changed bond::ptr into boost::shared_ptr.

Changes:

  • refactored some BondedParticle functions, cleaning up the interface in terms of private and public functionality, added some helper functions to find bonds.
  • ptr = NULL --> .reset().
  • now initialising to NULL.
  • BondsPerSP is now list of boost::shared_ptr as well.
  • some include of bond.hpp instead of forward references necessary.
  • leftatom and rightatom are now set to NULL on UnregisterBond().
  • bonds are not deleted anymore but simply unregistered.
  • FIX: BondedParticleInfo did unrequiredly inherit AtomObservable.
  • removed UnregisterAllBonds(), code is now in RemoveAllBonds() where UnregisterBond is called for both bond partners. This ensures that the bond is correctly released and shared_ptr free'd.
Location:
src
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • src/Atom/atom_bondedparticle.cpp

    rc8302f3 r7d82a5  
    114114  }
    115115
    116   bond* newBond = new bond((atom*) this, (atom*) Partner, 1);
     116  bond::ptr newBond(new bond((atom*) this, (atom*) Partner, 1));
    117117  RegisterBond(_step, newBond);
    118118  Partner->RegisterBond(_step, newBond);
     
    121121}
    122122
    123 /** Removes a bond of this atom to a given \a Partner.
    124  *
    125  * @param _step time step
    126  * @param Partner bond partner
    127  */
    128 void BondedParticle::removeBond(const unsigned int _step, BondedParticle * const Partner)
     123/** Helper function to find the time step to a given bond in \a Binder.
     124 *
     125 * \param Binder bond to look for
     126 * \return ListOfBonds::size() - not found, else - step containing \a Binder
     127 */
     128unsigned int BondedParticle::findBondsStep(bond::ptr const Binder) const
     129{
     130
     131  size_t _step = 0;
     132  for (;_step < ListOfBonds.size();++_step) {
     133    const BondList& ListOfBonds = getListOfBondsAtStep(_step);
     134    if (std::find(ListOfBonds.begin(), ListOfBonds.end(), Binder) != ListOfBonds.end())
     135      break;
     136  }
     137  return _step;
     138}
     139
     140/** Helper function to find the iterator to a bond at a given time \a step to
     141 * a given bond partner in \a Partner.
     142 *
     143 * \param _step time step to look at
     144 * \param Partner bond partner to look for
     145 * \return ListOfBonds::end() - not found, else - iterator pointing \a Binder
     146 */
     147BondList::const_iterator BondedParticle::findBondPartnerAtStep(
     148    const unsigned int _step,
     149    BondedParticle * const Partner) const
    129150{
    130151  const BondList& ListOfBonds = getListOfBondsAtStep(_step);
     
    134155          _1,
    135156          boost::cref(Partner)));
    136   if (iter != ListOfBonds.end()) {
    137     delete *iter; //dstor takes care of unregistering and all
     157  return iter;
     158}
     159
     160/** Removes a bond of this atom to a given \a Partner.
     161 *
     162 * @param _step time step
     163 * @param Partner bond partner
     164 */
     165void BondedParticle::removeBond(const unsigned int _step, BondedParticle * const Partner)
     166{
     167  BondList::const_iterator iter = findBondPartnerAtStep(_step, Partner);
     168  if (iter != getListOfBondsAtStep(_step).end()) {
     169    // iter becomes invalid upon first unregister,
     170    // hence store the bond someplace else first
     171    bond::ptr const Binder = *iter;
     172    UnregisterBond(_step, Binder);
     173    Partner->UnregisterBond(_step, Binder);
    138174  } else
    139175    ELOG(1, "BondedParticle::removeBond() - I cannot find the bond in between "
     
    145181 * @param Binder bond to remove
    146182 */
    147 void BondedParticle::removeBond(bond::ptr binder)
    148 {
    149   UnregisterBond(binder);
     183void BondedParticle::removeBond(bond::ptr &binder)
     184{
     185  if (binder != NULL) {
     186    atom * const Other = binder->GetOtherAtom(this);
     187    ASSERT( Other != NULL,
     188        "BondedParticle::removeBonds() - cannot find bond partner for "
     189        +toString(*binder)+".");
     190    // find bond at step
     191    unsigned int step = findBondsStep(binder);
     192    if (step != ListOfBonds.size()) {
     193      UnregisterBond(step, binder);
     194      Other->UnregisterBond(step, binder);
     195      binder.reset();
     196    }
     197  }
    150198}
    151199
     
    165213void BondedParticle::removeAllBonds(const unsigned int _step)
    166214{
    167   for (BondList::iterator iter = ListOfBonds[_step].begin();
    168       !ListOfBonds[_step].empty();
    169       iter = ListOfBonds[_step].begin()) {
    170     delete (*iter);
    171     // unregister/NOTIFY is done by bond::~bond()
     215  //LOG(3,"INFO: Clearing all bonds of " << *this << ": " << ListOfBonds[_step]);
     216  for (BondList::iterator iter = (ListOfBonds[_step]).begin();
     217      !(ListOfBonds[_step]).empty();
     218      iter = (ListOfBonds[_step]).begin()) {
     219    //LOG(3,"INFO: Clearing bond (" << *iter << ") " << *(*iter) << " of list " << &ListOfBonds);
     220    atom * const Other = (*iter)->GetOtherAtom(this);
     221    ASSERT( Other != NULL,
     222        "BondedParticle::removeAllBonds() - cannot find bond partner for "
     223        +toString(**iter)+".");
     224    Other->UnregisterBond(_step, *iter);
     225    UnregisterBond(_step, *iter);
    172226  }
    173227}
     
    179233bool BondedParticle::RegisterBond(const unsigned int _step, bond::ptr const Binder)
    180234{
    181   OBSERVE;
    182235  bool status = false;
    183236  if (Binder != NULL) {
     237    OBSERVE;
    184238    if (Binder->Contains(this)) {
    185239      //LOG(3,"INFO: Registering bond "<< *Binder << " with atom " << *this << " at step " << _step);
     
    200254
    201255/** Removes a given bond from atom::ListOfBonds.
     256 *
     257 * \warning This only removes this atom not its bond partner, i.e.
     258 * both atoms need to call this function to fully empty a bond.
     259 *
    202260 * @param _step time step to access
    203261 * \param *Binder bond to remove
    204262 */
    205 bool BondedParticle::UnregisterBond(bond::ptr const Binder)
    206 {
    207   OBSERVE;
     263bool BondedParticle::UnregisterBond(const unsigned int _step, bond::ptr const Binder)
     264{
    208265  bool status = false;
    209   ASSERT(Binder != NULL, "BondedParticle::UnregisterBond() - Binder is NULL.");
    210   const int step = ContainsBondAtStep(Binder);
    211   if (step != -1) {
    212     //LOG(0,"INFO: Unregistering bond "<< *Binder << " from list " << &ListOfBonds << " of atom " << *this << " at step " << step);
    213     ListOfBonds[step].remove(Binder);
    214     if (WorldTime::getTime() == step)
    215       NOTIFY(AtomObservable::BondsRemoved);
    216     status = true;
     266  if (Binder != NULL) {
     267    if (Binder->Contains(this)) {
     268      OBSERVE;
     269      //LOG(0,"INFO: Unregistering bond "<< *Binder << " from list " << &ListOfBonds << " of atom " << *this << " at step " << step);
     270#ifndef NDEBUG
     271      BondList::const_iterator iter =
     272          std::find(ListOfBonds[_step].begin(), ListOfBonds[_step].end(), Binder);
     273      ASSERT( iter != ListOfBonds[_step].end(),
     274          "BondedParticle::UnregisterBond() - "+toString(*Binder)+" not contained at "
     275          +toString(_step));
     276#endif
     277      Binder->removeAtom(this);
     278      ListOfBonds[_step].remove(Binder);
     279      if (WorldTime::getTime() == _step)
     280        NOTIFY(AtomObservable::BondsRemoved);
     281      status = true;
     282    } else {
     283      ELOG(1, *Binder << " does not contain " << *this << ".");
     284    }
    217285  } else {
    218     ELOG(1, *Binder << " does not contain " << *this << ".");
     286    ELOG(1, "Binder is " << Binder << ".");
    219287  }
    220288  return status;
    221289};
    222290
    223 /** Removes all bonds from atom::ListOfBonds.
    224  * \note Does not do any memory de-allocation.
    225  */
    226 void BondedParticle::UnregisterAllBond(const unsigned int _step)
    227 {
    228   OBSERVE;
    229   NOTIFY(AtomObservable::BondsRemoved);
    230   ListOfBonds[_step].clear();
    231 }
    232 
    233291/** Removes all bonds of given \a _step with freeing memory.
    234292 *
     
    237295void BondedParticle::ClearBondsAtStep(const unsigned int _step)
    238296{
    239   OBSERVE;
    240   NOTIFY(AtomObservable::BondsRemoved);
    241   //LOG(3,"INFO: Clearing all bonds of " << *this << ": " << ListOfBonds[_step]);
    242   for (BondList::iterator iter = (ListOfBonds[_step]).begin();
    243       !(ListOfBonds[_step]).empty();
    244       iter = (ListOfBonds[_step]).begin()) {
    245     //LOG(3,"INFO: Clearing bond (" << *iter << ") " << *(*iter) << " of list " << &ListOfBonds);
    246     delete((*iter)); // will also unregister with us and remove from list
    247   }
     297  removeAllBonds(_step);
    248298}
    249299
     
    286336  int FalseBondDegree = 0;
    287337  atom *OtherWalker = NULL;
    288   bond::ptr CandidateBond = NULL;
     338  bond::ptr CandidateBond;
    289339
    290340  NoBonds = CountBonds();
  • src/Atom/atom_bondedparticle.hpp

    rc8302f3 r7d82a5  
    2424#include "atom_atominfo.hpp"
    2525#include "atom_bondedparticleinfo.hpp"
     26#include "atom_observable.hpp"
    2627#include "atom_particleinfo.hpp"
     28#include "atom_observable.hpp"
    2729
    2830/****************************************** forward declarations *****************************/
     
    3234/********************************************** declarations *******************************/
    3335
    34 class BondedParticle : public BondedParticleInfo, public virtual ParticleInfo, public virtual AtomInfo {
     36class BondedParticle :
     37    public BondedParticleInfo,
     38    public virtual ParticleInfo,
     39    public virtual AtomInfo,
     40    public virtual AtomObservable
     41{
    3542public:
    3643  BondedParticle();
     
    3946  bond::ptr const addBond(const unsigned int _step, BondedParticle* Partner);
    4047  void removeBond(const unsigned int _step, BondedParticle* Partner);
    41   void removeBond(bond::ptr binder);
     48  void removeBond(bond::ptr &binder);
    4249  void removeAllBonds();
    4350  void removeAllBonds(const unsigned int _step);
     
    5562protected:
    5663  bool RegisterBond(const unsigned int _step, bond::ptr const Binder);
    57   bool UnregisterBond(bond::ptr const Binder);
    58   void UnregisterAllBond(const unsigned int _step);
     64  bool UnregisterBond(const unsigned int _step, bond::ptr const Binder);
    5965
    6066  int ContainsBondAtStep(bond::ptr Binder) const;
    6167
     68private:
     69  unsigned int findBondsStep(bond::ptr const Binder) const;
     70  BondList::const_iterator findBondPartnerAtStep(
     71      const unsigned int _step,
     72      BondedParticle * const Partner) const;
    6273};
    6374
  • src/Atom/atom_bondedparticleinfo.hpp

    rc8302f3 r7d82a5  
    1919#endif
    2020
    21 #include "atom_observable.hpp"
     21//#include "atom_observable.hpp"
    2222#include "Bond/bond.hpp"
    2323
     
    3232/********************************************** declarations *******************************/
    3333
    34 class BondedParticleInfo  : public virtual AtomObservable {
     34class BondedParticleInfo // : public virtual AtomObservable // must be virtual(!)
     35{
    3536  friend class BondedParticle;
    3637public:
  • src/Bond/bond.cpp

    rc8302f3 r7d82a5  
    8181    NOTIFY(BondRemoved);
    8282  }
    83   // remove this node from the list structure
    84   if (leftatom != NULL)
    85     leftatom->removeBond(this);
    86   // there might be self-bonds
    87   if ((leftatom != rightatom) && (rightatom != NULL))
    88     rightatom->removeBond(this);
     83  // atoms should have been destroyed and NULL'd their entry already
     84  ASSERT (leftatom == NULL,
     85      "~bond() - leftatom is not NULL.");
     86  ASSERT (rightatom == NULL,
     87      "~bond() - rightatom is not NULL.");
    8988};
    9089
     
    101100atom * bond::GetOtherAtom(const ParticleInfo * const Atom) const
    102101{
     102  ASSERT( (leftatom != NULL) && (rightatom != NULL),
     103      "bond::GetOtherAtom() - one of the atoms refs is NULL.");
    103104  if(leftatom == Atom)
    104105    return rightatom;
     
    143144  return (leftatom->DistanceSquared(*rightatom));
    144145};
     146
     147/** Sets either leftatom or rightatom to NULL.
     148 *
     149 * \param Atom atom to remove
     150 */
     151void bond::removeAtom(const ParticleInfo * const Atom)
     152{
     153  if (static_cast<const ParticleInfo *>(leftatom) == Atom)
     154    leftatom = NULL;
     155  if (static_cast<const ParticleInfo *>(rightatom) == Atom)
     156    rightatom = NULL;
     157}
  • src/Bond/bond.hpp

    rc8302f3 r7d82a5  
    1818#endif
    1919
     20#include <boost/shared_ptr.hpp>
     21
    2022#include "Bond/bond_observable.hpp"
    2123#include "Bond/GraphEdge.hpp"
     
    2426
    2527class atom;
     28class BondedParticle;
    2629class ParticleInfo;
    2730
     
    3942public:
    4043  //!> typedef for a bond ptr
    41   typedef bond* ptr;
     44  typedef boost::shared_ptr<bond> ptr;
    4245
    4346  atom *leftatom;    //!< first bond partner
     
    5659  bond(atom *left, atom *right, const int degree=1);
    5760  ~bond();
     61
     62private:
     63  //!> grant atom_bondedparticle access to unregister function
     64  friend class BondedParticle;
     65  void removeAtom(const ParticleInfo * const Atom);
    5866};
    5967
  • src/Fragmentation/BondsPerShortestPath.cpp

    rc8302f3 r7d82a5  
    9090    BondsPerSPCount[i] = 0;
    9191  BondsPerSPCount[0] = 1;
    92   bond::ptr Binder = new bond(_Root, _Root);
     92  bond::ptr Binder(new bond(_Root, _Root));
    9393  BondsPerSPList[0].push_back(Binder);
    9494};
     
    110110      (*iter)->leftatom = NULL;
    111111      (*iter)->rightatom = NULL;
    112       // now delete it, there we unregister but this checks for NULL
    113       delete(*iter);
    114112    }
    115113    BondsPerSPList[i].clear();
     
    138136  atom *OtherWalker = NULL;
    139137  atom *Predecessor = NULL;
    140   bond::ptr Binder = NULL;
     138  bond::ptr Binder;
    141139  int RootKeyNr = _RootKeyNr;
    142140  int RemainingWalkers = -1;
     
    180178          if ((OtherWalker != Predecessor) && (OtherWalker->GetTrueFather()->getNr() > RootKeyNr)) { // only pass through those with label bigger than Root's
    181179            // add the bond in between to the SP list
    182             Binder = new bond(Walker, OtherWalker); // create a new bond in such a manner, that bond::rightatom is always the one more distant
     180            Binder.reset(new bond(Walker, OtherWalker)); // create a new bond in such a manner, that bond::rightatom is always the one more distant
    183181            BondsPerSPList[SP+1].push_back(Binder);
    184182            BondsPerSPCount[SP+1]++;
  • src/Fragmentation/BondsPerShortestPath.hpp

    rc8302f3 r7d82a5  
    1414#endif
    1515
     16#include "Bond/bond.hpp"
    1617#include "Fragmentation/HydrogenSaturation_enum.hpp"
    1718
     
    2021
    2122class atom;
    22 class bond;
    2323class KeySet;
    2424
     
    3939  int getOrder() const;
    4040
    41   typedef std::list<bond*> BondsPerSP;
     41  typedef std::list<bond::ptr> BondsPerSP;
    4242  typedef std::vector< BondsPerSP > AllSPBonds;
    4343
  • src/Fragmentation/PowerSetGenerator.cpp

    rc8302f3 r7d82a5  
    220220
    221221    // prepare the subset and call the generator
    222     std::vector<bond*> BondsList;
     222    std::vector<bond::ptr> BondsList;
    223223    BondsList.resize(BondsPerSPList.BondsPerSPCount[0]);
    224224    ASSERT(BondsPerSPList.BondsPerSPList[0].size() != 0,
  • src/Graph/BreadthFirstSearchAdd.cpp

    rc8302f3 r7d82a5  
    152152  Info FunctionInfo("BreadthFirstSearchAdd");
    153153  atom *Walker = NULL, *OtherAtom = NULL;
    154   bond::ptr Binder = NULL;
     154  bond::ptr Binder;
    155155
    156156  // add Root if not done yet
  • src/Graph/CyclicStructureAnalysis.cpp

    rc8302f3 r7d82a5  
    332332  atom *Walker = NULL;
    333333  atom *OtherAtom = NULL;
    334   bond::ptr BackEdge = NULL;
     334  bond::ptr BackEdge;
    335335  int NumCycles = 0;
    336336  int MinRingSize = -1;
  • src/Graph/DepthFirstSearchAnalysis.cpp

    rc8302f3 r7d82a5  
    8585    if ((*Runner)->IsUsed() == GraphEdge::white)
    8686      return ((*Runner));
    87   return NULL;
     87  return bond::ptr();
    8888}
    8989
     
    264264      break;
    265265    }
    266     Binder = NULL;
     266    Binder.reset();
    267267  } while (1); // (3)
    268268}
     
    355355  int OldGraphNr = 0;
    356356  atom *Walker = NULL;
    357   bond::ptr Binder = NULL;
     357  bond::ptr Binder;
    358358
    359359  if (World::getInstance().numAtoms() == 0)
     
    385385          break;
    386386        } else
    387           Binder = NULL;
     387          Binder.reset();
    388388      } while (1); // (2)
    389389
  • src/Tesselation/boundary.cpp

    rc8302f3 r7d82a5  
    787787  Vector Inserter;
    788788  double FillIt = false;
    789   bond::ptr Binder = NULL;
     789  bond::ptr Binder;
    790790  double phi[NDIM];
    791791  map<molecule *, Tesselation *> TesselStruct;
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.cpp

    rc8302f3 r7d82a5  
    136136  _bond->leftatom->signOff(this, AtomObservable::PositionChanged);
    137137  _bond->rightatom->signOff(this, AtomObservable::PositionChanged);
    138   _bond = NULL;
     138  _bond.reset();
    139139  delete this;
    140140}
     
    147147      << notification->getChannelNo() << ".";
    148148#endif
    149   if (publisher == dynamic_cast<const Observable*>(_bond)){
     149  if (publisher == dynamic_cast<const Observable *>(_bond.get())){
    150150    // from the bond
    151151    switch (notification->getChannelNo()) {
     
    168168        _bond->leftatom->signOff(this, AtomObservable::PositionChanged);
    169169        _bond->rightatom->signOff(this, AtomObservable::PositionChanged);
    170         _bond = NULL;
     170        _bond.reset();
    171171        delete this;
    172172        break;
  • src/World.cpp

    rc8302f3 r7d82a5  
    245245    NOTIFY(MoleculeRemoved);
    246246  }
     247  mol->signOff(this);
    247248  DeleteMolecule(mol);
    248249  if (isMoleculeSelected(id))
  • src/molecule.cpp

    rc8302f3 r7d82a5  
    333333  double bondangle;  // bond angle of the bond to be replaced/cut
    334334  double BondRescale;   // rescale value for the hydrogen bond length
    335   bond::ptr FirstBond = NULL;
    336   bond::ptr SecondBond = NULL; // Other bonds in double bond case to determine "other" plane
     335  bond::ptr FirstBond;
     336  bond::ptr SecondBond; // Other bonds in double bond case to determine "other" plane
    337337  atom *FirstOtherAtom = NULL, *SecondOtherAtom = NULL, *ThirdOtherAtom = NULL; // pointer to hydrogen atoms to be added
    338338  double b,l,d,f,g, alpha, factors[NDIM];    // hold temporary values in triple bond case for coordination determination
     
    340340  Vector InBondvector;    // vector in direction of *Bond
    341341  const RealSpaceMatrix &matrix =  World::getInstance().getDomain().getM();
    342   bond::ptr Binder = NULL;
     342  bond::ptr Binder;
    343343
    344344  // create vector in direction of bond
     
    688688bond::ptr molecule::AddBond(atom *atom1, atom *atom2, int degree)
    689689{
    690   bond::ptr Binder = NULL;
     690  bond::ptr Binder;
    691691
    692692  // some checks to make sure we are able to create the bond
     
    704704      +" is not part of molecule");
    705705
    706   Binder = new bond(atom1, atom2, degree);
     706  Binder.reset(new bond(atom1, atom2, degree));
    707707  atom1->RegisterBond(WorldTime::getTime(), Binder);
    708708  atom2->RegisterBond(WorldTime::getTime(), Binder);
  • src/molecule_graph.cpp

    rc8302f3 r7d82a5  
    273273bool molecule::ScanForPeriodicCorrection()
    274274{
    275   bond::ptr Binder = NULL;
     275  bond::ptr Binder;
    276276  //bond::ptr OtherBinder = NULL;
    277277  atom *Walker = NULL;
  • src/moleculelist.cpp

    rc8302f3 r7d82a5  
    299299bool MoleculeListClass::AddHydrogenCorrection(std::string &path)
    300300{
    301   bond::ptr Binder = NULL;
     301  bond::ptr Binder;
    302302  double ***FitConstant = NULL, **correction = NULL;
    303303  int a, b;
  • src/unittests/ListOfBondsUnitTest.cpp

    rc8302f3 r7d82a5  
    4444#include "World.hpp"
    4545#include "Atom/atom.hpp"
     46#include "Atom/AtomObserver.hpp"
     47
    4648#include "Bond/bond.hpp"
    4749#include "Element/element.hpp"
     
    109111  // are all cleaned when the world is destroyed
    110112  World::purgeInstance();
     113  AtomObserver::purgeInstance();
    111114  logger::purgeInstance();
     115  errorLogger::purgeInstance();
     116  WorldTime::purgeInstance();
     117
    112118};
    113119
     
    126132void ListOfBondsTest::AddingBondTest()
    127133{
    128   bond::ptr Binder = NULL;
     134  bond::ptr Binder;
    129135  molecule::iterator iter = TestMolecule->begin();
    130136  atom *atom1 = *iter;
     
    160166void ListOfBondsTest::DeleteBondTest()
    161167{
    162   bond::ptr Binder = NULL;
     168  bond::ptr Binder;
    163169  molecule::iterator iter = TestMolecule->begin();
    164170  atom *atom1 = *iter;
     
    173179
    174180  // remove bond
    175   delete Binder;
    176   //atom1->removeBond(Binder);
    177   //atom2->removeBond(Binder);
     181  atom1->removeBond(Binder);
     182  // removed for atom2 automatically but check where nothing breaks
     183  atom2->removeBond(Binder);
    178184
    179185  // check if removed from atoms
     
    198204  atom *atom1 = NULL;
    199205  atom *atom2 = NULL;
    200   bond::ptr Binder = NULL;
     206  bond::ptr Binder;
    201207  {
    202208    molecule::iterator iter = TestMolecule->begin();
     
    207213  CPPUNIT_ASSERT( atom1 != NULL );
    208214  CPPUNIT_ASSERT( atom2 != NULL );
     215  CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->getListOfBonds().size() );
     216  CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom2->getListOfBonds().size() );
    209217
    210218  // add bond
     
    213221
    214222  // access test via CurrentTime
    215   {
    216     const BondList& ListOfBonds = atom1->getListOfBonds();
    217     CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
    218   }
    219   {
    220     const BondList& ListOfBonds = atom2->getListOfBonds();
    221     CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
    222   }
     223  CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom1->getListOfBonds().size() );
     224  CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom2->getListOfBonds().size() );
    223225
    224226  CPPUNIT_ASSERT_EQUAL( true, TestMolecule->hasBondStructure() );
     
    244246  atom *atom1 = NULL;
    245247  atom *atom2 = NULL;
    246   bond::ptr Binder = NULL;
     248  bond::ptr Binder;
    247249  {
    248250    molecule::iterator iter = TestMolecule->begin();
Note: See TracChangeset for help on using the changeset viewer.