|
reSIProcate/rutil
9694
|
00001 #include <ostream> 00002 #include <vector> 00003 #include <set> 00004 #include <map> 00005 #include <list> 00006 00007 #include "rutil/resipfaststreams.hxx" 00008 #include "rutil/Inserter.hxx" 00009 #include "rutil/Data.hxx" 00010 00011 using namespace resip; 00012 using namespace std; 00013 00014 struct Foo 00015 { 00016 Foo() : 00017 count(0), 00018 value() 00019 { 00020 } 00021 00022 Foo(int c, const Data& v) : 00023 count(c), 00024 value(v) 00025 { 00026 } 00027 00028 bool operator<(const Foo& rhs) const 00029 { 00030 if (count < rhs.count) 00031 { 00032 return true; 00033 } 00034 00035 if (count > rhs.count) 00036 { 00037 return false; 00038 } 00039 00040 return value < rhs.value; 00041 } 00042 00043 bool operator==(const Foo& rhs) const 00044 { 00045 return (!(*this < rhs) && !(rhs < *this)); 00046 } 00047 00048 int count; 00049 Data value; 00050 }; 00051 00052 HashValue(Foo); 00053 HashValueImp(Foo, data.value.hash()); 00054 00055 EncodeStream& operator<<(EncodeStream& str, const Foo& foo) 00056 { 00057 str << "Foo[" << foo.count << " " << foo.value << "]"; 00058 return str; 00059 } 00060 00061 int 00062 main(int argc, char** argv) 00063 { 00064 resipCerr << "Inserter tests..." << endl; 00065 00066 { 00067 resipCerr << Inserter(Foo(0, "null")) << endl; 00068 } 00069 00070 { 00071 vector<Foo> container; 00072 00073 container.push_back(Foo(1, "foo")); 00074 container.push_back(Foo(2, "bar")); 00075 container.push_back(Foo(3, "baz")); 00076 00077 resipCerr << Inserter(container) << endl; 00078 } 00079 00080 { 00081 set<Foo> container; 00082 00083 container.insert(Foo(1, "foo")); 00084 container.insert(Foo(2, "bar")); 00085 container.insert(Foo(3, "baz")); 00086 00087 resipCerr << Inserter(container) << endl; 00088 } 00089 00090 { 00091 map<int, Foo> container; 00092 container[1] = Foo(1, "foo"); 00093 container[2] = Foo(2, "bar"); 00094 container[3] = Foo(3, "baz"); 00095 00096 resipCerr << Inserter(container) << endl; 00097 } 00098 00099 { 00100 HashMap<int, Foo> container; 00101 container[1] = Foo(1, "foo"); 00102 container[2] = Foo(2, "bar"); 00103 container[3] = Foo(3, "baz"); 00104 00105 resipCerr << Inserter(container) << endl; 00106 } 00107 00108 { 00109 HashSet<Foo> container; 00110 container.insert(Foo(1, "foo")); 00111 container.insert(Foo(2, "bar")); 00112 container.insert(Foo(3, "baz")); 00113 00114 resipCerr << Inserter(container) << endl; 00115 } 00116 00117 00118 resipCerr << "InserterP tests..." << endl; 00119 00120 { 00121 Foo *foo = new Foo(0, "null"); 00122 resipCerr << InserterP(foo) << endl; 00123 delete foo; 00124 } 00125 00126 { 00127 vector<Foo*> container; 00128 00129 container.push_back(new Foo(1, "foo")); 00130 container.push_back(new Foo(2, "bar")); 00131 container.push_back(new Foo(3, "baz")); 00132 00133 resipCerr << InserterP(container) << endl; 00134 00135 // cleanup 00136 vector<Foo*>::iterator it = container.begin(); 00137 for(;it!=container.end(); it++) 00138 { 00139 delete *it; 00140 } 00141 } 00142 00143 { 00144 set<Foo*> container; 00145 00146 container.insert(new Foo(1, "foo")); 00147 container.insert(new Foo(2, "bar")); 00148 container.insert(new Foo(3, "baz")); 00149 00150 resipCerr << InserterP(container) << endl; 00151 00152 // cleanup 00153 set<Foo*>::iterator it = container.begin(); 00154 for(;it!=container.end(); it++) 00155 { 00156 delete *it; 00157 } 00158 } 00159 00160 { 00161 map<int, Foo*> container; 00162 container[1] = new Foo(1, "foo"); 00163 container[2] = new Foo(2, "bar"); 00164 container[3] = new Foo(3, "baz"); 00165 00166 resipCerr << InserterP(container) << endl; 00167 00168 // cleanup 00169 map<int, Foo*>::iterator it = container.begin(); 00170 for(;it!=container.end(); it++) 00171 { 00172 delete it->second; 00173 } 00174 } 00175 00176 { 00177 HashMap<int, Foo*> container; 00178 container[1] = new Foo(1, "foo"); 00179 container[2] = new Foo(2, "bar"); 00180 container[3] = new Foo(3, "baz"); 00181 00182 resipCerr << InserterP(container) << endl; 00183 00184 // cleanup 00185 HashMap<int, Foo*>::iterator it = container.begin(); 00186 for(;it!=container.end(); it++) 00187 { 00188 delete it->second; 00189 } 00190 } 00191 00192 { 00193 HashSet<Foo*> container; 00194 container.insert(new Foo(1, "foo")); 00195 container.insert(new Foo(2, "bar")); 00196 container.insert(new Foo(3, "baz")); 00197 00198 resipCerr << InserterP(container) << endl; 00199 00200 // cleanup 00201 HashSet<Foo*>::iterator it = container.begin(); 00202 for(;it!=container.end(); it++) 00203 { 00204 delete *it; 00205 } 00206 } 00207 00208 resipCerr << "All Ok" << endl; 00209 } 00210 00211 /* ==================================================================== 00212 * The Vovida Software License, Version 1.0 00213 * 00214 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00215 * 00216 * Redistribution and use in source and binary forms, with or without 00217 * modification, are permitted provided that the following conditions 00218 * are met: 00219 * 00220 * 1. Redistributions of source code must retain the above copyright 00221 * notice, this list of conditions and the following disclaimer. 00222 * 00223 * 2. Redistributions in binary form must reproduce the above copyright 00224 * notice, this list of conditions and the following disclaimer in 00225 * the documentation and/or other materials provided with the 00226 * distribution. 00227 * 00228 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00229 * and "Vovida Open Communication Application Library (VOCAL)" must 00230 * not be used to endorse or promote products derived from this 00231 * software without prior written permission. For written 00232 * permission, please contact vocal@vovida.org. 00233 * 00234 * 4. Products derived from this software may not be called "VOCAL", nor 00235 * may "VOCAL" appear in their name, without prior written 00236 * permission of Vovida Networks, Inc. 00237 * 00238 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00239 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00240 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00241 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00242 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00243 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00244 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00245 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00246 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00247 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00248 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00249 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00250 * DAMAGE. 00251 * 00252 * ==================================================================== 00253 * 00254 * This software consists of voluntary contributions made by Vovida 00255 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00256 * Inc. For more information on Vovida Networks, Inc., please see 00257 * <http://www.vovida.org/>. 00258 * 00259 */ 00260
1.7.5.1