Tulip  5.7.4
Large graphs analysis and drawing
BmdList.h
1 /*
2  *
3  * This file is part of Tulip (https://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 
53 private:
54  BMDTYPE *head;
55  BMDTYPE *tail;
56  int count;
57 };
58 
59 #include <tulip/cxx/BmdList.cxx>
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 = nullptr;
67  }
68  bool hasNext() override {
69  return pos != nullptr;
70  }
71  TYPE next() override {
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 
79 private:
80  tlp::BmdLink<TYPE> *pos;
81  tlp::BmdLink<TYPE> *pred;
82  BmdList<TYPE> &bmdList;
83 };
84 
85 template <typename TYPE>
86 struct BmdListRevIt : public Iterator<TYPE> {
87  BmdListRevIt(BmdList<TYPE> &bmdList) : bmdList(bmdList) {
88  pos = bmdList.lastItem();
89  suc = nullptr;
90  }
91  bool hasNext() override {
92  return pos != nullptr;
93  }
94  TYPE next() override {
95  TYPE val = pos->getData();
96  tlp::BmdLink<TYPE> *tmp = pos;
97  pos = bmdList.predItem(pos, suc);
98  suc = tmp;
99  return val;
100  }
101 
102 private:
103  tlp::BmdLink<TYPE> *pos;
104  tlp::BmdLink<TYPE> *suc;
105  BmdList<TYPE> &bmdList;
106 };
107 } // namespace tlp
108 #endif
109 
110 ///@endcond