sgpemv2/src/backend/policy_parameters.hh

117 lines
3.7 KiB
C++
Raw Normal View History

// src/backend/policy_parameters.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_PARAMETERS_HH
#define POLICY_PARAMETERS_HH 1
#include "config.h"
#include <map>
#include <stdexcept>
#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<typename T>
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<Glib::ustring, Parameter<int> > get_registered_int_parameters() const;
std::map<Glib::ustring, Parameter<float> > get_registered_float_parameters() const;
std::map<Glib::ustring, Parameter<Glib::ustring> > 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<Glib::ustring, Parameter<int> > int_map;
std::map<Glib::ustring, Parameter<float> > float_map;
std::map<Glib::ustring, Parameter<Glib::ustring> > string_map;
};
/**
This class is useful only to store informations about each parameter. No checks
on the values entered are done.
*/
template<typename T>
class PolicyParameters::Parameter
{
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;
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