Tulip  4.6.0
Better Visualization Through Research
library/tulip-core/include/tulip/BmdList.h
00001 /*
00002  *
00003  * This file is part of Tulip (www.tulip-software.org)
00004  *
00005  * Authors: David Auber and the Tulip development Team
00006  * from LaBRI, University of Bordeaux
00007  *
00008  * Tulip is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU Lesser General Public License
00010  * as published by the Free Software Foundation, either version 3
00011  * of the License, or (at your option) any later version.
00012  *
00013  * Tulip is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016  * See the GNU General Public License for more details.
00017  *
00018  */
00019 ///@cond DOXYGEN_HIDDEN
00020 
00021 
00022 #ifndef BMDLIST_H
00023 #define BMDLIST_H
00024 
00025 #ifndef DOXYGEN_NOTFOR_USER
00026 
00027 #include <cassert>
00028 #include <tulip/BmdLink.h>
00029 
00030 namespace tlp {
00031 template <typename TYPE>
00032 class BmdList {
00033 public:
00034   typedef  tlp::BmdLink<TYPE> BMDTYPE;
00035 
00036   BmdList();
00037   virtual ~BmdList();
00038   BMDTYPE *firstItem();
00039   BMDTYPE *lastItem();
00040   TYPE entry(BMDTYPE *it);
00041   int size();
00042   BMDTYPE *nextItem(BMDTYPE *p, BMDTYPE *predP);
00043   BMDTYPE *predItem(BMDTYPE *p, BMDTYPE *succP);
00044   BMDTYPE *cyclicPred(BMDTYPE *it, BMDTYPE *succIt);
00045   BMDTYPE *cyclicSucc(BMDTYPE *it, BMDTYPE *predIt);
00046   BMDTYPE *push(const TYPE &a);
00047   BMDTYPE *append(const TYPE &a);
00048   TYPE delItem(BMDTYPE *it);
00049   TYPE pop();
00050   TYPE popBack();
00051   void reverse();
00052   void conc(BmdList<TYPE> &l);
00053   void clear();
00054   void swap(BmdList<TYPE> &l);
00055 private:
00056   BMDTYPE *head;
00057   BMDTYPE *tail;
00058   int count;
00059 };
00060 
00061 #include <tulip/cxx/BmdList.cxx>
00062 
00063 
00064 template<typename TYPE>
00065 struct BmdListIt : public Iterator<TYPE> {
00066 
00067   BmdListIt(BmdList<TYPE> &bmdList):bmdList(bmdList) {
00068     pos = bmdList.firstItem();
00069     pred = 0;
00070   }
00071   bool hasNext() {
00072     return pos!=0;
00073   }
00074   TYPE next() {
00075     TYPE val = pos->getData();
00076     tlp::BmdLink< TYPE > *tmp = pos;
00077     pos = bmdList.nextItem(pos, pred);
00078     pred = tmp;
00079     return val;
00080   }
00081 private:
00082   tlp::BmdLink< TYPE > *pos;
00083   tlp::BmdLink< TYPE > *pred;
00084   BmdList<TYPE> &bmdList;
00085 };
00086 
00087 template<typename TYPE>
00088 struct BmdListRevIt : public Iterator<TYPE> {
00089   BmdListRevIt(BmdList<TYPE> &bmdList):bmdList(bmdList) {
00090     pos = bmdList.lastItem();
00091     suc = 0;
00092   }
00093   bool hasNext() {
00094     return pos!=0;
00095   }
00096   TYPE next() {
00097     TYPE val = pos->getData();
00098     tlp::BmdLink< TYPE > *tmp = pos;
00099     pos = bmdList.predItem(pos, suc);
00100     suc = tmp;
00101     return val;
00102   }
00103 private:
00104   tlp::BmdLink< TYPE > *pos;
00105   tlp::BmdLink< TYPE > *suc;
00106   BmdList<TYPE> &bmdList;
00107 };
00108 }
00109 #endif
00110 #endif
00111 ///@endcond
 All Classes Files Functions Variables Enumerations Enumerator Properties