Aleph-w  1.9
General library for algorithms and data structures
slink.H
1 
2 /* Aleph-w
3 
4  / \ | | ___ _ __ | |__ __ __
5  / _ \ | |/ _ \ '_ \| '_ \ ____\ \ /\ / / Data structures & Algorithms
6  / ___ \| | __/ |_) | | | |_____\ V V / version 1.9b
7  /_/ \_\_|\___| .__/|_| |_| \_/\_/ https://github.com/lrleon/Aleph-w
8  |_|
9 
10  This file is part of Aleph-w library
11 
12  Copyright (c) 2002-2018 Leandro Rabindranath Leon & Alejandro Mujica
13 
14  This program is free software: you can redistribute it and/or modify
15  it under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  This program is distributed in the hope that it will be useful, but
20  WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  General Public License for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with this program. If not, see <https://www.gnu.org/licenses/>.
26 */
27 
28 # ifndef SLINK_H
29 # define SLINK_H
30 
31 # include <aleph.H>
32 
33 using namespace Aleph;
34 
35 namespace Aleph {
36 
45 class Slink
46 {
47 protected:
48 
49  Slink * next;
50 
51 public:
52 
54  Slink() : next(this) { /* Empty */ }
55 
57  void reset()
58  {
59  next = this;
60  }
62  bool is_empty() const
63  {
64  return next == this;
65  }
66 
69  {
70  return next;
71  }
72 
80  void insert_next(Slink * p)
81  {
82  assert(p not_eq nullptr);
83  assert(p->is_empty());
84 
85  p->next = next;
86  next = p;
87  }
88 
98  {
99  Slink * ret_val = next;
100  next = ret_val->next;
101  ret_val->reset();
102  return ret_val;
103  }
104 };
142 # define SLINK_TO_TYPE(type_name, link_name) \
143  static type_name * slink_to_type(Slink * link) \
144  { \
145  type_name * ptr_zero = 0; \
146  size_t offset_link = (size_t) &(ptr_zero->link_name); \
147  unsigned long address_type = ((unsigned long) link) - offset_link; \
148  return (type_name *) address_type; \
149  }
150 
151 } // end namespace Aleph
152 # endif /* SLINK_H */
153 
Definition: ah-comb.H:35

Leandro Rabindranath León