- 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)));
}
std::vector<Thread*>
DynamicProcess::get_threads()
{

View File

@ -38,6 +38,15 @@ DynamicRequest::DynamicRequest(StaticRequest *core,
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*>
DynamicRequest::get_subrequests()
{

View File

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

View File

@ -23,12 +23,23 @@
#include "smartp.tcc"
#include <cassert>
using namespace sgpem;
DynamicResource::DynamicResource(StaticResource *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
DynamicResource::get_name() const
{

View File

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

View File

@ -22,6 +22,8 @@
#include "smartp.tcc"
#include <cassert>
using namespace sgpem;
using namespace std;
@ -32,9 +34,10 @@ DynamicSchedulable::DynamicSchedulable(StaticSchedulable& obj) :
{}
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

View File

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

View File

@ -35,6 +35,14 @@ DynamicSubRequest::DynamicSubRequest(StaticSubRequest* core,
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&
DynamicSubRequest::get_resource()
{

View File

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

View File

@ -18,10 +18,51 @@
// along with SGPEMv2; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "config.h"
#include "gettext.h"
#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
#include "config.h"
#include "glibmm/ustring.h"
#include <stdexcept>
#include <vector>
namespace sgpem
{
class ReadyQueue;
class Schedulable;
class SG_DLLEXPORT ReadyQueue
{
public:
virtual
~ReadyQueue();
typedef unsigned int position;
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 bool operator==(const Request& op2) const = 0;
virtual std::vector<SubRequest*> get_subrequests() = 0;
virtual unsigned int get_instant() const = 0;
virtual state get_current_state() const = 0;

View File

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

View File

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

View File

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

View File

@ -38,7 +38,7 @@ namespace sgpem
public:
virtual ~Thread();
virtual Process& get_process() = 0;
virtual Process& get_process() = 0;
virtual std::vector<Request*> get_requests() = 0;
virtual void serialize(SerializeVisitor& translator) const = 0;
};