LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Porting Code (https://www.linuxquestions.org/questions/programming-9/porting-code-392219/)

lucky6969b 12-13-2005 01:41 AM

Porting Code
 
Would anyone mind translating this code for me?
The code was extracted from the book design patterns
And i want to port it to Linux and it is based on Subject : Observer model

class Subject;

class Observer {
public:
virtual ~Observer();
virtual void Update (Subject* theChangedSubject) = 0;
protected:
Observer();
};

class Subject {
public:
virtual ~Subject();

virtual void Attach (Observer *);
virtual void Detach (Observer *);
virtual void Notify();
protected:
Subject();
private:
List<Observer *> *_observers;
};


void Subject::Attach (Observer *o)
{
_observers->Append(o); // I used push_back(o); here
// but Segmentation Fault
}

void Subject::Detach (Observer *o)
{
_observers->Remove(o); // I used remove(o) here
}

void Subject::Notify()
{
ListIterator<Observer *> i(_observers);
// in Linux C++, ListIterator doesn't exist
for (i.First(); !i.IsDone(); i.Next()) {
i.CurrentItem()->Update(this);
}
}

..... and so on so forth.
Thanks
Jack

Tinkster 12-13-2005 05:53 PM

What makes you think that there's any porting required?
Looks like plain C++ to me, with no OS dependencies I
can spot off the top of my head.


Cheers,
Tink

lucky6969b 12-14-2005 01:24 AM

Tinkster,
Thanks for the advice, I have had it solved. But forgot how I did this. Thanks
Jack

lucky6969b 12-14-2005 09:34 PM

Another porting question, when VC/BC generates __fastcall prologue, it would generally modify the structure of the opening idioms of the routine, does Linux has the same stuff cos my app is real time (time-critical)..
Thanks
Jack

paulsm4 12-14-2005 09:57 PM

Actually, I understand that Gcc gives you options to bypass the stack altogether and use registers for passing parameters (at least on some versions, on some platforms).

In any case, Gcc definitely gives you a LOT of choices, on ALL platforms.

Here are a couple of links that might be useful:

http://www.linuxjournal.com/article/7269

http://www.tldp.org/HOWTO/Assembly-HOWTO/gcc.html

http://www.samspublishing.com/articl...30865&seqNum=5

http://www.linuxgazette.com/issue71/joshi.html

lucky6969b 12-14-2005 10:11 PM

So all the optimizations are done during compilation (commandline). But you can't use any directives to specify optimizations in code?
Thanks
Jack


All times are GMT -5. The time now is 06:30 AM.