CppCMS
base_content.h
1 //
3 // Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
4 //
5 // See accompanying file COPYING.TXT file for licensing details.
6 //
8 #ifndef CPPCMS_BASE_CONTENT_H
9 #define CPPCMS_BASE_CONTENT_H
10 
11 #include <cppcms/defs.h>
12 #include <booster/copy_ptr.h>
13 
14 namespace cppcms {
15 
16  class application;
17 
23  class CPPCMS_API base_content {
24  public:
25 
26  base_content();
27  base_content(base_content const &);
28  base_content const &operator=(base_content const &);
29  virtual ~base_content();
30 
35  application &app();
41  void app(application &app);
42 
46  void reset_app();
50  bool has_app();
51 
56  class app_guard {
57  app_guard(app_guard const &);
58  void operator=(app_guard const &);
59  public:
65  {
66  if(!c.has_app()) {
67  p_=&c;
68  c.app(a);
69  }
70  }
76  app_guard(base_content &c,base_content &parent) : p_(0)
77  {
78  if(!c.has_app() && parent.has_app()) {
79  p_ = &c;
80  c.app(parent.app());
81  }
82  }
87  {
88  if(p_) {
89  p_->reset_app();
90  p_ = 0;
91  }
92  }
93  private:
94  base_content *p_;
95  };
96 
97  private:
98  struct _data;
100  application *app_;
101  };
102 
103 }
104 
105 
106 #endif
Special guard class that allows setting and resetting content&#39;s rendeding according to the specific s...
Definition: base_content.h:56
~app_guard()
Definition: base_content.h:86
app_guard(base_content &c, base_content &parent)
Definition: base_content.h:76
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
application class is the base class for all user created applications.
Definition: application.h:82
app_guard(base_content &c, application &a)
Definition: base_content.h:64
application & app()