Crystal Space
Welcome, Guest. Please login or register.
November 25, 2014, 11:27:39 pm

Login with username, password and session length
Search:     Advanced search
9026 Posts in 2046 Topics by 9129 Members
Latest Member: Kosmobruk66
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  Support
| | |-+  csInitializer::SetupEventHandler()
« previous next »
Pages: [1] Print
Author Topic: csInitializer::SetupEventHandler()  (Read 3176 times)
bernardofd
Jr. Member
**
Posts: 74


59948732 bernardofd@click21.com.br
View Profile WWW
« on: March 18, 2005, 04:07:56 pm »

Hello all;

I rather new in using CS, but we're on an project that will use it's libraries.

But I have an problem. I'm not a experienced programmer in C++, my experience resumes in C (so, no Object Oriented... wink ). And I having this function slowing my progress in development, so i would reaaly appreciate some help.

here is the function call and definitions:
Code:

bool ERD::EventHandler (iEvent& ev)
{
return event->HandleEvent(ev);
}

/* Initialize */
bool ERD::Initialize ()
{
event = new Event();

// Initialize Event Handler
if (!csInitializer::SetupEventHandler(object_reg,  erd->EventHandler))
{
csReport(object_reg, CS_REPORTER_SEVERITY_ERROR,
"Estrada Real Digital",
"Erro ao inicializar o Event Handler!");
return false;
}
bool Event::HandleEvent(iEvent &ev)


And the makefile output:
Code:

sisifo:~/csApp/erd/teste->make
g++  -I/crystalspace/CS/include      -o teste.o -c teste.cpp
teste.cpp: In member function `bool ERD::Initialize()':
teste.cpp:160: error: no matching function for call to `csInitializer::SetupEventHandler(iObjectRegistry*&, <unknown type>)'
/crystalspace/CS/include/cstool/initapp.h:340: note: candidates are: static bool csInitializer::SetupEventHandler(iObjectRegistry*, iEventHandler*, unsigned int)
/crystalspace/CS/include/cstool/initapp.h:360: note:                 static bool csInitializer::SetupEventHandler(iObjectRegistry*, bool (*)(iEvent&), unsigned int)
make: *** [teste.o] Error 1


I've already tried a lot of thigs to get this thing on, but I failed in all. If someone could lend me some help, I would be gratefull.

Thanks in advance.

P.S. - My system features:
Code:

sisifo:~->uname -a
Linux sisifo 2.6.10-1.766_FC3smp #1 SMP Wed Feb 9 23:21:37 EST 2005 i686 i686 i386 GNU/Linux
sisifo:~->gcc -v
Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-awt=gtk --host=i386-redhat-linux
Thread model: posix
gcc version 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)
Logged

__________________________
Bernardo Figuerêdo Domingues
Computer Science - UFMG - Brazil
acraig
Newbie
*
Posts: 14


View Profile Email
« Reply #1 on: March 18, 2005, 05:31:16 pm »

What you should have in your ERD class is something like:
Code:

class ERD
{
....
    static bool StaticEventHandler(iEvent &ev);
     bool EventHandler(iEvent &ev);
};


bool ERD::StaticEventHandler(iEvent& ev)
{
    // If the pointer is not valid, don't crash
    if (g_pApp)
        return g_pApp->EventHandler(ev);
    else
...
}


bool ERD::Initialize ()
{
    if (!csInitializer::SetupEventHandler(object_reg,StaticEventHandler))
   {
...
    }
}



And you would have one global var g_App that is set when you create your ERD class. [/code]
Logged
bernardofd
Jr. Member
**
Posts: 74


59948732 bernardofd@click21.com.br
View Profile WWW
« Reply #2 on: March 21, 2005, 01:30:14 pm »

Thanks for your help! But I coudn't understand what do you meant with that g_pApp pointer. Would I set it to what?

And, for code organization, I want to place the Event Handler in another class apart of the main one (ERD).

Is the StaticEventHandler() just a security function just for pass by the compiler?

Anyway, thanks for your help.

Regards
Logged

__________________________
Bernardo Figuerêdo Domingues
Computer Science - UFMG - Brazil
acraig
Newbie
*
Posts: 14


View Profile Email
« Reply #3 on: March 21, 2005, 08:51:13 pm »

In your main() function you would have something like:
Code:


ERD* g_App

int main()
{
    g_App = new ERD();
}


The function needs to be static because SetupEventHandler() takes a function point.  For classes you cannot use function pointers unless they are static.  So this is why there is a dummy ERD::StaticEventHandler that simply calls g_App->EventHandler().  This is a limitation of C++.
Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 6.205 seconds with 15 queries.