Changeset 8fc9b6


Ignore:
Timestamp:
Feb 2, 2010, 4:22:22 PM (16 years ago)
Author:
Tillmann Crueger <crueger@…>
Children:
4272f0
Parents:
f1ef9cc
Message:

Made more methods of the molecule observable

Location:
molecuilder/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/Patterns/Observer.hpp

    rf1ef9cc r8fc9b6  
    2020 * Observation blocks from there, these functions wont trigger notifications. Only the end
    2121 * of the final observation block triggers the update of Observers.
     22 *
     23 * Returning from observed code should be done using the RETURN_OBSERVER() macro. This way the Observer mechanism
     24 * is notified that the method is left.
    2225 *
    2326 * Each observerable can have sub-observables. When one of these sub-observables changes and
     
    7881#define START_OBSERVER Observable::start_observer_internal(this);do{do{}while(0)
    7982#define FINISH_OBSERVER }while(0);Observable::finish_observer_internal(this)
     83#define RETURN_OBSERVER( retval ) do{Observable::finish_observer_internal(this); return (retval);}while(0)
    8084#endif /* OBSERVER_HPP_ */
  • molecuilder/src/molecule.cpp

    rf1ef9cc r8fc9b6  
    103103bool molecule::AddAtom(atom *pointer)
    104104{
     105  bool retval = false;
     106  START_OBSERVER;
    105107  if (pointer != NULL) {
    106108    pointer->sort = &pointer->nr;
     
    119121      }
    120122    }
    121     return add(pointer, end);
    122   } else
    123     return false;
     123    retval = add(pointer, end);
     124  }
     125  FINISH_OBSERVER;
     126  return retval;
    124127};
    125128
     
    131134atom * molecule::AddCopyAtom(atom *pointer)
    132135{
     136  atom *retval = NULL;
     137  START_OBSERVER;
    133138  if (pointer != NULL) {
    134139    atom *walker = new atom(pointer);
     
    140145      NoNonHydrogen++;
    141146    AtomCount++;
    142     return walker;
    143   } else
    144     return NULL;
     147    retval=walker;
     148  }
     149  FINISH_OBSERVER;
     150  return retval;
    145151};
    146152
     
    181187bool molecule::AddHydrogenReplacementAtom(bond *TopBond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem)
    182188{
     189  bool AllWentWell = true;    // flag gathering the boolean return value of molecule::AddAtom and other functions, as return value on exit
     190  START_OBSERVER;
    183191  double bondlength;  // bond length of the bond to be replaced/cut
    184192  double bondangle;  // bond angle of the bond to be replaced/cut
    185193  double BondRescale;   // rescale value for the hydrogen bond length
    186   bool AllWentWell = true;    // flag gathering the boolean return value of molecule::AddAtom and other functions, as return value on exit
    187194  bond *FirstBond = NULL, *SecondBond = NULL; // Other bonds in double bond case to determine "other" plane
    188195  atom *FirstOtherAtom = NULL, *SecondOtherAtom = NULL, *ThirdOtherAtom = NULL; // pointer to hydrogen atoms to be added
     
    228235  if (BondRescale == -1) {
    229236    eLog() << Verbose(1) << "There is no typical hydrogen bond distance in replacing bond (" << TopOrigin->Name << "<->" << TopReplacement->Name << ") of degree " << TopBond->BondDegree << "!" << endl;
    230     return false;
     237    RETURN_OBSERVER(false);
    231238    BondRescale = bondlength;
    232239  } else {
     
    308315      if (bondangle == -1) {
    309316        eLog() << Verbose(1) << "There is no typical hydrogen bond angle in replacing bond (" << TopOrigin->Name << "<->" << TopReplacement->Name << ") of degree " << TopBond->BondDegree << "!" << endl;
    310         return false;
     317        RETURN_OBSERVER(false);
    311318        bondangle = 0;
    312319      }
     
    435442  Free(&matrix);
    436443
     444  FINISH_OBSERVER;
    437445//  Log() << Verbose(3) << "End of AddHydrogenReplacementAtom." << endl;
    438446  return AllWentWell;
     
    446454bool molecule::AddXYZFile(string filename)
    447455{
     456
    448457  istringstream *input = NULL;
    449458  int NumberOfAtoms = 0; // atom number in xyz read
     
    459468    return false;
    460469
     470  START_OBSERVER;
    461471  getline(xyzfile,line,'\n'); // Read numer of atoms in file
    462472  input = new istringstream(line);
     
    499509  xyzfile.close();
    500510  delete(input);
     511  FINISH_OBSERVER;
    501512  return true;
    502513};
Note: See TracChangeset for help on using the changeset viewer.