- Main Page
- Classes
- Files

- File List

# OptFrame/Util/NSSeqPairFirstAdapter.hpp

    00001 #ifndef OPTFRAME_NSSEQ_PAIRFIRST_ADAPTER_HPP_
    00002 #define OPTFRAME_NSSEQ_PAIRFIRST_ADAPTER_HPP_
    00003
    00004 // Framework includes
    00005 #include "../Move.hpp"
    00006 #include "../NSSeq.hpp"
    00007
    00008 using namespace std;
    00009
    00010 template<class T1, class T2, class M = OPTFRAME_DEFAULT_MEMORY>
    00011 class MovePairFirst: public Move<pair<T1, T2> , M>
    00012 {
    00013 protected:
    00014         Move<T1, M>& m;
    00015
    00016 public:
    00017
    00018         MovePairFirst(Move<T1, M>& _m) :
    00019                 m(_m)
    00020         {
    00021         }
    00022
    00023         Move<T1, M>& get_m()
    00024         {
    00025                 return m;
    00026         }
    00027
    00028         virtual ~MovePairFirst()
    00029         {
    00030                 delete &m;
    00031         }
    00032
    00033         bool canBeApplied(const pair<T1, T2>& rep)
    00034         {
    00035                 return m.canBeApplied(rep.first);
    00036         }
    00037
    00038         Move<pair<T1, T2> , M>& apply(pair<T1, T2>& rep)
    00039         {
    00040                 return *new MovePairFirst<T1, T2, M> (m.apply(rep.first));
    00041         }
    00042
    00043         virtual bool operator==(const Move<pair<T1, T2> , M>& _m) const
    00044         {
    00045                 const MovePairFirst<T1, T2, M>& m1 = (const MovePairFirst<T1, T2, M>&) _m;
    00046                 return m == m1.m;
    00047         }
    00048
    00049         void print()
    00050         {
    00051                 cout << "MovePairFirst: move = ";
    00052                 m.print();
    00053         }
    00054 };
    00055
    00056 class PairFirstAdapterIteratorOutOfBound
    00057 {
    00058 public:
    00059         PairFirstAdapterIteratorOutOfBound()
    00060         {
    00061         }
    00062 };
    00063
    00064 template<class T1, class T2, class M = OPTFRAME_DEFAULT_MEMORY, class MOVE = MovePairFirst<T1, T2, M> >
    00065 class IteratorNSSeqPairFirst: public NSIterator<pair<T1, T2> , M>
    00066 {
    00067 private:
    00068         NSIterator<T1, M>& iterator;
    00069
    00070 public:
    00071
    00072         IteratorNSSeqPairFirst(NSIterator<T1, M>& it) :
    00073                 iterator(it)
    00074         {
    00075         }
    00076
    00077         virtual ~IteratorNSSeqPairFirst()
    00078         {
    00079                 delete &iterator;
    00080         }
    00081
    00082         void first()
    00083         {
    00084                 iterator.first();
    00085         }
    00086
    00087         void next()
    00088         {
    00089                 iterator.next();
    00090         }
    00091
    00092         bool isDone()
    00093         {
    00094                 return iterator.isDone();
    00095         }
    00096
    00097         Move<pair<T1, T2> , M>& current()
    00098         {
    00099
    00100                 if (!iterator.isDone())
    00101                         return *new MOVE(iterator.current());
    00102                 else
    00103                         throw PairFirstAdapterIteratorOutOfBound();
    00104         }
    00105 };
    00106
    00107 template<class T1, class T2, class M = OPTFRAME_DEFAULT_MEMORY, class MOVE = MovePairFirst<T1, T2, M> >
    00108 class NSSeqPairFirstAdapter: public NSSeq<pair<T1, T2> , M>
    00109 {
    00110 protected:
    00111         NSSeq<T1, M>& ns;
    00112
    00113 public:
    00114
    00115         NSSeqPairFirstAdapter(NSSeq<T1, M>& _ns) :
    00116                 ns(_ns)
    00117         {
    00118         }
    00119
    00120         virtual ~NSSeqPairFirstAdapter()
    00121         {
    00122         }
    00123
    00124         Move<pair<T1, T2> , M>& move(const pair<T1, T2>& r)
    00125         {
    00126                 return *new MOVE(ns.move(r.first));
    00127         }
    00128
    00129         virtual NSIterator<pair<T1, T2> , M>& getIterator(const pair<T1, T2>& r)
    00130         {
    00131                 return *new IteratorNSSeqPairFirst<T1, T2, M, MOVE> (ns.getIterator(r.first));
    00132         }
    00133
    00134         virtual void print()
    00135         {
    00136                 cout << "NSSeqPairFirstAdapter {" << endl;
    00137                 ns.print();
    00138                 cout << "}" << endl;
    00139         }
    00140 };
    00141
    00142 #endif /*OPTFRAME_NSSEQ_PAIRFIRST_ADAPTER_HPP_*/

All Classes Functions