Tulip  5.1.0
Large graphs analysis and drawing
BmdList.h
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 ///@cond DOXYGEN_HIDDEN
20 
21 #ifndef BMDLIST_H
22 #define BMDLIST_H
23 
24 #include <cassert>
25 #include <tulip/BmdLink.h>
26 
27 namespace tlp {
28 template <typename TYPE>
29 class BmdList {
30 public:
31  typedef tlp::BmdLink<TYPE> BMDTYPE;
32 
33  BmdList();
34  virtual ~BmdList();
35  BMDTYPE *firstItem();
36  BMDTYPE *lastItem();
37  TYPE entry(BMDTYPE *it);
38  int size();
39  BMDTYPE *nextItem(BMDTYPE *p, BMDTYPE *predP);
40  BMDTYPE *predItem(BMDTYPE *p, BMDTYPE *succP);
41  BMDTYPE *cyclicPred(BMDTYPE *it, BMDTYPE *succIt);
42  BMDTYPE *cyclicSucc(BMDTYPE *it, BMDTYPE *predIt);
43  BMDTYPE *push(const TYPE &a);
44  BMDTYPE *append(const TYPE &a);
45  TYPE delItem(BMDTYPE *it);
46  TYPE pop();
47  TYPE popBack();
48  void reverse();
49  void conc(BmdList<TYPE> &l);
50  void clear();
51  void swap(BmdList<TYPE> &l);
52 private:
53  BMDTYPE *head;
54  BMDTYPE *tail;
55  int count;
56 };
57 
58 #include <tulip/cxx/BmdList.cxx>
59 
60 
61 template<typename TYPE>
62 struct BmdListIt : public Iterator<TYPE> {
63 
64  BmdListIt(BmdList<TYPE> &bmdList):bmdList(bmdList) {
65  pos = bmdList.firstItem();
66  pred = 0;
67  }
68  bool hasNext() {
69  return pos!=0;
70  }
71  TYPE next() {
72  TYPE val = pos->getData();
73  tlp::BmdLink< TYPE > *tmp = pos;
74  pos = bmdList.nextItem(pos, pred);
75  pred = tmp;
76  return val;
77  }
78 private:
79  tlp::BmdLink< TYPE > *pos;
80  tlp::BmdLink< TYPE > *pred;
81  BmdList<TYPE> &bmdList;
82 };
83 
84 template<typename TYPE>
85 struct BmdListRevIt : public Iterator<TYPE> {
86  BmdListRevIt(BmdList<TYPE> &bmdList):bmdList(bmdList) {
87  pos = bmdList.lastItem();
88  suc = 0;
89  }
90  bool hasNext() {
91  return pos!=0;
92  }
93  TYPE next() {
94  TYPE val = pos->getData();
95  tlp::BmdLink< TYPE > *tmp = pos;
96  pos = bmdList.predItem(pos, suc);
97  suc = tmp;
98  return val;
99  }
100 private:
101  tlp::BmdLink< TYPE > *pos;
102  tlp::BmdLink< TYPE > *suc;
103  BmdList<TYPE> &bmdList;
104 };
105 }
106 #endif
107 
108 ///@endcond
Interface for Tulip iterators. Allows basic iteration operations only.
Definition: Iterator.h:39