Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

mset.h

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

Generated on Thu Feb 10 20:06:42 2005 for LibMagiC by doxygen1.2.18