Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
list_node.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Roc authors
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8 
9 //! @file roc_core/list_node.h
10 //! @brief Linked list node.
11 
12 #ifndef ROC_CORE_LIST_NODE_H_
13 #define ROC_CORE_LIST_NODE_H_
14 
15 #include "roc_core/helpers.h"
16 #include "roc_core/noncopyable.h"
17 #include "roc_core/panic.h"
18 #include "roc_core/stddefs.h"
19 
20 namespace roc {
21 namespace core {
22 
23 //! Base class for list element.
24 //! @remarks
25 //! Object should inherit this class to be able to be a member of List.
26 class ListNode : public NonCopyable<ListNode> {
27 public:
28  //! List node data.
29  struct ListNodeData {
30  //! Previous list element.
32 
33  //! Next list element.
35 
36  //! The list this node is member of.
37  //! @remarks
38  //! NULL if node is not member of any list.
39  void* list;
40 
41  ListNodeData()
42  : prev(NULL)
43  , next(NULL)
44  , list(NULL) {
45  }
46 
47  //! Get ListNode object that contains this ListData object.
49  return ROC_CONTAINER_OF(this, ListNode, list_data_);
50  }
51  };
52 
53  ~ListNode() {
54  if (list_data_.list != NULL) {
55  roc_panic(
56  "list node: can't call destructor for an element that is still in list");
57  }
58  }
59 
60  //! Get list node data.
62  return &list_data_;
63  }
64 
65 private:
66  mutable ListNodeData list_data_;
67 };
68 
69 } // namespace core
70 } // namespace roc
71 
72 #endif // ROC_CORE_LIST_NODE_H_
void * list
The list this node is member of.
Definition: list_node.h:39
ListNodeData * prev
Previous list element.
Definition: list_node.h:31
#define ROC_CONTAINER_OF(ptr, type, member)
Cast a member of a structure out to the containing structure.
Definition: helpers.h:19
ListNode * container_of()
Get ListNode object that contains this ListData object.
Definition: list_node.h:48
Base class for list element.
Definition: list_node.h:26
Root namespace.
ListNodeData * next
Next list element.
Definition: list_node.h:34
Commonly used types and functions.
#define roc_panic(...)
Print error message and terminate program gracefully.
Definition: panic.h:42
Base class for non-copyable objects.
Definition: noncopyable.h:23
Panic function.
Non-copyable object.
Compile time helpers.
ListNodeData * list_node_data() const
Get list node data.
Definition: list_node.h:61