CppCMS
|
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_BASE_CONTENT_H 00009 #define CPPCMS_BASE_CONTENT_H 00010 00011 #include <cppcms/defs.h> 00012 #include <booster/copy_ptr.h> 00013 00014 namespace cppcms { 00015 00016 class application; 00017 00023 class CPPCMS_API base_content { 00024 public: 00025 00026 base_content(); 00027 base_content(base_content const &); 00028 base_content const &operator=(base_content const &); 00029 virtual ~base_content(); 00030 00035 application &app(); 00041 void app(application &app); 00042 00046 void reset_app(); 00050 bool has_app(); 00051 00056 class app_guard { 00057 app_guard(app_guard const &); 00058 void operator=(app_guard const &); 00059 public: 00064 app_guard(base_content &c,application &a) : p_(0) 00065 { 00066 if(!c.has_app()) { 00067 p_=&c; 00068 c.app(a); 00069 } 00070 } 00076 app_guard(base_content &c,base_content &parent) : p_(0) 00077 { 00078 if(!c.has_app() && parent.has_app()) { 00079 p_ = &c; 00080 c.app(parent.app()); 00081 } 00082 } 00086 ~app_guard() 00087 { 00088 if(p_) { 00089 p_->reset_app(); 00090 p_ = 0; 00091 } 00092 } 00093 private: 00094 base_content *p_; 00095 }; 00096 00097 private: 00098 struct _data; 00099 booster::copy_ptr<_data> d; 00100 application *app_; 00101 }; 00102 00103 } 00104 00105 00106 #endif