Partilhar via


SetIterator.Begin Method

Definition

Moves the iterator to the start of the set.

public:
 virtual void Begin();
public virtual void Begin ();
abstract member Begin : unit -> unit
override this.Begin : unit -> unit
Public Overridable Sub Begin ()

Remarks

Newly created set iterators are positioned at the first element in the set. Typically, you do not need to call the begin method before you start to iterate through the set; you need to do that only if you want to reset the pointer later on.

The following example returns set of class IDs of the classes that implement the specified interface, that is, the _id class. An iterator is used to remove classes from the set if they are superclasses, and the _onlyLeafClasses parameter is set to true. The begin method is used to reset the iterator after the superclasses have been removed from the set.

public static Set getImplements( 
    classId _id,  
    boolean _onlyLeafClasses = true) 
{ 
    Dictionary dictionary = new Dictionary(); 
    SysDictClass sysDictClass; 
    boolean removed; 
    Set set = new Set(Types::Integer); 
    SetIterator setIterator = new SetIterator(set); 
    int i; 
    for (i=1;i<=dictionary.classCnt();i++) 
    { 
        sysDictClass = new SysDictClass(dictionary.classCnt2Id(i)); 
        if (sysDictClass.isImplementing(_id)) 
        { 
            set.add(sysDictClass.id()); 
        } 
    } 
    //No superclasses included in return set 
    if (_onlyLeafClasses) 
    { 
        // begin method not needed here; only for clarity 
        setIterator.begin();  
        while (setIterator.more()) 
        { 
            removed = false; 
            sysDictClass = new SysDictClass(setIterator.value()); 
            while (sysDictClass.extend()) 
            { 
                removed = removed | set.remove(sysDictClass.extend()); 
                sysDictClass = new SysDictClass(sysDictClass.extend()); 
            } 
            if (removed) 
            { 
                // Restart search 
                setIterator.begin();  
            } 
            else 
            { 
                setIterator.next(); 
            } 
        } 
    } 
    return set; 
}

Applies to