Browse Source

done some virtual stuff and made dtors

master
Joshua Moerman 15 years ago
parent
commit
0576bdec93
  1. 4
      Attractor.cpp
  2. 4
      Attractor.hpp
  3. 3
      AttractorKernel.hpp
  4. 4
      defines.hpp
  5. 25
      kernels/KernelBasicParameter.cpp
  6. 3
      kernels/KernelBasicParameter.hpp
  7. 26
      kernels/KernelBasicVector.cpp
  8. 5
      kernels/KernelBasicVector.hpp
  9. 2
      kernels/Logistic.hpp
  10. 2
      kernels/Lorenz3D.hpp
  11. 11
      kernels/Polynomial.cpp
  12. 2
      kernels/Polynomial.hpp
  13. 2
      kernels/PolynomialA3D.hpp
  14. 2
      kernels/Unravel3D.hpp

4
Attractor.cpp

@ -90,6 +90,10 @@ Attractor::Attractor(const char* const fileName) {
std::cout << std::endl << " Reading file complete" << std::endl;
}
Attractor::~Attractor(){
delete myAttractor;
}
// this should probably done in the projector section
void Attractor::init_range() {

4
Attractor.hpp

@ -18,13 +18,15 @@ public:
Attractor();
Attractor(const char* const filename);
~Attractor();
void init_range();
bool is_chaos();
void iterate();
void plot();
void output();
};
#endif // ATTRACTOR_HPP

3
AttractorKernel.hpp

@ -25,6 +25,9 @@ public:
virtual unsigned int dimension() const = 0;
// dtor, default is generally good
virtual ~AttractorKernel() {};
};
#endif // ATTRACTORKERNEL_HPP

4
defines.hpp

@ -1,7 +1,7 @@
//TODO: do this with files
#define ATTRACTOR_FILE "attractors/testLorenz.stf"
#define ATTRACTOR_FILE "attractors/testPolynomial.stf"
#ifdef UNI_BUILD
#warning Building for the RU, are you sure?
@ -11,5 +11,5 @@
#else
#define WIDTH 800
#define HEIGHT 800
#define ITERATIONS 20000
#define ITERATIONS 1000000
#endif

25
kernels/KernelBasicParameter.cpp

@ -8,12 +8,27 @@
*/
#include "KernelBasicParameter.hpp"
#include <iostream>
#pragma mark -
#pragma mark Memory managment
KernelBasicParameter::KernelBasicParameter(const unsigned int numberOfParameters):
myNumberOfParameters(numberOfParameters){
init();
}
void KernelBasicParameter::resetNumberOfParameters(const unsigned int numberOfParameters){
dealloc();
myNumberOfParameters = numberOfParameters;
init();
}
KernelBasicParameter::~KernelBasicParameter(){
dealloc();
}
void KernelBasicParameter::init(){
parameters = new double[myNumberOfParameters];
@ -22,14 +37,14 @@ void KernelBasicParameter::init(){
}
}
void KernelBasicParameter::resetNumberOfParameters(const unsigned int numberOfParameters){
void KernelBasicParameter::dealloc(){
delete parameters;
myNumberOfParameters = numberOfParameters;
init();
}
#pragma mark -
#pragma mark Implementation
double & KernelBasicParameter::operator[](const unsigned int index){
return parameters[index];
}

3
kernels/KernelBasicParameter.hpp

@ -20,14 +20,15 @@ class KernelBasicParameter : virtual public AttractorKernel {
private:
void init();
void dealloc();
protected:
unsigned int myNumberOfParameters;
double * parameters;
KernelBasicParameter(const unsigned int numberOfParameters);
virtual ~KernelBasicParameter();
void resetNumberOfParameters(const unsigned int numberOfParameters);

26
kernels/KernelBasicVector.cpp

@ -8,17 +8,39 @@
*/
#include "KernelBasicVector.hpp"
#include <iostream>
#pragma mark -
#pragma mark Memory Managment
KernelBasicVector::KernelBasicVector(const unsigned int dimension):
myDimension(dimension){
vectorNew = new double[dimension];
vectorOld = new double[dimension];
init();
}
KernelBasicVector::~KernelBasicVector(){
dealloc();
}
void KernelBasicVector::init(){
vectorNew = new double[myDimension];
vectorOld = new double[myDimension];
for ( unsigned int i = 0; i < myDimension; i++ ) {
vectorNew[i] = vectorOld[i] = 0.0;
}
}
void KernelBasicVector::dealloc(){
delete vectorOld;
delete vectorNew;
}
#pragma mark -
#pragma mark Implementation
double * & KernelBasicVector::vector(){
return vectorNew;
}

5
kernels/KernelBasicVector.hpp

@ -17,6 +17,10 @@
you can easily use the constructor to initialise the vectors and stuff...
*/
class KernelBasicVector : virtual public AttractorKernel {
private:
void init();
void dealloc();
protected:
@ -26,6 +30,7 @@ protected:
double * vectorOld;
KernelBasicVector(const unsigned int dimension);
virtual ~KernelBasicVector();
public:

2
kernels/Logistic.hpp

@ -4,7 +4,7 @@
#include "KernelBasicParameter.hpp"
#include "KernelBasicVector.hpp"
class Logistic : virtual public KernelBasicParameter, virtual public KernelBasicVector {
class Logistic : public KernelBasicParameter, public KernelBasicVector {
private:
void init();

2
kernels/Lorenz3D.hpp

@ -4,7 +4,7 @@
#include "KernelBasicParameter.hpp"
#include "KernelBasicVector.hpp"
class Lorenz3D : virtual public KernelBasicParameter, virtual public KernelBasicVector {
class Lorenz3D : public KernelBasicParameter, public KernelBasicVector {
private:
void init();

11
kernels/Polynomial.cpp

@ -30,6 +30,7 @@ void Polynomial::init() {
KernelBasicParameter::resetNumberOfParameters(number);
}
// i want to has constexpr, so the ctor can be clean :]
unsigned int Polynomial::calculateNumberOfParameters() {
double n_coef = orde + 1;
for (unsigned int i = 2; i <= myDimension; i++) {
@ -46,10 +47,6 @@ void Polynomial::operator()() {
unsigned int m = 0;
for ( unsigned int i = 0; i < myDimension; i++ ) {
#ifdef HARDDEBUG
cout << "Entering new dimension: " << i << " With m = " << m << endl;
#endif
vectorNew[i] = parameters[m];
m++;
recur(i, 0, 1, m);
@ -61,12 +58,6 @@ void Polynomial::recur(unsigned int curr_dimension, unsigned int prev_i, unsigne
double product;
for (unsigned int i = prev_i; i < myDimension; i++) {
#ifdef HARDDEBUG
for ( unsigned int j = 0; j < n; j++ )
cout << " ";
cout << "Calculation in dimension: " << i << " With m = " << m << " And depth = " << n << endl;
#endif
product = prev_product * vectorOld[i];
vectorNew[curr_dimension] += parameters[m] * product;
m++;

2
kernels/Polynomial.hpp

@ -4,7 +4,7 @@
#include "KernelBasicParameter.hpp"
#include "KernelBasicVector.hpp"
class Polynomial : virtual public KernelBasicParameter, virtual public KernelBasicVector {
class Polynomial : public KernelBasicParameter, public KernelBasicVector {
private:
unsigned int orde;

2
kernels/PolynomialA3D.hpp

@ -4,7 +4,7 @@
#include "KernelBasicParameter.hpp"
#include "KernelBasicVector.hpp"
class PolynomialA3D : virtual public KernelBasicParameter, virtual public KernelBasicVector {
class PolynomialA3D : public KernelBasicParameter, public KernelBasicVector {
private:
void init();

2
kernels/Unravel3D.hpp

@ -4,7 +4,7 @@
#include "KernelBasicParameter.hpp"
#include "KernelBasicVector.hpp"
class Unravel3D : virtual public KernelBasicParameter, virtual public KernelBasicVector {
class Unravel3D : public KernelBasicParameter, public KernelBasicVector {
public:
Unravel3D();