From 487f00d8e4c05987ced8a40dec23a8c42cc2607e Mon Sep 17 00:00:00 2001 From: Nevik Rehnel Date: Wed, 18 Sep 2013 13:35:47 +0200 Subject: [PATCH] Add filtered operators and initializer --- eo/src/eoFilterMonOp.h | 75 +++++++++++++++++++++++++++++++++++++++ eo/src/eoFilterQuadOp.h | 77 +++++++++++++++++++++++++++++++++++++++++ eo/src/eoInitFilter.h | 75 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 227 insertions(+) create mode 100644 eo/src/eoFilterMonOp.h create mode 100644 eo/src/eoFilterQuadOp.h create mode 100644 eo/src/eoInitFilter.h diff --git a/eo/src/eoFilterMonOp.h b/eo/src/eoFilterMonOp.h new file mode 100644 index 000000000..50b10c91d --- /dev/null +++ b/eo/src/eoFilterMonOp.h @@ -0,0 +1,75 @@ +/* Software License Agreement (GNU GPLv3) + * + * Copyright (C) 2013 Patrick Lehner + * + * This program 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. + * + * This program 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 this program. If not, see . + */ + +#ifndef EO_FILTERMONOP_H +#define EO_FILTERMONOP_H + +// C++ library includes +#include +#include + +// EO library includes +#include // eo general include +#include + +template< class EOT > +class eoFilterMonOp: public eoMonOp< EOT > +{ + public: + typedef bool(*FilterFuncPtr)(const EOT&); + + eoFilterMonOp(eoMonOp* actualOp_) : + eoMonOp< EOT >(), actualOp(actualOp_) + {} + + virtual ~eoFilterMonOp() {} + + bool operator()(EOT& _eo1) { + EOT eo2(_eo1); + + if (!(*actualOp)(eo2)) + return false; + + bool accepted = true; + for (FilterFuncPtr fp : filters) + if ( !(*fp)(eo2) ) { + accepted = false; + break; + } + + if (accepted) { + _eo1 = eo2; + return true; + } else { + return false; + } + } + + bool add(FilterFuncPtr fp) { + if (!fp) + return false; + filters.push_back(fp); + return true; + } + + private: + eoMonOp* actualOp; + std::vector filters; +}; + +#endif // SOPARS_EO_FILTERMONOP_HPP diff --git a/eo/src/eoFilterQuadOp.h b/eo/src/eoFilterQuadOp.h new file mode 100644 index 000000000..245293b0c --- /dev/null +++ b/eo/src/eoFilterQuadOp.h @@ -0,0 +1,77 @@ +/* Software License Agreement (GNU GPLv3) + * + * Copyright (C) 2013 Patrick Lehner + * + * This program 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. + * + * This program 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 this program. If not, see . + */ + +#ifndef EO_FILTERQUADOP_H +#define EO_FILTERQUADOP_H + +// C++ library includes +#include +#include + +// EO library includes +#include // eo general include +#include + +template< class EOT > +class eoFilterQuadOp: public eoQuadOp< EOT > +{ + public: + typedef bool(*FilterFuncPtr)(const EOT&); + + eoFilterQuadOp(eoQuadOp* actualOp_) : + eoQuadOp< EOT >(), actualOp(actualOp_) + {} + + virtual ~eoFilterQuadOp() {} + + bool operator()(EOT& _eo1, EOT& _eo2) { + EOT cpeo1(_eo1); + EOT cpeo2(_eo2); + + if (!(*actualOp)(cpeo1, cpeo2)) + return false; + + bool accepted = true; + for (FilterFuncPtr fp : filters) + if ( !(*fp)(cpeo1) || !(*fp)(cpeo2) ) { + accepted = false; + break; + } + + if (accepted) { + _eo1 = cpeo1; + _eo2 = cpeo2; + return true; + } else { + return false; + } + } + + bool add(FilterFuncPtr fp) { + if (!fp) + return false; + filters.push_back(fp); + return true; + } + + private: + eoQuadOp* actualOp; + std::vector filters; +}; + +#endif // SOPARS_EO_FILTERQUADOP_HPP diff --git a/eo/src/eoInitFilter.h b/eo/src/eoInitFilter.h new file mode 100644 index 000000000..1687f1e1a --- /dev/null +++ b/eo/src/eoInitFilter.h @@ -0,0 +1,75 @@ +/* Software License Agreement (GNU GPLv3) + * + * Copyright (C) 2013 Patrick Lehner + * + * This program 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. + * + * This program 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 this program. If not, see . + */ + +#ifndef EO_INITFILTER_H +#define EO_INITFILTER_H + +// C++ library includes +#include +#include + +// EO library includes +#include // eo general include +#include + +template +class eoInitFilter : public eoInit { + + public: + typedef bool(*FilterFuncPtr)(const EOT&); + + eoInitFilter(eoInit* actualInit_) : + eoInit(), actualInit(actualInit_) + { + if (!actualInit_) + std::cerr << "ERROR: No actual initializer given for eoInitFilter" << std::endl; + } + + /// My class name + virtual std::string className() const { return "eoInteractiveInit"; }; + + void operator()(EOT& _eo) + { + bool accepted = false; + + while (!accepted) { + (*actualInit)(_eo); + + accepted = true; + for (FilterFuncPtr fp : filters) + if ( !(*fp)(_eo) ) { + accepted = false; + break; + } + } + } + + bool add(FilterFuncPtr fp) { + if (!fp) + return false; + filters.push_back(fp); + return true; + } + + private: + eoInit* actualInit; + std::vector filters; + +}; + +#endif // SOPARS_EO_INITFILTER_HPP