ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

Common::Functor1< Arg, Res > Struct Template Reference

Generic functor object for unary function objects. More...

#include <func.h>

Inheritance diagram for Common::Functor1< Arg, Res >:
Collaboration diagram for Common::Functor1< Arg, Res >:

List of all members.

Public Member Functions

virtual ~Functor1 ()
virtual bool isValid () const =0
virtual Res operator() (Arg) const =0

Detailed Description

template<class Arg, class Res>
struct Common::Functor1< Arg, Res >

Generic functor object for unary function objects.

A typical usage for an unary function object is for executing opcodes in a script interpreter. To achieve that one can create an Common::Array object with 'Functor1<Arg, Res> *' as type. Now after the right engine version has been determined and the opcode table to use is found one could easily add the opcode implementations like this:

Common::Array<Functor1<ScriptState, void> *> opcodeTable; opcodeTable[0] = new Functor1Mem<ScriptState, void, MyEngine_v1>(&myEngine, &MyEngine_v1::o1_foo); opcodeTable[1] = new Functor1Mem<ScriptState, void, MyEngine_v2>(&myEngine, &MyEngine_v2::o2_foo); // unimplemented/unused opcode opcodeTable[2] = 0; etc.

This makes it easy to add member functions of different classes as opcode functions to the function table. Since with the generic Functor1<ScriptState, void> object the only requirement for an function to be used is 'ScriptState' as argument and 'void' as return value.

Now for calling the opcodes one has simple to do: if (opcodeTable[opcodeNum] && opcodeTable[opcodeNum]->isValid()) (*opcodeTable[opcodeNum])(scriptState); else warning("Unimplemented opcode %d", opcodeNum);

If you want to see an real world example check the kyra engine. Files: engines/kyra/script.cpp and .h and engines/kyra/script_*.cpp are interesting for that matter.

Definition at line 428 of file func.h.

Constructor & Destructor Documentation

template<class Arg , class Res >
virtual Common::Functor1< Arg, Res >::~Functor1 (  )  [inline, virtual]

Definition at line 429 of file func.h.

Member Function Documentation

template<class Arg , class Res >
virtual bool Common::Functor1< Arg, Res >::isValid (  )  const [pure virtual]
template<class Arg , class Res >
virtual Res Common::Functor1< Arg, Res >::operator() ( Arg   )  const [pure virtual]

The documentation for this struct was generated from the following file:

Generated on Sat Sep 19 2020 05:04:45 for ResidualVM by doxygen 1.7.1
curved edge   curved edge