Changeset 01d28a for molecuilder/src


Ignore:
Timestamp:
Feb 19, 2010, 2:31:56 PM (16 years ago)
Author:
Tillmann Crueger <crueger@…>
Children:
7bfc19
Parents:
9ef76a
Message:

Added templates that allow arbitrary calculations on atoms to be mapped to sets of Atoms

Location:
molecuilder/src
Files:
5 added
5 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/Actions/Calculation.hpp

    r9ef76a r01d28a  
    1212
    1313template<typename T>
    14 class Calculation: public Process
     14class Calculation : public Process
    1515{
    1616public:
     
    2222  virtual bool canUndo();
    2323
    24   virtual void calc();
     24  virtual T operator()();
    2525  virtual bool hasResult();
    2626  virtual T getResult();
  • molecuilder/src/Actions/Calculation_impl.hpp

    r9ef76a r01d28a  
    99#define CALCULATION_IMPL_HPP_
    1010
     11#include "Actions/Calculation.hpp"
     12
    1113#include <cassert>
    1214
    1315template<typename T>
    14 Calculation<T>::Calculation(int _maxSteps, std::string _name, bool _doRegister=true) :
     16Calculation<T>::Calculation(int _maxSteps, std::string _name, bool _doRegister) :
    1517  Process(_maxSteps,_name,_doRegister),
    1618  done(false),
     
    2022template<typename T>
    2123Calculation<T>::~Calculation()
    22 {}
     24{
     25  delete result;
     26}
    2327
    2428// methods inherited from Action
     
    2630template<typename T>
    2731void Calculation<T>::call(){
    28   calc();
     32  reset();
     33  (*this)();
    2934}
    3035
     
    4146
    4247template<typename T>
    43 void Calculation<T>::calc(){
     48T Calculation<T>::operator()(){
    4449  if(!done){
    4550    result = doCalc();
    4651    done = true;
    4752  }
     53  return *result;
    4854}
    4955
     
    6268void Calculation<T>::reset(){
    6369  done = false;
     70  delete result;
    6471  result = 0;
    6572}
  • molecuilder/src/World.hpp

    r9ef76a r01d28a  
    2828class AtomDescriptor_impl;
    2929class ManipulateAtomsProcess;
     30template<typename T>
     31class AtomsCalculation;
    3032
    3133class World : public Observable
    3234{
     35// necessary for coupling with descriptors
    3336friend class AtomDescriptor_impl;
    3437friend class AtomDescriptor;
    3538
     39// Actions, calculations etc associated with the World
    3640friend class ManipulateAtomsProcess;
     41template<typename> friend class AtomsCalculation;
    3742
    3843typedef std::map<int,atom*> AtomList;
     
    4449  atom* getAtom(AtomDescriptor descriptor);
    4550  std::vector<atom*> getAllAtoms(AtomDescriptor descriptor);
     51
     52  template<typename T>
     53  AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,std::string,AtomDescriptor);
     54
    4655  int numAtoms();
    4756  int numMolecules();
  • molecuilder/src/unittests/Makefile.am

    r9ef76a r01d28a  
    3131  DescriptorUnittest \
    3232  manipulateAtomsTest \
     33  atomsCalculationTest \
    3334  ${MENUTESTS} 
    3435   
     
    115116manipulateAtomsTest_LDADD = ${ALLLIBS}
    116117
     118atomsCalculationTest_SOURCES = atomsCalculationTest.cpp atomsCalculationTest.hpp
     119atomsCalculationTest_LDADD = ${ALLLIBS}
     120
    117121#AUTOMAKE_OPTIONS = parallel-tests
    118122
  • molecuilder/src/unittests/manipulateAtomsTest.cpp

    r9ef76a r01d28a  
    77
    88#include "manipulateAtomsTest.hpp"
    9 
    10 #include "DescriptorUnittest.hpp"
    119
    1210#include <cppunit/CompilerOutputter.h>
Note: See TracChangeset for help on using the changeset viewer.