class CCL::ObjectArray

Overview

Container class for array of objects. More…

#include <objectarray.h>

class ObjectArray:
    public CCL::Container,
    public Core::Vector
{
public:
    // typedefs

    typedef Core::VectorCompareFunction CompareFunction;
    typedef ObjectArrayIterator IteratorClass;

    // fields

    int delta = 10);

    // construction

    ObjectArray (const InitializerList <Object*>& list);
    ObjectArray (const Container& objects);
    ObjectArray (const ObjectArray& objects);

    // methods

    virtual DECLARE_CLASS (ObjectArray, Container) = 0;
    void sort ();
    void sort (CompareFunction function);
    bool addSorted (Object* obj, CompareFunction function, bool reversed = false);
    Object* search (const Object& obj) const;
    int searchIndex (const Object& obj) const;
    bool insertAt (int index, Object* obj);
    bool replaceAt (int index, Object* obj);
    int getInsertIndex (const Object* object, CompareFunction function) const;
    int getInsertIndex (const Object* object) const;
    virtual Iterator* newIterator () const;
    virtual bool isEmpty () const;
    virtual int count () const;
    virtual Object* at (int idx) const;
    virtual int index (const Object& obj) const;
    virtual int index (const Object* obj) const;
    virtual bool add (Object* obj);
    virtual bool remove (Object* obj);
    virtual void removeAll ();
    virtual Object* findEqual (const Object& obj) const;
    virtual bool addSorted (Object* obj);
    Object* operator [] (int idx) const;

    template  <class Element = Object>
    RangeIterator <ObjectArray, ObjectArrayIterator, Element*> begin () const;

    template  <class Element = Object>
    RangeIterator <ObjectArray, ObjectArrayIterator, Element*> end () const;

    virtual bool add (Object* obj);
    void add (const Container& objects, CopyMode mode = kNormal);
    bool addOnce (Object* object);
    bool addOnce (const Object& object);
    bool contains (const Object& obj) const;
    bool contains (const Object* obj) const;

    template  <class Predicate>
    Object* findIf (const Predicate& recognize) const;

    template  <class Class, class Predicate>
    Class* findIf (const Predicate& recognize) const;

    template  <class T, class Predicate>
    T* findIf (const Predicate& recognize) const;

    template  <class Predicate>
    int removeIf (const Predicate& recognize);

    template  <class Class, class Predicate>
    int removeIf (const Predicate& recognize);
};

Inherited Members

public:
    // typedefs

    typedef CStringRef MemberID;
    typedef Iterator IteratorClass;

    // enums

    enum CopyMode;

    // fields

     IContainer;

    // methods

    virtual tresult CCL_API queryInterface (UIDRef iid, void** ptr) = 0;
    virtual unsigned int CCL_API retain () = 0;
    virtual unsigned int CCL_API release () = 0;
    Unknown& operator = (const Unknown&);
    unsigned int getRetainCount () const;
    virtual Object*CCL_API revealObject (const void* moduleAddress) = 0;
    virtual void CCL_API addObserver (IObserver* observer) = 0;
    virtual void CCL_API removeObserver (IObserver* observer) = 0;
    virtual void CCL_API signal (MessageRef msg) = 0;
    virtual void CCL_API deferSignal (IMessage* msg) = 0;
    static ISubject void addObserver (IUnknown* unknown, IObserver* observer);
    static void removeObserver (IUnknown* unknown, IObserver* observer);
    virtual void CCL_API notify (ISubject* subject, MessageRef msg) = 0;

    static IObserver void notify (
        IUnknown* unknown,
        ISubject* subject,
        MessageRef msg
    );

    virtual const ITypeInfo&CCL_API getTypeInfo () const = 0;
    virtual tbool CCL_API getProperty (Variant& var, MemberID propertyId) const = 0;
    virtual tbool CCL_API setProperty (MemberID propertyId, const Variant& var) = 0;
    virtual tbool CCL_API getPropertyNames (IPropertyCollector& collector) const = 0;
    virtual tbool CCL_API invokeMethod (Variant& returnValue, MessageRef msg) = 0;
    DECLARE_BASE_CLASS (Object);
    virtual void CCL_API removeObserver (IObserver* observer);
    virtual void CCL_API signal (MessageRef msg);
    virtual void CCL_API deferSignal (IMessage* msg);
    virtual void deferChanged ();
    virtual void CCL_API notify (ISubject* subject, MessageRef msg);
    virtual bool equals (const Object& obj) const;
    virtual int compare (const Object& obj) const;
    virtual bool load (const Storage& storage);
    virtual bool save (const Storage& storage) const;
    virtual bool save (const OutputStorage& storage) const;
    virtual bool toString (String& string, int flags = 0) const;
    virtual int getHashCode (int size) const;
    IUnknown* asUnknown ();
    static void addGarbageCollected (Object* obj, bool globalScope = true);
    static void deferDestruction (Object* obj);
    static const void* getModuleAddress ();
    virtual IUnknownIterator*CCL_API createIterator () const = 0;
    DECLARE_CLASS_ABSTRACT (Container, Object);
    void objectCleanup (bool state = true);
    bool isObjectCleanup () const;
    virtual Iterator* newIterator () const = 0;
    virtual bool isEmpty () const = 0;
    virtual int count () const = 0;
    virtual Object* at (int idx) const = 0;
    virtual int index (const Object& obj) const = 0;
    virtual int index (const Object* obj) const = 0;
    virtual bool add (Object* obj) = 0;
    virtual bool remove (Object* obj) = 0;
    virtual void removeAll () = 0;
    virtual Object* findEqual (const Object& obj) const = 0;
    virtual bool addSorted (Object* obj) = 0;

    template  <class Class, class Predicate>
    Class* findIf (const Predicate& recognize) const;

    void add (const Container& objects, CopyMode mode = kNormal);
    virtual bool load (const Storage& storage);
    virtual bool save (const Storage& storage) const;

    template  <class Element = Object>
    RangeIterator <CCL::Container, CCL::Iterator, Element*> begin () const;

    template  <class Element = Object>
    RangeIterator <CCL::Container, CCL::Iterator, Element*> end () const;

    bool isEmpty () const;
    INLINE int count () const;
    INLINE bool isValidIndex (int index) const;
    T& at (int idx) const;
    T& first () const;
    T& last () const;
    bool isEqual (const ConstVector <T>& other) const;
    bool operator == (const ConstVector& other) const;
    bool operator != (const ConstVector& other) const;
    int index (const T& data) const;
    int index (const T* item) const;
    bool contains (const T& data) const;
    bool containsAnyOf (const ConstVector <T>& other) const;
    T* search (const T& data) const;

    template  <class Predicate>
    T* findIf (const Predicate& recognize) const;

    T* findIf (ContainerPredicateFunction recognize) const;
    INLINE T* getItems () const;
    INLINE operator T* () const;
    RangeIterator <ConstVector <T>, VectorIterator <T>, T&> begin () const;
    RangeIterator <ConstVector <T>, VectorIterator <T>, T&> end () const;
    static T& getError ();
    void zeroFill ();
    void fill (const T& data);
    bool add (const T& data);
    bool addOnce (const T& data);
    void addAll (const ConstVector <T>& other);
    void addAllOnce (const ConstVector <T>& other);
    bool remove (const T& data);
    bool removeAt (int idx);

    template  <class Predicate>
    int removeIf (const Predicate& recognize);

    int removeIf (ContainerPredicateFunction recognize);
    bool removeFirst ();
    bool removeLast ();
    bool insertAt (int index, const T& data);
    void removeAll ();
    void setCount (int _count);
    void empty ();
    void sort ();
    void sort (VectorCompareFunction function);
    void reverse ();
    bool addSorted (const T& data);

    bool addSorted (
        const T& data,
        VectorCompareFunction function,
        bool reversed = false
    );

    bool swap (const T& t1, const T& t2);
    bool swapAt (int index1, int index2);
    MutableVector& operator << (const T& data);
    void copyVector (const Vector& other);
    void copyVector (const T vector [], int count);
    void takeVector (Vector& other);
    Vector& operator = (const Vector& other);
    bool resize (int capacity);
    void setDelta (int delta);
    int getDelta () const;
    int getCapacity () const;

Detailed Documentation

Container class for array of objects.

Methods

void sort (CompareFunction function)

use DEFINE_ARRAY_COMPARE for function

int getInsertIndex (const Object* object, CompareFunction function) const

Returns index for object to be inserted in a sorted array (binary search); item at index might be a “duplicate” of object (according to CompareFunction).

virtual Iterator* newIterator () const

Create new iterator.

virtual bool isEmpty () const

Check if container is empty.

virtual int count () const

Count number of items in container.

virtual Object* at (int idx) const

Get object at given index.

virtual int index (const Object& obj) const

Get index of object, compares via Object::equals.

virtual int index (const Object* obj) const

Get index of object, compares object address.

virtual bool add (Object* obj)

Add object.

virtual bool remove (Object* obj)

Remove object, ownership is transfered to caller.

virtual void removeAll ()

Remove (and optionally release) all object.

virtual Object* findEqual (const Object& obj) const

Find equal object.

virtual bool addSorted (Object* obj)

Add object sorted using Object::compare.

virtual bool add (Object* obj)

Add object.

void add (const Container& objects, CopyMode mode = kNormal)

Add from other container using given copy mode.

bool addOnce (Object* object)

Add object if not already in container.

bool addOnce (const Object& object)

Add a copy of object if not already in container.

bool contains (const Object& obj) const

Check if object is contained, compares via Object::equals.

bool contains (const Object* obj) const

Check if object is contained, compares object address.

template  <class Predicate>
Object* findIf (const Predicate& recognize) const

Check if object is contained using lamda function.

Predicate: (Object*) -> bool.

template  <class Class, class Predicate>
Class* findIf (const Predicate& recognize) const

Check if object is contained using lamda function; performs ccl_cast to check type.

Predicate: (Class&) -> bool.

template  <class Predicate>
int removeIf (const Predicate& recognize)

Delete all objects satisfying lambda function, releases object optionally.

Predicate: (Object*) -> bool.

Returns:

number of removed elements

template  <class Class, class Predicate>
int removeIf (const Predicate& recognize)

Delete all objects satisfying lambda function; performs ccl_cast to check type, releases object optionally.

Predicate: (Class&) -> bool.

Returns:

number of removed elements