2014-02-06 18:52:13 +00:00
|
|
|
/*
|
|
|
|
* Function.hpp, part of LatAnalyze 3
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 - 2014 Antonin Portelli
|
|
|
|
*
|
|
|
|
* LatAnalyze 3 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* LatAnalyze 3 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with LatAnalyze 3. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef Latan_Function_hpp_
|
|
|
|
#define Latan_Function_hpp_
|
2014-01-30 19:28:30 +00:00
|
|
|
|
|
|
|
#include <latan/Global.hpp>
|
2014-02-13 19:23:39 +00:00
|
|
|
#include <functional>
|
|
|
|
#include <memory>
|
2014-01-30 19:28:30 +00:00
|
|
|
#include <stack>
|
|
|
|
#include <vector>
|
|
|
|
#include <cstdarg>
|
|
|
|
|
2014-02-06 18:52:13 +00:00
|
|
|
BEGIN_NAMESPACE
|
2014-01-30 19:28:30 +00:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Base function class *
|
|
|
|
******************************************************************************/
|
|
|
|
class Function
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// constructor/destructor
|
|
|
|
explicit Function(const unsigned nArg);
|
2014-02-06 18:07:27 +00:00
|
|
|
virtual ~Function(void);
|
2014-01-30 19:28:30 +00:00
|
|
|
// access
|
2014-02-06 18:07:27 +00:00
|
|
|
unsigned int getNArg(void) const;
|
2014-01-30 19:28:30 +00:00
|
|
|
private:
|
|
|
|
const unsigned int nArg_;
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Double function class *
|
|
|
|
******************************************************************************/
|
|
|
|
class DoubleFunction: public Function
|
|
|
|
{
|
2014-02-12 18:32:08 +00:00
|
|
|
private:
|
2014-02-13 19:23:39 +00:00
|
|
|
typedef std::function<double(const std::vector<double> &)> vecFunc;
|
2014-01-30 19:28:30 +00:00
|
|
|
public:
|
|
|
|
// constructor/destructor
|
2014-02-13 19:23:39 +00:00
|
|
|
explicit DoubleFunction(const unsigned nArg, vecFunc f = nullptr);
|
2014-01-30 19:28:30 +00:00
|
|
|
virtual ~DoubleFunction(void);
|
|
|
|
// function call
|
2014-02-12 18:32:08 +00:00
|
|
|
virtual double evaluate(const std::vector<double> &arg) const;
|
|
|
|
double operator()(std::stack<double> &arg) const;
|
|
|
|
double operator()(const double x0, ...) const;
|
2014-01-30 19:28:30 +00:00
|
|
|
private:
|
2014-02-13 19:23:39 +00:00
|
|
|
std::shared_ptr<std::vector<double>> buffer_;
|
|
|
|
vecFunc f_;
|
2014-01-30 19:28:30 +00:00
|
|
|
};
|
|
|
|
|
2014-02-06 18:52:13 +00:00
|
|
|
END_NAMESPACE
|
2014-01-30 19:28:30 +00:00
|
|
|
|
2014-02-06 18:52:13 +00:00
|
|
|
#endif // Latan_Function_hpp_
|