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.
 
 
 
 
 
 

73 lines
1.9 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_COPY_FILTER_H
  9. #define CPPCMS_COPY_FILTER_H
  10. #include <booster/streambuf.h>
  11. #include <booster/noncopyable.h>
  12. #include <booster/hold_ptr.h>
  13. #include <cppcms/defs.h>
  14. #include <list>
  15. #include <ostream>
  16. namespace cppcms {
  17. ///
  18. /// \brief Copy the output stream part - "tee" filter
  19. ///
  20. /// This simple class designed to "copy" all the output that comes to the stream
  21. /// to internal buffer and the stream itself and return the copied data on detaching
  22. /// the filter.
  23. ///
  24. /// It is very useful to use with caching, for example:
  25. ///
  26. /// \code
  27. /// std::string frame;
  28. /// if(cache().fetch_frame("key",frame)) {
  29. /// out() << frame;
  30. /// }
  31. /// else {
  32. /// cppcms::copy_filter tee(out());
  33. /// ...
  34. /// // generate something heavy
  35. /// ...
  36. /// cache().store_frame("key",tee.detach());
  37. /// }
  38. /// \endcode
  39. ///
  40. class CPPCMS_API copy_filter : public booster::noncopyable {
  41. public:
  42. ///
  43. /// Create a filter copying all output to internal buffer
  44. ///
  45. copy_filter(std::ostream &output);
  46. ///
  47. /// When destroyed, if the stream wasn't detached aborts coping the data,
  48. /// making it exception safe.
  49. ///
  50. ~copy_filter();
  51. ///
  52. /// Stop the coping process and return all collected data as string.
  53. ///
  54. std::string detach();
  55. private:
  56. class tee_device;
  57. struct data;
  58. booster::hold_ptr<data> d;
  59. booster::streambuf copy_buffer_;
  60. std::ostream &output_;
  61. std::ostream real_output_stream_;
  62. std::list<std::string> data_;
  63. bool detached_;
  64. };
  65. } // cppcms
  66. #endif