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_ut( const ObjectWrapper &start_object,
				       const MetaClass* what );

sf_owned Iterator* object_iterator_ut( const ObjectWrapper &start_object,
				       const MetaClass* dont_search_beyond,
				       const MetaClass* what );

sf_owned Iterator* object_ref_iterator_ut( 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_ut( ObjectWrapper(start_object),
			     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_ut( ObjectWrapper(start_object),
				       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_ut( ObjectWrapper(start_object),
			     dont_search_beyond,
			     what );
  }
  return Iter<T>( it );
}

template<class T>
Iter<T> suif_subobject_iterator( SuifObject* start_object,
				 const LString& start_class = emptyLString,
				 const LString& end_class = emptyLString ) {
  return(collect_instance_objects(start_object, start_class, end_class));
}



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_ut( start_object,
					 what );
  return Iter<T>( it );
}

#endif

Generated at Wed Apr 25 17:35:23 2001 for NCI SUIF by doxygen  written by Dimitri van Heesch, © 1997-1999