• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

cppcms/views_pool.h

00001 
00002 //                                                                             
00003 //  Copyright (C) 2008-2012  Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>     
00004 //                                                                             
00005 //  See accompanying file COPYING.TXT file for licensing details.
00006 //
00008 #ifndef CPPCMS_VIEWS_POOL_H
00009 #define CPPCMS_VIEWS_POOL_H
00010 
00011 #include <cppcms/defs.h>
00012 #include <booster/noncopyable.h>
00013 #include <cppcms/base_view.h>
00014 
00015 #include <memory>
00016 #include <map>
00017 #include <vector>
00018 #include <ostream>
00019 
00020 namespace cppcms {
00021 
00022         namespace json { class value; }
00023 
00027         namespace views {
00028 
00034                 class CPPCMS_API generator : public booster::noncopyable {
00035                 public:
00037                         typedef std::auto_ptr<base_view> view_factory_type(std::ostream &,base_content *c);
00038 
00039                         generator();
00040                         ~generator();
00041 
00051                         template<typename View,typename Content>
00052                         void add_view(std::string const &view_name,bool safe = true)
00053                         {
00054                                 view_factory_type *factory = 0;
00055                                 if(safe)
00056                                         factory = view_builder<View,Content>;
00057                                 else
00058                                         factory = view_builder<View,Content>;
00059                                 add_factory(view_name,factory);
00060                         }
00061                         
00065                         void add_factory(std::string const &name,view_factory_type *factory);
00069                         std::string name() const;
00073                         void name(std::string const &n);
00078                         std::auto_ptr<base_view> create(std::string const &view_name,
00079                                                         std::ostream &output,
00080                                                         base_content *content) const;
00081                 private:
00082                         
00083                         template<typename View,typename Content>
00084                         static std::auto_ptr<base_view> view_builder(std::ostream &stream,base_content *c) 
00085                         {
00086                                 std::auto_ptr<base_view> p(new View(stream,dynamic_cast<Content &>(*c)));
00087                                 return p;
00088                         }
00089                         
00090                         template<typename View,typename Content>
00091                         static std::auto_ptr<base_view> unsafe_view_builder(std::ostream &stream,base_content *c) 
00092                         {
00093                                 std::auto_ptr<base_view> p(new View(stream,static_cast<Content &>(*c)));
00094                                 return p;
00095                         }
00096                         
00097 
00098                         struct data;
00099                         typedef std::map<std::string,view_factory_type *> views_type;
00100                         views_type views_;
00101                         std::string name_;
00102                         booster::hold_ptr<data> d;
00103                 };
00104 
00111                 class CPPCMS_API pool : public booster::noncopyable {
00112                 public:
00118                         void add(generator const &generator);
00124                         void remove(generator const &generator);
00125                 
00139                         void render(std::string const &skin,std::string const &template_name,std::ostream &out,base_content &content);
00140 
00146                         std::vector<std::string> enumerate();
00147                         
00151                         static pool &instance();
00152                 
00153                 private:
00154                         pool();
00155                         ~pool();
00156 
00157                         struct data;
00158                         booster::hold_ptr<data> d;
00159                 };
00160 
00165                 class CPPCMS_API manager : public booster::noncopyable {
00166                 public:
00172                         manager(json::value const &settings);
00173                         ~manager();
00174 
00178                         void render(std::string const &skin,std::string const &template_name,std::ostream &out,base_content &content);
00182                         std::string default_skin();
00183                 private:
00184                         struct data;
00185                         booster::hold_ptr<data> d;
00186                 };
00187         } // views
00188 
00189 }
00190 
00191 
00192 #endif

Generated on Wed Jan 18 2012 07:25:24 for CppCMS by  doxygen 1.7.1