- Add down_cast<> to safely checking dynamic_casts when in development. Be sure to read its documentation before use\!
git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1188 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
f1954c9f71
commit
deaf0702e5
3 changed files with 178 additions and 16 deletions
|
@ -32,9 +32,11 @@
|
|||
#include "static_request.hh"
|
||||
#include "static_sub_request.hh"
|
||||
|
||||
#include <sgpemv2/history_observer.hh>
|
||||
#include "concrete_history.hh"
|
||||
|
||||
#include <sgpemv2/history_observer.hh>
|
||||
|
||||
#include <sgpemv2/templates/down_cast.tcc>
|
||||
#include <sgpemv2/templates/deletor.tcc>
|
||||
#include <sgpemv2/templates/smartp.tcc>
|
||||
|
||||
|
@ -170,7 +172,7 @@ ConcreteHistory::remove(resource_key_t resource_key)
|
|||
typedef ConcreteEnvironment::Processes::iterator ProcIt;
|
||||
for (ProcIt it1 = processes.begin(); it1 != processes.end(); it1++)
|
||||
{
|
||||
Threads& threads = dynamic_cast<DynamicProcess&>(**it1).get_dynamic_threads();
|
||||
Threads& threads = down_cast<DynamicProcess&>(**it1).get_dynamic_threads();
|
||||
for (Threads::iterator it2 = threads.begin(); it2 != threads.end(); it2++)
|
||||
{
|
||||
Requests& reqs = (*it2)->get_dynamic_requests();
|
||||
|
@ -212,7 +214,7 @@ ConcreteHistory::remove(Process& process)
|
|||
void
|
||||
ConcreteHistory::remove(Thread& thread)
|
||||
{
|
||||
DynamicThread& dyn_thr = dynamic_cast<DynamicThread&>(thread);
|
||||
DynamicThread& dyn_thr = down_cast<DynamicThread&>(thread);
|
||||
|
||||
// Pay attention that initial isn't deleted by reset()
|
||||
ConcreteEnvironment& initial = *_snapshots.front();
|
||||
|
@ -223,7 +225,7 @@ ConcreteHistory::remove(Thread& thread)
|
|||
if (found == NULL)
|
||||
return; // not found, just return.
|
||||
|
||||
DynamicProcess& dynamic_found = dynamic_cast<DynamicProcess&>(*found);
|
||||
DynamicProcess& dynamic_found = down_cast<DynamicProcess&>(*found);
|
||||
bool removed = deep_remove<DynamicThread>(dynamic_found.get_dynamic_threads(), dyn_thr);
|
||||
|
||||
if (removed)
|
||||
|
@ -234,7 +236,7 @@ ConcreteHistory::remove(Thread& thread)
|
|||
void
|
||||
ConcreteHistory::remove(Request& request)
|
||||
{
|
||||
DynamicRequest& dyn_req = dynamic_cast<DynamicRequest&>(request);
|
||||
DynamicRequest& dyn_req = down_cast<DynamicRequest&>(request);
|
||||
DynamicThread& dyn_thr = dyn_req.get_thread();
|
||||
DynamicProcess& dyn_proc = dyn_thr.get_process();
|
||||
|
||||
|
@ -243,7 +245,7 @@ ConcreteHistory::remove(Request& request)
|
|||
ConcreteEnvironment::Processes& processes = initial.get_processes();
|
||||
|
||||
Process* proc_ref = deep_find<Process>(processes, dyn_proc);
|
||||
DynamicProcess* dyn_proc_ref = dynamic_cast<DynamicProcess*>(proc_ref);
|
||||
DynamicProcess* dyn_proc_ref = down_cast<DynamicProcess*>(proc_ref);
|
||||
if (dyn_proc_ref == NULL)
|
||||
return; // not found, just return.
|
||||
DynamicThread* thr_ref = deep_find<DynamicThread>(dyn_proc_ref->get_dynamic_threads(), dyn_thr);
|
||||
|
@ -263,7 +265,7 @@ ConcreteHistory::remove(SubRequest& subrequest)
|
|||
// this function makes one relevant assumption:
|
||||
// the initial environment does contain empty request queues only.
|
||||
|
||||
DynamicSubRequest& dyn_sub = dynamic_cast<DynamicSubRequest&>(subrequest);
|
||||
DynamicSubRequest& dyn_sub = down_cast<DynamicSubRequest&>(subrequest);
|
||||
DynamicRequest& dyn_req = dyn_sub.get_request();
|
||||
DynamicThread& dyn_thr = dyn_req.get_thread();
|
||||
DynamicProcess& dyn_proc = dyn_thr.get_process();
|
||||
|
@ -273,7 +275,7 @@ ConcreteHistory::remove(SubRequest& subrequest)
|
|||
ConcreteEnvironment::Processes& processes = initial.get_processes();
|
||||
|
||||
Process* proc_ref = deep_find<Process>(processes, dyn_proc);
|
||||
DynamicProcess* dyn_proc_ref = dynamic_cast<DynamicProcess*>(proc_ref);
|
||||
DynamicProcess* dyn_proc_ref = down_cast<DynamicProcess*>(proc_ref);
|
||||
if (dyn_proc_ref == NULL)
|
||||
return; // not found, just return.
|
||||
DynamicThread* thr_ref = deep_find<DynamicThread>(dyn_proc_ref->get_dynamic_threads(), dyn_thr);
|
||||
|
@ -346,7 +348,7 @@ ConcreteHistory::edit_resource(Resource& resource,
|
|||
{
|
||||
// And preemptable and availability?? FIXME!
|
||||
|
||||
DynamicResource* res = dynamic_cast<DynamicResource*>(&resource);
|
||||
DynamicResource* res = down_cast<DynamicResource*>(&resource);
|
||||
StaticResource& core = res->get_core();
|
||||
core.set_name(name);
|
||||
core.set_places(places);
|
||||
|
@ -379,7 +381,7 @@ ConcreteHistory::edit_process(Process& process,
|
|||
time_t arrival_time,
|
||||
prio_t base_priority)
|
||||
{
|
||||
DynamicProcess* proc = dynamic_cast<DynamicProcess*>(&process);
|
||||
DynamicProcess* proc = down_cast<DynamicProcess*>(&process);
|
||||
StaticProcess& core = proc->get_core();
|
||||
core.set_name(name);
|
||||
core.set_arrival_time(arrival_time);
|
||||
|
@ -399,7 +401,7 @@ ConcreteHistory::add_thread(const Glib::ustring& name,
|
|||
{
|
||||
reset(false);
|
||||
|
||||
DynamicProcess& parent_process = dynamic_cast<DynamicProcess&>(parent);
|
||||
DynamicProcess& parent_process = down_cast<DynamicProcess&>(parent);
|
||||
StaticProcess& parent_core = parent_process.get_core();
|
||||
StaticThread* core = new StaticThread(name, parent_core, cpu_time, arrival_time, base_priority);
|
||||
DynamicThread* thread = new DynamicThread(core, &parent_process);
|
||||
|
@ -415,7 +417,7 @@ ConcreteHistory::edit_thread(Thread& thread,
|
|||
time_t arrival_time,
|
||||
prio_t base_priority)
|
||||
{
|
||||
DynamicThread* thre = dynamic_cast<DynamicThread*>(&thread);
|
||||
DynamicThread* thre = down_cast<DynamicThread*>(&thread);
|
||||
StaticThread& core = thre->get_core();
|
||||
core.set_name(name);
|
||||
core.set_total_cpu_time(cpu_time);
|
||||
|
@ -431,7 +433,7 @@ ConcreteHistory::add_request(Thread& owner,
|
|||
{
|
||||
reset(false);
|
||||
|
||||
DynamicThread& dyn_owner = dynamic_cast<DynamicThread&>(owner);
|
||||
DynamicThread& dyn_owner = down_cast<DynamicThread&>(owner);
|
||||
StaticThread& owner_core = dyn_owner.get_core();
|
||||
|
||||
StaticRequest* core = new StaticRequest(&owner_core, instant);
|
||||
|
@ -447,7 +449,7 @@ void
|
|||
ConcreteHistory::edit_request(Request& request,
|
||||
time_t instant)
|
||||
{
|
||||
DynamicRequest* req = dynamic_cast<DynamicRequest*>(&request);
|
||||
DynamicRequest* req = down_cast<DynamicRequest*>(&request);
|
||||
StaticRequest& core = req->get_core();
|
||||
core.set_instant(instant);
|
||||
|
||||
|
@ -462,7 +464,7 @@ ConcreteHistory::add_subrequest(Request& request,
|
|||
{
|
||||
reset(false);
|
||||
|
||||
DynamicRequest& dyn_request = dynamic_cast<DynamicRequest&>(request);
|
||||
DynamicRequest& dyn_request = down_cast<DynamicRequest&>(request);
|
||||
|
||||
StaticSubRequest* core = new StaticSubRequest(resource_key, duration);
|
||||
DynamicSubRequest* subreq = new DynamicSubRequest(core, &dyn_request);
|
||||
|
@ -478,7 +480,7 @@ ConcreteHistory::edit_subrequest(SubRequest& subrequest,
|
|||
resource_key_t resource_key,
|
||||
time_t duration)
|
||||
{
|
||||
DynamicSubRequest* sreq = dynamic_cast<DynamicSubRequest*>(&subrequest);
|
||||
DynamicSubRequest* sreq = down_cast<DynamicSubRequest*>(&subrequest);
|
||||
StaticSubRequest& core = sreq->get_core();
|
||||
core.set_resource_key(resource_key);
|
||||
core.set_length(duration);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue