|
JX Application Framework
|
#include <JArray.h>
Public Member Functions | |
| JArray (const JSize blockSize=10) | |
| JArray (const JArray< T > &source) | |
| JArray (JArray< T > &&dyingSource) noexcept | |
| ~JArray () override | |
| JArray< T > & | operator= (const JArray< T > &source) |
| operator const T * () const | |
| const T * | GetCArray () const |
| T * | AllocateCArray () const |
| T | GetItem (const JIndex index) const |
| void | SetItem (const JIndex index, const T &data) |
| T | GetItemFromEnd (const JIndex index) const |
| void | SetItemFromEnd (const JIndex index, const T &data) |
| T | GetFirstItem () const override |
| T | GetLastItem () const override |
| void | InsertItemAtIndex (const JIndex index, const T &data) |
| void | PrependItem (const T &data) override |
| void | AppendItem (const T &data) override |
| void | RemoveItem (const JIndex index) |
| void | RemoveNextItems (const JIndex firstIndex, const JSize count) |
| void | RemovePrevItems (const JIndex lastIndex, const JSize count) |
| void | RemoveItems (const JIndexRange &range) |
| void | RemoveItems (const JListT::ItemsRemoved &info) |
| void | RemoveAll () override |
| void | MoveItemToIndex (const JIndex currentIndex, const JIndex newIndex) |
| void | MoveItemToIndex (const JListT::ItemMoved &info) |
| void | SwapItems (const JIndex index1, const JIndex index2) |
| void | SwapItems (const JListT::ItemsSwapped &info) |
| JListIterator< T > * | NewIterator (const JListT::Position start=JListT::kStartAtBeginning, const JIndex index=0) override |
| JListIterator< T > * | NewIterator (const JListT::Position start=JListT::kStartAtBeginning, const JIndex index=0) const override |
| JSize | GetBlockSize () const |
| void | SetBlockSize (const JSize newBlockSize) |
| void | Sort () |
| bool | InsertSorted (const T &data, const bool insertIfDuplicate=true, JIndex *index=nullptr) |
| JIndex | GetInsertionSortIndex (const T &data, bool *isDuplicate=nullptr) const |
| bool | SearchSorted (const T &target, const JListT::SearchReturn which, JIndex *index) const |
| JIndex | SearchSortedOTI (const T &target, const JListT::SearchReturn which, bool *found) const |
| void | QuickSort (int(*compare)(const void *, const void *)) |
| const T * | begin () const |
| const T * | end () const |
Public Member Functions inherited from JList< T > | |
| JList () | |
| JList (const JList< T > &source) | |
| ~JList () override | |
| void | SetCompareFunction (const std::function< std::weak_ordering(const T &, const T &)> compareFn) |
| void | CopyCompareFunction (const JList< T > &source) |
| void | ClearCompareFunction () |
| JListT::SortOrder | GetSortOrder () const |
| void | SetSortOrder (const JListT::SortOrder order) |
| bool | IsSorted () const |
Public Member Functions inherited from JCollection | |
| JCollection () | |
| JCollection (const JCollection &source) | |
| ~JCollection () override | |
| JCollection & | operator= (const JCollection &source) |
| JSize | GetItemCount () const |
| bool | IsEmpty () const |
| bool | IndexValid (const JIndex index) const |
| JIndex | GetIndexFromEnd (const JIndex index) const |
| JString | ToString () const override |
Public Member Functions inherited from JBroadcaster | |
| JBroadcaster () | |
| virtual | ~JBroadcaster () |
| JBroadcaster & | operator= (const JBroadcaster &source) |
| bool | HasSenders () const |
| JSize | GetSenderCount () const |
| bool | HasRecipients () const |
| JSize | GetRecipientCount () const |
| template<class T > | |
| void | ListenTo (const JBroadcaster *sender, const std::function< void(const T &)> &f) |
Protected Member Functions | |
| const T & | ProtectedGetItem (const JIndex index) const |
Protected Member Functions inherited from JList< T > | |
| std::function< std::weak_ordering(const T &, const T &)> * | GetCompareFunction () const |
| void | ListAssigned (const JList< T > &source) |
| void | NotifyIterators (const JBroadcaster::Message &message) |
Protected Member Functions inherited from JCollection | |
| void | ItemAdded () |
| void | ItemRemoved () |
| void | SetItemCount (const JSize newItemCount) |
Protected Member Functions inherited from JBroadcaster | |
| JBroadcaster (const JBroadcaster &source) | |
| void | ListenTo (const JBroadcaster *sender) |
| void | StopListening (const JBroadcaster *sender) |
| void | ClearWhenGoingAway (const JBroadcaster *sender, void *pointerToMember) |
| void | StopListening (const JBroadcaster *sender, const std::type_info &messageType) |
| template<class T > | |
| void | Send (JBroadcaster *recipient, const T &message) |
| template<class T > | |
| void | Broadcast (const T &message) |
| virtual void | Receive (JBroadcaster *sender, const Message &message) |
| void | SendWithFeedback (JBroadcaster *recipient, Message *message) |
| void | BroadcastWithFeedback (Message *message) |
| virtual void | ReceiveWithFeedback (JBroadcaster *sender, Message *message) |
| virtual void | ReceiveGoingAway (JBroadcaster *sender) |
Interface for JArray class
The JArray Template Class
Template for a dynamically sized array. The data is stored contiguously.
Since memcpy and memmove are used for large scale rearrangement of the array items, this can -only- be used for structs. To store objects, use the JPtrArray template class.
We do not override ToString(): Since this function is virtual, it is always instantiated. Thus, we cannot print the values, because they might not have operator<<
| T * JArray< T >::AllocateCArray | ( | ) | const |
|
overridevirtual |
Implements JList< T >.
|
inline |
|
inline |
itsBlockSize helps prevent constant reallocation of memory in a "noisy" environment. Increase it if you need to add and remove a lot of items without reallocating memory. The larger it is, the more memory can potentially be wasted (allocated but not used).
| const T * JArray< T >::GetCArray | ( | ) | const |
|
overridevirtual |
Implements JList< T >.
| JIndex JArray< T >::GetInsertionSortIndex | ( | const T & | data, |
| bool * | isDuplicate = nullptr |
||
| ) | const |
Returns index where jnew item should be inserted in order to keep the list sorted. If there is an item that matches the given one, isDuplicate is set to true.
|
overridevirtual |
Implements JList< T >.
Insert an item into the array at the specified index. Any items at or below index are moved down. If index is any value greater than the current size, then the item is appended to the end of the array.
| bool JArray< T >::InsertSorted | ( | const T & | data, |
| const bool | insertIfDuplicate = true, |
||
| JIndex * | index = nullptr |
||
| ) |
Returns true if the item was inserted. Obviously, this is only useful if insertIfDuplicate==false.
If index!=nullptr, it contains the index where the item was inserted.
| void JArray< T >::MoveItemToIndex | ( | const JIndex | currentIndex, |
| const JIndex | newIndex | ||
| ) |
| void JArray< T >::MoveItemToIndex | ( | const JListT::ItemMoved & | info | ) |
|
overridevirtual |
Implements JList< T >.
|
overridevirtual |
Implements JList< T >.
|
explicit |
|
overridevirtual |
Implements JList< T >.
| void JArray< T >::QuickSort | ( | int(*)(const void *, const void *) | compare | ) |
Calls qsort() and broadcasts JListT::Sorted afterwards.
Since qsort() wants the sort order to be encoded in the comparison function, and since the comparison function prototype is different, we do -not- use the sorting information from JList.
Do NOT use this for JPtrArrays:
Downcasting or upcasting a pointer in C++ usually requires changing its value to include or exclude parts of the object data. Casting from void* to a base class is therefore fatal because the compiler can't perform the adjustment.
|
overridevirtual |
Implements JList< T >.
| void JArray< T >::RemoveItems | ( | const JIndexRange & | range | ) |
| void JArray< T >::RemoveItems | ( | const JListT::ItemsRemoved & | info | ) |
| bool JArray< T >::SearchSorted | ( | const T & | target, |
| const JListT::SearchReturn | which, | ||
| JIndex * | index | ||
| ) | const |
Returns true if the specified target is found.
"which" specifies what to return if more than one item matches the given target.
| JIndex JArray< T >::SearchSortedOTI | ( | const T & | target, |
| const JListT::SearchReturn | which, | ||
| bool * | found | ||
| ) | const |
Returns index where the item is or where it should be inserted in order to keep the list sorted. If there is an item that matches the given one, *found is set to true.
OTI = option to insert
| void JArray< T >::Sort | ( | ) |
We minimize the number of moves (O(N)) because MoveItemToIndex() invokes JBroadcaster::Broadcast(), which can take arbitrary amounts of time.
By using insertion sort to sort item k+1 into the already sorted list of k items, we obtain O(N log N) comparisons.
The number of moves is always O(N^2).
| void JArray< T >::SwapItems | ( | const JListT::ItemsSwapped & | info | ) |