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"
16 class module_container
19 module_container(session_base
& session
);
21 /** Registers a module.
23 template<typename ModuleType
>
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);
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.")