Class Hierarchy   Compound List   File List   Header Files   Compound Members   File Members  

suifkernel/utilities.h

This is the verbatim text of the utilities.h include file.
#ifndef SUIFKERNEL__UTILITIES_H
#define SUIFKERNEL__UTILITIES_H

#include "iokernel/object_factory.h"
#include "suifkernel/suif_object.h"

#include "suifkernel_forwarders.h"
#include "suif_env.h"

#include "iter.h"


// --------------- type less accessor functions ------------
sf_owned Iterator* object_iterator( const Address start_object,
				    const MetaClass* object_type,
				    const MetaClass* what );

sf_owned Iterator* object_iterator( const Address start_object,
				    const MetaClass* start_object_type,			
				    const MetaClass* dont_search_beyond,
				    const MetaClass* what );


sf_owned Iterator* object_ref_iterator( SuifObject *start_object,
					const MetaClass* what );



// -------------- typed accessor functions ----------------
template<class T>
Iter<T> object_iterator( const SuifObject* start_object ) {
  Iterator* it = 0;
  if ( start_object ) {
    MetaClass* what = start_object->get_object_factory()->
                           find_meta_class( T::get_class_name() );
    it = object_iterator( (const Address)start_object,
                          start_object->get_meta_class(),
			  what );
  }
  return Iter<T>( it );
}




template<class T>
list<T*>* collect_objects( const SuifObject* start_object ) {
  list<T*>* l = new list<T*>;
  if ( start_object ) {
    MetaClass* what = start_object->get_object_factory()->
                           find_meta_class( T::get_class_name() );

    Iterator* it = object_iterator( (const Address)start_object,
				    start_object->get_meta_class(),
				    what );
    while ( it->is_valid() ) {
      suif_assert( it->current_meta_class() == what );
      l->push_back( (T*)it->current() );
      it->next();
    }
    delete it;
  }
  return l;
}




template<class T>
Iter<T> collect_instance_objects( SuifObject* start_object,
                                   const LString& start_class = emptyLString,
                                   const LString& end_class = emptyLString ) {
  Iterator* it = 0;
  if ( start_object ) {
    ObjectFactory* of = start_object->get_suif_env()->get_object_factory();

    MetaClass* what = of->find_meta_class( T::get_class_name() );
    suif_assert( what );

    MetaClass* dont_search_beyond = of->find_meta_class( SuifObject::get_class_name() );
    suif_assert( dont_search_beyond );

    it = object_iterator( start_object,
			  start_object->get_meta_class(),
			  dont_search_beyond,
			  what );
  }
  return Iter<T>( it );
}



template<class T>
Iter<T> suif_object_ref_iterator( SuifObject* start_object,
				  const LString& start_class = 
				  SuifObject::get_class_name()) {
  // ask a stupid question
  if (!start_object) return(NULL);

  ObjectFactory* of = start_object->get_suif_env()->get_object_factory();
  
  MetaClass* what = of->find_meta_class( T::get_class_name() );
  suif_assert( what );
  // the stop object BETTER be a subclass of suif object.
  suif_assert(is_kind_of_suif_object_meta_class(what));
  Iterator *it = object_ref_iterator( start_object,
				      what );
  return Iter<T>( it );
}


#endif

Generated at Mon Nov 22 19:44:02 1999 for NCI SUIF by doxygen  written by Dimitri van Heesch, © 1997-1999