- Add operator== methods to dynamic schedulables, and in their interfaces too

- Write class ReadyQueue


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@688 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-07-02 12:44:05 +00:00
parent 9da0ef3137
commit fa06e2f4f1
16 changed files with 112 additions and 12 deletions

View File

@ -43,6 +43,7 @@ DynamicProcess::DynamicProcess(const DynamicProcess &other) :
_dynamic_threads.push_back(new DynamicThread(*(*it))); _dynamic_threads.push_back(new DynamicThread(*(*it)));
} }
std::vector<Thread*> std::vector<Thread*>
DynamicProcess::get_threads() DynamicProcess::get_threads()
{ {

View File

@ -38,6 +38,15 @@ DynamicRequest::DynamicRequest(StaticRequest *core,
assert(owner != NULL); assert(owner != NULL);
} }
bool
DynamicRequest::operator==(const Request& op2) const
{
assert(dynamic_cast<const DynamicRequest*>(&op2) != NULL);
return _static_request == dynamic_cast<const DynamicRequest&>(op2)._static_request;
}
vector<SubRequest*> vector<SubRequest*>
DynamicRequest::get_subrequests() DynamicRequest::get_subrequests()
{ {

View File

@ -43,6 +43,8 @@ namespace sgpem
public: public:
DynamicRequest(StaticRequest *core, DynamicThread* owner); DynamicRequest(StaticRequest *core, DynamicThread* owner);
virtual bool operator==(const Request& op2) const;
std::vector<SubRequest*> get_subrequests(); std::vector<SubRequest*> get_subrequests();
DynamicThread& get_thread(); DynamicThread& get_thread();

View File

@ -23,12 +23,23 @@
#include "smartp.tcc" #include "smartp.tcc"
#include <cassert>
using namespace sgpem; using namespace sgpem;
DynamicResource::DynamicResource(StaticResource *core) : DynamicResource::DynamicResource(StaticResource *core) :
_static_resource(core) _static_resource(core)
{} {}
bool
DynamicResource::operator==(const Resource& op2) const
{
assert(dynamic_cast<const DynamicResource*>(&op2) != NULL);
return _static_resource == dynamic_cast<const DynamicResource&>(op2)._static_resource;
}
Glib::ustring Glib::ustring
DynamicResource::get_name() const DynamicResource::get_name() const
{ {

View File

@ -39,6 +39,8 @@ namespace sgpem
public: public:
DynamicResource(StaticResource *core); DynamicResource(StaticResource *core);
virtual bool operator==(const Resource& op2) const;
Glib::ustring get_name() const; Glib::ustring get_name() const;
unsigned int get_places() const; unsigned int get_places() const;

View File

@ -22,6 +22,8 @@
#include "smartp.tcc" #include "smartp.tcc"
#include <cassert>
using namespace sgpem; using namespace sgpem;
using namespace std; using namespace std;
@ -32,9 +34,10 @@ DynamicSchedulable::DynamicSchedulable(StaticSchedulable& obj) :
{} {}
bool bool
DynamicSchedulable::operator==(const DynamicSchedulable& dx) const DynamicSchedulable::operator==(const Schedulable& op2) const
{ {
return _ref == dx._ref; assert(dynamic_cast<const DynamicSchedulable*>(&op2) != NULL);
return _ref == dynamic_cast<const DynamicSchedulable&>(op2)._ref;
} }
Glib::ustring Glib::ustring

View File

@ -54,7 +54,7 @@ namespace sgpem
* actual represented process is the same, and if the status is also the * actual represented process is the same, and if the status is also the
* same. * same.
*/ */
bool operator==(const DynamicSchedulable&) const; bool operator==(const Schedulable&) const;
Glib::ustring get_name() const; Glib::ustring get_name() const;

View File

@ -35,6 +35,14 @@ DynamicSubRequest::DynamicSubRequest(StaticSubRequest* core,
assert(resource != NULL); assert(resource != NULL);
} }
bool
DynamicSubRequest::operator==(const SubRequest& op2) const
{
assert(dynamic_cast<const DynamicSubRequest*>(&op2) != NULL);
return _static_subrequest == dynamic_cast<const DynamicSubRequest&>(op2)._static_subrequest;
}
DynamicResource& DynamicResource&
DynamicSubRequest::get_resource() DynamicSubRequest::get_resource()
{ {

View File

@ -40,6 +40,8 @@ namespace sgpem
public: public:
DynamicSubRequest(StaticSubRequest* core, DynamicResource* resource); DynamicSubRequest(StaticSubRequest* core, DynamicResource* resource);
virtual bool operator==(const SubRequest& op2) const;
DynamicResource& get_resource(); DynamicResource& get_resource();
unsigned int get_places() const; unsigned int get_places() const;

View File

@ -18,10 +18,51 @@
// along with SGPEMv2; if not, write to the Free Software // along with SGPEMv2; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "config.h"
#include "gettext.h"
#include "ready_queue.hh" #include "ready_queue.hh"
using namespace sgpem; using sgpem::ReadyQueue;
ReadyQueue::~ReadyQueue() void
{} ReadyQueue::swap(position a, position b)
throw (std::out_of_range)
{
size_t size = _scheds.size();
if(a > size || b > size)
throw std::out_of_range(_("Trying to access a Schedulable "
"with an index outside of the "
"queue limits."));
if(a == b) return;
Schedulable* temp = _scheds[a];
_scheds[a] = _scheds[b];
_scheds[b] = temp;
}
ReadyQueue::size_t
ReadyQueue::size() const
{
return _scheds.size();
}
sgpem::Schedulable&
ReadyQueue::get_item_at(position index)
throw (std::out_of_range)
{
if(index > size())
throw std::out_of_range(_("Trying to access a Schedulable "
"with an index outside of the "
"queue limits."));
return *(_scheds[index]);
}
void
ReadyQueue::append(Schedulable& schedulable)
{
_scheds.push_back(&schedulable);
}

View File

@ -22,17 +22,29 @@
#define READY_QUEUE_HH 1 #define READY_QUEUE_HH 1
#include "config.h" #include "config.h"
#include "glibmm/ustring.h"
#include <stdexcept>
#include <vector>
namespace sgpem namespace sgpem
{ {
class ReadyQueue;
class Schedulable;
class SG_DLLEXPORT ReadyQueue class SG_DLLEXPORT ReadyQueue
{ {
public: public:
virtual typedef unsigned int position;
~ReadyQueue(); typedef unsigned int size_t;
void swap(position a, position b) throw (std::out_of_range);
inline size_t size() const;
Schedulable& get_item_at(position index) throw (std::out_of_range);
inline void append(Schedulable& schedulable);
private:
typedef std::vector<Schedulable*> Schedulables;
Schedulables _scheds;
}; };
} }

View File

@ -41,6 +41,8 @@ namespace sgpem
virtual ~Request(); virtual ~Request();
virtual bool operator==(const Request& op2) const = 0;
virtual std::vector<SubRequest*> get_subrequests() = 0; virtual std::vector<SubRequest*> get_subrequests() = 0;
virtual unsigned int get_instant() const = 0; virtual unsigned int get_instant() const = 0;
virtual state get_current_state() const = 0; virtual state get_current_state() const = 0;

View File

@ -34,6 +34,8 @@ namespace sgpem
public: public:
virtual ~Resource(); virtual ~Resource();
virtual bool operator==(const Resource& op2) const = 0;
virtual Glib::ustring get_name() const = 0; virtual Glib::ustring get_name() const = 0;
virtual unsigned int get_places() const = 0; virtual unsigned int get_places() const = 0;

View File

@ -22,7 +22,8 @@
#define SCHEDULABLE_HH 1 #define SCHEDULABLE_HH 1
#include "config.h" #include "config.h"
#include "glibmm/ustring.h"
#include <glibmm/ustring.h>
namespace sgpem namespace sgpem
{ {
@ -50,6 +51,8 @@ namespace sgpem
virtual ~Schedulable() = 0; virtual ~Schedulable() = 0;
virtual bool operator==(const Schedulable& op2) const = 0;
virtual Glib::ustring get_name() const = 0; virtual Glib::ustring get_name() const = 0;
virtual unsigned int get_arrival_time() const = 0; virtual unsigned int get_arrival_time() const = 0;

View File

@ -34,6 +34,8 @@ namespace sgpem
public: public:
virtual ~SubRequest(); virtual ~SubRequest();
virtual bool operator==(const SubRequest& op2) const = 0;
virtual Resource& get_resource() = 0; virtual Resource& get_resource() = 0;
virtual unsigned int get_places() const = 0; virtual unsigned int get_places() const = 0;