Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/assign/doc/email_example.html @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

  • Property svn:executable set to *
File size: 21.0 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
2
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>Boost.Assignment Documentation </title>
7<link rel="stylesheet" href="style.css" type="text/css">
8</head>
9
10<body>
11<pre>
12<span class=comment>// Boost.Assign library
13//
14//  Copyright Thorsten Ottosen 2003-2004. Use, modification and
15//  distribution is subject to the Boost Software License, Version
16//  1.0. (See accompanying file LICENSE_1_0.txt or copy at
17//  http://www.boost.org/LICENSE_1_0.txt)
18//
19// For more information, see http://www.boost.org/libs/assign/
20//
21
22</span>
23<span class=preprocessor>#include </span><span class=special>&lt;</span><span class=identifier>boost</span><span class=special>/</span><span class=identifier>detail</span><span class=special>/</span><span class=identifier>workaround</span><span class=special>.</span><span class=identifier>hpp</span><span class=special>&gt;
24</span>
25<span class=preprocessor>#if </span><span class=identifier>BOOST_WORKAROUND</span><span class=special>(</span><span class=identifier>__BORLANDC__</span><span class=special>, </span><span class=identifier>BOOST_TESTED_AT</span><span class=special>(</span><span class=number>0</span><span class=identifier>x564</span><span class=special>))</span>
26###<span class=identifier>pragma </span><span class=identifier>warn </span><span class=special>-</span><span class=number>8091 </span><span class=comment>// supress warning in Boost.Test</span>
27###<span class=identifier>pragma </span><span class=identifier>warn </span><span class=special>-</span><span class=number>8057 </span><span class=comment>// unused argument argc/argv in Boost.Test</span>
28<span class=preprocessor>#endif
29</span>
30<span class=preprocessor>#include </span><span class=special>&lt;</span><span class=identifier>boost</span><span class=special>/</span><span class=identifier>assign</span><span class=special>/</span><span class=identifier>list_inserter</span><span class=special>.</span><span class=identifier>hpp</span><span class=special>&gt;</span>
31<span class=preprocessor>#include </span><span class=special>&lt;</span><span class=identifier>boost</span><span class=special>/</span><span class=identifier>test</span><span class=special>/</span><span class=identifier>unit_test</span><span class=special>.</span><span class=identifier>hpp</span><span class=special>&gt;</span>
32<span class=preprocessor>#include </span><span class=special>&lt;</span><span class=identifier>boost</span><span class=special>/</span><span class=identifier>test</span><span class=special>/</span><span class=identifier>test_tools</span><span class=special>.</span><span class=identifier>hpp</span><span class=special>&gt;</span>
33<span class=preprocessor>#include </span><span class=special>&lt;</span><span class=identifier>boost</span><span class=special>/</span><span class=identifier>function</span><span class=special>.</span><span class=identifier>hpp</span><span class=special>&gt;</span>
34<span class=preprocessor>#include </span><span class=special>&lt;</span><span class=identifier>boost</span><span class=special>/</span><span class=identifier>bind</span><span class=special>.</span><span class=identifier>hpp</span><span class=special>&gt;</span>
35<span class=preprocessor>#include </span><span class=special>&lt;</span><span class=identifier>vector</span><span class=special>&gt;</span>
36<span class=preprocessor>#include </span><span class=special>&lt;</span><span class=identifier>map</span><span class=special>&gt;
37</span>
38<span class=keyword>namespace </span><span class=identifier>ba </span><span class=special>= </span><span class=identifier>boost</span><span class=special>::</span><span class=identifier>assign</span><span class=special>;
39</span>
40<span class=keyword>class </span><span class=identifier>email</span>
41<span class=special>{</span>
42<span class=keyword>public</span><span class=special>:
43    </span><span class=keyword>enum </span><span class=identifier>address_option
44    </span><span class=special>{
45        </span><span class=identifier>check_addr_book</span><span class=special>,
46        </span><span class=identifier>dont_check_addr_book
47    </span><span class=special>};
48   
49    </span><span class=keyword>typedef </span><span class=identifier>std</span><span class=special>::</span><span class=identifier>pair</span><span class=special>&lt;</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string</span><span class=special>,</span><span class=identifier>address_option</span><span class=special>&gt; </span><span class=identifier>bcc_type</span><span class=special>;
50    </span><span class=keyword>typedef </span><span class=identifier>std</span><span class=special>::</span><span class=identifier>vector</span><span class=special>&lt; </span><span class=identifier>bcc_type </span><span class=special>&gt;               </span><span class=identifier>bcc_map</span><span class=special>;
51    </span><span class=keyword>typedef </span><span class=identifier>std</span><span class=special>::</span><span class=identifier>map</span><span class=special>&lt;</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string</span><span class=special>,</span><span class=identifier>address_option</span><span class=special>&gt;  </span><span class=identifier>address_map</span><span class=special>;
52   
53    </span>
54<span class=keyword>private</span><span class=special>:
55
56    </span><span class=keyword>mutable </span><span class=identifier>address_map      </span><span class=identifier>cc_list</span><span class=special>;
57    </span><span class=keyword>mutable </span><span class=identifier>address_map      </span><span class=identifier>to_list</span><span class=special>;
58    </span><span class=identifier>bcc_map                  </span><span class=identifier>bcc_list</span><span class=special>;
59           
60    </span><span class=keyword>struct </span><span class=identifier>add_to_map
61    </span><span class=special>{
62        </span><span class=identifier>address_map</span><span class=special>&amp; </span><span class=identifier>m</span><span class=special>;
63   
64        </span><span class=identifier>add_to_map</span><span class=special>( </span><span class=identifier>address_map</span><span class=special>&amp; </span><span class=identifier>m </span><span class=special>) </span><span class=special>: </span><span class=identifier>m</span><span class=special>(</span><span class=identifier>m</span><span class=special>)       
65        </span><span class=special>{}
66   
67        </span><span class=keyword>void </span><span class=keyword>operator</span><span class=special>()( </span><span class=keyword>const </span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string</span><span class=special>&amp; </span><span class=identifier>name</span><span class=special>, </span><span class=identifier>address_option </span><span class=identifier>ao </span><span class=special>)
68        </span><span class=special>{
69            </span><span class=identifier>m</span><span class=special>[ </span><span class=identifier>name </span><span class=special>] </span><span class=special>= </span><span class=identifier>ao</span><span class=special>;
70        </span><span class=special>}
71       
72        </span><span class=keyword>void </span><span class=keyword>operator</span><span class=special>()( </span><span class=keyword>const </span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string</span><span class=special>&amp; </span><span class=identifier>name </span><span class=special>)
73        </span><span class=special>{
74            </span><span class=identifier>m</span><span class=special>[ </span><span class=identifier>name </span><span class=special>] </span><span class=special>= </span><span class=identifier>check_addr_book</span><span class=special>;
75        </span><span class=special>}
76    </span><span class=special>};
77
78    </span><span class=keyword>struct </span><span class=identifier>add_to_vector
79    </span><span class=special>{
80        </span><span class=identifier>bcc_map</span><span class=special>&amp; </span><span class=identifier>m</span><span class=special>;
81       
82        </span><span class=identifier>add_to_vector</span><span class=special>( </span><span class=identifier>bcc_map</span><span class=special>&amp; </span><span class=identifier>m </span><span class=special>) </span><span class=special>: </span><span class=identifier>m</span><span class=special>(</span><span class=identifier>m</span><span class=special>)
83        </span><span class=special>{}
84       
85        </span><span class=keyword>void </span><span class=keyword>operator</span><span class=special>()( </span><span class=keyword>const </span><span class=identifier>bcc_type</span><span class=special>&amp; </span><span class=identifier>r </span><span class=special>)
86        </span><span class=special>{
87            </span><span class=identifier>m</span><span class=special>.</span><span class=identifier>push_back</span><span class=special>( </span><span class=identifier>r </span><span class=special>);
88        </span><span class=special>}
89    </span><span class=special>};
90</span>
91<span class=keyword>public</span><span class=special>:
92   
93    </span><span class=identifier>ba</span><span class=special>::</span><span class=identifier>list_inserter</span><span class=special>&lt; </span><span class=identifier>add_to_map </span><span class=special>&gt;
94    </span><span class=identifier>add_cc</span><span class=special>( </span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string </span><span class=identifier>name</span><span class=special>, </span><span class=identifier>address_option </span><span class=identifier>ao </span><span class=special>)
95    </span><span class=special>{
96        </span><span class=keyword>return </span><span class=identifier>ba</span><span class=special>::</span><span class=identifier>make_list_inserter</span><span class=special>( </span><span class=identifier>add_to_map</span><span class=special>( </span><span class=identifier>cc_list </span><span class=special>) </span><span class=special>)( </span><span class=identifier>name</span><span class=special>, </span><span class=identifier>ao </span><span class=special>);
97    </span><span class=special>}
98
99    </span><span class=identifier>ba</span><span class=special>::</span><span class=identifier>list_inserter</span><span class=special>&lt; </span><span class=identifier>add_to_map </span><span class=special>&gt;
100    </span><span class=identifier>add_to</span><span class=special>( </span><span class=keyword>const </span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string</span><span class=special>&amp; </span><span class=identifier>name </span><span class=special>)
101    </span><span class=special>{
102        </span><span class=keyword>return </span><span class=identifier>ba</span><span class=special>::</span><span class=identifier>make_list_inserter</span><span class=special>( </span><span class=identifier>add_to_map</span><span class=special>( </span><span class=identifier>to_list </span><span class=special>) </span><span class=special>)( </span><span class=identifier>name </span><span class=special>);
103    </span><span class=special>}
104   
105    </span><span class=identifier>ba</span><span class=special>::</span><span class=identifier>list_inserter</span><span class=special>&lt; </span><span class=identifier>add_to_vector</span><span class=special>, </span><span class=identifier>bcc_type </span><span class=special>&gt;
106    </span><span class=identifier>add_bcc</span><span class=special>( </span><span class=keyword>const </span><span class=identifier>bcc_type</span><span class=special>&amp; </span><span class=identifier>bcc </span><span class=special>)
107    </span><span class=special>{
108        </span><span class=keyword>return </span><span class=identifier>ba</span><span class=special>::</span><span class=identifier>make_list_inserter</span><span class=special>( </span><span class=identifier>add_to_vector</span><span class=special>( </span><span class=identifier>bcc_list </span><span class=special>) </span><span class=special>)( </span><span class=identifier>bcc </span><span class=special>);     
109    </span><span class=special>}
110   
111    </span><span class=identifier>address_option
112    </span><span class=identifier>cc_at</span><span class=special>( </span><span class=keyword>const </span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string</span><span class=special>&amp; </span><span class=identifier>name </span><span class=special>) </span><span class=keyword>const
113    </span><span class=special>{
114        </span><span class=keyword>return </span><span class=identifier>cc_list</span><span class=special>[ </span><span class=identifier>name </span><span class=special>];
115    </span><span class=special>}
116   
117    </span><span class=identifier>address_option
118    </span><span class=identifier>to_at</span><span class=special>( </span><span class=keyword>const </span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string</span><span class=special>&amp; </span><span class=identifier>name </span><span class=special>) </span><span class=keyword>const
119    </span><span class=special>{
120        </span><span class=keyword>return </span><span class=identifier>to_list</span><span class=special>[ </span><span class=identifier>name </span><span class=special>];
121    </span><span class=special>}
122   
123    </span><span class=identifier>address_option
124    </span><span class=identifier>bcc_at</span><span class=special>( </span><span class=keyword>unsigned </span><span class=identifier>index </span><span class=special>) </span><span class=keyword>const
125    </span><span class=special>{
126        </span><span class=keyword>return </span><span class=identifier>bcc_list</span><span class=special>.</span><span class=identifier>at</span><span class=special>( </span><span class=identifier>index </span><span class=special>).</span><span class=identifier>second</span><span class=special>;
127    </span><span class=special>}</span>
128<span class=special>};
129
130
131</span>
132<span class=keyword>void </span><span class=identifier>check_list_inserter</span><span class=special>()</span>
133<span class=special>{
134    </span><span class=keyword>using </span><span class=keyword>namespace </span><span class=identifier>boost</span><span class=special>::</span><span class=identifier>assign</span><span class=special>;
135
136    </span><span class=identifier>email </span><span class=identifier>e</span><span class=special>;
137    </span><span class=identifier>e</span><span class=special>.</span><span class=identifier>add_cc</span><span class=special>( </span><span class=string>&quot;franz&quot;</span><span class=special>, </span><span class=identifier>email</span><span class=special>::</span><span class=identifier>dont_check_addr_book </span><span class=special>)
138            </span><span class=special>( </span><span class=string>&quot;hanz&quot;</span><span class=special>, </span><span class=identifier>email</span><span class=special>::</span><span class=identifier>check_addr_book </span><span class=special>)
139            </span><span class=special>( </span><span class=string>&quot;betty&quot;</span><span class=special>, </span><span class=identifier>email</span><span class=special>::</span><span class=identifier>dont_check_addr_book </span><span class=special>);
140    </span><span class=identifier>BOOST_CHECK_EQUAL</span><span class=special>( </span><span class=identifier>e</span><span class=special>.</span><span class=identifier>cc_at</span><span class=special>( </span><span class=string>&quot;franz&quot; </span><span class=special>), </span><span class=identifier>email</span><span class=special>::</span><span class=identifier>dont_check_addr_book </span><span class=special>);
141    </span><span class=identifier>BOOST_CHECK_EQUAL</span><span class=special>( </span><span class=identifier>e</span><span class=special>.</span><span class=identifier>cc_at</span><span class=special>( </span><span class=string>&quot;hanz&quot; </span><span class=special>), </span><span class=identifier>email</span><span class=special>::</span><span class=identifier>check_addr_book </span><span class=special>);
142    </span><span class=identifier>BOOST_CHECK_EQUAL</span><span class=special>( </span><span class=identifier>e</span><span class=special>.</span><span class=identifier>cc_at</span><span class=special>( </span><span class=string>&quot;betty&quot; </span><span class=special>), </span><span class=identifier>email</span><span class=special>::</span><span class=identifier>dont_check_addr_book </span><span class=special>);
143
144    </span><span class=identifier>e</span><span class=special>.</span><span class=identifier>add_to</span><span class=special>( </span><span class=string>&quot;betsy&quot; </span><span class=special>)( </span><span class=string>&quot;peter&quot; </span><span class=special>);
145    </span><span class=identifier>BOOST_CHECK_EQUAL</span><span class=special>( </span><span class=identifier>e</span><span class=special>.</span><span class=identifier>cc_at</span><span class=special>( </span><span class=string>&quot;betsy&quot; </span><span class=special>), </span><span class=identifier>email</span><span class=special>::</span><span class=identifier>check_addr_book </span><span class=special>);
146    </span><span class=identifier>BOOST_CHECK_EQUAL</span><span class=special>( </span><span class=identifier>e</span><span class=special>.</span><span class=identifier>cc_at</span><span class=special>( </span><span class=string>&quot;peter&quot; </span><span class=special>), </span><span class=identifier>email</span><span class=special>::</span><span class=identifier>check_addr_book </span><span class=special>);
147   
148    </span><span class=identifier>e</span><span class=special>.</span><span class=identifier>add_bcc</span><span class=special>( </span><span class=identifier>email</span><span class=special>::</span><span class=identifier>bcc_type</span><span class=special>( </span><span class=string>&quot;Mr. Foo&quot;</span><span class=special>, </span><span class=identifier>email</span><span class=special>::</span><span class=identifier>check_addr_book </span><span class=special>) </span><span class=special>)
149             </span><span class=special>( </span><span class=string>&quot;Mr. Bar&quot;</span><span class=special>, </span><span class=identifier>email</span><span class=special>::</span><span class=identifier>dont_check_addr_book </span><span class=special>);
150    </span><span class=identifier>BOOST_CHECK_EQUAL</span><span class=special>( </span><span class=identifier>e</span><span class=special>.</span><span class=identifier>bcc_at</span><span class=special>( </span><span class=number>0 </span><span class=special>), </span><span class=identifier>email</span><span class=special>::</span><span class=identifier>check_addr_book </span><span class=special>);
151    </span><span class=identifier>BOOST_CHECK_EQUAL</span><span class=special>( </span><span class=identifier>e</span><span class=special>.</span><span class=identifier>bcc_at</span><span class=special>( </span><span class=number>1 </span><span class=special>), </span><span class=identifier>email</span><span class=special>::</span><span class=identifier>dont_check_addr_book </span><span class=special>);
152    </span>
153<span class=special>}
154
155
156</span>
157<span class=preprocessor>#include </span><span class=special>&lt;</span><span class=identifier>boost</span><span class=special>/</span><span class=identifier>test</span><span class=special>/</span><span class=identifier>included</span><span class=special>/</span><span class=identifier>unit_test_framework</span><span class=special>.</span><span class=identifier>hpp</span><span class=special>&gt; 
158</span>
159<span class=keyword>using </span><span class=identifier>boost</span><span class=special>::</span><span class=identifier>unit_test_framework</span><span class=special>::</span><span class=identifier>test_suite</span><span class=special>;
160</span>
161<span class=identifier>test_suite</span><span class=special>* </span><span class=identifier>init_unit_test_suite</span><span class=special>( </span><span class=keyword>int </span><span class=identifier>argc</span><span class=special>, </span><span class=keyword>char</span><span class=special>* </span><span class=identifier>argv</span><span class=special>[] </span><span class=special>)</span>
162<span class=special>{
163    </span><span class=identifier>test_suite</span><span class=special>* </span><span class=identifier>test </span><span class=special>= </span><span class=identifier>BOOST_TEST_SUITE</span><span class=special>( </span><span class=string>&quot;List Test Suite&quot; </span><span class=special>);
164
165    </span><span class=identifier>test</span><span class=special>-&gt;</span><span class=identifier>add</span><span class=special>( </span><span class=identifier>BOOST_TEST_CASE</span><span class=special>( </span><span class=special>&amp;</span><span class=identifier>check_list_inserter </span><span class=special>) </span><span class=special>);
166
167    </span><span class=keyword>return </span><span class=identifier>test</span><span class=special>;</span>
168<span class=special>}
169
170</span>
171
172</pre>
173</body>
174</html>
Note: See TracBrowser for help on using the repository browser.