source: molecuilder/src/Actions/Calculation_impl.hpp@ f2efcf

Last change on this file since f2efcf was 01d28a, checked in by Tillmann Crueger <crueger@…>, 16 years ago

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

  • Property mode set to 100644
File size: 1.2 KB
Line 
1/*
2 * Calculation_impl.hpp
3 *
4 * Created on: Feb 19, 2010
5 * Author: crueger
6 */
7
8#ifndef CALCULATION_IMPL_HPP_
9#define CALCULATION_IMPL_HPP_
10
11#include "Actions/Calculation.hpp"
12
13#include <cassert>
14
15template<typename T>
16Calculation<T>::Calculation(int _maxSteps, std::string _name, bool _doRegister) :
17 Process(_maxSteps,_name,_doRegister),
18 done(false),
19 result(0)
20{}
21
22template<typename T>
23Calculation<T>::~Calculation()
24{
25 delete result;
26}
27
28// methods inherited from Action
29
30template<typename T>
31void Calculation<T>::call(){
32 reset();
33 (*this)();
34}
35
36template<typename T>
37void Calculation<T>::undo(){}
38
39template<typename T>
40bool Calculation<T>::canUndo()
41{
42 return false;
43}
44
45// methods for calculation infrastructure
46
47template<typename T>
48T Calculation<T>::operator()(){
49 if(!done){
50 result = doCalc();
51 done = true;
52 }
53 return *result;
54}
55
56template<typename T>
57bool Calculation<T>::hasResult(){
58 return done;
59}
60
61template<typename T>
62T Calculation<T>::getResult(){
63 assert(done && "No result calculated");
64 return *result;
65}
66
67template<typename T>
68void Calculation<T>::reset(){
69 done = false;
70 delete result;
71 result = 0;
72}
73
74#endif /* CALCULATION_IMPL_HPP_ */
Note: See TracBrowser for help on using the repository browser.