Tulip  4.3.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
BmdList.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
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 
22 #ifndef BMDLIST_H
23 #define BMDLIST_H
24 
25 #ifndef DOXYGEN_NOTFOR_USER
26 
27 #include <cassert>
28 #include <tulip/BmdLink.h>
29 
30 namespace tlp {
31 template <typename TYPE>
32 class BmdList {
33 public:
34  typedef tlp::BmdLink<TYPE> BMDTYPE;
35 
36  BmdList();
37  virtual ~BmdList();
38  BMDTYPE *firstItem();
39  BMDTYPE *lastItem();
40  TYPE entry(BMDTYPE *it);
41  int size();
42  BMDTYPE *nextItem(BMDTYPE *p, BMDTYPE *predP);
43  BMDTYPE *predItem(BMDTYPE *p, BMDTYPE *succP);
44  BMDTYPE *cyclicPred(BMDTYPE *it, BMDTYPE *succIt);
45  BMDTYPE *cyclicSucc(BMDTYPE *it, BMDTYPE *predIt);
46  BMDTYPE *push(const TYPE &a);
47  BMDTYPE *append(const TYPE &a);
48  TYPE delItem(BMDTYPE *it);
49  TYPE pop();
50  TYPE popBack();
51  void reverse();
52  void conc(BmdList<TYPE> &l);
53  void clear();
54  void swap(BmdList<TYPE> &l);
55 private:
56  BMDTYPE *head;
57  BMDTYPE *tail;
58  int count;
59 };
60 
61 #include <tulip/cxx/BmdList.cxx>
62 
63 
64 template<typename TYPE>
65 struct BmdListIt : public Iterator<TYPE> {
66 
67  BmdListIt(BmdList<TYPE> &bmdList):bmdList(bmdList) {
68  pos = bmdList.firstItem();
69  pred = 0;
70  }
71  bool hasNext() {
72  return pos!=0;
73  }
74  TYPE next() {
75  TYPE val = pos->getData();
76  tlp::BmdLink< TYPE > *tmp = pos;
77  pos = bmdList.nextItem(pos, pred);
78  pred = tmp;
79  return val;
80  }
81 private:
82  tlp::BmdLink< TYPE > *pos;
83  tlp::BmdLink< TYPE > *pred;
84  BmdList<TYPE> &bmdList;
85 };
86 
87 template<typename TYPE>
88 struct BmdListRevIt : public Iterator<TYPE> {
89  BmdListRevIt(BmdList<TYPE> &bmdList):bmdList(bmdList) {
90  pos = bmdList.lastItem();
91  suc = 0;
92  }
93  bool hasNext() {
94  return pos!=0;
95  }
96  TYPE next() {
97  TYPE val = pos->getData();
98  tlp::BmdLink< TYPE > *tmp = pos;
99  pos = bmdList.predItem(pos, suc);
100  suc = tmp;
101  return val;
102  }
103 private:
104  tlp::BmdLink< TYPE > *pos;
105  tlp::BmdLink< TYPE > *suc;
106  BmdList<TYPE> &bmdList;
107 };
108 }
109 #endif
110 #endif
111 ///@endcond