Top Content Up
Prec

5.5 Extending the functor classes

Next

For a component foo, there is a struct _F_foo. We know functags are member functions of a class derived from _F_foo. What differentiate a functag from another member function. Not much in fact. Beside it special declaration (using preprocessor macros) a functag is just a virtual member function. From a functag, we are allowed to call other member function of the class _F_foo. In general, those extra member function are not virtual since Extending class such as _F_foo is convenient to provide a richer runtime environment to functags. This generally offers convenience to the client code of a component (avoid redundant details) and provides more control to the component itself.

Here is a small example. First we have the component definition. In this component (some sort of iterator), we add two member function to offers greater control over the iteration.

#define _TLMP_foo
struct _F_foo {
	// Called if the result set if empty, so there won't be any
	// iteration (no start, loop and end functag called)
	#define _F_foo_empty(n) void n empty()
	virtual _F_foo_sempty( );
	// Called at the start of the iteration
	#define _F_foo_start(n) void n start()
	virtual _F_foo_start( );
	// Called for every step of the iteration
	#define _F_foo_loop(n) void n loop(int count)
	virtual _F_foo_loop( )=0;
	// Called at the end of the iteration
	#define _F_foo_end(n) void n end()
	virtual _F_foo_end( );
	// Restart the iteration
	void rewind();
	// Seek to a specific position
	int seek (int pos);
};


Then we use the component. In functags, we are allowed to use the rewind and seek function.
Top Content Up
Prec

Next
Table of content
One big HTML document