Changes in src/atom.cpp [1b2d30:ad2b411]
- File:
-
- 1 edited
-
src/atom.cpp (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/atom.cpp
r1b2d30 rad2b411 4 4 * 5 5 */ 6 7 #include "Helpers/MemDebug.hpp" 6 8 7 9 #include "atom.hpp" … … 14 16 #include "vector.hpp" 15 17 #include "World.hpp" 18 #include "molecule.hpp" 16 19 17 20 /************************************* Functions for class atom *************************************/ … … 21 24 */ 22 25 atom::atom() : 23 previous(NULL), next(NULL), father(this), sort(&nr)26 father(this), sort(&nr), mol(0) 24 27 { 25 28 node = &x; // TesselPoint::x can only be referenced from here … … 29 32 */ 30 33 atom::atom(atom *pointer) : 31 ParticleInfo(pointer), 32 previous(NULL), next(NULL), father(pointer), sort(&nr) 34 ParticleInfo(pointer),father(pointer), sort(&nr) 33 35 { 34 36 type = pointer->type; // copy element of atom … … 37 39 FixedIon = pointer->FixedIon; 38 40 node = &x; 41 mol = 0; 39 42 }; 40 43 41 44 atom *atom::clone(){ 42 45 atom *res = new atom(this); 43 res->previous=0;44 res->next=0;45 46 res->father = this; 46 47 res->sort = &res->nr; … … 50 51 res->FixedIon = FixedIon; 51 52 res->node = &x; 53 res->mol = 0; 52 54 World::getInstance().registerAtom(res); 53 55 return res; … … 59 61 atom::~atom() 60 62 { 63 removeFromMolecule(); 64 for(BondList::iterator iter=ListOfBonds.begin(); iter!=ListOfBonds.end();){ 65 // deleting the bond will invalidate the iterator !!! 66 bond *bond =*(iter++); 67 delete(bond); 68 } 61 69 }; 62 70 … … 67 75 atom *atom::GetTrueFather() 68 76 { 69 atom *walker = this; 70 do { 71 if (walker == walker->father) // top most father is the one that points on itself 72 break; 73 walker = walker->father; 74 } while (walker != NULL); 75 return walker; 77 if(father == this){ // top most father is the one that points on itself 78 return this; 79 } 80 else if(!father) { 81 return 0; 82 } 83 else { 84 return father->GetTrueFather(); 85 } 76 86 }; 77 87 … … 149 159 * \return true - \a *out present, false - \a *out is NULL 150 160 */ 151 bool atom::OutputArrayIndexed(o stream * const out, const int *ElementNo, int *AtomNo, const char *comment) const161 bool atom::OutputArrayIndexed(ofstream * const out, const int *ElementNo, int *AtomNo, const char *comment) const 152 162 { 153 163 AtomNo[type->Z]++; // increment number … … 226 236 * \param *AtomNo pointer to atom counter that is increased by one 227 237 */ 228 void atom::OutputMPQCLine(o stream * const out, const Vector *center, int *AtomNo = NULL) const238 void atom::OutputMPQCLine(ofstream * const out, const Vector *center, int *AtomNo = NULL) const 229 239 { 230 240 *out << "\t\t" << type->symbol << " [ " << x[0]-center->at(0) << "\t" << x[1]-center->at(1) << "\t" << x[2]-center->at(2) << " ]" << endl; … … 305 315 } 306 316 307 atomId_t atom::getId() {317 atomId_t atom::getId() const { 308 318 return id; 309 319 } 320 321 void atom::setMolecule(molecule *_mol){ 322 // take this atom from the old molecule 323 removeFromMolecule(); 324 mol = _mol; 325 if(!mol->containsAtom(this)){ 326 mol->AddAtom(this); 327 } 328 } 329 330 void atom::removeFromMolecule(){ 331 if(mol){ 332 if(mol->containsAtom(this)){ 333 mol->erase(this); 334 } 335 mol=0; 336 } 337 } 338 310 339 311 340 atom* NewAtom(atomId_t _id){
Note:
See TracChangeset
for help on using the changeset viewer.
