Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filtered operators and initializer #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions eo/src/eoFilterMonOp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* Software License Agreement (GNU GPLv3)
*
* Copyright (C) 2013 Patrick Lehner <[email protected]>
*
* 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 changes: 77 additions & 0 deletions eo/src/eoFilterQuadOp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/* Software License Agreement (GNU GPLv3)
*
* Copyright (C) 2013 Patrick Lehner <[email protected]>
*
* 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 changes: 75 additions & 0 deletions eo/src/eoInitFilter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* Software License Agreement (GNU GPLv3)
*
* Copyright (C) 2013 Patrick Lehner <[email protected]>
*
* 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