Changeset f1ef9cc


Ignore:
Timestamp:
Feb 2, 2010, 3:53:04 PM (16 years ago)
Author:
Tillmann Crueger <crueger@…>
Children:
8fc9b6
Parents:
d0c7ec
Message:

Added simple way to retrieve formula of a molecule using caching

Location:
molecuilder/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/molecule.cpp

    rd0c7ec rf1ef9cc  
    66
    77#include <cstring>
     8#include <boost/bind.hpp>
    89
    910#include "atom.hpp"
     
    3233  first(new bond(start, end, 1, -1)), last(new bond(start, end, 1, -1)), MDSteps(0), AtomCount(0),
    3334  BondCount(0), ElementCount(0), NoNonHydrogen(0), NoNonBonds(0), NoCyclicBonds(0), BondDistance(0.),
    34   ActiveFlag(false), IndexNr(-1), last_atom(0), InternalPointer(start)
     35  ActiveFlag(false), IndexNr(-1), last_atom(0), InternalPointer(start),
     36  formula(this,boost::bind(&molecule::calcFormula,this))
    3537{
    3638  // init atom chain list
     
    7274  strncpy(name,_name.c_str(),MAXSTRINGSIZE);
    7375  FINISH_OBSERVER;
     76}
     77
     78const std::string molecule::getFormula(){
     79  return *formula;
     80}
     81
     82std::string molecule::calcFormula(){
     83  int Counts[MAX_ELEMENTS];
     84  stringstream sstr;
     85  for (int j = 0; j<MAX_ELEMENTS;j++)
     86    Counts[j] = 0;
     87  for(atom *Walker = start; Walker != end; Walker = Walker->next) {
     88    Counts[Walker->type->Z]++;
     89  }
     90  for(element* Elemental = elemente->end; Elemental != elemente->start; Elemental = Elemental->previous) {
     91    if (Counts[Elemental->Z] != 0)
     92      sstr << Elemental->symbol << Counts[Elemental->Z];
     93  }
     94  return sstr.str();
    7495}
    7596
  • molecuilder/src/molecule.hpp

    rd0c7ec rf1ef9cc  
    3333#include "tesselation.hpp"
    3434#include "Patterns/Observer.hpp"
     35#include "Patterns/Cacheable.hpp"
    3536
    3637/****************************************** forward declarations *****************************/
     
    105106    char name[MAXSTRINGSIZE];         //!< arbitrary name
    106107
     108  private:
     109    Cacheable<string> formula;
     110
    107111public:
    108112  molecule(const periodentafel * const teil);
     
    112116  const std::string getName();
    113117  void setName(const std::string);
     118  const std::string getFormula();
     119  std::string calcFormula();
    114120
    115121  // re-definition of virtual functions from PointCloud
Note: See TracChangeset for help on using the changeset viewer.