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>
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,
84 template<
typename View,
typename Content>
85 static std::auto_ptr<base_view> view_builder(std::ostream &stream,
base_content *c)
87 std::auto_ptr<base_view> p;
90 p.reset(
new View(stream,dynamic_cast<Content &>(*c)));
92 catch(std::bad_cast
const &) {
93 throw cppcms_error(
"cppcms::views::generator: an attempt to use content of invalid type");
98 template<
typename View,
typename Content>
99 static std::auto_ptr<base_view> unsafe_view_builder(std::ostream &stream,base_content *c)
101 std::auto_ptr<base_view> p(
new View(stream,static_cast<Content &>(*c)));
107 typedef std::map<std::string,view_factory_type *> views_type;
132 void remove(generator
const &generator);
147 void render(std::string
const &skin,std::string
const &template_name,std::ostream &out,
base_content &content);
154 std::vector<std::string> enumerate();
159 static pool &instance();
186 void render(std::string
const &skin,std::string
const &template_name,std::ostream &out,
base_content &content);
190 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:173
void add_view(std::string const &view_name, bool safe=true)
Definition: views_pool.h:53
This class is central representation of json objects.
Definition: json.h:142
The class that represents a single skin and generates its views.
Definition: views_pool.h:35
Exception thrown by CppCMS framework.
Definition: cppcms_error.h:22
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:119
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 makes impossible to copy any class derived from this one.
Definition: noncopyable.h:15