![]() |
KSquare Utilities
|
A typed container class/template that keeps track of entries via pointers only. More...
#include <KKQueue.h>
Inheritance diagram for KKB::KKQueue< Entry >:Public Types | |
| typedef std::vector< Entry * >::const_iterator | const_iterator |
| typedef std::vector< Entry * >::iterator | iterator |
Public Member Functions | |
| KKQueue (bool _owner=true) | |
| KKQueue (const KKQueue &q, bool _owner) | |
| Constructor, similar to the Copy Constructor except that you can control whether it duplicates the contents. More... | |
| virtual | ~KKQueue () |
| Virtual destructor; if owns its contents will also call the destructor on each one entry that it contains. More... | |
| virtual void | Add (EntryPtr _entry) |
| virtual void | AddFirst (EntryPtr _entry) |
| virtual void | AddQueue (const KKQueue &q) |
| Add the contents of a separate KKQueue container to this container. More... | |
| EntryPtr | BackOfQueue () const |
| void | DeleteContents () |
| void | DeleteEntry (EntryPtr _entry) |
| void | DeleteEntry (kkuint32 _idx) |
| KKQueue * | DuplicateListAndContents () const |
| Creates a new container including duplicating the contents, which also makes the new instance the owner of those contents. More... | |
| template<typename Functor > | |
| kkuint32 | FindTheKthElement (kkuint32 k, Functor pred) |
| EntryPtr | FrontOfQueue () const |
| EntryPtr | GetFirst () const |
| EntryPtr | GetLast () const |
| EntryPtr | IdxToPtr (kkuint32 idx) const |
| kkint32 | LocateEntry (EntryConstPtr _entry) const |
| EntryPtr | LookAtBack () const |
| EntryPtr | LookAtFront () const |
| bool | operator!= (const KKQueue< Entry > &rightSide) const |
| returns False if NOT every entry in both containers point to the same elements More... | |
| KKQueue & | operator= (const KKQueue &q) |
| Assignment Operator. More... | |
| bool | operator== (const KKQueue< Entry > &rightSide) const |
| Returns True if every entry in both containers point to the same elements. More... | |
| Entry & | operator[] (kkuint32 i) const |
| bool | Owner () const |
| void | Owner (bool _owner) |
| virtual EntryPtr | PopFromBack () |
| virtual EntryPtr | PopFromFront () |
| kkint32 | PtrToIdx (EntryConstPtr _entry) const |
| virtual void | PushOnBack (EntryPtr _entry) |
| virtual void | PushOnFront (EntryPtr _entry) |
| kkint32 | QueueSize () const |
| void | RandomizeOrder () |
| Randomizes the order of the vector. More... | |
| void | RandomizeOrder (kkint64 seed) |
| void | RandomizeOrder (RandomNumGenerator &randomVariable) |
| Randomizes the order of the vector. More... | |
| virtual EntryPtr | RemoveFirst () |
| virtual EntryPtr | RemoveLast () |
| void | SetIdxToPtr (kkuint32 _idx, Entry *_ptr) |
| void | SwapIndexes (size_t idx1, size_t idx2) |
Protected Member Functions | |
| KKQueue (const KKQueue &q) | |
| Copy Constructor creating new instance; including duplicating contents if owner set to true. More... | |
A typed container class/template that keeps track of entries via pointers only.
Will act as an Array, Queue or Stack structure. Items are added by the 'PushOnFront' and 'PushOnBack' methods. They are removed by the 'PopFromFront' and 'PopFromBack' methods. What is important to keep in mind is that it holds pointers to its contents, not the actual instances. It is important to keep track who owns the objects you put in an instance of KKQueue. KKQueue has a 'Owner' flag that you can set. If it is set to 'true' then it will call the destructor on all its contents when you call KKQueue's destructor or the 'DestroyContents' method. When you add an element to a KKQueue container you can not delete it separately until you either remove it from KKQueue or delete the KKQueue container. If the KKQueue derived container owned its contents and you call its destructor then there is no need to delete the contents separately.
KKQueue is sub-classed from vector<Entry*> so you can use any method that is available for the vector<> template.
| Entry | The type of objects that are to be held in this container. When you add new instances of 'Entry', you need to add a pointer to it not the actual entry. |
| typedef std::vector<Entry*>::const_iterator KKB::KKQueue< Entry >::const_iterator |
| typedef std::vector<Entry*>::iterator KKB::KKQueue< Entry >::iterator |
| KKQueue::KKQueue | ( | bool | _owner = true | ) |
|
protected |
Copy Constructor creating new instance; including duplicating contents if owner set to true.
If the parameter 'q' owns its contents then will create new instances of its contents. That is it will call the Copy Constructor for each one of the elements it contains. If 'q' does not own its contents it will just copy over the pointers from 'q', meaning that the new instance of KKQueue will point to the same locations as 'q' does.
Definition at line 227 of file KKQueue.h.
| KKQueue::KKQueue | ( | const KKQueue< Entry > & | q, |
| bool | _owner | ||
| ) |
Constructor, similar to the Copy Constructor except that you can control whether it duplicates the contents.
If the '_owner' parameter is set to true then it will create new instances of the contents otherwise it will just point to the instances that already exist.
Definition at line 243 of file KKQueue.h.
|
virtual |
|
inlinevirtual |
|
inlinevirtual |
|
virtual |
Add the contents of a separate KKQueue container to this container.
Be careful how the Owner flags are set; this method adds the pointers of 'q' to the end of its own container; it does not concern itself with the state of the 'Owner' flags. If you are not careful you can have both containers thinking they own the same entries. I suggest that after you add the contents of 'q' to this container that the caller set the 'owner' flag of 'q' to false.
Definition at line 355 of file KKQueue.h.
| KKQueue< Entry >::EntryPtr KKQueue::BackOfQueue | ( | ) | const |
| void KKQueue::DeleteContents | ( | ) |
| void KKQueue::DeleteEntry | ( | EntryPtr | _entry | ) |
| void KKQueue::DeleteEntry | ( | kkuint32 | _idx | ) |
| KKQueue< Entry > * KKQueue::DuplicateListAndContents | ( | ) | const |
Creates a new container including duplicating the contents, which also makes the new instance the owner of those contents.
Definition at line 263 of file KKQueue.h.
| kkuint32 KKQueue::FindTheKthElement | ( | kkuint32 | k, |
| Functor | pred | ||
| ) |
Definition at line 527 of file KKQueue.h.
| KKQueue< Entry >::EntryPtr KKQueue::FrontOfQueue | ( | ) | const |
|
inline |
|
inline |
Returns back a pointer to the element who's index is 'idx'. If 'idx' is less than 0 or >= QueueSize() will return NULL.
| kkint32 KKQueue::LocateEntry | ( | EntryConstPtr | _entry | ) | const |
Returns the index of the element who's address is '_entry'. If not found in container will return back -1.
Definition at line 745 of file KKQueue.h.
| KKQueue< Entry >::EntryPtr KKQueue::LookAtBack | ( | ) | const |
| KKQueue< Entry >::EntryPtr KKQueue::LookAtFront | ( | ) | const |
| bool KKQueue::operator!= | ( | const KKQueue< Entry > & | rightSide | ) | const |
Assignment Operator.
Definition at line 415 of file KKQueue.h.
| bool KKQueue::operator== | ( | const KKQueue< Entry > & | rightSide | ) | const |
| Entry & KKQueue::operator[] | ( | kkuint32 | i | ) | const |
| bool KKQueue::Owner | ( | ) | const |
| void KKQueue::Owner | ( | bool | _owner | ) |
|
virtual |
Removes the last element in the container and returns its pointer. If the container is empty will return NULL.
Reimplemented in KKMLL::MLClassList, KKMLL::GrayScaleImagesFVList, and KKB::XmlAttributeList.
|
virtual |
Removes the first element in the container and returns its pointer. If the container is empty will return NULL.
Reimplemented in KKMLL::MLClassList.
Definition at line 596 of file KKQueue.h.
| kkint32 KKQueue::PtrToIdx | ( | EntryConstPtr | _entry | ) | const |
|
virtual |
Adds '_entry' to the End of the container.
Reimplemented in KKB::XmlAttributeList.
Definition at line 398 of file KKQueue.h.
|
virtual |
Adds '_entry' to the Front of the container.
Reimplemented in KKB::XmlAttributeList.
Definition at line 383 of file KKQueue.h.
| kkint32 KKQueue::QueueSize | ( | ) | const |
| void KKQueue::RandomizeOrder | ( | ) |
Randomizes the order of the vector.
Implements the "Fisher-Yates Uniform Random Sort"; this implementation was done by Sergiy Fefilatyev (2011-01-27)
Definition at line 469 of file KKQueue.h.
| void KKQueue::RandomizeOrder | ( | kkint64 | seed | ) |
Definition at line 490 of file KKQueue.h.
| void KKQueue::RandomizeOrder | ( | RandomNumGenerator & | randomVariable | ) |
|
inlinevirtual |
|
inlinevirtual |
| void KKQueue::SetIdxToPtr | ( | kkuint32 | _idx, |
| Entry * | _ptr | ||
| ) |
| void KKQueue::SwapIndexes | ( | size_t | idx1, |
| size_t | idx2 | ||
| ) |