~ubuntu-branches/ubuntu/maverick/glbsp/maverick

« back to all changes in this revision

Viewing changes to nodeview/lists.h

  • Committer: Bazaar Package Importer
  • Author(s): Darren Salt
  • Date: 2008-01-30 13:33:49 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080130133349-kgojg33vyiu8xbvp
Tags: 2.24-1
* New upstream release.
* Bumped the lib soname and the library package name due to one silly
  little binary incompatibility caused by changes in an exported struct.
  (Safe; nothing else currently in the archive has ever used libglbsp2.)
* Removed my patches since they're all applied upstream.
* Updated the list of documentation files.
* Build-time changes:
  - Switched from dh_movefiles to dh_install.
  - Updated my makefile to cope with upstream changes.
  - Corrected for debian-rules-ignores-make-clean-error.
  - Corrected for substvar-source-version-is-deprecated.
  - Link libglbsp, rather than glbsp, with libm and libz.
* Fixed shlibdeps. (Closes: #460387)
* Bumped standards version to 3.7.3 (no other changes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//------------------------------------------------------------------------
 
2
//  LIST library
 
3
//------------------------------------------------------------------------
 
4
//
 
5
//  GL-Node Viewer (C) 2004-2007 Andrew Apted
 
6
//
 
7
//  This program is free software; you can redistribute it and/or
 
8
//  modify it under the terms of the GNU General Public License
 
9
//  as published by the Free Software Foundation; either version 2
 
10
//  of the License, or (at your option) any later version.
 
11
//
 
12
//  This program is distributed in the hope that it will be useful,
 
13
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
//  GNU General Public License for more details.
 
16
//
 
17
//------------------------------------------------------------------------
 
18
 
 
19
#ifndef __NODEVIEW_LIST_H__
 
20
#define __NODEVIEW_LIST_H__
 
21
 
 
22
// (Yes, I'm probably nuts for not using std::list)
 
23
 
 
24
class listnode_c
 
25
{
 
26
friend class list_c;
 
27
 
 
28
private:
 
29
  listnode_c *nd_next;
 
30
  listnode_c *nd_prev;
 
31
 
 
32
public:
 
33
  listnode_c() : nd_next(NULL), nd_prev(NULL) { }
 
34
  listnode_c(const listnode_c& other) : nd_next(other.nd_next),
 
35
    nd_prev(other.nd_prev) { }
 
36
  ~listnode_c() { }
 
37
 
 
38
  inline listnode_c& operator= (const listnode_c& rhs)
 
39
  {
 
40
    if (this != &rhs)
 
41
    {
 
42
      nd_next = rhs.nd_next;
 
43
      nd_prev = rhs.nd_prev;
 
44
    }
 
45
    return *this;
 
46
  }
 
47
 
 
48
  inline listnode_c *NodeNext() const { return nd_next; }
 
49
  inline listnode_c *NodePrev() const { return nd_prev; }
 
50
};
 
51
 
 
52
class list_c
 
53
{
 
54
private:
 
55
  listnode_c *head;
 
56
  listnode_c *tail;
 
57
 
 
58
public:
 
59
  list_c() : head(NULL), tail(NULL) { }
 
60
  list_c(const list_c& other) : head(other.head), tail(other.tail) { }
 
61
  ~list_c() { }
 
62
 
 
63
  inline list_c& operator= (const list_c& rhs)
 
64
  {
 
65
    if (this != &rhs)
 
66
    {
 
67
      head = rhs.head;
 
68
      tail = rhs.tail;
 
69
    }
 
70
    return *this;
 
71
  }
 
72
 
 
73
  void clear()
 
74
  {
 
75
    head = NULL;
 
76
    tail = NULL;
 
77
  }
 
78
 
 
79
  inline listnode_c *begin() const { return head; }
 
80
  inline listnode_c *end()   const { return tail; }
 
81
 
 
82
  // insert_before
 
83
  // insert_after
 
84
 
 
85
  void remove(listnode_c *cur)
 
86
  {
 
87
    SYS_NULL_CHECK(cur);
 
88
 
 
89
    if (cur->nd_next)
 
90
      cur->nd_next->nd_prev = cur->nd_prev;
 
91
    else
 
92
      tail = cur->nd_prev;
 
93
 
 
94
    if (cur->nd_prev)
 
95
      cur->nd_prev->nd_next = cur->nd_next;
 
96
    else
 
97
      head = cur->nd_next;
 
98
  }
 
99
 
 
100
  void push_back(listnode_c *cur)
 
101
  {
 
102
    cur->nd_next = NULL;
 
103
    cur->nd_prev = tail;
 
104
 
 
105
    if (tail)
 
106
      tail->nd_next = cur;
 
107
    else
 
108
      head = cur;
 
109
 
 
110
    tail = cur;
 
111
  }
 
112
 
 
113
  void push_front(listnode_c *cur)
 
114
  {
 
115
    cur->nd_next = head;
 
116
    cur->nd_prev = NULL;
 
117
 
 
118
    if (head)
 
119
      head->nd_prev = cur;
 
120
    else
 
121
      tail = cur;
 
122
 
 
123
    head = cur;
 
124
  }
 
125
 
 
126
  inline listnode_c *pop_back()
 
127
  {
 
128
    listnode_c *cur = tail;
 
129
 
 
130
    if (cur)
 
131
      remove(cur);
 
132
 
 
133
    return cur;
 
134
  }
 
135
 
 
136
  inline listnode_c *pop_front()
 
137
  {
 
138
    listnode_c *cur = head;
 
139
 
 
140
    if (cur)
 
141
      remove(cur);
 
142
 
 
143
    return cur;
 
144
  }
 
145
};
 
146
 
 
147
#endif /* __NODEVIEW_LIST_H__ */