Main Page   Class Hierarchy   Compound List   File List   Compound Members  

mset.h

00001 #ifndef __SET_H__
00002 #define __SET_H__
00003 
00004 #include <mobject.h>
00005 
00006 class AnySet : public Object {
00007 };
00008 
00009 
00010 
00012 //                                                                           //
00013 //                     |   |           o                                     //
00014 //                     |   |  ___         ___    _    |                      //
00015 //                     |   |  ___| |/\ |  ___| |/ \  -+-                     //
00016 //                      \ /  (   | |   | (   | |   |  |                      //
00017 //                       V    \__| |   |  \__| |   |   \                     //
00018 //                                                                           //
00020 
00021 template <class ttype>
00022 class Variant : public AnySet {
00023   public:
00024     ttype   i;
00025 
00026                             operator ttype  () const {return i;}
00027     //virtual DumpContext&  operator>>  (DumpContext& out) const {MUST_OVERLOAD}
00028 };
00029 
00030 template<class ttype>
00031 class IteratorInterface {
00032   public:
00033     virtual void    start       ()=0;
00034     virtual void    next        ()=0;
00035     virtual bool    exhausted   () const=0;
00036     virtual bool    next_ends   () const {MUST_OVERLOAD}
00037 };
00038 
00039 
00041 //                                                                          //
00042 //           -----                                                          //
00043 //           |       _                ___       ___   |                     //
00044 //           |---  |/ \  |   | |/|/| /   ) |/\  ___| -+-  __  |/\           //
00045 //           |     |   | |   | | | | |---  |   (   |  |  /  \ |             //
00046 //           |____ |   |  \__! | | |  \__  |    \__|   \ \__/ |             //
00047 //                                                                          //
00049 
00050 
00051 template <class ttype>
00052 class Iterator : public Variant<ttype>, public IteratorInterface<ttype> {
00053     ttype   m_start, m_end, m_step;
00054   public:
00055     
00056                 Iterator    (ttype s, ttype e=-9999, ttype stp=1) {
00057                     m_start = s;
00058                     ASSERTWITH (s<=e, "Start of a variant must be less than end");
00059                     m_end = (e==-9999)? s:e;
00060                     ASSERTWITH (stp>0, "Finite variant violation");
00061                     m_step = stp;
00062                     start ();
00063                 }
00064     void        start       () {i = m_start;}
00065     void        next        () {i += m_step;}
00066     bool        exhausted   () const {return i>m_end;}
00067     bool        next_ends   () const {return i+m_step>m_end;}
00068     ttype       max         () const {return m_end;}
00069 //  
00070 //  OStream&    operator>>  (OStream& o) {
00071 //      o.print ("{");
00072 //      if (m_start != m_end)
00073 //          ; else
00074 //              o << i;
00075 //      o.print ("}");
00076 //  }
00077 //  DumpContext&    operator>>  (DumpContext& out) const {
00078 //      out.name ("m_start") << m_start;
00079 //      out.name ("m_end") << m_end;
00080 //      out.name ("m_step") << m_step;
00081 //  }
00082 //  
00083 };
00084 
00085 /*
00086 template<class maintype, class subtype>
00087 class Iterator {//: public IteratorInterface<Array<TYPE> > {
00088     //  mutable Array<TYPE>&    mArray;
00089     //Iterator<int>             mIter;
00090   public:
00091     Iterator    (const maintype& array) //:
00092 //                      mArray (const_cast<Array<TYPE>&>(array)),
00093         //                      mIter(array.lower, array.upper, 1) {}
00094                 {}
00095     void        start       () {}//mIter.start();}
00096     void        next        () {}//mIter.next();}
00097     bool        exhausted   () const {return false;}//mIter.exhausted();}
00098     //              operator const ttype& () const {return mArray[mIter.i];}
00099 };
00100 */
00101 
00102 
00103 
00105 //                                                                           //
00106 //                ---                       o                                //
00107 //                 |    _          ___         ___    _    |                 //
00108 //                 |  |/ \  |   |  ___| |/\ |  ___| |/ \  -+-                //
00109 //                 |  |   |  \ /  (   | |   | (   | |   |  |                 //
00110 //                _|_ |   |   V    \__| |   |  \__| |   |   \                //
00111 //                                                                           //
00113 
00114 // A "variant" that does not change (i.e., a constant)
00115 template <class ttype>
00116 class Invariant : public Variant<ttype> {
00117   public:
00118                 Invariant   (ttype s) {
00119                     i = s;
00120                 }
00121     DumpContext&    operator>>  (DumpContext& out) const {
00122         out.name ("i") << i;
00123     }
00124 };
00125 
00126 
00127 
00128 #define forSet(name) for (name.start(); !name.exhausted(); name.next())
00129 
00130 #endif

Generated at Tue Dec 4 19:53:27 2001 for MagiC++ by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001