Skip to content
Snippets Groups Projects
Commit 0baedf77 authored by Sacha Percot-Tétu's avatar Sacha Percot-Tétu
Browse files

Improved the conception of operations set

parent 3f82bc0c
No related branches found
No related tags found
No related merge requests found
/*
* Copyright 2011-2012 INSA Rennes
*
* This file is part of EIImage.
*
* EIImage 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.
*
* EIImage 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 EIImage. If not, see <http://www.gnu.org/licenses/>.
*/
#include "BuiltinOpSet.h"
BuiltinOpSet::BuiltinOpSet(std::string name) : OpSet(name) {
}
std::vector<Operation*> BuiltinOpSet::getOperations() {
return _operations;
}
void BuiltinOpSet::addOperation(Operation* operation) {
_operations.push_back(operation);
}
/*
* Copyright 2011-2012 INSA Rennes
*
* This file is part of EIImage.
*
* EIImage 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.
*
* EIImage 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 EIImage. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef EIIMAGE_BUILTINOPSET_H
#define EIIMAGE_BUILTINOPSET_H
#include <string>
#include <vector>
#include "OpSet.h"
class BuiltinOpSet : public OpSet {
public:
BuiltinOpSet(std::string name);
std::vector<Operation*> getOperations();
protected:
void addOperation(Operation*);
private:
std::vector<Operation*> _operations;
};
#endif //!EIIMAGE_BUILTINOPSET_H
......@@ -23,67 +23,23 @@
#include <vector>
#include <string>
#include "Input.h"
#include "Parameter.h"
#include "Output.h"
#include "Image.h"
class QWidget;
struct CurrentImg {
};
class Operation {
private:
template<class D, class B> struct Derived_from {
static void constraints(D* p) { B* pb = p; }
Derived_from() { void(*p)(D*) = constraints; }
};
public:
Operation(std::string name);
Operation(std::string name) : _name(name) {}
std::vector<QWidget*> operator()(const imagein::Image*);
std::string getName();
inline bool needCurrentImg() { return _needCurrentImg; }
protected:
virtual void operation() = 0;
void addInput(Input* input);
void addInput(const Input& input);
void addOutput(const Output& output);
template<typename T, class C>
void addParam(const Parameter<T>& param, T C::* ptr) {
Derived_from<C, Operation>();
C* object = dynamic_cast<C*>(this);
if(object==NULL) {
throw "The parameter's pointer doesn't belong to the class which add it";
}
Parameter<T>* newParam = param.clone();
newParam->_ptr = &(object->*ptr);
this->_inputs.push_back(newParam);
}
virtual std::vector<QWidget*> operator()(const imagein::Image*, const std::vector<const imagein::Image*>&) = 0;
inline std::string getName() { return _name; };
template<class C>
void addParam(const CurrentImg&, imagein::Image C::* ptr) {
Derived_from<C, Operation>();
C* object = dynamic_cast<C*>(this);
if(object==NULL) {
throw "The parameter's pointer doesn't belong to the class which add it";
}
_needCurrentImg = true;
_currentImg = &(object->*ptr);
}
virtual bool needCurrentImg() = 0;
private:
std::string _name;
std::vector<Input*> _inputs;
std::vector<Output*> _outputs;
bool _needCurrentImg;
imagein::Image* _currentImg;
};
#endif //!EIIMAGE_OPERATION_H
\ No newline at end of file
#endif //!EIIMAGE_OPERATION_H
......@@ -37,8 +37,8 @@ class Parameter : public Input {
T* _ptr;
std::string _name;
friend class Operation;
friend class PlugOperation;
};
#endif //!EIIMAGE_PARAMETER_H
\ No newline at end of file
#endif //!EIIMAGE_PARAMETER_H
......@@ -22,33 +22,29 @@
#include <QVBoxLayout>
#include <QPushButton>
#include "Operation.h"
#include "PlugOperation.h"
using namespace std;
using namespace imagein;
Operation::Operation(string name) : _name(name), _needCurrentImg(false), _currentImg(NULL) {
PlugOperation::PlugOperation(string name) : Operation(name), _needCurrentImg(false), _currentImg(NULL) {
}
std::string Operation::getName() {
return _name;
}
void Operation::addInput(Input* input) {
void PlugOperation::addInput(Input* input) {
this->_inputs.push_back(input);
}
void Operation::addInput(const Input& input) {
void PlugOperation::addInput(const Input& input) {
this->_inputs.push_back(input.clone());
}
void Operation::addOutput(const Output& output) {
void PlugOperation::addOutput(const Output& output) {
_outputs.push_back(output.clone());
}
std::vector<QWidget*> Operation::operator()(const Image* currentImg) {
std::vector<QWidget*> PlugOperation::operator()(const Image* currentImg, const std::vector<const Image*>&) {
vector<QWidget*> result;
if(this->needCurrentImg()) {
......@@ -92,4 +88,4 @@ std::vector<QWidget*> Operation::operator()(const Image* currentImg) {
result.push_back((*it)->getWidget());
}
return result;
}
\ No newline at end of file
}
/*
* Copyright 2011-2012 INSA Rennes
*
* This file is part of EIImage.
*
* EIImage 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.
*
* EIImage 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 EIImage. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef EIIMAGE_PLUGOPERATION_H
#define EIIMAGE_PLUGOPERATION_H
#include <vector>
#include <string>
#include "Input.h"
#include "Parameter.h"
#include "Output.h"
#include "Image.h"
#include "Operation.h"
class QWidget;
struct CurrentImg {
};
class PlugOperation : public Operation {
private:
template<class D, class B> struct Derived_from {
static void constraints(D* p) { B* pb = p; }
Derived_from() { void(*p)(D*) = constraints; }
};
public:
PlugOperation(std::string name);
std::vector<QWidget*> operator()(const imagein::Image*, const std::vector<const imagein::Image*>&);
inline bool needCurrentImg() { return _needCurrentImg; }
protected:
virtual void operation() = 0;
void addInput(Input* input);
void addInput(const Input& input);
void addOutput(const Output& output);
template<typename T, class C>
void addParam(const Parameter<T>& param, T C::* ptr) {
Derived_from<C, Operation>();
C* object = dynamic_cast<C*>(this);
if(object==NULL) {
throw "The parameter's pointer doesn't belong to the class which add it";
}
Parameter<T>* newParam = param.clone();
newParam->_ptr = &(object->*ptr);
this->_inputs.push_back(newParam);
}
template<class C>
void addParam(const CurrentImg&, imagein::Image C::* ptr) {
Derived_from<C, Operation>();
C* object = dynamic_cast<C*>(this);
if(object==NULL) {
throw "The parameter's pointer doesn't belong to the class which add it";
}
_needCurrentImg = true;
_currentImg = &(object->*ptr);
}
private:
std::vector<Input*> _inputs;
std::vector<Output*> _outputs;
bool _needCurrentImg;
imagein::Image* _currentImg;
};
#endif //!EIIMAGE_OPERATION_H
......@@ -19,17 +19,13 @@
#include "Plugin.h"
Plugin::Plugin(std::string name) : _name(name) {
}
std::string Plugin::getName() {
return _name;
Plugin::Plugin(std::string name) : OpSet(name) {
}
std::vector<Operation*> Plugin::getOperations() {
return _operations;
}
void Plugin::addOperation(Operation* operation) {
void Plugin::addOperation(PlugOperation* operation) {
_operations.push_back(operation);
}
\ No newline at end of file
}
......@@ -23,20 +23,17 @@
#include <string>
#include <vector>
#include "Operation.h"
#include "OpSet.h"
#include "PlugOperation.h"
class Plugin {
class Plugin : public OpSet {
public:
Plugin(std::string name);
std::vector<Operation*> getOperations();
std::string getName();
protected:
void addOperation(Operation*);
void addOperation(PlugOperation*);
private:
std::vector<Operation*> _operations;
std::string _name;
};
#endif //!EIIMAGE_PLUGIN_H
\ No newline at end of file
#endif //!EIIMAGE_PLUGIN_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment