[fdo-internals] Using FDO collections without inheritance

Mateusz Loskot mateusz at loskot.net
Mon Mar 5 22:03:03 EST 2007


Hi,

Is there any collection in FDO that can be used without
creating a new type of specialized collection, by inheriting
from base class like FdoCollection?

I'd like to achieve something similar like std::list<T>
but parametrized with FDO type (based on FdoIDisposable).

Here is small snipped presenting the idea I'm asking about.
It tries to:
- create new collection using read-write proxy based on FdoCollection
- wrap it with FdoReadOnlyCollection
- return read-only collection of items back to user

Certainly, the snipped below does not even compile,
because MyCollection is still an abstract type due to the fact that
FdoIDisposable::Dispose() interface is not implemented.

I'm just trying to present what I'd like to achieve from a client
point of view.

////////////////////////////////////////////////////////////////
class MyItem : public FdoIDisposable;

typedef FdoReadOnlyCollection
<
    MyItem,
    FdoCollection<MyItem, FdoException>,
    FdoException
> 
MyCollection;

MyCollection* GetMyItems() const
{
    typedef FdoCollection<MyItem, FdoException> MyCollectionBase;

    FdoPtr<MyCollectionBase> items = new MyCollectionBase();

    FdoPtr<MyItem> c1(new Myitem(L"item1"));
    items->Add(c1);

    FdoPtr<MyItem> c2(new Myitem(L"item2"));
    items->Add(c2);

    FdoPtr<MyCollection> roItems(new MyCollection());
    roItems->SetBaseCollection(items);

    FDO_SAFE_ADDREF(roItems.p);
    return roItems.p;
}
////////////////////////////////////////////////////////////////

I would not like to create new collections by inheritance from
FdoCollection and next from FdoReadOnlyCollection, in order to fulfill
requirements of Dispose() implementation, etc.

Is this possible?

Cheers
-- 
Mateusz Loskot
http://mateusz.loskot.net


More information about the fdo-internals mailing list