8 #ifndef CPPCMS_VIEWS_POOL_H 9 #define CPPCMS_VIEWS_POOL_H 11 #include <cppcms/defs.h> 12 #include <booster/noncopyable.h> 13 #include <cppcms/base_view.h> 14 #include <cppcms/cppcms_error.h> 16 #include <booster/auto_ptr_inc.h> 23 namespace json {
class value; }
52 template<
typename View,
typename Content>
53 void add_view(std::string
const &view_name,
bool safe =
true)
55 view_factory_type *factory = 0;
57 factory = view_builder<View,Content>;
59 factory = unsafe_view_builder<View,Content>;
60 add_factory(view_name,factory);
66 void add_factory(std::string
const &name,view_factory_type *factory);
70 std::string name()
const;
74 void name(std::string
const &n);
79 std::auto_ptr<base_view> create(std::string
const &view_name,
85 std::vector<std::string> enumerate()
const;
88 template<
typename View,
typename Content>
89 static std::auto_ptr<base_view> view_builder(std::ostream &stream,
base_content *c)
91 std::auto_ptr<base_view> p;
94 p.reset(
new View(stream,dynamic_cast<Content &>(*c)));
96 catch(std::bad_cast
const &) {
97 throw cppcms_error(
"cppcms::views::generator: an attempt to use content of invalid type");
102 template<
typename View,
typename Content>
103 static std::auto_ptr<base_view> unsafe_view_builder(std::ostream &stream,
base_content *c)
105 std::auto_ptr<base_view> p(
new View(stream,static_cast<Content &>(*c)));
111 typedef std::map<std::string,view_factory_type *> views_type;
131 view_lock(std::string
const &skin,std::string
const &template_name,std::ostream &out,
base_content &content);
139 template<
typename View>
142 return dynamic_cast<View &
>(view());
173 void remove(generator
const &generator);
188 void render(std::string
const &skin,std::string
const &template_name,std::ostream &out,
base_content &content);
196 std::vector<std::string> enumerate();
201 static pool &instance();
209 base_view *create_view(std::string
const &skin,std::string
const &template_name,std::ostream &out,
base_content &content);
234 void render(std::string
const &skin,std::string
const &template_name,std::ostream &out,
base_content &content);
238 std::string default_skin();
This class controls the views used my application it knows to load them dynamically and reload if nee...
Definition: views_pool.h:221
void add_view(std::string const &view_name, bool safe=true)
Definition: views_pool.h:53
A class that allows to use the view withing the internal lock used inside pool class.
Definition: views_pool.h:126
This class is central representation of json objects.
Definition: json.h:140
The class that represents a single skin and generates its views.
Definition: views_pool.h:35
View & use_view()
Definition: views_pool.h:140
Exception thrown by CppCMS framework.
Definition: cppcms_error.h:22
This is the namespace where all CppCMS functionality is placed.
Definition: application.h:19
This is a simple polymorphic class that every content for templates rendering should be derided from ...
Definition: base_content.h:23
This is a singleton object that holds all views in the process. Any view is registered and unregister...
Definition: views_pool.h:160
std::auto_ptr< base_view > view_factory_type(std::ostream &, base_content *c)
The callback that creates a single view.
Definition: views_pool.h:38
This class is base class for all views (skins) rendered by CppCMS template engine.
Definition: base_view.h:35
This class makes impossible to copy any class derived from this one.
Definition: noncopyable.h:15