/* * AttractorKernel.cpp * AwesomeAttractor * * Created by Joshua Moerman on 07-08-10. * Copyright 2010 Rodo. All rights reserved. * */ #include "AttractorKernel.hpp" #include #include #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; }