(nvidia SDK, nv_win lib) can someone explain to me whats going on here please?

hi guys,
i’m going through the src for the nv_win library packaged with the nvidia sdk, and i’ve come across some confusing bits of code, and was wondering if someone might beable to explain to me whats going on.

ok, whats confusing me the the vn_app_cmd and nv_cmd_mgr functions (located in vn_win_app.h, and vn_command.h/.cpp)

I will cut the code a bit to lessen the amount of explaination i have to do.

so, first we have the definition of the nv_app_cmd class

// sniplet from nv_win_app.h

class nv_app_cmd
// force it to create a vtable?
virtual ~nv_app_cmd() { }

// function pointer prototype for command handling functions.
typedef void (nv_app_cmd::*PFN_APP_CMD)(nv_cmd_args * args);

struct nv_fn_app_cmd
nv_app_cmd * fn_app_cmd;

first, what exactly is happening with the typedef?
i can understand it without the nv_app_cmd:: part, but i can’t quite figure out how the nv_app_cmd:: bit works. how does PFN_APP_CMD relate to vn_app_cmd?

also, the nv_app_cmd * fn_app_cmd confuses me. the nv_app_cmd class has nothing but a deconstructor, so what is the point of it?

// sniplet from nv_command.h

typedef std::mapstd::string,nv_fn_app_cmd* app_cmd_map;
typedef app_cmd_map::value_type app_cmd_pair;
typedef app_cmd_map::iterator app_cmd_it;

class nv_cmd_mgr : public nv_app_cmd

bool add_cmd(const char * name, nv_fn_app_cmd * pfn);
bool send_cmd(const char * str_cmd, nv_cmd_args * args);

void set(nv_cmd_args * args);

app_cmd_map m_cmd_map;

this part is fine, except again for the inheretance from nv_app_cmd, whats the point inheriting from a class that has nothing but a deconstructor?

// sniplet from nv_command.cpp


nv_fn_app_cmd * fn_set = new nv_fn_app_cmd;
fn_set->pfn = (PFN_APP_CMD)&nv_cmd_mgr::set;
fn_set->fn_app_cmd = reinterpret_cast<nv_app_cmd*>(this);


bool nv_cmd_mgr::add_cmd(const char * name, nv_fn_app_cmd * pfn)
app_cmd_it it = m_cmd_map.find(name);
if (it == m_cmd_map.end())
return true;
return false;

bool nv_cmd_mgr::send_cmd(const char * str_cmd, nv_cmd_args * args)
app_cmd_it it = m_cmd_map.find(str_cmd);
if (it != m_cmd_map.end())
nv_fn_app_cmd * pfn = (it).second;
return true;
return false;

This is the most confusing section for me :stuck_out_tongue:

fn_set->fn_app_cmd = reinterpret_cast<nv_app_cmd*>(this);

what does the reinterpret_cast thing do?
and what is the main purpose of line?

    nv_fn_app_cmd * pfn = (*it).second;

Ok, so here we retreive the command, and a pointer to the commands nv_fn_app_cmd struct and we want to call the function associated with the command.
but what the hell is all that mess? maybe an answer to the above questions will help me realise, but at the moment, my head huts just looking at it :stuck_out_tongue:

anyways. any help would be much appreciated!
thanks in advance

[This message has been edited by torisutan (edited 09-28-2003).]

in very short: learn c++
in less short: they wrote some manager where they can register method-pointers including objects to strings, and all them by name.