Page MenuHomec4science

Function.hpp
No OneTemporary

File Metadata

Created
Wed, May 22, 15:20

Function.hpp

/*
* Created by Tristan Liardon on 02.12.2018.
*
* A function object that needs a pointer to a user defined function. This allows the user defined function to be called
* using a simple syntax FunctionObject.GetResult(input) from everywhere without risking mistakes in the complex
* writing of the function pointer argument.
*
* For using a function-object :
* - Create a method that accepts vector<double> and return a double
* - Create a pointer to the method created above. You can use the following syntax :
* double (*functionPointer)(vector<double>) = &myFunction;
* - Gives functionPointer as arguments to the Function's constructor
*
*/
#ifndef PCSC_PROJET_FUNCTION_HPP
#define PCSC_PROJET_FUNCTION_HPP
#include <vector>
#include <cmath>
#include "OutOfRangeException.hpp"
#include "Exception.hpp"
using namespace std;
class Function {
public:
// Constructor and destructor
Function();
explicit Function(double (*functionPointer_)(vector<double>));
virtual ~Function();
// Get result function
double GetResult(vector<double> input);
private:
double(*functionPointer)(vector<double>); // Pointer to the user-defined function
};
#endif //PCSC_PROJET_FUNCTION_HPP

Event Timeline