2014-01-24 12:37:43 +01:00
|
|
|
/*
|
|
|
|
* InspIRCd -- Internet Relay Chat Daemon
|
|
|
|
*
|
2024-06-07 10:37:56 +01:00
|
|
|
* Copyright (C) 2020, 2022 Sadie Powell <sadie@witchery.services>
|
2020-01-11 22:02:47 +00:00
|
|
|
* Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com>
|
2014-01-24 12:37:43 +01:00
|
|
|
*
|
|
|
|
* This file is part of InspIRCd. InspIRCd is free software: you can
|
|
|
|
* redistribute it and/or modify it under the terms of the GNU General Public
|
|
|
|
* License as published by the Free Software Foundation, version 2.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <iterator>
|
|
|
|
|
2014-08-30 10:35:21 +02:00
|
|
|
namespace insp
|
|
|
|
{
|
|
|
|
|
2014-01-24 12:37:43 +01:00
|
|
|
struct intrusive_list_def_tag { };
|
|
|
|
|
|
|
|
template <typename T, typename Tag = intrusive_list_def_tag> class intrusive_list;
|
2014-07-09 14:50:47 +02:00
|
|
|
template <typename T, typename Tag = intrusive_list_def_tag> class intrusive_list_tail;
|
2014-01-24 12:37:43 +01:00
|
|
|
|
|
|
|
template <typename T, typename Tag = intrusive_list_def_tag>
|
2014-04-07 13:59:10 +02:00
|
|
|
class intrusive_list_node
|
2014-01-24 12:37:43 +01:00
|
|
|
{
|
2020-02-06 11:25:42 +00:00
|
|
|
T* ptr_next = nullptr;
|
|
|
|
T* ptr_prev = nullptr;
|
2014-01-24 12:37:43 +01:00
|
|
|
|
|
|
|
void unlink()
|
|
|
|
{
|
|
|
|
if (ptr_next)
|
|
|
|
ptr_next->intrusive_list_node<T, Tag>::ptr_prev = this->ptr_prev;
|
|
|
|
if (ptr_prev)
|
|
|
|
ptr_prev->intrusive_list_node<T, Tag>::ptr_next = this->ptr_next;
|
2022-07-22 18:33:38 +01:00
|
|
|
ptr_next = ptr_prev = nullptr;
|
2014-01-24 12:37:43 +01:00
|
|
|
}
|
|
|
|
|
2022-01-25 13:59:42 +00:00
|
|
|
public:
|
2014-01-24 12:37:43 +01:00
|
|
|
friend class intrusive_list<T, Tag>;
|
2014-07-09 14:50:47 +02:00
|
|
|
friend class intrusive_list_tail<T, Tag>;
|
2014-01-24 12:37:43 +01:00
|
|
|
};
|
|
|
|
|
2014-08-30 10:35:21 +02:00
|
|
|
} // namespace insp
|
|
|
|
|
2014-07-09 14:50:47 +02:00
|
|
|
// Intrusive list where the list only has a pointer to the head element
|
2014-07-09 14:38:06 +02:00
|
|
|
#define INSPIRCD_INTRUSIVE_LIST_NAME intrusive_list
|
2014-07-09 14:26:49 +02:00
|
|
|
#include "intrusive_list_impl.h"
|
2014-07-09 14:38:06 +02:00
|
|
|
#undef INSPIRCD_INTRUSIVE_LIST_NAME
|
2014-07-09 14:50:47 +02:00
|
|
|
|
|
|
|
// Intrusive list where the list maintains a pointer to both the head and the tail elements.
|
|
|
|
// Additional methods: back(), push_back(), pop_back()
|
|
|
|
#define INSPIRCD_INTRUSIVE_LIST_NAME intrusive_list_tail
|
|
|
|
#define INSPIRCD_INTRUSIVE_LIST_HAS_TAIL
|
|
|
|
#include "intrusive_list_impl.h"
|
|
|
|
#undef INSPIRCD_INTRUSIVE_LIST_NAME
|
|
|
|
#undef INSPIRCD_INTRUSIVE_LIST_HAS_TAIL
|