View_Composite.h
bakery/View/View.h
vector
algorithm
bakery.h
ViewBase.h
vector
sigc++/sigc++.h
../Document/Document.h
iostream
sigc++/trackable.h
View_Composite.h
algorithm
bakery/View/View.h
glibmm.h
bakery.h
View_Composite.h
Bakery::View_Composite
Bakery

    /*
    *Copyright2000MurrayCumming
    *
    *Thislibraryisfreesoftware;youcanredistributeitand/or
    *modifyitunderthetermsoftheGNULibraryGeneralPublic
    *LicenseaspublishedbytheFreeSoftwareFoundation;either
    *version2oftheLicense,or(atyouroption)anylaterversion.
    *
    *Thislibraryisdistributedinthehopethatitwillbeuseful,
    *butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
    *MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.SeetheGNU
    *LibraryGeneralPublicLicenseformoredetails.
    *
    *YoushouldhavereceivedacopyoftheGNULibraryGeneralPublic
    *Licensealongwiththislibrary;ifnot,writetotheFree
    *SoftwareFoundation,Inc.,675MassAve,Cambridge,MA02139,USA.
    */

    #ifndefBAKERY_VIEW_COMPOSITE_H
    #defineBAKERY_VIEW_COMPOSITE_H

    #include"bakery/View/View.h"
    #include<vector>
    #include<algorithm>//Forstd::find

    namespaceBakery
    {

    template<classT_Document>
    classView_Composite:publicView<T_Document>
    {
    public:
    View_Composite()
    {
    }

    virtual~View_Composite()
    {
    }

    typedefView<T_Document>type_view;

    virtualvoidadd_view(type_view*pView)
    {
    //Ensurethattheviewhasthesamedocument:
    //Thisshouldbeunnecessary.
    if(pView)
    {
    pView->set_document(View<T_Document>::get_document());

    //Addittothelistofchildviews:
    m_vecViews.push_back(pView);
    }
    }

    virtualvoidremove_view(type_view*pView)
    {
    typenametype_vecViews::iteratoriter=std::find(m_vecViews.begin(),m_vecViews.end(),pView);
    if(iter!=m_vecViews.end())
    m_vecViews.erase(iter);
    }

    virtualvoidset_document(T_Document*pDocument)
    {
    //Callbaseclass:
    View<T_Document>::set_document(pDocument);

    //Changethedocumentinthechildviews.
    for(typenametype_vecViews::iteratoriter=m_vecViews.begin();iter!=m_vecViews.end();iter++)
    {
    type_view*pView=*iter;
    if(pView)
    pView->set_document(pDocument);
    }
    }

    virtualvoidload_from_document()
    {
    //Delegatetothechildviews:
    for(typenametype_vecViews::iteratoriter=m_vecViews.begin();iter!=m_vecViews.end();iter++)
    {
    type_view*pView=*iter;
    if(pView)
    pView->load_from_document();
    }
    }

    virtualvoidsave_to_document()
    {
    //Delegatetothechildviews:
    for(typenametype_vecViews::iteratoriter=m_vecViews.begin();iter!=m_vecViews.end();iter++)
    {
    type_view*pView=*iter;
    if(pView)
    pView->save_to_document();
    }
    }

    protected:
    typedefstd::vector<type_view*>type_vecViews;
    type_vecViewsm_vecViews;
    };

    }//namespace

    #endif