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 Streaming 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/macro_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_
Base class for list element.
Definition: list_node.h:26
ListNodeData * list_node_data() const
Get list node data.
Definition: list_node.h:61
Base class for non-copyable objects.
Definition: noncopyable.h:23
Helper macros.
#define ROC_CONTAINER_OF(ptr, type, member)
Cast a member of a structure out to the containing structure.
Definition: macro_helpers.h:37
Root namespace.
Non-copyable object.
Panic.
#define roc_panic(...)
Print error message and terminate program gracefully.
Definition: panic.h:50
Commonly used types and functions.
ListNodeData * next
Next list element.
Definition: list_node.h:34
ListNodeData * prev
Previous list element.
Definition: list_node.h:31
void * list
The list this node is member of.
Definition: list_node.h:39
ListNode * container_of()
Get ListNode object that contains this ListData object.
Definition: list_node.h:48