00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 #ifndef SSETTOPOLOGY_H
00014 #define SSETTOPOLOGY_H
00015 
00016 
00017 #include <iostream>
00018 
00019 #include <LEDA/array.h>
00020 #include <LEDA/h_array.h>
00021 #include <LEDA/list.h>
00022 
00023 #ifndef leda_list_item
00024 #define leda_list_item list_item
00025 #endif
00026 
00027 
00028 #include "STopology.h"
00029 #include "SSetTopologyMod.h"
00030 #include "../SPassiveMachinesMod.h"
00031 
00032 
00033 
00034 class SSetTopEntry {
00035 public:
00036   int ID, card, pos;
00037   SSetTopEntry() : ID(0), card(0), pos(-1) {};
00038   SSetTopEntry(int i, int c, int p) : ID(i), card(c), pos(p) {};
00039 
00040   friend std::istream &operator>>(std::istream &i, SSetTopEntry &e) { return i; };
00041   friend std::ostream &operator<<(std::ostream &o, const SSetTopEntry &e) { return o; };
00042 };
00043 
00052 class SSetTopology : public virtual STopology {
00053   TYPEINFO0(SSetTopology,"set")
00054   friend class SSetTopologyMod;
00055 public:
00059   SSetTopology(int cardinality);
00062   virtual ~SSetTopology() {}
00063   
00066   virtual STopologyMod &getModifier() 
00067     { return _mod; };
00068   
00073   virtual int getCount() const { return _cardinality; };
00074 
00079   virtual int getIDAt(int pos) const { return _positions[pos]; };
00080 
00087   virtual int getPos(int ID) const { return _IDtoEntry[ID]->pos; };
00088 
00093   virtual bool isPosFree(int pos) const { return _free.size() > 0; };
00094 
00098   virtual leda_list<int> getFreePos() const { return _free; };
00099 
00104   virtual bool canEmbedAt(const STopology &top, int pos) const;
00105 
00111   virtual leda_list<int> canEmbedAt(const STopology &top) const;
00112 
00118   virtual void embed(const STopology& top, int pos, int ID);
00119 
00123   virtual void remove(int ID);
00124 
00125   virtual bool fitsInto(const STopology *top) const
00126     { return (_cardinality <= top->getCount()); }
00127 
00128 private:
00129   int _cardinality;
00130   leda_list<SSetTopEntry> _tops;  
00131   leda_array<int> _positions; 
00132   leda_h_array<int, SSetTopEntry*> _IDtoEntry;
00133   leda_list<int> _free;   
00134         
00135         
00136   static leda_list<int> _zeroList;  
00137   static leda_list<int> _emptyList; 
00138   static SSetTopEntry _defaultEntry;
00139 
00140   SSetTopologyMod _mod;
00141 
00142   
00143   void setSize(int cardinality);
00144 };
00145 
00146 
00147 #endif //SSETTOPOLOGY_H
00148 
00149 
00150 
00151 
00152 
00153