Changeset 9952bd in git for libpolys/coeffs/Enumerator.h


Ignore:
Timestamp:
Sep 10, 2012, 2:13:09 PM (12 years ago)
Author:
Oleksandr Motsak <motsak@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
8d341e5425f8b7b26cdf77eec4ee78cbbb121c5c
Parents:
6dffa9e5b66ac5a81df2b68ff1c38dafc918b1f9
Message:
Changed enumerators to handle empty sets just like C# does

chg: enumerators handle empty sets just like C# does (together with Alexander Dreyer and Bjarke Roune)
fix: fixed comments for the above change
chg: adaptation of and minor changes to n[dl]Clear* implementations
add: introduced IBaseEnumerator::IsValid() = 0 (right now - for debug purpose only)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libpolys/coeffs/Enumerator.h

    r6dffa9 r9952bd  
    2222/** @class IBaseEnumerator
    2323 *
    24  * Base enumerator interface for simple iteration over a generic non-empty collection.
    25  *
    26  * Abstract API of enumerators for non-empty enumerable collections of standalone
    27  * objects. Inspired by IEnumerator from C#. Usage parrten can be as
    28  * follows:
     24 * Base enumerator interface for simple iteration over a generic collection.
     25 *
     26 * Abstract API of enumerators for enumerable collections of standalone objects.
     27 * Just like IEnumerator from C#. Usage pattern can be as follows:
    2928 *
    3029 * @code
    31  *   IBaseEnumerator itr = ...;
    32  *   itr.Reset(); // goes to the first element (must exist)
    33  *   do
     30 *   IBaseEnumerator& itr = ...;
     31 *   itr.Reset(); // goes to the "-1" element
     32 *   // NOTE: itr is not useable here!
     33 *   while( itr.MoveNext() )
    3434 *   {
    3535 *      do something custom with itr...
    3636 *   }
    37  *   while( itr.MoveNext() )
    3837 * @endcode
    3938 *
    40  * Note that the first element must exist and available directly after Reset() call.
     39 * Note that the Reset()
    4140 *
    4241 * @sa IEnumerator
     
    5150    virtual bool MoveNext() = 0;   
    5251
    53     /// Sets the enumerator to its initial position, which is at the first element in the collection.
     52    /// Sets the enumerator to its initial position: -1,
     53    /// which is before the first element in the collection.
    5454    virtual void Reset() = 0;
    55 //    virtual ~IEnumerator() {} // TODO: needed?
     55
     56    virtual ~IBaseEnumerator() {} // TODO: needed?
     57
     58  private:
     59    IBaseEnumerator(const IBaseEnumerator&);
     60    void operator=(const IBaseEnumerator&);
     61
     62  protected:
     63    IBaseEnumerator(){}
     64
     65    /// Current position is inside the collection (not -1 or past the end)
     66    virtual bool IsValid() const = 0;
    5667};
    5768
     
    7889    /// Gets the current element in the collection (read only).
    7990    virtual const_reference Current() const = 0;
     91
     92    virtual ~IAccessor() {} // TODO: needed?
     93 
    8094};
    8195
    8296/** @class IEnumerator
    8397 *
    84  * Templated enumerator interface for simple iteration over a generic non-empty collection of T's.
    85  *
    86  * Abstract API of enumerators for non-empty enumerable collections of standalone
    87  * objects. Inspired by IEnumerator from C#. Usage parrten can be as
     98 * Templated enumerator interface for simple iteration over a generic collection of T's.
     99 *
     100 * Abstract API of enumerators for generic enumerable collections of standalone
     101 * objects of type T. Inspired by IEnumerator from C#. Usage parrten can be as
    88102 * follows:
    89103 *
    90104 * @code
    91  *   IEnumerator<T> itr = ...;
    92  *   itr.Reset(); // goes to the first element (must exist)
    93  *   do
     105 *   IEnumerator<T>& itr = ...;
     106 *   
     107 *   itr.Reset(); // goes before the first element, thus no itr.Current() is available here!
     108 *   
     109 *   while( itr.MoveNext() )
    94110 *   {
    95111 *      use/change itr.Current()...
    96112 *   }
    97  *   while( itr.MoveNext() )
    98113 * @endcode
    99114 *
Note: See TracChangeset for help on using the changeset viewer.