- added console interpreter

- added string_utils

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@342 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
fpaparel 2006-02-17 22:19:25 +00:00
parent 8cb6b81c38
commit 759dfdad25
16 changed files with 670 additions and 45 deletions

View file

@ -57,7 +57,8 @@ libbackend_la_SOURCES = \
schedulable_list.cc \
schedulable_status.cc \
scheduler.cc \
slice.cc
slice.cc \
string_utils.cc
noinst_HEADERS = \
history.hh \
@ -70,4 +71,5 @@ noinst_HEADERS = \
schedulable_list.hh \
schedulable_status.hh \
scheduler.hh \
slice.hh
slice.hh \
string_utils.hh

View file

@ -30,35 +30,36 @@
namespace sgpem
{
class Policy;
class Policy;
/** \brief
e' una Strategy che rappresenta un algoritmo di scheduling che implementa una politica
di scheduling.
*/
class SG_DLLEXPORT Policy
{
public:
virtual ~Policy();
/** \brief
e' una Strategy che rappresenta un algoritmo di scheduling che implementa una politica
di scheduling.
*/
class SG_DLLEXPORT Policy
{
public:
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;
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;
const PolicyParameters& get_parameters() const;
private:
PolicyParameters _parameters;
int _id;
};
private:
PolicyParameters _parameters;
int _id;
};
}//~ namespace sgpem
#endif
#endif

View file

@ -0,0 +1,96 @@
// src/backend/string_utils.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 "string_utils.hh"
using Glib::ustring;
/**
\brief A function that converts a Unicode string to an integer value
The string can contain ONLY digits and the "minus" character.
\returns TRUE if the string is well formatted
\returns FALSE otherwise
*/
bool
string_to_int(const ustring& str, int& num)
{
static const ustring allvalid = "0123456789-";
static const ustring digits = "0123456789";
// the string can't be empty
if (str.length() == 0 || (str.length() == 1 && str[0] == '-'))
return false;
//checks if the string contains only digits
if (str.find_first_not_of(allvalid) < str.length())
return false;
if (str.substr(1).find_first_not_of(digits) < str.length()-1)
return false;
num=0;
int multiplier = 1, val;
int start; //the position of the biggest digit
if (str[0] == '-')
start = 1;
else
start = 0;
for (int pos = str.length() - 1; pos >= start ; pos--)
{
val = str[pos] - 48; //the INTEGER value of the digit
num += val*multiplier;
multiplier *= 10;
}
//if there is the minus then multiply for -1
if (start == 1)
num *= -1;
return true;
}
/**
\brief A function that converts an integer value to an Unicode string
*/
void
int_to_string(const int& num, ustring& str)
{
if (num == 0)
{
str = '0';
return;
}
str = "";
int val = num;
bool negative = (val < 0)? true : false;
if (negative) val *= -1;
while (true)
{
str = char(val % 10 + 48) + str;
if (val > 1 && val / 10 != 0)
val /= 10;
else
break;
}
if (negative)
str = '-' + str;
}

View file

@ -0,0 +1,33 @@
// src/backend/string_utils.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 STRING_UTILS_HH
#define STRING_UTILS_HH 1
#include "config.h"
#include "glibmm/ustring.h"
bool SG_DLLEXPORT string_to_int(const Glib::ustring&, int&);
void SG_DLLEXPORT int_to_string(const int&, Glib::ustring&);
#endif