- Pretty-indenting code

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@674 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-06-29 08:44:30 +00:00
parent 7aecc910ba
commit 6b27a8461b
94 changed files with 3073 additions and 3066 deletions

View file

@ -46,165 +46,162 @@
namespace sgpem
{
/** An hard-coded Priority Round Robin policy
* It's actually called PRRPolicy, altough my personal taste would have suggested
* naming it
* Prioriy-Reliant Roughly-Realized Recently-Reimplemented Round-Robin Policy,
* i.e. PRRRRRRR-Policy.
* it adds a new constructor taking the quantum size (time slice)*/
/** An hard-coded Priority Round Robin policy
* It's actually called PRRPolicy, altough my personal taste would have suggested
* naming it
* Prioriy-Reliant Roughly-Realized Recently-Reimplemented Round-Robin Policy,
* i.e. PRRRRRRR-Policy.
* it adds a new constructor taking the quantum size (time slice)*/
class PRRPolicy : public Policy
class PRRPolicy : public Policy
{
public:
Policy()
{
public:
_instance = this;
}
Policy()
{
_instance = this;
}
Policy(int quantum) : _quantum(quantum)
{
_instance = this;
}
static Policy& get_instance()
{
if(!_instance) _instance = new Policy(3); // quantum size
return *_instance;
}
virtual ~Policy()
{
}
virtual void configure()
{
}
virtual void sort_queue() const throw(UserInterruptException)
{ // here a lot of fun, exactly O(n^2) fun!
SchedulableQueue sl = History.get_instance().get_simulation_status_at(get_current_time());
for (int i = 0; i < sl.size(); i++)
{
for (int j = 0; j < sl.size()-1; j++)
{
if (sl.get_item_at(j).get_schedulable().get_priority() < sl.get_item_at(j+1).get_schedulable().get_priority())
{
sl.swap(j, j+1);
}
}
}
}
int get_id() const
{
return 42;
}
virtual Glib::ustring get_description()
{
return "42";
}
virtual bool is_pre_emptive() const throw(UserInterruptException)
{
return 1;
}
virtual int get_time_slice() const throw(UserInterruptException)
{
return _quantum;
}
PolicyParameters& get_parameters()
{
return _parameters;
}
protected:
PolicyParameters _parameters;
int _id;
int _quantum;
private:
static Policy* _instance;
};
Policy*
PRRPolicy::_instance = NULL;
// A PolicyManager stub
class PolicyManager
Policy(int quantum) : _quantum(quantum)
{
public:
_instance = this;
}
PolicyManager();
virtual ~PolicyManager();
virtual Policy& get_policy()
{
return PRRPolicy.get_instance();
}
virtual void init()
{
}
static PolicyManager& get_registered_manager();
private:
static PolicyManager* _registered;
};
PolicyManager*
PolicyManager::_registered = NULL;
PolicyManager::PolicyManager()
static Policy& get_instance()
{
_registered = this;
if(!_instance) _instance = new Policy(3); // quantum size
return *_instance;
}
virtual ~Policy()
{}
virtual void configure()
{}
virtual void sort_queue() const throw(UserInterruptException)
{ // here a lot of fun, exactly O(n^2) fun!
SchedulableQueue sl = History.get_instance().get_simulation_status_at(get_current_time());
for (int i = 0; i < sl.size(); i++)
{
for (int j = 0; j < sl.size() - 1; j++)
{
if (sl.get_item_at(j).get_schedulable().get_priority() < sl.get_item_at(j + 1).get_schedulable().get_priority())
{
sl.swap(j, j + 1);
}
}
}
}
int get_id() const
{
return 42;
}
virtual Glib::ustring get_description()
{
return "42";
}
virtual bool is_pre_emptive() const throw(UserInterruptException)
{
return 1;
}
virtual int get_time_slice() const throw(UserInterruptException)
{
return _quantum;
}
PolicyParameters& get_parameters()
{
return _parameters;
}
PolicyManager::~PolicyManager()
{
if(_registered == this) _registered = NULL;
}
protected:
PolicyManager&
PolicyManager::get_registered_manager()
{
return *_registered;
}
PolicyParameters _parameters;
int _id;
int _quantum;
private:
// a History stub, should only save the last state included. but...
class History : public ObservedSubject
{
public:
memory::smart_ptr<sgpem::DynamicSchedulable> get_scheduled_at(int time) const {}
memory::smart_ptr<sgpem::SchedulableQueue> get_simulation_status_at(int time) const;
int get_current_time() const {return _total_time_elapsed;}
void enqueue_slice(const sgpem::SchedulableQueue& status);
void truncate_at(int instant) {}
static History& get_instance();
private:
History(int); //private constructor. The parameter is discarded
static History _instance;
int _total_time_elapsed;
std::vector<sgpem::Slice> _slices;
static Policy* _instance;
};
History&
History::get_instance()
{
if(!_instance) _instance = new Policy(3); // quantum size
return *_instance;
}
Policy*
PRRPolicy::_instance = NULL;
// A PolicyManager stub
class PolicyManager
{
public:
PolicyManager();
virtual ~PolicyManager();
virtual Policy& get_policy()
{
return PRRPolicy.get_instance();
}
virtual void init()
{}
static PolicyManager& get_registered_manager();
private:
static PolicyManager* _registered;
};
PolicyManager*
PolicyManager::_registered = NULL;
PolicyManager::PolicyManager()
{
_registered = this;
}
PolicyManager::~PolicyManager()
{
if(_registered == this) _registered = NULL;
}
PolicyManager&
PolicyManager::get_registered_manager()
{
return *_registered;
}
// a History stub, should only save the last state included. but...
class History : public ObservedSubject
{
public:
memory::smart_ptr<sgpem::DynamicSchedulable> get_scheduled_at(int time) const {}
memory::smart_ptr<sgpem::SchedulableQueue> get_simulation_status_at(int time) const;
int get_current_time() const {return _total_time_elapsed;}
void enqueue_slice(const sgpem::SchedulableQueue& status);
void truncate_at(int instant) {}
static History& get_instance();
private:
History(int); //private constructor. The parameter is discarded
static History _instance;
int _total_time_elapsed;
std::vector<sgpem::Slice> _slices;
};
History&
History::get_instance()
{
if(!_instance) _instance = new Policy(3); // quantum size
return *_instance;
}
@ -217,85 +214,85 @@ namespace sgpem
class StepForwardTester
{
}
// from here and further until the bottom, all to throw away I suppose
int
main(int argc, char** argv) {
main(int argc, char** argv)
{
using namespace sgpem;
using Glib::Module;
using namespace sgpem;
using Glib::Module;
std::string command(ERERERT); // the sequence of commands to test
std::string command(ERERERT); // the sequence of commands to test
// sets up the test data
StaticProcess p1("P1", 1,5,1);
StaticProcess p2("P2", 5,55,2);
StaticProcess p3("P3", 36,30,3);
StaticProcess p4("P4", 4,26,3);
StaticProcess p5("P5", 15,200,3);
StaticProcess p6("P6", 6,250,1);
StaticProcess p7("P7", 8,42,15);
StaticProcess p8("P8", 8,56,1);
StaticProcess p9("P9", 9,42,1);
StaticProcess p10("PA", 12,42,1);
StaticProcess p11("PB", 106,42,1);
StaticProcess p12("PC", 100,42,1);
StaticProcess p13("PD", 29,42,18);
StaticProcess p14("PE", 0,42,1);
StaticProcess p15("PF", 2,88,1);
StaticProcess p16("PG", 3666,9,1);
StaticProcess p17("PH", 5,72,10);
StaticProcess p18("PJ", 6,26,1);
StaticProcess p19("PK", 10,24,17);
StaticProcess p20("PK2", 11,34,67); // not used!
// sets up the test data
StaticProcess p1("P1", 1, 5, 1);
StaticProcess p2("P2", 5, 55, 2);
StaticProcess p3("P3", 36, 30, 3);
StaticProcess p4("P4", 4, 26, 3);
StaticProcess p5("P5", 15, 200, 3);
StaticProcess p6("P6", 6, 250, 1);
StaticProcess p7("P7", 8, 42, 15);
StaticProcess p8("P8", 8, 56, 1);
StaticProcess p9("P9", 9, 42, 1);
StaticProcess p10("PA", 12, 42, 1);
StaticProcess p11("PB", 106, 42, 1);
StaticProcess p12("PC", 100, 42, 1);
StaticProcess p13("PD", 29, 42, 18);
StaticProcess p14("PE", 0, 42, 1);
StaticProcess p15("PF", 2, 88, 1);
StaticProcess p16("PG", 3666, 9, 1);
StaticProcess p17("PH", 5, 72, 10);
StaticProcess p18("PJ", 6, 26, 1);
StaticProcess p19("PK", 10, 24, 17);
StaticProcess p20("PK2", 11, 34, 67); // not used!
DynamicSchedulable ss1(p1);
DynamicSchedulable ss2(p2);
DynamicSchedulable ss3(p3);
DynamicSchedulable ss4(p4);
DynamicSchedulable ss5(p5);
DynamicSchedulable ss6(p6);
DynamicSchedulable ss7(p7);
DynamicSchedulable ss8(p8);
DynamicSchedulable ss9(p9);
DynamicSchedulable ss10(p10);
DynamicSchedulable ss11(p11);
DynamicSchedulable ss12(p12);
DynamicSchedulable ss13(p13);
DynamicSchedulable ss14(p14);
DynamicSchedulable ss15(p15);
DynamicSchedulable ss16(p16);
DynamicSchedulable ss17(p17);
DynamicSchedulable ss18(p18);
DynamicSchedulable ss19(p19); // not used!
DynamicSchedulable ss1(p1);
DynamicSchedulable ss2(p2);
DynamicSchedulable ss3(p3);
DynamicSchedulable ss4(p4);
DynamicSchedulable ss5(p5);
DynamicSchedulable ss6(p6);
DynamicSchedulable ss7(p7);
DynamicSchedulable ss8(p8);
DynamicSchedulable ss9(p9);
DynamicSchedulable ss10(p10);
DynamicSchedulable ss11(p11);
DynamicSchedulable ss12(p12);
DynamicSchedulable ss13(p13);
DynamicSchedulable ss14(p14);
DynamicSchedulable ss15(p15);
DynamicSchedulable ss16(p16);
DynamicSchedulable ss17(p17);
DynamicSchedulable ss18(p18);
DynamicSchedulable ss19(p19); // not used!
SchedulableQueue initial;
initial.add_at_bottom(ss1);
initial.add_at_bottom(ss2);
initial.add_at_bottom(ss3);
initial.add_at_bottom(ss4);
initial.add_at_bottom(ss5);
initial.add_at_bottom(ss6);
initial.add_at_bottom(ss7);
initial.add_at_bottom(ss8);
initial.add_at_bottom(ss9);
initial.add_at_bottom(ss10);
initial.add_at_bottom(ss11);
initial.add_at_bottom(ss12);
initial.add_at_bottom(ss13);
initial.add_at_bottom(ss14);
initial.add_at_bottom(ss15);
initial.add_at_bottom(ss16);
initial.add_at_bottom(ss17);
initial.add_at_bottom(ss18);
SchedulableQueue initial;
initial.add_at_bottom(ss1);
initial.add_at_bottom(ss2);
initial.add_at_bottom(ss3);
initial.add_at_bottom(ss4);
initial.add_at_bottom(ss5);
initial.add_at_bottom(ss6);
initial.add_at_bottom(ss7);
initial.add_at_bottom(ss8);
initial.add_at_bottom(ss9);
initial.add_at_bottom(ss10);
initial.add_at_bottom(ss11);
initial.add_at_bottom(ss12);
initial.add_at_bottom(ss13);
initial.add_at_bottom(ss14);
initial.add_at_bottom(ss15);
initial.add_at_bottom(ss16);
initial.add_at_bottom(ss17);
initial.add_at_bottom(ss18);
HistoryTester HT(initial);
HT.test("ERERERERTTTETRERERETETTTTTTTTTTTTTT");
HistoryTester HT(initial);
HT.test("ERERERERTTTETRERERETETTTTTTTTTTTTTT");
exit(0);
exit(0);
}