ChipMaster's trial hacks on C++CMS starting with v1.2.1. Not sure I'll follow on with the v2 since it looks to be breaking and mostly frivolous.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

107 lines
2.6 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
  4. //
  5. // See accompanying file COPYING.TXT file for licensing details.
  6. //
  7. ///////////////////////////////////////////////////////////////////////////////
  8. #ifndef CPPCMS_BASE_CONTENT_H
  9. #define CPPCMS_BASE_CONTENT_H
  10. #include <cppcms/defs.h>
  11. #include <booster/copy_ptr.h>
  12. namespace cppcms {
  13. class application;
  14. ///
  15. /// \brief This is a simple polymorphic class that every content for templates rendering should be derided from it.
  16. /// It does not carry much information with exception of RTTI that allows type-safe casting of user provided
  17. /// content instances to target content class that is used by specific template.
  18. ///
  19. class CPPCMS_API base_content {
  20. public:
  21. base_content();
  22. base_content(base_content const &);
  23. base_content const &operator=(base_content const &);
  24. virtual ~base_content();
  25. ///
  26. /// Get the application that renders current
  27. /// content, throw cppcms_error if the application was not set
  28. ///
  29. application &app();
  30. ///
  31. /// Set the application that renders current
  32. ///
  33. /// Called automatically by application::render
  34. ///
  35. void app(application &app);
  36. ///
  37. /// Resets the application
  38. ///
  39. void reset_app();
  40. ///
  41. /// Returns true of the application is assigned
  42. ///
  43. bool has_app();
  44. ///
  45. /// \brief Special guard class that allows setting and resetting
  46. /// content's rendeding according to the specific scope
  47. ///
  48. class app_guard {
  49. app_guard(app_guard const &);
  50. void operator=(app_guard const &);
  51. public:
  52. ///
  53. /// Initialize set the applicaton \a to a content \a c if have
  54. /// not one ready
  55. ///
  56. app_guard(base_content &c,application &a) : p_(0)
  57. {
  58. if(!c.has_app()) {
  59. p_=&c;
  60. c.app(a);
  61. }
  62. }
  63. ///
  64. /// Assign the application to \a c from the \a parent's application.
  65. ///
  66. /// It is assigned if it is not already defined
  67. ///
  68. app_guard(base_content &c,base_content &parent) : p_(0)
  69. {
  70. if(!c.has_app() && parent.has_app()) {
  71. p_ = &c;
  72. c.app(parent.app());
  73. }
  74. }
  75. ///
  76. /// Reset the application if the content if it was assigned in constructor
  77. ///
  78. ~app_guard()
  79. {
  80. if(p_) {
  81. p_->reset_app();
  82. p_ = 0;
  83. }
  84. }
  85. private:
  86. base_content *p_;
  87. };
  88. private:
  89. struct _data;
  90. booster::copy_ptr<_data> d;
  91. application *app_;
  92. };
  93. }
  94. #endif