state_saver.html 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!--
  4. (C) Copyright 2002-4 Robert Ramey - http://www.rrsd.com .
  5. Use, modification and distribution is subject to the Boost Software
  6. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. http://www.boost.org/LICENSE_1_0.txt)
  8. -->
  9. <head>
  10. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  11. <link rel="stylesheet" type="text/css" href="../../../boost.css">
  12. <link rel="stylesheet" type="text/css" href="style.css">
  13. <title>Serialization - <code style="white-space: normal">state_saver</code></title>
  14. </head>
  15. <body link="#0000ff" vlink="#800080">
  16. <table border="0" cellpadding="7" cellspacing="0" width="100%" summary="header">
  17. <tr>
  18. <td valign="top" width="300">
  19. <h3><a href="../../../index.htm"><img height="86" width="277" alt="C++ Boost" src="../../../boost.png" border="0"></a></h3>
  20. </td>
  21. <td valign="top">
  22. <h1 align="center">Serialization</h1>
  23. <h2 align="center"><code style="white-space: normal">state_saver</code</h2>
  24. </td>
  25. </tr>
  26. </table>
  27. <hr>
  28. <p>
  29. Sometimes a certain value has to change only for a limited scope.
  30. This class wrapper saves a copy of the current state of some object,
  31. and resets the object's state at destruction time, undoing any change the object
  32. may have gone through. Here is the interface:
  33. <pre><code>
  34. template<class T>
  35. // T requirements:
  36. // - POD or object semantic (cannot be reference, function, ...)
  37. // - copy constructor
  38. // - operator = (no-throw one preferred)
  39. class state_saver : private boost::noncopyable
  40. {
  41. private:
  42. ... // implementation
  43. public:
  44. state_saver(T & object);
  45. ~state_saver();
  46. };
  47. </code></pre>
  48. The complete implementation can be found
  49. <a target="state_saver" href="../../../boost/serialization/state_saver.hpp">here</a>
  50. The following illustrates how this is expected to be used.
  51. <pre><code>
  52. #include &lt;boost/state_saver.hpp&gt;
  53. void func(A & a)
  54. boost::state_saver&lt;A&gt; s(a);
  55. ... // alter state of a by calling non-const functions
  56. ... // call other functions
  57. // original state of a automatically restored on exit
  58. }
  59. </pre></code>
  60. <h3>History</h3>
  61. This is a generalization of Daryle Walker's
  62. <a href="../../../libs/io/doc/ios_state.html">io_state_saver</a> library.
  63. <p>
  64. Robert Ramey made an initial version for the serialization library.
  65. <p>
  66. Pavel Vozenilek made several non-obvious refinements to make it more
  67. secure and boost friendly
  68. <hr>
  69. <p><i>&copy; Copyright <a href="http://www.rrsd.com">Robert Ramey</a> 2002-2004.
  70. Distributed under the Boost Software License, Version 1.0. (See
  71. accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  72. </i></p>
  73. </body>
  74. </html>