Joshua Moerman
15 years ago
18 changed files with 150 additions and 259 deletions
@ -0,0 +1,89 @@ |
|||
/*
|
|||
* AttractorKernel.cpp |
|||
* AwesomeAttractor |
|||
* |
|||
* Created by Joshua Moerman on 07-08-10. |
|||
* Copyright 2010 Rodo. All rights reserved. |
|||
* |
|||
*/ |
|||
|
|||
#include "AttractorKernel.hpp" |
|||
#include <algorithm> |
|||
#include <iostream> |
|||
|
|||
#pragma mark - |
|||
#pragma mark memory |
|||
|
|||
AttractorKernel::AttractorKernel(const unsigned int dimension, const unsigned int numberOfParameters): |
|||
numberOfParameters(numberOfParameters), dimension(dimension) { |
|||
|
|||
try { |
|||
parameters = new double[numberOfParameters]; |
|||
|
|||
vectorNew = new double[dimension]; |
|||
vectorOld = new double[dimension]; |
|||
} catch (std::bad_alloc& e) { |
|||
std::cerr << "Exception: " << e.what() << std::endl; |
|||
std::cerr << "Quiting because nothing to do... " << std::endl; |
|||
exit(1); |
|||
} |
|||
|
|||
std::fill_n(parameters, numberOfParameters, 0.0); |
|||
std::fill_n(vectorNew, dimension, 0.0); |
|||
std::fill_n(vectorOld, dimension, 0.0); |
|||
|
|||
} |
|||
|
|||
AttractorKernel::~AttractorKernel(){ |
|||
delete[] vectorOld; |
|||
delete[] vectorNew; |
|||
delete[] parameters; |
|||
} |
|||
|
|||
void AttractorKernel::reallocParameters(const unsigned int newNumberOfParameters){ |
|||
delete[] parameters; |
|||
|
|||
numberOfParameters = newNumberOfParameters; |
|||
|
|||
try { |
|||
parameters = new double[numberOfParameters]; |
|||
} |
|||
catch (std::bad_alloc& e) { |
|||
std::cerr << "Exception: " << e.what() << std::endl; |
|||
std::cerr << "Quiting because nothing to do... " << std::endl; |
|||
exit(1); |
|||
} |
|||
|
|||
std::fill_n(parameters, numberOfParameters, 0.0); |
|||
} |
|||
|
|||
#pragma mark - |
|||
#pragma mark parameters |
|||
|
|||
double & AttractorKernel::operator[](const unsigned int index){ |
|||
return parameters[index]; |
|||
} |
|||
|
|||
double const & AttractorKernel::operator[](const unsigned int index) const{ |
|||
return parameters[index]; |
|||
} |
|||
|
|||
unsigned int AttractorKernel::getNumberOfParameters() const{ |
|||
return numberOfParameters; |
|||
} |
|||
|
|||
#pragma mark - |
|||
#pragma mark vector |
|||
|
|||
double const * AttractorKernel::vector() const{ |
|||
return vectorNew; |
|||
} |
|||
|
|||
double const * AttractorKernel::previousVector() const{ |
|||
return vectorOld; |
|||
} |
|||
|
|||
unsigned int AttractorKernel::getDimension() const{ |
|||
return dimension; |
|||
} |
|||
|
@ -1,58 +0,0 @@ |
|||
/*
|
|||
* KernelBasicParameter.cpp |
|||
* AwesomeAttractor |
|||
* |
|||
* Created by Joshua Moerman on 18-07-10. |
|||
* Copyright 2010 Rodo. All rights reserved. |
|||
* |
|||
*/ |
|||
|
|||
#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]; |
|||
|
|||
for ( unsigned int i = 0; i < myNumberOfParameters; i++ ) { |
|||
parameters[i] = 0.0; |
|||
} |
|||
} |
|||
|
|||
void KernelBasicParameter::dealloc(){ |
|||
delete[] parameters; |
|||
} |
|||
|
|||
|
|||
#pragma mark - |
|||
#pragma mark Implementation |
|||
|
|||
double & KernelBasicParameter::operator[](const unsigned int index){ |
|||
return parameters[index]; |
|||
} |
|||
|
|||
double const & KernelBasicParameter::operator[](const unsigned int index) const{ |
|||
return parameters[index]; |
|||
} |
|||
|
|||
unsigned int KernelBasicParameter::numberOfParameters() const{ |
|||
return myNumberOfParameters; |
|||
} |
@ -1,46 +0,0 @@ |
|||
/*
|
|||
* KernelBasicParameter.hpp |
|||
* AwesomeAttractor |
|||
* |
|||
* Created by Joshua Moerman on 18-07-10. |
|||
* Copyright 2010 Rodo. All rights reserved. |
|||
* |
|||
*/ |
|||
|
|||
#ifndef KERNELBASICPARAMETER_HPP |
|||
#define KERNELBASICPARAMETER_HPP |
|||
|
|||
#include "../AttractorKernel.hpp" |
|||
|
|||
/*
|
|||
This is a partial default implementation of the abstract AttractorKernel class |
|||
you can easily use the constructor to initialise the parameters and stuff... |
|||
*/ |
|||
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); |
|||
|
|||
public: |
|||
|
|||
// parameters are stored in a array of doubles
|
|||
// if you want to use other types, use the properties
|
|||
virtual double & operator[](const unsigned int index); |
|||
virtual double const & operator[](const unsigned int index) const; |
|||
|
|||
virtual unsigned int numberOfParameters() const; |
|||
|
|||
}; |
|||
|
|||
#endif |
@ -1,55 +0,0 @@ |
|||
/*
|
|||
* KernelBasicVector.cpp |
|||
* AwesomeAttractor |
|||
* |
|||
* Created by Joshua Moerman on 18-07-10. |
|||
* Copyright 2010 Rodo. All rights reserved. |
|||
* |
|||
*/ |
|||
|
|||
#include "KernelBasicVector.hpp" |
|||
#include <iostream> |
|||
|
|||
|
|||
#pragma mark - |
|||
#pragma mark Memory Managment |
|||
|
|||
KernelBasicVector::KernelBasicVector(const unsigned int dimension): |
|||
myDimension(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; |
|||
} |
|||
|
|||
double * & KernelBasicVector::previousVector(){ |
|||
return vectorOld; |
|||
} |
|||
|
|||
unsigned int KernelBasicVector::dimension() const{ |
|||
return myDimension; |
|||
} |
|||
|
@ -1,45 +0,0 @@ |
|||
/*
|
|||
* KernelBasicVector.hpp |
|||
* AwesomeAttractor |
|||
* |
|||
* Created by Joshua Moerman on 18-07-10. |
|||
* Copyright 2010 Rodo. All rights reserved. |
|||
* |
|||
*/ |
|||
|
|||
#ifndef KERNELBASICVECTOR_HPP |
|||
#define KERNELBASICVECTOR_HPP |
|||
|
|||
#include "../AttractorKernel.hpp" |
|||
|
|||
/*
|
|||
This is a partial default implementation of the abstract AttractorKernel class |
|||
you can easily use the constructor to initialise the vectors and stuff... |
|||
*/ |
|||
class KernelBasicVector : virtual public AttractorKernel { |
|||
private: |
|||
|
|||
void init(); |
|||
void dealloc(); |
|||
|
|||
protected: |
|||
|
|||
unsigned int myDimension; |
|||
|
|||
double * vectorNew; |
|||
double * vectorOld; |
|||
|
|||
KernelBasicVector(const unsigned int dimension); |
|||
virtual ~KernelBasicVector(); |
|||
|
|||
public: |
|||
|
|||
// getter functions for teh resulta (can be used as setters, and it may be used as such)
|
|||
virtual double * & vector(); |
|||
virtual double * & previousVector(); |
|||
|
|||
virtual unsigned int dimension() const; |
|||
|
|||
}; |
|||
|
|||
#endif |
Reference in new issue