initial commit
[raggin.git] / src / module_container.hpp
blobc8ab816d0374aca6418bc55e165eebcd35453061
1 #ifndef module_manager_hpp_INCLUDED
2 #define module_manager_hpp_INCLUDED
4 #include <boost/static_assert.hpp>
5 #include <boost/shared_ptr.hpp>
6 #include "module_base.hpp"
7 #include "command.hpp"
8 #include "data.hpp"
11 namespace raggin
13 //fwd
14 class session_base;
16 class module_container
18 public:
19 module_container(session_base& session);
21 /** Registers a module.
23 template<typename ModuleType>
24 void add();
26 /** Returns registered module with type of ModuleType.
28 template<typename ModuleType>
29 boost::shared_ptr<ModuleType> get();
31 // void process_cmd(command& cmd);
32 // void process_data(data& data);
34 private:
35 session_base& session_;
36 std::vector<module_base_ptr> modules_;
40 template<typename ModuleType>
41 void raggin::module_container::add()
43 BOOST_STATIC_ASSERT((boost::is_convertible<ModuleType, module_base>::value));
45 module_base_ptr module(new ModuleType(session_));
46 modules_.push_back(module);
49 template<typename ModuleType>
50 boost::shared_ptr<ModuleType> raggin::module_container::get()
52 BOOST_STATIC_ASSERT((boost::is_convertible<ModuleType, module_base>::value));
54 typedef std::vector<module_base_ptr> iterator;
55 iterator itr = std::find_if(modules_.begin(), modules_.end(),
56 (typeid(*_1) == typeid(ModuleType)));
58 if(itr == modules_.end())
59 throw runtime_error("Module of type" + typeid(ModuleType).name() + "is not registered.")
63 #endif