next up previous contents
Next: Iterators Up: Visitors Previous: CascadingMap   Contents


VisitorMap

VisitorMap is declared in suifkernel/visitor_map.h. The VisitorMap is a special-purpose Visitor which dynamically dispatches a SuifObject and the address of state to one of several functions, depending on its type. Each function is of type VisitMethod:          typedef void *Address; // declared in iokernel/iokernel_forwarders.h
         typedef void (*VisitMethod)( Address state, Object *object );
   
The constructor takes a pointer to the SuifEnv, which is used to interact with the MetaClass system to determine the appropriate action. It has the following operations: Here is an example use:
       class MyVisitorInfo {
            static void do_static_procedure_definition( 
                             void *info,
                             ProcedureDefinition *obj) {
                (MyVisitorInfo *)info->do_procedure_definition(obj);
            }
            void do_procedure_definition(ProcedureDefinition *proc_def) {
                ...do something...
            }
       } 
       // register the visitor functions
       VisitorMap *map = new VisitorMap(suif_env);
       MyVisitorClass my_info;
       map->registerVisitMethod( &myinfo, 
                                 &MyVisitorClass::do_static_procedure_definition,
                                 ProcedureDefinition::get_class_name() );
       // Pick an object:
       SuifObject *so;
       ...
       map->apply(so);



SUIF Nightly Build
2000-08-14