Release 1.39.0
[boost.git] / Boost_1_39_0 / libs / serialization / doc / state_saver.html
blob53d90b6e018094e85542f35d7f48183e4a577c5f
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:
34 <pre><code>
35 template<class T>
36 // T requirements:
37 // - POD or object semantic (cannot be reference, function, ...)
38 // - copy constructor
39 // - operator = (no-throw one preferred)
40 class state_saver : private boost::noncopyable
42 private:
43 ... // implementation
45 public:
46 state_saver(T & object);
47 ~state_saver();
49 </code></pre>
51 The complete implementation can be found
52 <a target="state_saver" href="../../../boost/state_saver.hpp">here</a>
54 The following illustrates how this is expected to be used.
56 <pre><code>
57 #include &lt;boost/state_saver.hpp&gt;
59 void func(A & a)
60 boost::state_saver&lt;A&gt; s(a);
61 ... // alter state of a by calling non-const functions
62 ... // call other functions
63 // original state of a automatically restored on exit
65 </pre></code>
67 <h3>History</h3>
68 This is a generalization of Daryle Walker's
69 <a href="../../../libs/io/doc/ios_state.html">io_state_saver</a> library.
70 <p>
71 Robert Ramey made an initial version for the serialization library.
72 <p>
73 Pavel Vozenilek made several non-obvious refinements to make it more
74 secure and boost friendly
76 <hr>
77 <p><i>&copy; Copyright <a href="http://www.rrsd.com">Robert Ramey</a> 2002-2004.
78 Distributed under the Boost Software License, Version 1.0. (See
79 accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
80 </i></p>
81 </body>
82 </html>