UTRoot.h

// UTRoot.h
//
// Author David Barrett-Lennard
// (C)opyright Cedanet Pty Ltd 2008

@import "cxOperation.h"
@import "IWorkingSetMachine.h"
@import "Ceda/cxPersistStore/IPersistStore.h"
@import "Ceda/cxPersistStore/xmap.h"
@import "Ceda/cxObject/Object.h"

namespace ceda
{
// Define but don't implement
mImplement_xmap(true,false,true,xstring,xvector<pref<IObject> >,false,true)

// todo : where should this go?
$type+ xvector<pref<IObject> >;

$struct+ UTRoot isa IPersistable :
    model
    {
        xmap<xstring,xvector<movable<pref<IObject> > > > Map;
    }
{
    // todo : really should use pval's so this is implied
    bool operator==(const UTRoot& rhs) const
    {
        return OT_equiv( _model_.Map, rhs._model_.Map );
    }
    bool operator!=(const UTRoot& rhs) const
    {
        return !operator==(rhs);
    }
};

/*
'name' is an application defined key into the UTRoot namespace.

Returns the 0th object, assumed to be of concrete type T stored under the UTRoot, keyed by 
'name', or returns NULL if not found.
*/

template<typename T>
T* GetUTRootEntry(WorkingSetMachine* ws, const xstring& name)
{
    cxAssert(ws);
    const UTRoot& r = GetUTRoot(ws);
    const xvector<pref<IObject> >& v = r.Map[name].read();
    ssize_t n = v.size();
    if (n > 0)
    {
        pref<IObject> p = v[0];
        cxAssert(p);
        T* t = qccast<T>(p.Get());
        cxAssert(t);
        return t;
    }
    else
    {
        return nullptr;
    }
}

// TODO remove this after python supports maps
$function+ void SetUTRootEntry(UTRoot* root, const xstring& name, ptr<IObject> obj);
$function+ ptr<IObject> GetUTRootEntry(UTRoot* root, const xstring& name);

} // namespace ceda