aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
link.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief Headers of the Link and LinkedList classes.
25  *
26  * @author Pierre-Henri WUILLEMIN(@LIP6) and Jean-Christophe MAGNAN and Christophe
27  * GONZALES(@AMU)
28  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
29  */
30 #ifndef GUM_MULTI_DIM_FUNCTION_GRAPH_LINK_H
31 #define GUM_MULTI_DIM_FUNCTION_GRAPH_LINK_H
32 
33 // ============================================================================
34 #include <agrum/agrum.h>
35 // ============================================================================
36 #include <agrum/tools/core/smallobjectallocator/smallObjectAllocator.h>
37 // ============================================================================
38 
39 namespace gum {
40 
41  /**
42  * @class Link
43  * @headerfile link.h <agrum/tools/multidim/FunctionGraphUtilities/link.h>
44  * @ingroup multidim_group
45  *
46  * @brief Link of a chain list allocated using the SmallObjectAllocator
47  *
48  * @tparam T The type stored by the chain list.
49  */
50  template < typename T >
51  class Link {
52  public:
53  // ============================================================================
54  /// @name Constructors and Destructors
55  // ============================================================================
56  /// @{
57 
58  /**
59  * @brief Constructor
60  */
61  explicit Link(const T& elem);
62 
63  /**
64  * @brief Constructor that insert link before the given link
65  */
66  Link(const T& elem, Link< T >* nextLink);
67 
68  /**
69  * @brief Destructor
70  */
71  ~Link();
72 
73  /**
74  * @brief Operator new overload to use the SmallObjectAllocator
75  */
76  void* operator new(size_t s);
77 
78  /**
79  * @brief Operator delete overload to use the SmallObjectAllocator
80  */
81  void operator delete(void* p);
82 
83  /// @}
84  // ============================================================================
85  /// @name Getters and setters
86  // ============================================================================
87  /// @{
88 
89  /**
90  * @brief Returns the element stored in this link.
91  */
92  const T& element() const;
93 
94  /**
95  * @brief Returns the element stored in this link.
96  */
97  T& element();
98 
99  /**
100  * @brief Returns next link.
101  */
102  const Link< T >* nextLink() const;
103 
104  /**
105  * @brief Returns next link.
106  */
107  Link< T >* nextLink();
108 
109  /**
110  * @brief Sets the next link.
111  */
112  void setNextLink(Link< T >* newLink);
113 
114  /// @}
115 
116  private:
117  /// The element embedded in this link
119 
120  /// The next link in the list
122  };
123 
124  /**
125  * @class LinkedList
126  * @headerfile link.h <agrum/tools/multidim/FunctionGraphUtilities/link.h>
127  * @ingroup multidim_group
128  *
129  * @brief Chain list allocated using the SmallObjectAllocator
130  *
131  * @tparam T The type stored by the chain list.
132  */
133  template < typename T >
134  class LinkedList {
135  public:
136  // ============================================================================
137  /// @name Constructors and Destructors
138  // ============================================================================
139  /// @{
140 
141  // ============================================================================
142  /// Constructor
143  // ============================================================================
144  LinkedList();
145 
146  // ============================================================================
147  /// Destructor
148  // ============================================================================
149  ~LinkedList();
150 
151  // ============================================================================
152  /// Operator new overload to use the SmallObjectAllocator
153  // ============================================================================
154  void* operator new(size_t s);
155 
156  // ============================================================================
157  /// Operator delete overload to use the SmallObjectAllocator
158  // ============================================================================
159  void operator delete(void* p);
160 
161  /// @}
162  // ============================================================================
163  /// @name Misceleanous methods
164  // ============================================================================
165  /// @{
166 
167  /**
168  * @brief Returns the first link in the chained list.
169  */
170  const Link< T >* list() const;
171 
172  /**
173  * @brief Returns the first link in the chained list.
174  */
175  Link< T >* list();
176 
177  /**
178  * @brief Clears the list.
179  */
180  void clear();
181 
182  /**
183  * @brief Adds a link.
184  */
185  void addLink(const T& elem);
186 
187  /**
188  * @brief Removes a element from the list.
189  */
190  void searchAndRemoveLink(const T& elem);
191 
192  /// @}
193 
194  private:
195  /// The first link of our list
197  };
198 
199 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
200  extern template class Link< Idx >;
201 #endif
202 
203 } // End of namespace gum
204 
205 #include <agrum/tools/multidim/utils/FunctionGraphUtilities/link_tpl.h>
206 
207 #endif /* GUM_MULTI_DIM_FUNCTION_GRAPH_LINK_H */
Link< T > * list()
Returns the first link in the chained list.
Definition: link_tpl.h:120
Link< T > * _firstLink_
The first link of our list.
Definition: link.h:196
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
void clear()
Clears the list.
Definition: link_tpl.h:125
void searchAndRemoveLink(const T &elem)
Removes a element from the list.
Definition: link_tpl.h:142
~LinkedList()
Destructor.
Definition: link_tpl.h:99
LinkedList()
Constructor.
Definition: link_tpl.h:92
Chain list allocated using the SmallObjectAllocator.
Definition: link.h:134
void * operator new(size_t s)
Operator new overload to use the SmallObjectAllocator.
Definition: link_tpl.h:105
const Link< T > * list() const
Returns the first link in the chained list.
Definition: link_tpl.h:115
void operator delete(void *p)
Operator delete overload to use the SmallObjectAllocator.
Definition: link_tpl.h:110
void addLink(const T &elem)
Adds a link.
Definition: link_tpl.h:136