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);
217 typedef BaseTypesInfo<Object, ICollection<T>> ThisTypeBaseTypesInfo;
225 ASPOSE_COLLECTION_POINTER_MODE_CONTROL(T)
229 typedef std::list<T, typename pointer_mode_t::allocator_type>
list_t;
244 typedef BaseTypesInfo<Object, IEnumerator<T>> ThisTypeBaseTypesInfo;
246 RTTI_INFO_TEMPLATE_CLASS(
LinkedList<T>, ThisTypeBaseTypesInfo);
255 bool m_was_first_move;
257 bool m_was_not_reached_end;
265 , m_was_first_move(false)
266 , m_was_not_reached_end(true), m_tracker(list.get())
281 throw InvalidOperationException(u
"Collection was modified after the enumerator was instantiated.");
282 else if (!m_was_first_move)
284 m_was_first_move =
true;
286 if ((m_current = m_list->
begin()) != m_list->
end())
290 m_was_not_reached_end =
false;
294 else if (m_was_not_reached_end)
296 if (++m_current != m_list->
end())
300 m_was_not_reached_end =
false;
313#ifdef ASPOSE_GET_SHARED_MEMBERS
316 void GetSharedMembers(System::Object::shared_members_type& result)
const override
318 System::Object::GetSharedMembers(result);
320 result.Add(
"System::Collections::Generic::LinkedList::Enumerator::m_list", this->m_list);
332 if (collection ==
nullptr)
333 throw ArgumentNullException(u
"Value cannot be null. Parameter name: collection");
335 for (
auto enumerator = collection->GetEnumerator(); enumerator->MoveNext();)
337 m_data.emplace_back(enumerator->get_Current());
348 return MakeSharedLinkedListNode(m_data.begin());
358 return MakeSharedLinkedListNode(--m_data.end());
365 return ASPOSECPP_CHECKED_CAST(
int, m_data.size());
375 throw ArgumentNullException(u
"Value cannot be null. Parameter name: node");
377 if (node->get_List().get() !=
this)
378 throw InvalidOperationException(u
"The LinkedList node does not belong to current LinkedList.");
382 auto it = m_data.emplace(++node->CopyIterator(), element);
392 throw ArgumentNullException(u
"Value cannot be null. Parameter name: node");
394 if (newNode ==
nullptr)
395 throw ArgumentNullException(u
"Value cannot be null. Parameter name: newNode");
397 if (node->m_list.get() !=
this)
398 throw InvalidOperationException(u
"The LinkedList node does not belong to current LinkedList.");
400 if (newNode->m_list !=
nullptr)
401 throw InvalidOperationException(u
"The LinkedList node already belongs to a LinkedList.");
405 auto it = m_data.emplace(++node->CopyIterator(), newNode->m_value);
416 throw ArgumentNullException(u
"Value cannot be null. Parameter name: node");
418 if (node->get_List().get() !=
this)
419 throw InvalidOperationException(u
"The LinkedList node does not belong to current LinkedList.");
423 auto it = m_data.emplace(node->m_it, element);
433 throw ArgumentNullException(u
"Value cannot be null. Parameter name: node");
435 if (newNode ==
nullptr)
436 throw ArgumentNullException(u
"Value cannot be null. Parameter name: newNode");
438 if (node->m_list.get() !=
this)
439 throw InvalidOperationException(u
"The LinkedList node does not belong to current LinkedList.");
441 if (newNode->m_list !=
nullptr)
442 throw InvalidOperationException(u
"The LinkedList node already belongs to a LinkedList.");
446 auto it = m_data.emplace(node->m_it, newNode->m_value);
457 auto it = m_data.emplace(m_data.begin(), element);
465 if (newNode ==
nullptr)
466 throw ArgumentNullException(u
"Value cannot be null. Parameter name: newNode");
468 if (newNode->m_list !=
nullptr)
469 throw InvalidOperationException(u
"The LinkedList node already belongs to a LinkedList.");
473 auto it = m_data.emplace(m_data.begin(), newNode->m_value);
484 auto it = m_data.emplace(m_data.end(), element);
492 if (newNode ==
nullptr)
493 throw ArgumentNullException(u
"Value cannot be null. Parameter name: newNode");
495 if (newNode->m_list !=
nullptr)
496 throw InvalidOperationException(u
"The LinkedList node already belongs to a LinkedList.");
500 auto it = m_data.emplace(m_data.end(), newNode->m_value);
506 void Add(
const T& element)
override
516 std::for_each(m_ptr_node_map.begin(), m_ptr_node_map.end(),
518 it_node_pair.second->UnbindNode();
520 m_ptr_node_map.clear();
529 return std::find(m_data.begin(), m_data.end(), element) != m_data.end();
537 if (array ==
nullptr)
538 throw ArgumentNullException(u
"Value cannot be null. Parameter name: array");
541 throw ArgumentOutOfRangeException(u
"Index is out of range. Parameter name: index");
543 if (array->get_Count() - index < get_Count())
544 throw ArgumentException(u
"Insufficient space in the target location to copy the information.");
546 std::copy(m_data.begin(), m_data.end(), array.
begin() + index);
554 auto it = std::find(m_data.begin(), m_data.end(), element);
555 if (it == m_data.end())
558 return MakeSharedLinkedListNode(it);
566 auto rit = std::find(m_data.rbegin(), m_data.rend(), element);
567 if (rit == m_data.rend())
570 return MakeSharedLinkedListNode(--rit.base());
585 auto it = std::find(m_data.begin(), m_data.end(), element);
586 if (it == m_data.end())
592 auto ptr_node_it = m_ptr_node_map.find(&*it);
593 if (ptr_node_it != m_ptr_node_map.end())
595 ptr_node_it->second->Unbind();
608 throw ArgumentNullException(u
"Value cannot be null. Parameter name: node");
610 if (node->m_list.get() !=
this)
611 throw InvalidOperationException(u
"The LinkedList node does not belong to current LinkedList.");
615 auto it = node->m_it;
625 throw InvalidOperationException(u
"The LinkedList is empty.");
629 auto ptr_node_it = m_ptr_node_map.find(&*m_data.begin());
630 if (ptr_node_it != m_ptr_node_map.end())
632 ptr_node_it->second->Unbind();
643 throw InvalidOperationException(u
"The LinkedList is empty.");
647 auto ptr_node_it = m_ptr_node_map.find(&*--m_data.end());
648 if (ptr_node_it != m_ptr_node_map.end())
650 ptr_node_it->second->Unbind();
660 return m_data.begin();
673 return m_data.begin();
687 return m_data.cbegin();
694 return m_data.cend();
701 return m_data.rbegin();
708 return m_data.rend();
715 return m_data.rbegin();
722 return m_data.rend();
729 return m_data.crbegin();
736 return m_data.crend();
742 return new System::Details::NativeIteratorWrapper<T, iterator>(begin(), end());
747 return new System::Details::NativeIteratorWrapper<T, iterator>(end(), end());
752 return new System::Details::NativeConstIteratorWrapper<T, const_iterator>(begin(), end());
757 return new System::Details::NativeConstIteratorWrapper<T, const_iterator>(end(), end());
760#ifdef __DBG_FOR_EACH_MEMBER
763 void DBG_for_each_member(DBG::for_each_member_visitor& visitor)
const override
765 visitor.add_self(
this);
766 DBG::for_each_of_Object(
this, m_data, visitor);
771 const char* DBG_class_name()
const override {
return "LinkedList<T>"; }
779#ifdef ASPOSE_GET_SHARED_MEMBERS
780 DEFINE_GET_SHARED_MEMBERS(m_data)
788 auto ptr_node_it = m_ptr_node_map.find(&*it);
789 if (ptr_node_it != m_ptr_node_map.end())
796 mutable list_t m_data;
799 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:242
MakeConstRef_t< T > get_Current() const override
Gets current element.
Definition: linkedlist.h:271
Enumerator(const SharedPtr< LinkedList< T > > &list)
Creates enumerator.
Definition: linkedlist.h:264
~Enumerator() override
Destructor.
Definition: linkedlist.h:310
bool MoveNext() override
Points enumerator to the next element (if any).
Definition: linkedlist.h:278
LinkedList forward declaration.
Definition: linkedlist.h:215
~LinkedList() override
Destructor.
Definition: linkedlist.h:776
void CopyTo(ArrayPtr< T > array, int index) override
Copies container data into existing array elements.
Definition: linkedlist.h:535
reverse_iterator rbegin() noexcept
Gets a reverse iterator to the last element of collection (first in reverse).
Definition: linkedlist.h:699
SharedPtr< LinkedListNode< T > > get_Last() const
Gets pointer to the last element in the list.
Definition: linkedlist.h:353
void RemoveLast()
Removes last node from list.
Definition: linkedlist.h:640
LinkedList()
Creates empty LinkedList.
Definition: linkedlist.h:326
System::Details::VirtualizedIteratorBase< T > * virtualizeBeginConstIterator() const override
Gets the implementation of begin const iterator for the current container.
Definition: linkedlist.h:750
SharedPtr< LinkedListNode< T > > FindLast(const T &element) const
Performs reverse direction find of an element in the list.
Definition: linkedlist.h:564
void Add(const T &element) override
Adds element to the end of the list.
Definition: linkedlist.h:506
void AddLast(const SharedPtr< LinkedListNode< T > > &newNode)
Adds newNode to the end of the list.
Definition: linkedlist.h:490
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:734
LinkedList(const SharedPtr< IEnumerable< T > > &collection)
Copy constructor.
Definition: linkedlist.h:330
SharedPtr< LinkedListNode< T > > AddFirst(const T &element)
Adds element to the beginning of the list.
Definition: linkedlist.h:453
list_t::iterator iterator
Iterator type.
Definition: linkedlist.h:232
SharedPtr< IEnumerator< T > > GetEnumerator() override
Gets enumerator to iterate through current LinkedList.
Definition: linkedlist.h:575
System::Details::VirtualizedIteratorBase< T > * virtualizeBeginIterator() override
Gets the implementation of begin iterator for the current container.
Definition: linkedlist.h:740
const_reverse_iterator crbegin() const noexcept
Gets a reverse iterator to the last const-qualified element of collection (first in reverse).
Definition: linkedlist.h:727
int get_Count() const override
Gets number of elements in list.
Definition: linkedlist.h:363
reverse_iterator rend() noexcept
Gets a reverse iterator for a non-existent element before the start of the collection.
Definition: linkedlist.h:706
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:720
const_iterator begin() const noexcept
Gets iterator to the first element of the const-qualified collection.
Definition: linkedlist.h:671
const_iterator cend() const noexcept
Gets iterator for a non-existent const-qualified element behind the end of the collection.
Definition: linkedlist.h:692
list_t::const_iterator const_iterator
Const iterator type.
Definition: linkedlist.h:234
iterator begin() noexcept
Gets iterator to the first element of collection.
Definition: linkedlist.h:658
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:713
list_t::reverse_iterator reverse_iterator
Reverse iterator type.
Definition: linkedlist.h:236
SharedPtr< LinkedListNode< T > > get_First() const
Gets pointer to the first element in the list.
Definition: linkedlist.h:343
const_iterator cbegin() const noexcept
Gets iterator to the first const-qualified element of collection.
Definition: linkedlist.h:685
void AddFirst(const SharedPtr< LinkedListNode< T > > &newNode)
Adds newNode to the beginning of the list.
Definition: linkedlist.h:463
bool Contains(const T &element) const override
Checks if element is present in list.
Definition: linkedlist.h:527
std::list< T, typename pointer_mode_t::allocator_type > list_t
Underlying data type.
Definition: linkedlist.h:229
SharedPtr< LinkedListNode< T > > Find(const T &element) const
Performs forward direction find of an element in the list.
Definition: linkedlist.h:552
SharedPtr< LinkedListNode< T > > AddLast(const T &element)
Adds element to the end of the list.
Definition: linkedlist.h:480
const_iterator end() const noexcept
Gets iterator for a non-existent element behind the end of the const-qualified collection.
Definition: linkedlist.h:678
void AddAfter(const SharedPtr< LinkedListNode< T > > &node, const SharedPtr< LinkedListNode< T > > &newNode)
Adds newNode after node of the list.
Definition: linkedlist.h:389
void RemoveFirst()
Removes first node from list.
Definition: linkedlist.h:622
void Remove(const SharedPtr< LinkedListNode< T > > &node)
Removes node from list.
Definition: linkedlist.h:605
System::Details::VirtualizedIteratorBase< T > * virtualizeEndConstIterator() const override
Gets the implementation of end const iterator for the current container.
Definition: linkedlist.h:755
iterator end() noexcept
Gets iterator for a non-existent element behind the end of the collection.
Definition: linkedlist.h:664
SharedPtr< LinkedListNode< T > > AddBefore(const SharedPtr< LinkedListNode< T > > &node, const T &element)
Adds element before node of the list.
Definition: linkedlist.h:413
System::Details::VirtualizedIteratorBase< T > * virtualizeEndIterator() override
Gets the implementation of end iterator for the current container.
Definition: linkedlist.h:745
void Clear() override
Deletes all elements in list.
Definition: linkedlist.h:512
void AddBefore(const SharedPtr< LinkedListNode< T > > &node, const SharedPtr< LinkedListNode< T > > &newNode)
Adds newNode before node of the list.
Definition: linkedlist.h:430
list_t::const_reverse_iterator const_reverse_iterator
Const reverse iterator type.
Definition: linkedlist.h:238
SharedPtr< LinkedListNode< T > > AddAfter(const SharedPtr< LinkedListNode< T > > &node, const T &element)
Adds element after node of the list.
Definition: linkedlist.h:372
bool Remove(const T &element) override
Removes first occurance of the specified element from list.
Definition: linkedlist.h:583
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