VR-Forces 4.0.4 Class Documentation
include/vrvCore/DtSubjectObserver.h
Go to the documentation of this file.
00001 /****************************************************************************** 
00002 ** Copyright (c) 2010 MAK Technologies, Inc. 
00003 ** All rights reserved. 
00004 ******************************************************************************/ 
00005  
00009  
00010 #pragma once
00011  
00012 #include <vrvCore/vrvCore.h> 
00013 #include <vrvCore/DtDe.h> 
00014 #include <vrvCore/DtSubjectAnnouncer.h> 
00015 #include <vrvCore/DtSubjectBinder.h>
00016 
00017 #include <vrvUtil/templateUtil.h>
00018 
00019 #include <boost/signal.hpp>
00020 #include <boost/bind.hpp>
00021 
00022 namespace makVrv 
00023 { 
00024 
00029    template<class T>
00030    class DtSubjectObserver : public virtual DtSubjectBinder
00031    { 
00032 
00033    public:
00034 
00039       DtSubjectObserver();
00040 
00041       virtual ~DtSubjectObserver();
00042 
00043       virtual void slot_activate(T* subject) = 0;
00044 
00045       virtual void slot_deactivate(T* subject) = 0;
00046 
00047    protected:
00048 
00049       virtual void connect(DtDe& de);
00050 
00051 
00052    }; 
00053 
00054    template<class T>
00055    DtSubjectObserver<T>::DtSubjectObserver()
00056    {
00058       BindFunction functor =  boost::bind(&DtSubjectObserver<T>::connect, this, _1);
00059 
00060       myBindFunctionList.push_back(functor);
00061    }
00062 
00063    template<class T>
00064    DtSubjectObserver<T>::~DtSubjectObserver()
00065    {
00066 
00067    }
00068 
00069    template<class T>
00070    void DtSubjectObserver<T>::connect( DtDe& de )
00071    {
00075       DtSubjectAnnouncer<T>* announcer = DtSubjectAnnouncer<T>::findInstance(de);
00076 
00077       if(announcer)
00078       {
00080          announcer->signal_activate.connect(
00081             boost::bind(&DtSubjectObserver<T>::slot_activate, this, _1));
00082 
00084          // w/ each activated subject instance.
00085          typename std::list<T*>::iterator curIter = announcer->activatedList().begin();
00086          typename std::list<T*>::iterator endIter = announcer->activatedList().end();
00087          for(;curIter != endIter; ++curIter)
00088          {
00089             this->slot_activate(*curIter);
00090          }
00091       }
00092    }
00093 
00094    EXPORT_TEMPLATE_TYPEDEF(DtSubjectObserver<DtDe>, DtDeObserver)
00095    EXPORT_TEMPLATE_TYPEDEF(DtSubjectObserver<DtDisplay>, DtDisplayObserver)
00096    EXPORT_TEMPLATE_TYPEDEF(DtSubjectObserver<DtDeCommunicator>, DtDeCommunicatorObserver)
00097 }  

Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)