Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
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
17#include "roc_core/panic.h"
18#include "roc_core/stddefs.h"
19
20namespace roc {
21namespace core {
22
23//! List node internal data.
24struct ListData {
25 //! Previous list element.
27
28 //! Next list element.
30
31 //! The list this node is member of.
32 //! @remarks
33 //! NULL if node is not member of any list.
34 void* list;
35
36 ListData()
37 : prev(NULL)
38 , next(NULL)
39 , list(NULL) {
40 }
41};
42
43//! Base class for List element.
44//! @remarks
45//! Object should inherit this class to be able to be a member of List.
46//! Tag allows to inherit multiple copies of ListNode and include same
47//! object into multiple lists.
48template <class Tag = void> class ListNode : public NonCopyable<ListNode<Tag> > {
49public:
50 ~ListNode() {
51 if (list_data_.list != NULL) {
52 roc_panic("list node: attempt to destroy node while it's still in queue");
53 }
54 }
55
56 //! Get pointer to parent node from pointer to internal data.
57 static ListNode* list_node(ListData* data) {
58 return ROC_CONTAINER_OF(data, ListNode, list_data_);
59 }
60
61 //! Get pointer to internal data.
63 return &list_data_;
64 }
65
66private:
67 mutable ListData list_data_;
68};
69
70} // namespace core
71} // namespace roc
72
73#endif // ROC_CORE_LIST_NODE_H_
Base class for List element.
Definition list_node.h:48
static ListNode * list_node(ListData *data)
Get pointer to parent node from pointer to internal data.
Definition list_node.h:57
ListData * list_data() const
Get pointer to internal data.
Definition list_node.h:62
Base class for non-copyable objects.
Definition noncopyable.h:23
Shared ownership intrusive pointer.
Definition shared_ptr.h:32
Helper macros.
#define ROC_CONTAINER_OF(ptr, type, member)
Cast a member of a structure out to the containing structure.
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.
List node internal data.
Definition list_node.h:24
ListData * next
Next list element.
Definition list_node.h:29
void * list
The list this node is member of.
Definition list_node.h:34
ListData * prev
Previous list element.
Definition list_node.h:26