Add filtered operators and initializer

This commit is contained in:
Nevik Rehnel 2013-09-18 13:35:47 +02:00
commit 487f00d8e4
3 changed files with 227 additions and 0 deletions

75
eo/src/eoFilterMonOp.h Normal file
View file

@ -0,0 +1,75 @@
/* Software License Agreement (GNU GPLv3)
*
* Copyright (C) 2013 Patrick Lehner <lehner.patrick@gmx.de>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef EO_FILTERMONOP_H
#define EO_FILTERMONOP_H
// C++ library includes
#include <iostream>
#include <vector>
// EO library includes
#include <eo> // eo general include
#include <eoOp.h>
template< class EOT >
class eoFilterMonOp: public eoMonOp< EOT >
{
public:
typedef bool(*FilterFuncPtr)(const EOT&);
eoFilterMonOp(eoMonOp<EOT>* 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<EOT>* actualOp;
std::vector<FilterFuncPtr> filters;
};
#endif // SOPARS_EO_FILTERMONOP_HPP

77
eo/src/eoFilterQuadOp.h Normal file
View file

@ -0,0 +1,77 @@
/* Software License Agreement (GNU GPLv3)
*
* Copyright (C) 2013 Patrick Lehner <lehner.patrick@gmx.de>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef EO_FILTERQUADOP_H
#define EO_FILTERQUADOP_H
// C++ library includes
#include <iostream>
#include <vector>
// EO library includes
#include <eo> // eo general include
#include <eoOp.h>
template< class EOT >
class eoFilterQuadOp: public eoQuadOp< EOT >
{
public:
typedef bool(*FilterFuncPtr)(const EOT&);
eoFilterQuadOp(eoQuadOp<EOT>* 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<EOT>* actualOp;
std::vector<FilterFuncPtr> filters;
};
#endif // SOPARS_EO_FILTERQUADOP_HPP

75
eo/src/eoInitFilter.h Normal file
View file

@ -0,0 +1,75 @@
/* Software License Agreement (GNU GPLv3)
*
* Copyright (C) 2013 Patrick Lehner <lehner.patrick@gmx.de>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef EO_INITFILTER_H
#define EO_INITFILTER_H
// C++ library includes
#include <iostream>
#include <vector>
// EO library includes
#include <eo> // eo general include
#include <eoInit.h>
template<class EOT>
class eoInitFilter : public eoInit<EOT> {
public:
typedef bool(*FilterFuncPtr)(const EOT&);
eoInitFilter(eoInit<EOT>* actualInit_) :
eoInit<EOT>(), 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<EOT>* actualInit;
std::vector<FilterFuncPtr> filters;
};
#endif // SOPARS_EO_INITFILTER_HPP