linked list

Login to reply to this topic.
Mon, 2004-12-20 23:38
Joined: 2004-06-18
Forum posts: 20
Hi Everyone

I have used the command pattern design and put all the different command object in a linked list type TSglQue<TCmd(interface)>, but when I extract a command object and call its execute funktion then
everything closes down... It works if I only have one type of object
in the linked list and the linked list template is of that type
TSglQue<TSomeCmd(concrete command)>, ... it seem
to me that TSglQue cannot handle different types of objects...?

the thing is that I would like to have a linked list of different commands
which I can iterate and execute..?

Thanks in advance

Christian

Tue, 2004-12-21 10:01
Joined: 2004-06-18
Forum posts: 20
linked list
I hope their arent any replies bc im to fuzzy about what i would like to do,
but here it goes:

I would like to have a linked list TSglQue<ClassInterface> where the
interface is an abstract class with on virtuel functions.

I would then like the list to contain different child classes of ClassInterface

ex.

ClassInterfaceChild1 -> ClassInterfaceChild2 -> ClassInterfaceChild1

thanks in advance
Tue, 2004-12-21 10:16
NewLC AdministratorSymbian AccreditedForum Nokia Champion
Joined: 2003-01-14
Forum posts: 2029
linked list
Have you integrated a TSglQueLink iLink; item in your ClassInterface definition ?

This is required for TSglQue to work (and in that sense, your interface class cannot be an abstract class as it needs to have this data member).

Eric Bustarret
NewLC Founder & CEO / Professional Symbian OS Consultant

Tue, 2004-12-21 10:24
Joined: 2004-06-18
Forum posts: 20
linked list
The two classes... interface TCmd and the concrete class TCmdMakeNewArrangement
 

class TCmd : public CBase

{

public:                                              

           virtual void Execute(CArrangementEngine *engine) = 0;

private:

           TSglQueLink iLink;    

};

 

class TCmdMakeNewArrangement : public TCmd

{

public:

 

           void Execute(CArrangementEngine *engine);

           TSglQue<TDeltager> qContacts;

           TSglQue<TTidsInterval> qTimeintervalsAppointment;    
           TTimeIntervalMinutes timAppointmentLength;            
};

 

This works... where the TSglQue<TCmdMakeNewArrangement>
 

TCmdMakeNewArrangement* arr = new(ELeave) TCmdMakeNewArrangement;

arr->Execute(iArrangementEngine);

 

But when TSglQue<TCmd> it doesn't work
 

TCmdMakeNewArrangement* arr = new(ELeave) TCmdMakeNewArrangement;

 

iArrangementEngine->AddCommand(arr);

void CArrangementEngine::AddCommand(TCmd *aCommandTask)

{

           iCommandTasks.AddLast(*aCommandTask);

}

 

if(!iCommandTasks.IsEmpty())

{

TCmd *command = iCommandTasks.First();

command->Execute(this);  here it goes wrong

iCommandTasks.Remove(*command);

delete command;

}
Tue, 2004-12-21 12:13
Joined: 2004-06-18
Forum posts: 20
linked list
another reply I got...

> Sander van der Wal wrote:
> What's missing here is the call that constructs the iArrangementEngine
> object. If not properly constructed, the linked list will not be properly
> linkied.
>
>
> --

Im sorry to say that this isn't the problem... I didn't include the code
which
initializes the the iArrangementEngine. And I have tried the exact same code
where I instead of using the interface TCmd like this TSglQue<TCmd>
uses the concrete class TCmdMakeNewArrangement  like this
TSglQue<TCmdMakeNewArrangement> where it works.

the code that works - TSglQue<TCmdMakeNewArrangement>:

TCmdMakeNewArrangement *command = iCommandTasks.First();
command->Execute(this);
iCommandTasks.Remove(*command);

before which doesn't work - TSglQue<TCmd>:

TCmd *command = iCommandTasks.First();
command->Execute(this); <-- fails
iCommandTasks.Remove(*command);

I wonder if u have to calculate the pointer TSglQueLink iLink in the
constructor for every class when u use an abstract class, because of
the different sizes for the different child object which the class holds?
Tue, 2004-12-21 14:38
NewLC AdministratorSymbian AccreditedForum Nokia Champion
Joined: 2003-01-14
Forum posts: 2029
linked list
Quote
I wonder if u have to calculate the pointer TSglQueLink iLink in the
constructor for every class when u use an abstract class, because of
the different sizes for the different child object which the class holds?

I am afraid that this value might need to be of fixed size (not sure however)

Eric Bustarret
NewLC Founder & CEO / Professional Symbian OS Consultant

  • Login to reply to this topic.