4#include <system/object.h>
5#include <system/string.h>
6#include <system/type_info.h>
7#include <system/shared_ptr.h>
8#include <system/exceptions.h>
9#include <system/collections/ienumerator.h>
10#include <system/collections/ienumerable.h>
11#include <system/collections/icollection.h>
12#include <system/collections/invalidatable.h>
13#include <system/array.h>
15#include <system/diagnostics/debug.h>
17#include <unordered_map>
21namespace System {
namespace Collections {
namespace Generic {
37 RTTI_INFO_TEMPLATE_CLASS(
LinkedListNode<T>, System::BaseTypesInfo<System::Object>)
57 list->m_ptr_node_map[&*it] =
this;
65 if (m_list !=
nullptr)
67 m_list->m_ptr_node_map.erase(&*m_it);
76 if (m_list !=
nullptr)
84 iterator CopyIterator()
const
106 if (m_list !=
nullptr)
108 auto next_it = ++CopyIterator();
109 if (next_it == m_list->m_data.end())
112 return m_list->MakeSharedLinkedListNode(next_it);
122 if (m_list !=
nullptr && m_it != m_list->m_data.begin())
123 return m_list->MakeSharedLinkedListNode(--CopyIterator());
140 if (m_list !=
nullptr)
150 if (m_list !=
nullptr)
152 m_list->m_ptr_node_map.erase(&*m_it);
156#ifdef ASPOSE_GET_SHARED_MEMBERS
159 void GetSharedMembers(System::Object::shared_members_type& result)
const override
161 System::Object::GetSharedMembers(result);
163 result.Add(
"System::Collections::Generic::LinkedListNode::m_list", this->m_list);
168#ifdef __DBG_FOR_EACH_MEMBER
172 void DBG_for_each_member(DBG::for_each_member_visitor &visitor)
const override
174 Object::DBG_for_each_member(visitor);
176 visitor.add_self(
this);
177 visitor.add_member(
this, m_list,
"m_list");
182 const char* DBG_class_name()
const override {
return "LinkedListNode<T>"; }
189 SharedPtr<LinkedList<T>> m_list;
235 typedef BaseTypesInfo<Object, ICollection<T>> ThisTypeBaseTypesInfo;
243 ASPOSE_COLLECTION_POINTER_MODE_CONTROL(T)
247 typedef std::list<T, typename pointer_mode_t::allocator_type>
list_t;
262 typedef BaseTypesInfo<Object, IEnumerator<T>> ThisTypeBaseTypesInfo;
264 RTTI_INFO_TEMPLATE_CLASS(
LinkedList<T>, ThisTypeBaseTypesInfo);
273 bool m_was_first_move;
275 bool m_was_not_reached_end;
283 , m_was_first_move(false)
284 , m_was_not_reached_end(true), m_tracker(list.get())
299 throw InvalidOperationException(u
"Collection was modified after the enumerator was instantiated.");
300 else if (!m_was_first_move)
302 m_was_first_move =
true;
304 if ((m_current = m_list->
begin()) != m_list->
end())
308 m_was_not_reached_end =
false;
312 else if (m_was_not_reached_end)
314 if (++m_current != m_list->
end())
318 m_was_not_reached_end =
false;
331#ifdef ASPOSE_GET_SHARED_MEMBERS
334 void GetSharedMembers(System::Object::shared_members_type& result)
const override
336 System::Object::GetSharedMembers(result);
338 result.Add(
"System::Collections::Generic::LinkedList::Enumerator::m_list", this->m_list);
342#ifdef __DBG_FOR_EACH_MEMBER
346 void DBG_for_each_member(DBG::for_each_member_visitor& visitor)
const override
348 Object::DBG_for_each_member(visitor);
350 visitor.add_self(
this);
351 visitor.add_member(
this, m_list,
"m_list");
356 const char* DBG_class_name()
const override {
return "LinkedList::Enumerator<T>"; }
367 if (collection ==
nullptr)
368 throw ArgumentNullException(u
"Value cannot be null. Parameter name: collection");
370 for (
auto enumerator = collection->GetEnumerator(); enumerator->MoveNext();)
372 m_data.emplace_back(enumerator->get_Current());
383 return MakeSharedLinkedListNode(m_data.begin());
393 return MakeSharedLinkedListNode(--m_data.end());
400 return ASPOSECPP_CHECKED_CAST(
int, m_data.size());
410 throw ArgumentNullException(u
"Value cannot be null. Parameter name: node");
412 if (node->get_List().get() !=
this)
413 throw InvalidOperationException(u
"The LinkedList node does not belong to current LinkedList.");
417 auto it = m_data.emplace(++node->CopyIterator(), element);
427 throw ArgumentNullException(u
"Value cannot be null. Parameter name: node");
429 if (newNode ==
nullptr)
430 throw ArgumentNullException(u
"Value cannot be null. Parameter name: newNode");
432 if (node->m_list.get() !=
this)
433 throw InvalidOperationException(u
"The LinkedList node does not belong to current LinkedList.");
435 if (newNode->m_list !=
nullptr)
436 throw InvalidOperationException(u
"The LinkedList node already belongs to a LinkedList.");
440 auto it = m_data.emplace(++node->CopyIterator(), newNode->m_value);
451 throw ArgumentNullException(u
"Value cannot be null. Parameter name: node");
453 if (node->get_List().get() !=
this)
454 throw InvalidOperationException(u
"The LinkedList node does not belong to current LinkedList.");
458 auto it = m_data.emplace(node->m_it, element);
468 throw ArgumentNullException(u
"Value cannot be null. Parameter name: node");
470 if (newNode ==
nullptr)
471 throw ArgumentNullException(u
"Value cannot be null. Parameter name: newNode");
473 if (node->m_list.get() !=
this)
474 throw InvalidOperationException(u
"The LinkedList node does not belong to current LinkedList.");
476 if (newNode->m_list !=
nullptr)
477 throw InvalidOperationException(u
"The LinkedList node already belongs to a LinkedList.");
481 auto it = m_data.emplace(node->m_it, newNode->m_value);
492 auto it = m_data.emplace(m_data.begin(), element);
500 if (newNode ==
nullptr)
501 throw ArgumentNullException(u
"Value cannot be null. Parameter name: newNode");
503 if (newNode->m_list !=
nullptr)
504 throw InvalidOperationException(u
"The LinkedList node already belongs to a LinkedList.");
508 auto it = m_data.emplace(m_data.begin(), newNode->m_value);
519 auto it = m_data.emplace(m_data.end(), element);
527 if (newNode ==
nullptr)
528 throw ArgumentNullException(u
"Value cannot be null. Parameter name: newNode");
530 if (newNode->m_list !=
nullptr)
531 throw InvalidOperationException(u
"The LinkedList node already belongs to a LinkedList.");
535 auto it = m_data.emplace(m_data.end(), newNode->m_value);
541 void Add(
const T& element)
override
551 std::for_each(m_ptr_node_map.begin(), m_ptr_node_map.end(),
553 it_node_pair.second->UnbindNode();
555 m_ptr_node_map.clear();
564 return std::find(m_data.begin(), m_data.end(), element) != m_data.end();
572 if (array ==
nullptr)
573 throw ArgumentNullException(u
"Value cannot be null. Parameter name: array");
576 throw ArgumentOutOfRangeException(u
"Index is out of range. Parameter name: index");
578 if (array->get_Count() - index < get_Count())
579 throw ArgumentException(u
"Insufficient space in the target location to copy the information.");
581 std::copy(m_data.begin(), m_data.end(), array.
begin() + index);
589 auto it = std::find(m_data.begin(), m_data.end(), element);
590 if (it == m_data.end())
593 return MakeSharedLinkedListNode(it);
601 auto rit = std::find(m_data.rbegin(), m_data.rend(), element);
602 if (rit == m_data.rend())
605 return MakeSharedLinkedListNode(--rit.base());
620 auto it = std::find(m_data.begin(), m_data.end(), element);
621 if (it == m_data.end())
627 auto ptr_node_it = m_ptr_node_map.find(&*it);
628 if (ptr_node_it != m_ptr_node_map.end())
630 ptr_node_it->second->Unbind();
643 throw ArgumentNullException(u
"Value cannot be null. Parameter name: node");
645 if (node->m_list.get() !=
this)
646 throw InvalidOperationException(u
"The LinkedList node does not belong to current LinkedList.");
650 auto it = node->m_it;
660 throw InvalidOperationException(u
"The LinkedList is empty.");
664 auto ptr_node_it = m_ptr_node_map.find(&*m_data.begin());
665 if (ptr_node_it != m_ptr_node_map.end())
667 ptr_node_it->second->Unbind();
678 throw InvalidOperationException(u
"The LinkedList is empty.");
682 auto ptr_node_it = m_ptr_node_map.find(&*--m_data.end());
683 if (ptr_node_it != m_ptr_node_map.end())
685 ptr_node_it->second->Unbind();
695 return m_data.begin();
708 return m_data.begin();
722 return m_data.cbegin();
729 return m_data.cend();
736 return m_data.rbegin();
743 return m_data.rend();
750 return m_data.rbegin();
757 return m_data.rend();
764 return m_data.crbegin();
771 return m_data.crend();
777 return new System::Details::NativeIteratorWrapper<T, iterator>(begin(), end());
782 return new System::Details::NativeIteratorWrapper<T, iterator>(end(), end());
787 return new System::Details::NativeConstIteratorWrapper<T, const_iterator>(begin(), end());
792 return new System::Details::NativeConstIteratorWrapper<T, const_iterator>(end(), end());
795#ifdef __DBG_FOR_EACH_MEMBER
798 void DBG_for_each_member(DBG::for_each_member_visitor& visitor)
const override
800 Object::DBG_for_each_member(visitor);
802 visitor.add_self(
this);
803 visitor.add_member(
this, m_data,
"m_data");
808 const char* DBG_class_name()
const override {
return "LinkedList<T>"; }
816#ifdef ASPOSE_GET_SHARED_MEMBERS
817 DEFINE_GET_SHARED_MEMBERS(m_data)
825 auto ptr_node_it = m_ptr_node_map.find(&*it);
826 if (ptr_node_it != m_ptr_node_map.end())
833 mutable list_t m_data;
836 std::unordered_map<const T*, LinkedListNode<T>*> m_ptr_node_map;
Interface of collection of elements. Objects of this class should only be allocated using System::Mak...
Definition: icollection.h:20
Interface of object providing enumerator on contained elements.
Definition: ienumerable.h:25
System::Details::VirtualizedConstIterator< T > const_iterator
Const iterator type.
Definition: ienumerable.h:216
System::Details::VirtualizedIterator< T > iterator
Iterator type.
Definition: ienumerable.h:214
Interface of enumerator which can be used to iterate through some elements. Objects of this class sho...
Definition: ienumerator.h:63
Enumerator to iterate through linked list.
Definition: linkedlist.h:260
MakeConstRef_t< T > get_Current() const override
Gets current element.
Definition: linkedlist.h:289
Enumerator(const SharedPtr< LinkedList< T > > &list)
Creates enumerator.
Definition: linkedlist.h:282
~Enumerator() override
Destructor.
Definition: linkedlist.h:328
bool MoveNext() override
Points enumerator to the next element (if any).
Definition: linkedlist.h:296
LinkedList forward declaration.
Definition: linkedlist.h:233
~LinkedList() override
Destructor.
Definition: linkedlist.h:813
void CopyTo(ArrayPtr< T > array, int index) override
Copies container data into existing array elements.
Definition: linkedlist.h:570
reverse_iterator rbegin() noexcept
Gets a reverse iterator to the last element of collection (first in reverse).
Definition: linkedlist.h:734
SharedPtr< LinkedListNode< T > > get_Last() const
Gets pointer to the last element in the list.
Definition: linkedlist.h:388
void RemoveLast()
Removes last node from list.
Definition: linkedlist.h:675
LinkedList()
Creates empty LinkedList.
Definition: linkedlist.h:361
System::Details::VirtualizedIteratorBase< T > * virtualizeBeginConstIterator() const override
Gets the implementation of begin const iterator for the current container.
Definition: linkedlist.h:785
SharedPtr< LinkedListNode< T > > FindLast(const T &element) const
Performs reverse direction find of an element in the list.
Definition: linkedlist.h:599
void Add(const T &element) override
Adds element to the end of the list.
Definition: linkedlist.h:541
void AddLast(const SharedPtr< LinkedListNode< T > > &newNode)
Adds newNode to the end of the list.
Definition: linkedlist.h:525
const_reverse_iterator crend() const noexcept
Gets a reverse iterator for a non-existent const-qualified element before the start of the collection...
Definition: linkedlist.h:769
LinkedList(const SharedPtr< IEnumerable< T > > &collection)
Copy constructor.
Definition: linkedlist.h:365
SharedPtr< LinkedListNode< T > > AddFirst(const T &element)
Adds element to the beginning of the list.
Definition: linkedlist.h:488
list_t::iterator iterator
Iterator type.
Definition: linkedlist.h:250
SharedPtr< IEnumerator< T > > GetEnumerator() override
Gets enumerator to iterate through current LinkedList.
Definition: linkedlist.h:610
System::Details::VirtualizedIteratorBase< T > * virtualizeBeginIterator() override
Gets the implementation of begin iterator for the current container.
Definition: linkedlist.h:775
const_reverse_iterator crbegin() const noexcept
Gets a reverse iterator to the last const-qualified element of collection (first in reverse).
Definition: linkedlist.h:762
int get_Count() const override
Gets number of elements in list.
Definition: linkedlist.h:398
reverse_iterator rend() noexcept
Gets a reverse iterator for a non-existent element before the start of the collection.
Definition: linkedlist.h:741
const_reverse_iterator rend() const noexcept
Gets a reverse iterator for a non-existent element before the start of the const-qualified collection...
Definition: linkedlist.h:755
const_iterator begin() const noexcept
Gets iterator to the first element of the const-qualified collection.
Definition: linkedlist.h:706
const_iterator cend() const noexcept
Gets iterator for a non-existent const-qualified element behind the end of the collection.
Definition: linkedlist.h:727
list_t::const_iterator const_iterator
Const iterator type.
Definition: linkedlist.h:252
iterator begin() noexcept
Gets iterator to the first element of collection.
Definition: linkedlist.h:693
const_reverse_iterator rbegin() const noexcept
Gets a reverse iterator to the last element of the const-qualified collection (first in reverse).
Definition: linkedlist.h:748
list_t::reverse_iterator reverse_iterator
Reverse iterator type.
Definition: linkedlist.h:254
SharedPtr< LinkedListNode< T > > get_First() const
Gets pointer to the first element in the list.
Definition: linkedlist.h:378
const_iterator cbegin() const noexcept
Gets iterator to the first const-qualified element of collection.
Definition: linkedlist.h:720
void AddFirst(const SharedPtr< LinkedListNode< T > > &newNode)
Adds newNode to the beginning of the list.
Definition: linkedlist.h:498
bool Contains(const T &element) const override
Checks if element is present in list.
Definition: linkedlist.h:562
std::list< T, typename pointer_mode_t::allocator_type > list_t
Underlying data type.
Definition: linkedlist.h:247
SharedPtr< LinkedListNode< T > > Find(const T &element) const
Performs forward direction find of an element in the list.
Definition: linkedlist.h:587
SharedPtr< LinkedListNode< T > > AddLast(const T &element)
Adds element to the end of the list.
Definition: linkedlist.h:515
const_iterator end() const noexcept
Gets iterator for a non-existent element behind the end of the const-qualified collection.
Definition: linkedlist.h:713
void AddAfter(const SharedPtr< LinkedListNode< T > > &node, const SharedPtr< LinkedListNode< T > > &newNode)
Adds newNode after node of the list.
Definition: linkedlist.h:424
void RemoveFirst()
Removes first node from list.
Definition: linkedlist.h:657
void Remove(const SharedPtr< LinkedListNode< T > > &node)
Removes node from list.
Definition: linkedlist.h:640
System::Details::VirtualizedIteratorBase< T > * virtualizeEndConstIterator() const override
Gets the implementation of end const iterator for the current container.
Definition: linkedlist.h:790
iterator end() noexcept
Gets iterator for a non-existent element behind the end of the collection.
Definition: linkedlist.h:699
SharedPtr< LinkedListNode< T > > AddBefore(const SharedPtr< LinkedListNode< T > > &node, const T &element)
Adds element before node of the list.
Definition: linkedlist.h:448
System::Details::VirtualizedIteratorBase< T > * virtualizeEndIterator() override
Gets the implementation of end iterator for the current container.
Definition: linkedlist.h:780
void Clear() override
Deletes all elements in list.
Definition: linkedlist.h:547
void AddBefore(const SharedPtr< LinkedListNode< T > > &node, const SharedPtr< LinkedListNode< T > > &newNode)
Adds newNode before node of the list.
Definition: linkedlist.h:465
list_t::const_reverse_iterator const_reverse_iterator
Const reverse iterator type.
Definition: linkedlist.h:256
SharedPtr< LinkedListNode< T > > AddAfter(const SharedPtr< LinkedListNode< T > > &node, const T &element)
Adds element after node of the list.
Definition: linkedlist.h:407
bool Remove(const T &element) override
Removes first occurance of the specified element from list.
Definition: linkedlist.h:618
Node of linked list. Implements a wrapper over an iterator of std::list that is wrapped in linked lis...
Definition: linkedlist.h:35
~LinkedListNode() override
Destructor.
Definition: linkedlist.h:148
LinkedListNode(const T &value)
Constructor.
Definition: linkedlist.h:92
T get_Value() const
Gets stored value.
Definition: linkedlist.h:130
SharedPtr< LinkedListNode< T > > get_Next() const
Gets next node.
Definition: linkedlist.h:104
void set_Value(const T &value)
Sets stored value.
Definition: linkedlist.h:137
SharedPtr< LinkedListNode< T > > get_Previous() const
Gets previous node.
Definition: linkedlist.h:120
SharedPtr< LinkedList< T > > get_List() const
Gets containing list.
Definition: linkedlist.h:97
Class that makes it possible to track the state of its descendants through InvalidatableTracker objec...
Definition: invalidatable.h:12
void Invalidate()
Changes the current state, invalidating all previously created trackers.
Class that implements trackers of Invalidatable objects.
Definition: invalidatable.h:32
bool CheckValidity() const
Checks if the state of the tracked object has changed.
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:62
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
auto end() -> decltype(std::declval< Q >().end())
Accessor for end() method of an underling collection. Only compiles if SmartPtr_ is specialization ty...
Definition: smart_ptr.h:838
auto begin() -> decltype(std::declval< Q >().begin())
Accessor for begin() method of an underling collection. Only compiles if SmartPtr_ is specialization ...
Definition: smart_ptr.h:830
Definition: db_command.h:9
SmartPtr< X > MakeSharedPtr(X *p)
Converts raw pointer to smart pointer.
Definition: smart_ptr.h:1650
typename MakeConstRef< T >::type MakeConstRef_t
Helper type for MakeConstRef modifier.
Definition: make_const_ref.h:20