libUTL++
utl::Collection Class Referenceabstract

A collection of objects. More...

#include <Collection.h>

Inheritance diagram for utl::Collection:

Public Member Functions

void assertOwner ()
 Assert ownership of contained objects. More...
 
virtual void copy (const Object &rhs)
 Copy another instance. More...
 
virtual void steal (Object &rhs)
 "Steal" the internal representation from another instance. More...
 
virtual void vclone (const Object &rhs)
 Make an exact copy of another instance. More...
 
virtual void dump (Stream &os, uint_t level=uint_t_max) const
 Dump a human-readable representation of self to the given output stream. More...
 
virtual void serialize (Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize to or from a stream. More...
 
void serialize (const RunTimeClass *rtc, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize to/from the given stream. More...
 
virtual size_t innerAllocatedSize () const
 Get the "inner" allocated size. More...
 
virtual bool update (const Object *object)
 Update the given object. More...
 
Accessors
bool isOwner () const
 Get the owner flag. More...
 
void setOwner (bool owner)
 Set the owner flag. More...
 
const Orderingordering () const
 Get the ordering. More...
 
Orderingordering ()
 Get the ordering. More...
 
void setOrdering (const Ordering &ordering, uint_t algorithm=sort_quickSort)
 Set the ordering, and optionally sort the collection to reflect the new ordering. More...
 
virtual void setOrdering (Ordering *ordering, uint_t algorithm=sort_quickSort)
 Set the ordering, and optionally sort the collection to reflect the new ordering. More...
 
bool empty () const
 Determine whether the collection is empty. More...
 
bool isMultiSet () const
 Get the multiSet flag. More...
 
void setMultiSet (bool multiSet)
 Set the multiSet flag. More...
 
bool isMarked () const
 Get marked flag. More...
 
void setMarked (bool marked=true)
 Set marked flag. More...
 
size_t items () const
 Get the number of contained objects. More...
 
size_t size () const
 Get the number of contained objects. More...
 
Adding Objects
bool add (const Object &object)
 Add an object to the collection. More...
 
virtual bool add (const Object *object)=0
 Add an object to the collection. More...
 
void add (const Collection &collection)
 Add another collection's objects. More...
 
virtual BidItaddIt (const Object *object)
 Add an object to the collection. More...
 
ObjectaddOrFind (const Object &object)
 Add the given object, or find a matching object already contained. More...
 
virtual ObjectaddOrFind (const Object *object)
 Add the given object, or find a matching object already contained. More...
 
bool addOrUpdate (const Object &object)
 Add or update the given object. More...
 
virtual bool addOrUpdate (const Object *object)
 Add or update the given object. More...
 
CollectioncopyItems (const Collection *src, const Predicate *pred=nullptr, bool predVal=true)
 Copy objects from another collection. More...
 
CollectioncopyItems (const ListNode *src, const Predicate *pred=nullptr, bool predVal=true)
 Copy objects from a double-linked list. More...
 
CollectioncopyItems (const SlistNode *src, const Predicate *pred=nullptr, bool predVal=true)
 Copy objects from a single-linked list. More...
 
CollectionstealItems (Collection *src)
 "Steal" items from another collection. More...
 
Collectionoperator+= (const Object &rhs)
 Add an object to the collection. More...
 
Collectionoperator+= (const Object *rhs)
 Add an object to the collection. More...
 
Collectionoperator+= (const Collection &rhs)
 Add another collection's objects. More...
 
Collectionoperator-= (const Object &rhs)
 Remove an object from the collection. More...
 
Human-Readable Representation
void dump (Stream &os, uint_t level, bool key, bool printClassName, uint_t indent, const char *separator) const
 Dump contained objects to a stream. More...
 
virtual String toString () const
 Obtain a string representation by invoking Object::toString() on all contained objects.
 
String toString (bool key) const
 Obtain a string representation by invoking Object::toString() on all contained objects (or their keys). More...
 
String toString (const char *sep, bool key=false) const
 Obtain a string represenation by invoking Object::toString() on all contained objects (or their keys). More...
 
String toString (const String &sep, bool key=false) const
 Obtain a string represenation of the collection by invoking Object::toString() on all contained objects (or their keys). More...
 
Iterators
iterator begin () const
 Return a const iterator pointing to the first object in the collection. More...
 
iterator begin ()
 Return an iterator pointing to the first object in the collection. More...
 
virtual BidItbeginNew () const =0
 Return a const iterator pointing to the beginning of the collection. More...
 
virtual BidItbeginNew ()=0
 Return an iterator pointing to the beginning of the collection. More...
 
virtual BidItcreateIt () const
 Create a const iterator. More...
 
virtual BidItcreateIt ()
 Create an iterator. More...
 
iterator end () const
 Return a const iterator pointing to the end of the collection. More...
 
iterator end ()
 Return an iterator pointing to the end of the collection. More...
 
virtual BidItendNew () const =0
 Return a const iterator pointing to the end of the collection. More...
 
virtual BidItendNew ()=0
 Return an iterator pointing to the end of the collection. More...
 
Querying and Searching
bool contains (const Object *key) const
 Determine whether the collection contains an object matching the given key. More...
 
bool contains (const Object &key) const
 Determine whether the collection contains an object matching the given key. More...
 
size_t count (const Predicate *pred=nullptr, bool predVal=true) const
 Count contained objects. More...
 
Objectfind (const Object *key) const
 Find an object matching a given key. More...
 
virtual Objectfind (const Object &key) const
 Find an object matching a given key. More...
 
void findIt (const Object &key, BidIt &it) const
 Find an object matching a given key. More...
 
virtual void findIt (const Object &key, BidIt &it)
 Find an object matching a given key. More...
 
Objectfirst () const
 Return the first object (nullptr if empty). More...
 
bool has (const Object *key) const
 See contains(). More...
 
bool has (const Object &key) const
 See contains(). More...
 
Objectlast () const
 Get the last object (nullptr if empty). More...
 
Removing Objects
virtual void clear ()=0
 Clear the collection by removing all objects. More...
 
bool remove (const Object *key)
 Remove the object matching the given key. More...
 
virtual bool remove (const Object &key)
 Remove the object matching the given key. More...
 
virtual void removeIt (BidIt &it)
 Remove the object the given iterator points to. More...
 
Objecttake (BidIt &it)
 Remove the object the given iterator points to, but do not delete the object even if the collection owns its objects. More...
 
Operators
Objectoperator[] (const Object *object)
 add-or-find access operator (returns Object*). More...
 
Objectoperator() (const Object *object)
 add-or-find access operator (returns Object&). More...
 
- Public Member Functions inherited from utl::Object
void clear ()
 Revert to initial state. More...
 
virtual int compare (const Object &rhs) const
 Compare with another object. More...
 
void dumpWithClassName (Stream &os, uint_t indent=4, uint_t level=uint_t_max) const
 Front-end for dump() that prints the object's class name. More...
 
virtual const ObjectgetKey () const
 Get the key for this object. More...
 
bool hasKey () const
 Determine whether or not the object has a key. More...
 
virtual const ObjectgetProxiedObject () const
 Get the proxied object (= self if none). More...
 
virtual ObjectgetProxiedObject ()
 Get the proxied object (= self if none). More...
 
virtual size_t hash (size_t size) const
 Get the hash code for the object. More...
 
bool _isA (const RunTimeClass *runTimeClass) const
 Determine whether self's class is a descendent of the given class. More...
 
 operator String () const
 Conversion to String. More...
 
size_t allocatedSize () const
 Get the total allocated size of this object. More...
 
virtual void addOwnedIt (const class FwdIt *it) const
 Notify self that it owns the given iterator. More...
 
virtual void removeOwnedIt (const class FwdIt *it) const
 Notify self that the given owned iterator has been destroyed. More...
 
bool operator< (const Object &rhs) const
 Less-than operator. More...
 
bool operator<= (const Object &rhs) const
 Less-than-or-equal-to operator. More...
 
bool operator> (const Object &rhs) const
 Greater-than operator. More...
 
bool operator>= (const Object &rhs) const
 Greater-than-or-equal-to operator. More...
 
bool operator== (const Object &rhs) const
 Equal-to operator. More...
 
bool operator!= (const Object &rhs) const
 Unequal-to operator. More...
 
void serializeIn (Stream &is, uint_t mode=ser_default)
 Serialize from an input stream. More...
 
void serializeOut (Stream &os, uint_t mode=ser_default) const
 Serialize to an output stream. More...
 
void serializeOutBoxed (Stream &os, uint_t mode=ser_default) const
 Serialize a boxed object to an output stream. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from utl::Object
static ObjectserializeInNullable (Stream &is, uint_t mode=ser_default)
 Serialize a nullptr-able object from an input stream. More...
 
static void serializeOutNullable (const Object *object, Stream &os, uint_t mode=ser_default)
 Serialize a nullptr-able object to an output stream. More...
 
static void serializeNullable (Object *&object, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize a nullptr-able object to or from a stream. More...
 
static ObjectserializeInBoxed (Stream &is, uint_t mode=ser_default)
 Serialize a boxed object from an input stream. More...
 
static void serializeBoxed (Object *&object, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize a boxed object to or from a stream. More...
 
- Protected Member Functions inherited from utl::FlagsMI
 FlagsMI ()
 Constructor. More...
 
virtual ~FlagsMI ()
 Destructor. More...
 
void copyFlags (const FlagsMI &rhs)
 Copy the given flags. More...
 
void copyFlags (const FlagsMI &rhs, uint_t lsb, uint_t msb)
 Copy (some of) the given flags. More...
 
void copyFlags (uint64_t flags, uint_t lsb, uint_t msb)
 Copy (some of) the given flags. More...
 
bool getFlag (uint_t flagNum) const
 Get a user-defined flag. More...
 
void setFlag (uint_t flagNum, bool val)
 Set a user-defined flag. More...
 
uint64_t getFlagsNumber (uint64_t mask, uint64_t shift=0)
 Get a multi-bit value in the flags data (which is stored as one 64-bit integer). More...
 
void setFlagsNumber (uint64_t mask, uint64_t shift, uint64_t num)
 Set a multi-bit value in the flags data (which is stored as one 64-bit integer). More...
 
uint64_t getFlags () const
 Get the flags. More...
 
void setFlags (uint64_t flags)
 Set the flags. More...
 

Detailed Description

A collection of objects.

Collection is an abstraction for container classes. As such, it provides a standard interface for functionality that is useful for all kinds of collection classes:

  • copying
  • serialization
  • iterating over contained objects
  • adding, updating, removing, and finding objects
  • writing a human-readable representation of the contained objects

Attributes

  • owner flag : If a collection owns its objects, it is responsible for deleting them when appropriate (e.g. upon its destruction). This means that copies of objects must also be made when appropriate. For example, if you copy objects into a collection that owns its objects, copies will be made of those objects (via Object::copy()) instead of just copying the pointers.
  • multiSet flag : If a collection is a multi-set, it may contain two or more objects that are equivalent.
  • ordering : The utl::Ordering specified for a collection will be called upon to perform comparisons between objects. If no ordering object is provided, objects will be compared using utl::Object::compare(). Whenever contained objects are compared to search keys (e.g. when invoking find()), the left-hand-side object is the contained object and the right-hand-side object is the search key. This consistent behavior is meant to simplify the implementation of utl::Object::compare() overrides and utl::Ordering specializations, which can assume the class (or at least the base class) of the left-hand-side object involved in the comparison. The right-hand-side object in a comparison may either be another contained object (possibly from another collection) or a search key.
Author
Adam McKee

Definition at line 62 of file Collection.h.

Member Function Documentation

◆ assertOwner()

void utl::Collection::assertOwner ( )

Assert ownership of contained objects.

Make copies of all contained objects, and set the owner flag to true.

◆ copy()

virtual void utl::Collection::copy ( const Object rhs)
virtual

Copy another instance.

When you override copy(), you should usually call the superclass's copy().

Parameters
rhsobject to copy

Reimplemented from utl::Object.

Reimplemented in utl::Array, and utl::SpanAllocator< T, D >.

◆ steal()

virtual void utl::Collection::steal ( Object rhs)
virtual

"Steal" the internal representation from another instance.

The default implementation just calls vclone(), so you have to override this if you want a "move" capability.

Reimplemented from utl::Object.

Reimplemented in utl::Array, utl::Hashtable, utl::List, utl::Heap, utl::SkipList, utl::RBtree, utl::BinTree, and utl::Deque.

◆ vclone()

virtual void utl::Collection::vclone ( const Object rhs)
virtual

Make an exact copy of another instance.

The default implementation just calls copy(), so you have to override this if you want different behavior for copy construction and cloning.

Reimplemented from utl::Object.

Reimplemented in utl::Hashtable.

◆ dump() [1/2]

virtual void utl::Collection::dump ( Stream os,
uint_t  level = uint_t_max 
) const
virtual

Dump a human-readable representation of self to the given output stream.

A common use of this is for debugging & testing.

Parameters
osstream to dump to
levellevel of 'verbosity' for the dump

Reimplemented from utl::Object.

Reimplemented in utl::SpanAllocator< T, D >.

◆ serialize() [1/2]

virtual void utl::Collection::serialize ( Stream stream,
uint_t  io,
uint_t  mode = ser_default 
)
inlinevirtual

Serialize to or from a stream.

This is the only virtual method for serialization. You must override this in any class that has data to be serialized, and ensure that the superclass's serialize() gets called.

Parameters
streamstream to serialize from/to
iosee utl::io_t
modesee utl::serialize_t

Reimplemented from utl::Object.

Reimplemented in utl::SpanAllocator< T, D >.

Definition at line 87 of file Collection.h.

References utl::ser_default, and utl::serialize().

◆ serialize() [2/2]

void utl::Collection::serialize ( const RunTimeClass rtc,
Stream stream,
uint_t  io,
uint_t  mode = ser_default 
)

Serialize to/from the given stream.

If a RunTimeClass is given, it is assumed that all objects in the collection are of that same type.

See also
Object::serialize
utl::serialize

◆ innerAllocatedSize()

virtual size_t utl::Collection::innerAllocatedSize ( ) const
virtual

Get the "inner" allocated size.

Reimplemented from utl::Object.

Reimplemented in utl::Array, utl::Hashtable, utl::List, utl::Heap, utl::SkipList, utl::RBtree, and utl::Deque.

◆ update()

virtual bool utl::Collection::update ( const Object object)
virtual

Update the given object.

Returns
true if object successfully found and updated, false otherwise
Parameters
objectobject to be updated

◆ isOwner()

bool utl::Collection::isOwner ( ) const
inline

Get the owner flag.

Definition at line 113 of file Collection.h.

◆ setOwner()

void utl::Collection::setOwner ( bool  owner)
inline

Set the owner flag.

Definition at line 120 of file Collection.h.

◆ ordering() [1/2]

const Ordering* utl::Collection::ordering ( ) const
inline

Get the ordering.

Definition at line 127 of file Collection.h.

◆ ordering() [2/2]

Ordering* utl::Collection::ordering ( )
inline

Get the ordering.

Definition at line 134 of file Collection.h.

◆ setOrdering() [1/2]

void utl::Collection::setOrdering ( const Ordering ordering,
uint_t  algorithm = sort_quickSort 
)
inline

Set the ordering, and optionally sort the collection to reflect the new ordering.

Parameters
orderingnew ordering (make a copy)
algorithm(optional : sort_quickSort) sort algorithm

Definition at line 145 of file Collection.h.

References utl::sort_quickSort.

◆ setOrdering() [2/2]

virtual void utl::Collection::setOrdering ( Ordering ordering,
uint_t  algorithm = sort_quickSort 
)
virtual

Set the ordering, and optionally sort the collection to reflect the new ordering.

Parameters
orderingnew ordering
algorithm(optional : sort_quickSort) sort algorithm

Reimplemented in utl::List, and utl::SortedCollection.

◆ empty()

bool utl::Collection::empty ( ) const
inline

Determine whether the collection is empty.

Definition at line 159 of file Collection.h.

◆ isMultiSet()

bool utl::Collection::isMultiSet ( ) const
inline

Get the multiSet flag.

Definition at line 166 of file Collection.h.

◆ setMultiSet()

void utl::Collection::setMultiSet ( bool  multiSet)
inline

Set the multiSet flag.

Definition at line 173 of file Collection.h.

◆ isMarked()

bool utl::Collection::isMarked ( ) const
inline

Get marked flag.

Definition at line 180 of file Collection.h.

◆ setMarked()

void utl::Collection::setMarked ( bool  marked = true)
inline

Set marked flag.

Definition at line 187 of file Collection.h.

◆ items()

size_t utl::Collection::items ( ) const
inline

Get the number of contained objects.

Definition at line 194 of file Collection.h.

◆ size()

size_t utl::Collection::size ( ) const
inline

Get the number of contained objects.

Definition at line 201 of file Collection.h.

◆ add() [1/3]

bool utl::Collection::add ( const Object object)
inline

Add an object to the collection.

If isOwner(), a copy of the object will be made.

Returns
true if successful, false otherwise
Parameters
objectobject to add

Definition at line 215 of file Collection.h.

References utl::clone().

◆ add() [2/3]

virtual bool utl::Collection::add ( const Object object)
pure virtual

Add an object to the collection.

Returns
true if successful, false otherwise
Parameters
objectobject to add

Implemented in utl::Array, utl::List, utl::Hashtable, utl::BinTree, utl::ObjectCache, utl::SkipList, utl::Heap, utl::Deque, and utl::SpanCol< T, D >.

◆ add() [3/3]

void utl::Collection::add ( const Collection collection)
inline

Add another collection's objects.

If isOwner(), copies will be made of all objects added.

Parameters
collectioncollection to copy objects from

Definition at line 235 of file Collection.h.

◆ addIt()

virtual BidIt* utl::Collection::addIt ( const Object object)
virtual

Add an object to the collection.

Returns
iterator pointing to added object (end() if add failed).
Parameters
objectobject to add

◆ addOrFind() [1/2]

Object* utl::Collection::addOrFind ( const Object object)
inline

Add the given object, or find a matching object already contained.

Returns
found object (or provided object, if it was added)

Definition at line 252 of file Collection.h.

References utl::clone().

◆ addOrFind() [2/2]

virtual Object* utl::Collection::addOrFind ( const Object object)
virtual

Add the given object, or find a matching object already contained.

Returns
found object (or provided object, if it was added)

Reimplemented in utl::Hashtable, and utl::SortedCollection.

◆ addOrUpdate() [1/2]

bool utl::Collection::addOrUpdate ( const Object object)
inline

Add or update the given object.

If the object already exists, it will be updated, otherwise it will be added. If isOwner(), a copy of the object will be made.

Returns
true if object was added, false if existing object was replaced
Parameters
objectobject to add or update

Definition at line 271 of file Collection.h.

References utl::clone().

◆ addOrUpdate() [2/2]

virtual bool utl::Collection::addOrUpdate ( const Object object)
virtual

Add or update the given object.

If the object already exists, it will be updated, otherwise it will be added.

Returns
true if object was replaced, false if it was newly added
Parameters
objectobject to add or update

Reimplemented in utl::Hashtable, and utl::SortedCollection.

◆ copyItems() [1/3]

Collection& utl::Collection::copyItems ( const Collection src,
const Predicate pred = nullptr,
bool  predVal = true 
)

Copy objects from another collection.

See also
utl::copy
Returns
self
Parameters
srcsource collection
pred(optional) predicate : require (pred(object) == predVal)
predVal(optional : true) predicate value

◆ copyItems() [2/3]

Collection& utl::Collection::copyItems ( const ListNode src,
const Predicate pred = nullptr,
bool  predVal = true 
)

Copy objects from a double-linked list.

Returns
self
Parameters
srchead of source list
pred(optional) predicate : require (pred(object) == predVal)
predVal(optional : true) predicate value

◆ copyItems() [3/3]

Collection& utl::Collection::copyItems ( const SlistNode src,
const Predicate pred = nullptr,
bool  predVal = true 
)

Copy objects from a single-linked list.

Returns
self
Parameters
srchead of source list
pred(optional) predicate : require (pred(object) == predVal)
predVal(optional : true) predicate value

◆ stealItems()

Collection& utl::Collection::stealItems ( Collection src)

"Steal" items from another collection.

◆ operator+=() [1/3]

Collection& utl::Collection::operator+= ( const Object rhs)
inline

Add an object to the collection.

If isOwner(), make a copy of the object.

Returns
self
Parameters
rhsobject to add

Definition at line 325 of file Collection.h.

◆ operator+=() [2/3]

Collection& utl::Collection::operator+= ( const Object rhs)
inline

Add an object to the collection.

Returns
self
Parameters
rhsobject to add

Definition at line 336 of file Collection.h.

◆ operator+=() [3/3]

Collection& utl::Collection::operator+= ( const Collection rhs)
inline

Add another collection's objects.

If isOwner(), make copies of all objects added.

Returns
self
Parameters
rhscollection to copy objects from

Definition at line 347 of file Collection.h.

◆ operator-=()

Collection& utl::Collection::operator-= ( const Object rhs)
inline

Remove an object from the collection.

Returns
self
Parameters
rhskey to remove

Definition at line 358 of file Collection.h.

References utl::dump(), and utl::toString().

◆ dump() [2/2]

void utl::Collection::dump ( Stream os,
uint_t  level,
bool  key,
bool  printClassName,
uint_t  indent,
const char *  separator 
) const

Dump contained objects to a stream.

Parameters
osoutput stream
levellevel of 'verbosity' for the dump
keydump object keys?
printClassNameprint each object's class name?
indentindent each object?
separatordumped between each object

◆ toString() [1/3]

String utl::Collection::toString ( bool  key) const

Obtain a string representation by invoking Object::toString() on all contained objects (or their keys).

See also
Object::getKey
utl::toString
Returns
string representation of collection
Parameters
keyinvoke Object::toString() on object keys?

◆ toString() [2/3]

String utl::Collection::toString ( const char *  sep,
bool  key = false 
) const
inline

Obtain a string represenation by invoking Object::toString() on all contained objects (or their keys).

See also
Object::getKey
utl::toString
Returns
string representation of collection
Parameters
sepseparator, such as ", "
keyinvoke Object::toString() on object keys?

Definition at line 408 of file Collection.h.

References utl::toString().

◆ toString() [3/3]

String utl::Collection::toString ( const String sep,
bool  key = false 
) const

Obtain a string represenation of the collection by invoking Object::toString() on all contained objects (or their keys).

See also
Object::getKey
utl::toString
Returns
string representation of collection
Parameters
sepseparator, such as ", "
keyinvoke Object::toString() on object keys?

◆ begin() [1/2]

iterator utl::Collection::begin ( ) const

Return a const iterator pointing to the first object in the collection.

◆ begin() [2/2]

iterator utl::Collection::begin ( )

Return an iterator pointing to the first object in the collection.

◆ beginNew() [1/2]

virtual BidIt* utl::Collection::beginNew ( ) const
pure virtual

Return a const iterator pointing to the beginning of the collection.

Implemented in utl::Array, utl::List, utl::Hashtable, utl::BinTree, utl::SkipList, utl::Heap, utl::ObjectCache, and utl::Deque.

◆ beginNew() [2/2]

virtual BidIt* utl::Collection::beginNew ( )
pure virtual

Return an iterator pointing to the beginning of the collection.

Implemented in utl::Array, utl::List, utl::Hashtable, utl::BinTree, utl::SkipList, utl::Heap, utl::ObjectCache, and utl::Deque.

◆ createIt() [1/2]

virtual BidIt* utl::Collection::createIt ( ) const
virtual

Create a const iterator.

◆ createIt() [2/2]

virtual BidIt* utl::Collection::createIt ( )
virtual

Create an iterator.

◆ end() [1/2]

iterator utl::Collection::end ( ) const

Return a const iterator pointing to the end of the collection.

◆ end() [2/2]

iterator utl::Collection::end ( )

Return an iterator pointing to the end of the collection.

◆ endNew() [1/2]

virtual BidIt* utl::Collection::endNew ( ) const
pure virtual

Return a const iterator pointing to the end of the collection.

Implemented in utl::Array, utl::List, utl::BinTree, utl::Hashtable, utl::ObjectCache, utl::SkipList, utl::Heap, and utl::Deque.

◆ endNew() [2/2]

virtual BidIt* utl::Collection::endNew ( )
pure virtual

Return an iterator pointing to the end of the collection.

Implemented in utl::Array, utl::List, utl::BinTree, utl::Hashtable, utl::ObjectCache, utl::SkipList, utl::Heap, and utl::Deque.

◆ contains() [1/2]

bool utl::Collection::contains ( const Object key) const
inline

Determine whether the collection contains an object matching the given key.

Returns
true if matching object exists, false otherwise
Parameters
keysearch key

Definition at line 466 of file Collection.h.

References ASSERTD, and utl::count().

◆ contains() [2/2]

bool utl::Collection::contains ( const Object key) const

Determine whether the collection contains an object matching the given key.

Returns
true if matching object exists, false otherwise
Parameters
keysearch key

◆ count()

size_t utl::Collection::count ( const Predicate pred = nullptr,
bool  predVal = true 
) const

Count contained objects.

Parameters
pred(optional) predicate : require (pred(object) == predVal)
predVal(optional : true) predicate value

◆ find() [1/2]

Object* utl::Collection::find ( const Object key) const
inline

Find an object matching a given key.

Returns
found object (nullptr if none)
Parameters
keysearch key

Definition at line 492 of file Collection.h.

References ASSERTD.

◆ find() [2/2]

virtual Object* utl::Collection::find ( const Object key) const
virtual

Find an object matching a given key.

Returns
found object (nullptr if none)
Parameters
keysearch key

Reimplemented in utl::Array, utl::ObjectCache, utl::List, utl::Hashtable, utl::Heap, utl::BinTree, and utl::SkipList.

◆ findIt() [1/2]

void utl::Collection::findIt ( const Object key,
BidIt it 
) const
inline

Find an object matching a given key.

Parameters
keysearch key
itconst result iterator (= end() if no object found)

Definition at line 511 of file Collection.h.

References const_cast_this, IFDEBUG, and utl::FwdIt::setConst().

◆ findIt() [2/2]

virtual void utl::Collection::findIt ( const Object key,
BidIt it 
)
virtual

◆ first()

Object* utl::Collection::first ( ) const

Return the first object (nullptr if empty).

◆ has() [1/2]

bool utl::Collection::has ( const Object key) const
inline

See contains().

Definition at line 529 of file Collection.h.

References ASSERTD.

◆ has() [2/2]

bool utl::Collection::has ( const Object key) const
inline

See contains().

Definition at line 537 of file Collection.h.

◆ last()

Object* utl::Collection::last ( ) const

Get the last object (nullptr if empty).

◆ clear()

virtual void utl::Collection::clear ( )
pure virtual

◆ remove() [1/2]

bool utl::Collection::remove ( const Object key)
inline

Remove the object matching the given key.

Returns
true if object found and removed, false otherwise
Parameters
keysearch key

Definition at line 557 of file Collection.h.

References ASSERTD.

◆ remove() [2/2]

virtual bool utl::Collection::remove ( const Object key)
virtual

◆ removeIt()

virtual void utl::Collection::removeIt ( BidIt it)
virtual

Remove the object the given iterator points to.

The iterator will be updated so that it points to the removed object's successor.

Parameters
ititerator specifying object to be removed

Reimplemented in utl::Array, utl::List, utl::ObjectCache, utl::SortedCollection, utl::TArray< T >, utl::TArray< REnode >, utl::TArray< utl::String >, utl::TArray< utl::Span< size_t > >, utl::TArray< LogStream >, utl::TArray< Terminal >, utl::TArray< utl::Stream >, utl::Hashtable, utl::BinTree, utl::SkipList, and utl::Heap.

◆ take()

Object* utl::Collection::take ( BidIt it)

Remove the object the given iterator points to, but do not delete the object even if the collection owns its objects.

Returns
removed object
Parameters
ititerator specifying object to be removed

◆ operator[]()

Object* utl::Collection::operator[] ( const Object object)
inline

add-or-find access operator (returns Object*).

Definition at line 589 of file Collection.h.

◆ operator()()

Object& utl::Collection::operator() ( const Object object)
inline

add-or-find access operator (returns Object&).

Definition at line 595 of file Collection.h.

References ASSERTD, utl::Object::compare(), utl::deInit(), and utl::init().


The documentation for this class was generated from the following file: