From f4bc127704082ba013559e050474940f175781bc Mon Sep 17 00:00:00 2001 From: Adriano dos Santos Fernandes Date: Fri, 4 Mar 2022 20:44:33 -0300 Subject: [PATCH] Add class DoublyLinkedList. It internally uses std::list with PoolAllocator. --- builds/win32/msvc15/common.vcxproj | 1 + builds/win32/msvc15/common.vcxproj.filters | 3 + src/common/classes/DoublyLinkedList.h | 149 +++++++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 src/common/classes/DoublyLinkedList.h diff --git a/builds/win32/msvc15/common.vcxproj b/builds/win32/msvc15/common.vcxproj index 90a062e04d..86baeb4be8 100644 --- a/builds/win32/msvc15/common.vcxproj +++ b/builds/win32/msvc15/common.vcxproj @@ -124,6 +124,7 @@ + diff --git a/builds/win32/msvc15/common.vcxproj.filters b/builds/win32/msvc15/common.vcxproj.filters index 8f41a256cf..700b1d4543 100644 --- a/builds/win32/msvc15/common.vcxproj.filters +++ b/builds/win32/msvc15/common.vcxproj.filters @@ -392,6 +392,9 @@ headers + + headers + headers diff --git a/src/common/classes/DoublyLinkedList.h b/src/common/classes/DoublyLinkedList.h new file mode 100644 index 0000000000..18bd8897c7 --- /dev/null +++ b/src/common/classes/DoublyLinkedList.h @@ -0,0 +1,149 @@ +/* + * The contents of this file are subject to the Initial + * Developer's Public License Version 1.0 (the "License"); + * you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl. + * + * Software distributed under the License is distributed AS IS, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. + * See the License for the specific language governing rights + * and limitations under the License. + * + * The Original Code was created by Adriano dos Santos Fernandes + * for the Firebird Open Source RDBMS project. + * + * Copyright (c) 2022 Adriano dos Santos Fernandes + * and all contributors signed below. + * + * All Rights Reserved. + * Contributor(s): ______________________________________. + */ + +#ifndef CLASSES_DOUBLY_LINKED_LIST_H +#define CLASSES_DOUBLY_LINKED_LIST_H + +#include "../common/classes/alloc.h" +#include +#include + + +namespace Firebird +{ + +template +class DoublyLinkedList +{ +private: + using StdList = std::list>; + +public: + using Iterator = typename StdList::iterator; + using ConstIterator = typename StdList::const_iterator; + +public: + explicit DoublyLinkedList(MemoryPool& p) + : stdList(p) + { + } + +public: + constexpr T& front() noexcept + { + return stdList.front(); + } + + constexpr const T& front() const noexcept + { + return stdList.front(); + } + + constexpr T& back() noexcept + { + return stdList.back(); + } + + constexpr const T& back() const noexcept + { + return stdList.back(); + } + + constexpr Iterator begin() noexcept + { + return stdList.begin(); + } + + constexpr ConstIterator begin() const noexcept + { + return stdList.begin(); + } + + constexpr ConstIterator cbegin() const noexcept + { + return stdList.cbegin(); + } + + constexpr Iterator end() noexcept + { + return stdList.end(); + } + + constexpr ConstIterator end() const noexcept + { + return stdList.end(); + } + + constexpr ConstIterator cend() const noexcept + { + return stdList.cend(); + } + + constexpr bool isEmpty() const noexcept + { + return stdList.empty(); + } + + constexpr void clear() noexcept + { + stdList.clear(); + } + + constexpr void erase(Iterator pos) + { + stdList.erase(pos); + } + + constexpr void erase(ConstIterator pos) + { + stdList.erase(pos); + } + + constexpr void pushBack(const T& value) + { + stdList.push_back(value); + } + + constexpr void pushBack(T&& value) + { + stdList.push_back(std::move(value)); + } + + constexpr void splice(ConstIterator pos, DoublyLinkedList& other, ConstIterator it) + { + fb_assert(stdList.get_allocator() == other.stdList.get_allocator()); + stdList.splice(pos, other.stdList, it); + } + + constexpr void splice(ConstIterator pos, DoublyLinkedList&& other, ConstIterator it) + { + fb_assert(stdList.get_allocator() == other.stdList.get_allocator()); + stdList.splice(pos, std::move(other.stdList), it); + } + +private: + StdList stdList; +}; + +} // namespace Firebird + +#endif // CLASSES_DOUBLY_LINKED_LIST_H