00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef BAKERY_VIEW_COMPOSITE_H
00020 #define BAKERY_VIEW_COMPOSITE_H
00021
00022 #include "bakery/View/View.h"
00023 #include <vector>
00024 #include <algorithm>
00025
00026 namespace Bakery
00027 {
00028
00032 template< class T_Document >
00033 class View_Composite : public View<T_Document>
00034 {
00035 public:
00036 View_Composite()
00037 {
00038 }
00039
00040 virtual ~View_Composite()
00041 {
00042 }
00043
00044 typedef View<T_Document> type_view;
00045
00046 virtual void add_view(type_view* pView)
00047 {
00048
00049
00050 if(pView)
00051 {
00052 pView->set_document(View<T_Document>::get_document());
00053
00054
00055 m_vecViews.push_back(pView);
00056 }
00057 }
00058
00059 virtual void remove_view(type_view* pView)
00060 {
00061 typename type_vecViews::iterator iter = std::find(m_vecViews.begin(), m_vecViews.end(), pView);
00062 if(iter != m_vecViews.end())
00063 m_vecViews.erase(iter);
00064 }
00065
00066 virtual void set_document(T_Document* pDocument)
00067 {
00068
00069 View<T_Document>::set_document(pDocument);
00070
00071
00072 for(typename type_vecViews::iterator iter = m_vecViews.begin(); iter != m_vecViews.end(); iter++)
00073 {
00074 type_view* pView = *iter;
00075 if(pView)
00076 pView->set_document(pDocument);
00077 }
00078 }
00079
00080 virtual void load_from_document()
00081 {
00082
00083 for(typename type_vecViews::iterator iter = m_vecViews.begin(); iter != m_vecViews.end(); iter++)
00084 {
00085 type_view* pView = *iter;
00086 if(pView)
00087 pView->load_from_document();
00088 }
00089 }
00090
00091 virtual void save_to_document()
00092 {
00093
00094 for(typename type_vecViews::iterator iter = m_vecViews.begin(); iter != m_vecViews.end(); iter++)
00095 {
00096 type_view* pView = *iter;
00097 if(pView)
00098 pView->save_to_document();
00099 }
00100 }
00101
00102 protected:
00103 typedef std::vector<type_view*> type_vecViews;
00104 type_vecViews m_vecViews;
00105 };
00106
00107 }
00108
00109 #endif