|
reSIProcate/stack
9694
|
00001 #include <iostream> 00002 00003 #include "rutil/Id.hxx" 00004 00005 //class A; 00006 00007 //template class resip::Id<A>; 00008 00009 //resip::Id<A>::value_type resip::Id<A>::theGenerator = 0; 00010 //resip::Id<A>::map_type resip::Id<A>::theIdMap; 00011 00012 using namespace std; 00013 00014 class A; 00015 template class resip::Id<A>; 00016 00017 class A 00018 { 00019 public: 00020 typedef resip::Id<A> Id; 00021 00022 //friend ostream& operator<<(ostream& , const A&); 00023 00024 A(); 00025 virtual ~A(); 00026 const A::Id& getId() const; 00027 int callme() { return mynumber; } 00028 private: 00029 static int generator; 00030 int mynumber; 00031 A::Id mId; 00032 00033 }; 00034 00035 int A::generator = 100; 00036 #if 0 00037 ostream& operator << (ostream& os, const A& a) 00038 { 00039 os << "A(mynumber=" << a.mynumber << " id=" << a.mId.value() << ')' <<endl; 00040 return os; 00041 } 00042 #endif 00043 00044 A::A() : mynumber(++generator) {}; 00045 00046 A::~A(){}; 00047 00048 const A::Id& 00049 A::getId() const { return mId; } 00050 00051 00052 int 00053 main(int, char*[]) 00054 { 00055 A arr[4]; 00056 00057 for(unsigned int i = 0 ; i < sizeof(arr)/sizeof(*arr); i++) 00058 { 00059 cout << "arr["<<i<<"].getId().value() == " << arr[i].getId().value() 00060 << endl 00061 << " and access example: " 00062 << " arr["<<i<<"].getId()->callme() == " 00063 << arr[i].getId()->callme() 00064 << endl; 00065 } 00066 00067 00068 A* na = new A; 00069 00070 A::Id aid( na->getId()); 00071 00072 cout << "na==" << (void*)na << endl; 00073 cout << "na->callme(): " << na->callme() << endl; 00074 if (aid.valid()) 00075 { 00076 cout << "aid is valid" << endl; 00077 cout << "aid->callme() " << aid->callme() << endl; 00078 cout << "deleting na" << endl; 00079 } 00080 delete na; 00081 cout << "aid.valid() == " << aid.valid() << endl; 00082 00083 return 0; 00084 } 00085 00086 /* ==================================================================== 00087 * The Vovida Software License, Version 1.0 00088 * 00089 * Copyright (c) 2000-2005 Vovida Networks, Inc. All rights reserved. 00090 * 00091 * Redistribution and use in source and binary forms, with or without 00092 * modification, are permitted provided that the following conditions 00093 * are met: 00094 * 00095 * 1. Redistributions of source code must retain the above copyright 00096 * notice, this list of conditions and the following disclaimer. 00097 * 00098 * 2. Redistributions in binary form must reproduce the above copyright 00099 * notice, this list of conditions and the following disclaimer in 00100 * the documentation and/or other materials provided with the 00101 * distribution. 00102 * 00103 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00104 * and "Vovida Open Communication Application Library (VOCAL)" must 00105 * not be used to endorse or promote products derived from this 00106 * software without prior written permission. For written 00107 * permission, please contact vocal@vovida.org. 00108 * 00109 * 4. Products derived from this software may not be called "VOCAL", nor 00110 * may "VOCAL" appear in their name, without prior written 00111 * permission of Vovida Networks, Inc. 00112 * 00113 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00114 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00115 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00116 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00117 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00118 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00119 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00120 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00121 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00122 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00123 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00124 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00125 * DAMAGE. 00126 * 00127 * ==================================================================== 00128 * 00129 * This software consists of voluntary contributions made by Vovida 00130 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00131 * Inc. For more information on Vovida Networks, Inc., please see 00132 * <http://www.vovida.org/>. 00133 * 00134 */
1.7.5.1