PureMVC PureMVC

include/PureMVC/Patterns/Facade/Facade.hpp

Go to the documentation of this file.
00001 //  Facade.hpp
00002 //  PureMVC_C++
00003 //
00004 //  PureMVC Port to C++ by Tang Khai Phuong <phuong.tang@puremvc.org>
00005 //  PureMVC - Copyright(c) 2006-2011 Futurescale, Inc., Some rights reserved.
00006 //  Your reuse is governed by the Creative Commons Attribution 3.0 License
00007 //
00008 
00009 #if !defined(__PUREMVC_PATTERNS_FACADE_FACADE_HPP__)
00010 #define __PUREMVC_PATTERNS_FACADE_FACADE_HPP__
00011 
00012 // STL include
00013 #include <string>
00014 #include <exception>
00015 #include <stdexcept>
00016 #include <cassert>
00017 // PureMVC include
00018 #if !defined(__PUREMVC_HPP__)
00019 #define __PUREMVC_INCLUDE__
00020 #include "../PureMVC.hpp"
00021 #endif /* __PUREMVC_HPP__ */
00022 
00023 #include "../../Interfaces/IFacade.hpp"
00024 #include "../../Interfaces/ICommand.hpp"
00025 #include "../../Interfaces/IModel.hpp"
00026 #include "../../Interfaces/IView.hpp"
00027 #include "../../Interfaces/IController.hpp"
00028 #include "../../Interfaces/IMediator.hpp"
00029 #include "../../Interfaces/IAggregate.hpp"
00030 #include "../../Interfaces/IProxy.hpp"
00031 #include "../../Patterns/Observer/Notifier.hpp"
00032 
00033 namespace PureMVC
00034 {
00035     namespace Patterns
00036     {
00037         using Interfaces::IFacade;
00038         using Interfaces::ICommand;
00039         using Interfaces::IModel;
00040         using Interfaces::IView;
00041         using Interfaces::IController;
00042         using Interfaces::IMediator;
00043         using Interfaces::IProxy;
00044         using Interfaces::IAggregate;
00045         using Patterns::Notifier;
00046 
00054         class PUREMVC_API Facade : public virtual IFacade, public Notifier
00055         {
00056         public:
00057             typedef std::auto_ptr<IAggregate<std::string> > CoreNames;
00058         public:
00059             static char const* const DEFAULT_KEY;
00060         private:
00061             Facade(Facade const&);
00062             Facade(IFacade const&);
00063             Facade& operator=(Facade const&);
00064             Facade& operator=(IFacade const&);
00065         protected:
00066             static IFacade* find(std::string const& key);
00067             static void insert(std::string const& key, IFacade* facade);
00068         public:
00082             explicit Facade(std::string const& key = Facade::DEFAULT_KEY);
00083 
00084         protected:
00109             template<typename _DerivedType>
00110             explicit Facade(_DerivedType* instance, std::string const& key = Facade::DEFAULT_KEY)
00111             :_controller(NULL)
00112             ,_model(NULL)
00113             ,_view(NULL)
00114             {
00115                 if (find(key))
00116                     throw std::runtime_error(MULTITON_MSG);
00117                 instance->_DerivedType::initializeNotifier(key);
00118                 insert(key, this);
00119                 instance->_DerivedType::initializeFacade();
00120             }
00121 
00130             virtual void initializeFacade(void);
00131 
00132         public:
00138             static IFacade& getInstance(std::string const& key = Facade::DEFAULT_KEY);
00139 
00140         protected:
00157             virtual void initializeController(void);
00158 
00182             virtual void initializeModel(void);
00183 
00206             virtual void initializeView(void);
00207 
00208         public:
00215             virtual void registerCommand(std::string const& notification_name, ICommand* command);
00216 
00223             virtual ICommand* removeCommand(std::string const& notification_name);
00224 
00231             virtual ICommand const& retrieveCommand(std::string const& notification_name) const;
00232 
00239             virtual ICommand& retrieveCommand(std::string const& notification_name);
00240 
00247             virtual bool hasCommand(std::string const& notification_name) const;
00248 
00255             virtual void registerProxy (IProxy* proxy);
00256 
00263             virtual IProxy const& retrieveProxy (std::string const& proxy_name) const;
00264 
00271             virtual IProxy& retrieveProxy (std::string const& proxy_name);
00272 
00279             virtual IProxy* removeProxy (std::string const& proxy_name);
00280 
00287             virtual bool hasProxy(std::string const& proxy_name) const;
00288 
00294             virtual void registerMediator(IMediator* mediator);
00295 
00302             virtual IMediator const& retrieveMediator(std::string const& mediator_name) const;
00303 
00310             virtual IMediator& retrieveMediator(std::string const& mediator_name);
00311 
00318             virtual IMediator* removeMediator(std::string const& mediator_name);
00319 
00326             virtual bool hasMediator(std::string const& mediator_name) const;
00327 
00338              virtual void sendNotification(std::string const& notification_name, void const* body = NULL, std::string const& type = "");
00339 
00353             virtual void notifyObservers(INotification const& notification);
00354 
00361             static bool hasCore(std::string const& key);
00362 
00371             static void removeCore(std::string const& key);
00372 
00378             static CoreNames listCores(void);
00379 
00383             virtual ~Facade(void);
00384 
00385         protected:
00386             // References to Model, View and Controller
00387             IController* _controller;
00388             IModel* _model;
00389             IView* _view;
00390             // Message Constants
00391             static char const* const MULTITON_MSG;
00392         };
00393     }
00394 }
00395 
00396 #endif /* __PUREMVC_PATTERNS_FACADE_FACADE_HPP__ */