From 146b3c99ccbb5e92c5124012a070ee946e490c8d Mon Sep 17 00:00:00 2001 From: fpaparel Date: Mon, 13 Feb 2006 11:32:05 +0000 Subject: [PATCH] - Now all backend classes are present (not all complete) - Can't compile when trying to link with Python + check -pedantic parameter + when compiling main.cc there is no -I/..../Python parameter git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@321 3ecf2c5c-341e-0410-92b4-d18e462d057c --- src/backend/Makefile.am | 6 + src/backend/policy.cc | 16 +++ src/backend/policy.hh | 21 ++- src/backend/policy_manager.cc | 27 ++++ src/backend/policy_manager.hh | 45 +++++++ src/backend/policy_parameters.cc | 195 +++++++++++++++++++++++++++ src/backend/policy_parameters.hh | 71 ++++++++-- src/backend/python_policy.cc | 40 ++++++ src/backend/python_policy.hh | 61 +++++++++ src/backend/python_policy_manager.cc | 52 +++++++ src/backend/python_policy_manager.hh | 54 ++++++++ src/backend/schedulable_list.cc | 11 +- src/backend/scheduler.cc | 4 +- src/backend/scheduler.hh | 2 +- src/main.cc | 34 +++-- src/templates/parameter.tcc | 90 +++++++++++++ 16 files changed, 699 insertions(+), 30 deletions(-) create mode 100644 src/backend/policy_manager.cc create mode 100644 src/backend/policy_manager.hh create mode 100644 src/backend/python_policy.cc create mode 100644 src/backend/python_policy.hh create mode 100644 src/backend/python_policy_manager.cc create mode 100644 src/backend/python_policy_manager.hh create mode 100644 src/templates/parameter.tcc diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am index 6f3a047..a68b54e 100644 --- a/src/backend/Makefile.am +++ b/src/backend/Makefile.am @@ -50,8 +50,11 @@ libbackend_la_SOURCES = \ history.cc \ observed_subject.cc \ policy.cc \ + policy_manager.cc \ policy_parameters.cc \ process.cc \ + python_policy.cc \ + python_policy_manager.cc \ schedulable.cc \ schedulable_list.cc \ schedulable_status.cc \ @@ -63,8 +66,11 @@ noinst_HEADERS = \ history.hh \ observed_subject.hh \ policy.hh \ + policy_manager.hh \ policy_parameters.hh \ process.hh \ + python_policy.hh \ + python_policy_manager.hh \ schedulable.hh \ schedulable_list.hh \ schedulable_status.hh \ diff --git a/src/backend/policy.cc b/src/backend/policy.cc index e73a891..bfbda82 100644 --- a/src/backend/policy.cc +++ b/src/backend/policy.cc @@ -23,3 +23,19 @@ using namespace std; using namespace sgpem; using namespace memory; +Policy::~Policy() +{ +} + +int +Policy::get_id() const +{ + return _id; +} + + +const PolicyParameters& +Policy::get_parameters() const +{ + return _parameters; +} \ No newline at end of file diff --git a/src/backend/policy.hh b/src/backend/policy.hh index c5976d3..f76f4fa 100644 --- a/src/backend/policy.hh +++ b/src/backend/policy.hh @@ -22,7 +22,11 @@ #define POLICY_HH 1 #include "config.h" + +#include "glibmm/ustring.h" + #include "scheduler.hh" +#include "policy_parameters.hh" namespace sgpem { @@ -36,12 +40,21 @@ namespace sgpem class SG_DLLEXPORT Policy { public: - void sort_queue(sgpem::Scheduler::event) {} - bool is_pre_emptive() {return true;} - int get_time_slice() {return 2;} + virtual ~Policy(); + + virtual void configure() = 0; + virtual void sort_queue(sgpem::Scheduler::event) const = 0; + int get_id() const; + virtual Glib::ustring get_description() const = 0; + virtual bool is_pre_emptive() const = 0; + virtual int get_time_slice() const = 0; + virtual void set_time_slice(const int&) = 0; + const PolicyParameters& get_parameters() const; + private: - + PolicyParameters _parameters; + int _id; }; }//~ namespace sgpem diff --git a/src/backend/policy_manager.cc b/src/backend/policy_manager.cc new file mode 100644 index 0000000..27a4a94 --- /dev/null +++ b/src/backend/policy_manager.cc @@ -0,0 +1,27 @@ +// src/backend/policy_manager.cc - Copyright 2005, 2006, University +// of Padova, dept. of Pure and Applied +// Mathematics +// +// This file is part of SGPEMv2. +// +// This 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 2 of the License, or +// (at your option) any later version. +// +// SGPEMv2 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 SGPEMv2; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +#include "policy_manager.hh" + + +PolicyManager::~PolicyManager() +{ +} diff --git a/src/backend/policy_manager.hh b/src/backend/policy_manager.hh new file mode 100644 index 0000000..9adfe40 --- /dev/null +++ b/src/backend/policy_manager.hh @@ -0,0 +1,45 @@ +// src/backend/policy_manager.hh - Copyright 2005, 2006, University +// of Padova, dept. of Pure and Applied +// Mathematics +// +// This file is part of SGPEMv2. +// +// This 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 2 of the License, or +// (at your option) any later version. +// +// SGPEMv2 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 SGPEMv2; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +#ifndef POLICY_MANAGER_HH +#define POLICY_MANAGER_HH 1 + +#include "config.h" + +#include "policy.hh" + +namespace sgpem +{ + + + class PolicyManager; + + class SG_DLLEXPORT PolicyManager + { + public: + virtual ~PolicyManager() = 0; + + virtual Policy* get_policy() = 0; + virtual void init() = 0; + }; + +} + +#endif diff --git a/src/backend/policy_parameters.cc b/src/backend/policy_parameters.cc index 8990d38..b7d25ea 100644 --- a/src/backend/policy_parameters.cc +++ b/src/backend/policy_parameters.cc @@ -21,5 +21,200 @@ #include "policy_parameters.hh" using namespace std; using namespace sgpem; +using Glib::ustring; + +/** + Register a new parameter of type integer. + If there is a parameter with the same name and type it will be overwritten. +*/ +void +PolicyParameters::register_int(Glib::ustring name,const int& lower_bound, const int& upper_bound, const bool& required, const int& default_value) +{ + //there is a parameter with the same name!! + map >::iterator i = int_map.find(name); + if (i != int_map.end()) + int_map.erase(i); + + map >::value_type v(name, Parameter(name, default_value, lower_bound, upper_bound, required, default_value)); + int_map.insert(v); + +} + +/** + Register a new parameter of type float. + If there is a parameter with the same name and type it will be overwritten. + */ +void +PolicyParameters::register_float(Glib::ustring name,const float& lower_bound, const float& upper_bound, const bool& required, const float& default_value) +{ + //there is a parameter with the same name!! + map >::iterator i = float_map.find(name); + if (i != float_map.end()) + float_map.erase(i); + + map >::value_type v(name, Parameter(name, default_value, lower_bound, upper_bound, required, default_value)); + float_map.insert(v); +} + +/** + Register a new parameter of type string. + If there is a parameter with the same name and type it will be overwritten. + */ +void +PolicyParameters::register_string(Glib::ustring name, const bool& required, const Glib::ustring& default_value) +{ + //there is a parameter with the same name!! + map >::iterator i = string_map.find(name); + if (i != string_map.end()) + string_map.erase(i); + + map >::value_type v(name, Parameter(name, default_value, "", "", required, default_value)); + string_map.insert(v); +} + +/** + Deletes all registred parameters. +*/ + +void +PolicyParameters::clear() +{ + int_map.clear(); + float_map.clear(); + string_map.clear(); +} + +/** + Retruns a copy of the map containing all registered integer parameters. +*/ +map > +PolicyParameters::get_registered_int_parameters() const +{ + return int_map; +} + +/** + Retruns a copy of the map containing all registered float parameters. + */ +map > + PolicyParameters::get_registered_float_parameters() const +{ + return float_map; +} + +/** + Retruns a copy of the map containing all registered string parameters. + */ +map > +PolicyParameters::get_registered_string_parameters() const +{ + return string_map; +} + +/** + Tries to set the value to the parameter named "name". + \returns TRUE if the parameter named "name" has been previously registered and the value + stays in the range permitted by the parameter. + \returns FALSE in the other cases. +*/ +bool +PolicyParameters::set_int(ustring name, const int& value) +{ + map >::iterator i = int_map.find(name); + if (i == int_map.end()) + //the parameter doesn't exist!! + return false; + + if (value < i->second.get_lower_bound() || value > i->second.get_upper_bound()) + return false; + + i->second.set_value(value); + return true; +} +/** + Tries to set the value to the parameter named "name". + \returns TRUE if the parameter named "name" has been previously registered and the value + stays in the range permitted by the parameter. + \returns FALSE in the other cases. + */ +bool +PolicyParameters::set_float(ustring name, const float& value) +{ + map >::iterator i = float_map.find(name); + if (i == float_map.end()) + //the parameter doesn't exist!! + return false; + + if (value < i->second.get_lower_bound() || value > i->second.get_upper_bound()) + return false; + + i->second.set_value(value); + return true; +} + +/** + Tries to set the value to the parameter named "name". For the type "string" there are + no upper/lower bound limitations. + \returns TRUE if the parameter named "name" has been previously registered. + \returns FALSE in the other case. + */ +bool +PolicyParameters::set_string(ustring name, const ustring& value) +{ + map >::iterator i = string_map.find(name); + if (i == string_map.end()) + //the parameter doesn't exist!! + return false; + + i->second.set_value(value); + return true; +} + +/** + Looks for a parameter of integer type named "name". + \returns The value of the parameter + \throws A PolicyParametersException if the parameter has not been found. + */ +int +PolicyParameters::get_int(ustring name) const +{ + map >::const_iterator i = int_map.find(name); + if (i == int_map.end()) + throw PolicyParametersException("Unregistred parameter"); + else + return i->second.get_value(); +} + + +/** + Looks for a parameter of float type named "name". + \returns The value of the parameter + \throws A PolicyParametersException if the parameter has not been found. + */ +float +PolicyParameters::get_float(ustring name) const +{ + map >::const_iterator i = float_map.find(name); + if (i == float_map.end()) + throw PolicyParametersException("Unregistred parameter"); + else + return i->second.get_value(); +} + + +/** + Looks for a parameter of string type named "name". + \returns The value of the parameter + \throws A PolicyParametersException if the parameter has not been found. + */ +ustring +PolicyParameters::get_string(ustring name) const +{ + map >::const_iterator i = string_map.find(name); + if (i == string_map.end()) + throw PolicyParametersException("Unregistred parameter"); + else + return i->second.get_value(); +} diff --git a/src/backend/policy_parameters.hh b/src/backend/policy_parameters.hh index 056ce49..f855075 100644 --- a/src/backend/policy_parameters.hh +++ b/src/backend/policy_parameters.hh @@ -23,40 +23,95 @@ #include "config.h" +#include +#include +#include "glibmm/ustring.h" namespace sgpem { - + class PolicyParametersException : public std::runtime_error { + public: + PolicyParametersException(char* msg): std::runtime_error(msg) {} + }; class PolicyParameters; + /** \brief - + Represents all configurable parameters of a single scheduling algorithm. Is is used by the user + interface: it's useful to know which parameters the user will be asked for. + Each Policy object owns only one instance of this class. */ class SG_DLLEXPORT PolicyParameters { public: template class Parameter; + + //methods to CREATE PARAMETERS + void register_int(Glib::ustring name,const int& lower_bound, const int& upper_bound, const bool& required, const int& default_value = 0); + void register_float(Glib::ustring name,const float& lower_bound, const float& upper_bound, const bool& required, const float& default_value = 0.0f); + void register_string(Glib::ustring name, const bool& required, const Glib::ustring& default_value = ""); + + void clear(); + + //methods to RETRIEVE CREATED PARAMETERS + std::map > get_registered_int_parameters() const; + std::map > get_registered_float_parameters() const; + std::map > get_registered_string_parameters() const; + + //methods to SET the VALUE of PARAMETERS + + bool set_int(Glib::ustring name, const int& value); + bool set_float(Glib::ustring name, const float& value); + bool set_string(Glib::ustring name, const Glib::ustring& value); + + //methods to GET the VALUE of PARAMETERS + + int get_int(Glib::ustring name) const; + float get_float(Glib::ustring name) const; + Glib::ustring get_string(Glib::ustring name) const; + + private: - + std::map > int_map; + std::map > float_map; + std::map > string_map; }; + + /** + This class is useful only to store informations about each parameter. No checks + on the values entered are done. + */ template class PolicyParameters::Parameter { - public: - + public: + Parameter(Glib::ustring name, const T& value, const T& lower_bound, const T& upper_bound, const bool& required, const T& default_value = 0); + Glib::ustring get_name() const; + T get_lower_bound() const; + T get_upper_bound() const; + bool is_required() const; + T get_default() const; + T get_value() const; - private: + void set_value(const T&); + + private: + Glib::ustring _name; + T _value; + T _lower_bound; + T _upper_bound; + bool _is_required; + T _default; }; - }//~ namespace sgpem - +#include "../templates/parameter.tcc" #endif \ No newline at end of file diff --git a/src/backend/python_policy.cc b/src/backend/python_policy.cc new file mode 100644 index 0000000..29b4b33 --- /dev/null +++ b/src/backend/python_policy.cc @@ -0,0 +1,40 @@ +// src/backend/python_policy.cc - Copyright 2005, 2006, University +// of Padova, dept. of Pure and Applied +// Mathematics +// +// This file is part of SGPEMv2. +// +// This 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 2 of the License, or +// (at your option) any later version. +// +// SGPEMv2 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 SGPEMv2; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +#include "python_policy.hh" +using namespace sgpem; +using namespace std; + +PythonPolicy::PythonPolicy() +{ + // The following line is ugly, but necessary if we use + // non-standard installation directories. Theoretically, + // it should be up to the user to set correct + // environment variables. + // FIXME: find better way to achieve this. + //PyRun_SimpleString("import sys\n" + // "sys.path[:0] = [ '" MODDIR "', '" PYCDIR "' ]\n" + //"print '[II] Module search path is :', sys.path\n"); + + const char* filename = PYCDIR "/loadme.py"; + cout << filename; + cout.flush(); +} + diff --git a/src/backend/python_policy.hh b/src/backend/python_policy.hh new file mode 100644 index 0000000..4ecb560 --- /dev/null +++ b/src/backend/python_policy.hh @@ -0,0 +1,61 @@ +// src/backend/python_policy.hh - Copyright 2005, 2006, University +// of Padova, dept. of Pure and Applied +// Mathematics +// +// This file is part of SGPEMv2. +// +// This 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 2 of the License, or +// (at your option) any later version. +// +// SGPEMv2 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 SGPEMv2; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +#ifndef PYTHON_POLICY_HH +#define PYTHON_POLICY_HH 1 + +#include "config.h" + +#include +#include + +#include "policy.hh" + + +namespace sgpem +{ + + class PythonPolicy; + class PythonPolicyManager; + + class SG_DLLEXPORT PythonPolicy : public Policy + { + public: + //only PythonPolicyManager can create a PythonPolicy object + friend class PythonPolicyManager; + + void configure() {} + void sort_queue(sgpem::Scheduler::event) const {} + Glib::ustring get_description() const {} + bool is_pre_emptive() const {} + int get_time_slice() const {} + void set_time_slice(const int&) {} + + + + private: + + PythonPolicy(); + + }; + +} + +#endif \ No newline at end of file diff --git a/src/backend/python_policy_manager.cc b/src/backend/python_policy_manager.cc new file mode 100644 index 0000000..1f6d97a --- /dev/null +++ b/src/backend/python_policy_manager.cc @@ -0,0 +1,52 @@ +// src/backend/python_policy_manager.cc - Copyright 2005, 2006, University +// of Padova, dept. of Pure and Applied +// Mathematics +// +// This file is part of SGPEMv2. +// +// This 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 2 of the License, or +// (at your option) any later version. +// +// SGPEMv2 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 SGPEMv2; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +#include "python_policy_manager.hh" + +using namespace sgpem; + + +//static object +PythonPolicyManager PythonPolicyManager::_instance(10); //dummy parameter + + +PythonPolicyManager::PythonPolicyManager(int) //private constructor. The parameter is discarded +{ +} + +PythonPolicyManager& +PythonPolicyManager::get_instance() +{ + return _instance; +} + +Policy* +PythonPolicyManager::get_policy() +{ + return &_python_policy; +} + +void +PythonPolicyManager::init() +{ + Py_Initialize(); +} + + diff --git a/src/backend/python_policy_manager.hh b/src/backend/python_policy_manager.hh new file mode 100644 index 0000000..c73d0fc --- /dev/null +++ b/src/backend/python_policy_manager.hh @@ -0,0 +1,54 @@ +// src/backend/python_policy_manager.hh - Copyright 2005, 2006, University +// of Padova, dept. of Pure and Applied +// Mathematics +// +// This file is part of SGPEMv2. +// +// This 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 2 of the License, or +// (at your option) any later version. +// +// SGPEMv2 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 SGPEMv2; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +#ifndef PYTHON_POLICY_MANAGER_HH +#define PYTHON_POLICY_MANAGER_HH 1 + +#include "config.h" + +#include + +#include "policy_manager.hh" +#include "python_policy.hh" + +namespace sgpem +{ + //class PolicyManager; + class PythonPolicyManager; + + class SG_DLLEXPORT PythonPolicyManager : public PolicyManager + { + public: + + Policy* get_policy(); + void init(); + PyObject* get_py_dict(); + + static PythonPolicyManager& get_instance(); + + private: + PythonPolicyManager(int); //dummy parameter + static PythonPolicyManager _instance; + PythonPolicy _python_policy; + }; + +} + +#endif \ No newline at end of file diff --git a/src/backend/schedulable_list.cc b/src/backend/schedulable_list.cc index 1bb755c..f1156e1 100644 --- a/src/backend/schedulable_list.cc +++ b/src/backend/schedulable_list.cc @@ -153,11 +153,12 @@ SchedulableList::insert_at(const uint& which, const uint& where) for (uint f=0; f < which; f++) i_which++; - //save the one to replace - SchedulableStatus temp = *i_where; - //replace them - *i_where = *i_which; - *i_which = temp; + //save and pop WHICH + SchedulableStatus temp = *i_which; + _list.erase(i_which); + + //insert WHICH before WHERE + _list.insert(i_where, temp); return true; } diff --git a/src/backend/scheduler.cc b/src/backend/scheduler.cc index a61d51c..dbf87c1 100644 --- a/src/backend/scheduler.cc +++ b/src/backend/scheduler.cc @@ -76,7 +76,7 @@ Scheduler::step_forward() //adds each new ready schedulable and sorts the queue for(uint i=0; i < initial->size(); i++) if (initial->get_item_at(i)->get_state() == SchedulableStatus::state_ready - && initial->get_item_at(i)->get_schedulable()->get_arrival_time() == h.get_current_time()) + && (int)initial->get_item_at(i)->get_schedulable()->get_arrival_time() == h.get_current_time()) { _ready_queue.add_at_bottom(*initial->get_item_at(i)); @@ -137,7 +137,7 @@ Scheduler::step_forward() || initial->get_item_at(i)->get_state() == SchedulableStatus::state_future || initial->get_item_at(i)->get_state() == SchedulableStatus::state_terminated || (initial->get_item_at(i)->get_state() == SchedulableStatus::state_ready - && initial->get_item_at(i)->get_schedulable()->get_arrival_time() != h.get_current_time()) ) + && (int)initial->get_item_at(i)->get_schedulable()->get_arrival_time() != h.get_current_time()) ) final.add_at_bottom(*initial->get_item_at(i)); h.enqueue_slice(final); diff --git a/src/backend/scheduler.hh b/src/backend/scheduler.hh index a341441..2104e80 100644 --- a/src/backend/scheduler.hh +++ b/src/backend/scheduler.hh @@ -42,7 +42,7 @@ namespace sgpem */ - class SG_DLLEXPORT Scheduler : public ObservedSubject + class SG_DLLEXPORT Scheduler { public: enum event diff --git a/src/main.cc b/src/main.cc index 5d814d7..97dd1b1 100644 --- a/src/main.cc +++ b/src/main.cc @@ -32,6 +32,10 @@ #include "backend/schedulable_status.hh" #include "backend/slice.hh" #include "backend/process.hh" +#include "backend/policy.hh" +#include "backend/policy_parameters.hh" +#include "backend/python_policy.hh" +#include "backend/python_policy_manager.hh" #include #include @@ -40,7 +44,8 @@ using namespace std; using namespace sgpem; using namespace memory; - +using Glib::ustring; + int main(int argc, char* argv[]) { @@ -63,8 +68,10 @@ main(int argc, char* argv[]) */ start_gui(argc, argv); + PythonPolicyManager p = PythonPolicyManager::get_instance(); + //SMOKE-TEST for backend classes - cout << "\n\n********************************"; + /* cout << "\n\n********************************"; Process p1("P1", 0,10,1); Process p2("P2", 0,30,2); Process p3("P3", 5,15,3); @@ -105,7 +112,7 @@ main(int argc, char* argv[]) quale = h.get_simulation_status_at(0); //stato iniziale cout << bool(quale) << " " << quale->get_item_at(0)->get_schedulable()->get_name(); - + */ /* smart_ptr quale; @@ -128,20 +135,27 @@ main(int argc, char* argv[]) */ //************** TEST QUEUE - cout << "\n\nTEST QUEUE\n"; + /* cout << "\n\nTEST QUEUE\n"; - /* SchedulableQueue sq; - sq.add_at_top(ss1); - sq.add_at_top(ss2); + SchedulableList sq; + sq.add_at_bottom(ss1); + sq.add_at_bottom(ss2); sq.add_at_bottom(ss3); cout << sq.get_item_at(0)->get_schedulable()->get_name() << "\n"; cout << sq.get_item_at(1)->get_schedulable()->get_name() << "\n"; cout << sq.get_item_at(2)->get_schedulable()->get_name() << "\n"; - sq.insert_at(0,2); + sq.insert_at(2,0); cout << sq.get_item_at(0)->get_schedulable()->get_name() << "\n"; cout << sq.get_item_at(1)->get_schedulable()->get_name() << "\n"; cout << sq.get_item_at(2)->get_schedulable()->get_name() << "\n"; - */ + + cout << "\n\nTEST POLICYPARAMETERS\n"; + PolicyParameters pp; + pp.register_int("ciao", 0, 100, true, 50); + pp.set_int("ciao",1); + cout << pp.get_int("ciao"); + cout << "\n\n"; - return 0; + */ +return 0; } diff --git a/src/templates/parameter.tcc b/src/templates/parameter.tcc new file mode 100644 index 0000000..579dd43 --- /dev/null +++ b/src/templates/parameter.tcc @@ -0,0 +1,90 @@ +// src/templates/parameter.tcc - Copyright 2005, 2006, University +// of Padova, dept. of Pure and Applied +// Mathematics +// +// This file is part of SGPEMv2. +// +// This 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 2 of the License, or +// (at your option) any later version. +// +// SGPEMv2 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 SGPEMv2; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +#ifndef PARAMETERS_HH +#define PARAMETERS_HH 1 + +#include "../backend/policy_parameters.hh" + +using namespace sgpem; + + +template +PolicyParameters::Parameter::Parameter(Glib::ustring name, const T& value, const T& lower_bound, const T& upper_bound, const bool& required, const T& default_value) + :_name(name), _value(value), _lower_bound(lower_bound), _upper_bound(upper_bound), _is_required(required), _default(default_value) +{ +} + +template +Glib::ustring +PolicyParameters::Parameter::get_name() const +{ + return _name; +} + +template +T +PolicyParameters::Parameter::get_lower_bound() const +{ + return _lower_bound; +} + + +template +T +PolicyParameters::Parameter::get_upper_bound() const +{ + return _upper_bound; +} + +template +bool +PolicyParameters::Parameter::is_required() const +{ + return _is_required; +} + +template +T +PolicyParameters::Parameter::get_default() const +{ + return _default; +} + +template +T +PolicyParameters::Parameter::get_value() const +{ + return _value; +} + +template +void +PolicyParameters::Parameter::set_value(const T& val) +{ + _value = val; +} + + + + + +#endif