/* UpTools v8.6 * * Copyright (c) 2005-2013 Fundacion Universidad de Palermo (Argentina). * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * 4. Redistributions of any form whatsoever must retain the following * acknowledgment: 'This product includes software developed by the * "Universidad de Palermo, Argentina" (http://www.palermo.edu/).' * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ // test program for UpLinkable's and UpSmartLinkPtr's // debug options: should be deactivated in programs already debgged in // order to obtain the full library performance // define to activate UpLinkable heap check (must be constructed in // the heap with new) #define UPLINKABLE_HEAPCHECK 1 // define to activate UpLinkable logging of constructor and destructor #define UPLINKABLE_LOG_EVENTS 1 // define to activate UpSmartLinkPtr logging of linking and unlinking #define UPLINKABLE_LOG_LINKS 1 #include <UpTools/UpSmartLinkPtr.h> #include <iostream> using namespace std; class MyClass : public UpLinkable { public: MyClass() : UpLinkable("MyClass") {} private: int a; }; class YourClass : public UpLinkable { public: YourClass() : UpLinkable("YourClass") {} private: int a; }; class AnyClass : public UpLinkable { public: AnyClass() { } private: int a; }; UpSmartLinkPtr<MyClass> f1() { UpSmartLinkPtr<MyClass> ret; ret = new MyClass; return ret; } UpSmartLinkPtr<YourClass> f2(UpSmartLinkPtr<YourClass> p) { UpSmartLinkPtr<YourClass> x = p; return x; } int main() { upOpenLogFile("",0,"stdout",LOG_DEBUG); UpSmartLinkPtr<MyClass> myptr1 = new MyClass; UpSmartLinkPtr<MyClass> myptr2 = myptr1; UpSmartLinkPtr<MyClass> myptr3; UpSmartLinkPtr<YourClass> yourptr1 = new YourClass; UpSmartLinkPtr<YourClass> yourptr2 = yourptr1; UpSmartLinkPtr<YourClass> yourptr3; UpSmartLinkPtr<AnyClass> anyptr1 = new AnyClass; UpSmartLinkPtr<AnyClass> anyptr2 = anyptr1; UpSmartLinkPtr<AnyClass> anyptr3; cout<<"upLinkableMonitor.getCount(\"AnyClass\")="<<upLinkableMonitor.getCount("AnyClass")<<" (AnyClass does not use UpLinkable named declaration)"<<endl; cout<<"upLinkableMonitor.getCount(\"MyClass\")="<<upLinkableMonitor.getCount("MyClass")<<endl; cout<<"upLinkableMonitor.getCount(\"YourClass\")="<<upLinkableMonitor.getCount("YourClass")<<endl; cout<<"upLinkableMonitor.getUnnamedCount()="<<upLinkableMonitor.getUnnamedCount()<<endl; cout<<"upLinkableMonitor.getNamedCount()="<<upLinkableMonitor.getNamedCount()<<endl; cout<<"upLinkableMonitor.getCount()="<<upLinkableMonitor.getCount()<<endl<<endl; upLinkableMonitor.report(cout); cout<<flush; myptr3 = myptr2; myptr1 = f1(); myptr2 = 0; yourptr3 = new YourClass; yourptr2 = f2(yourptr3); anyptr1 = anyptr2 = anyptr3 = new AnyClass; anyptr1 = anyptr2 = anyptr3 = 0; upLinkableMonitor.report(cout); cout<<flush; myptr1 = myptr2 = myptr3 = 0; UpSmartLinkPtr<AnyClass> ptrToZero; UpSmartLinkPtr<AnyClass> ptrToSomeInstance = new AnyClass; cout<<"\n\n( ! ptrToZero )=" << ( !ptrToZero ) << endl; cout<<"( ! ptrToSomeInstance )=" << ( !ptrToSomeInstance ) << endl; cout<<"( (bool)ptrToZero )=" << ( (bool)ptrToZero ) << endl; cout<<"( (bool)ptrToSomeInstance )=" << ( (bool)ptrToSomeInstance ) << endl; if( ptrToZero ) cout<<"error in (bool)ptrToZero" << endl; if( ptrToSomeInstance ) { } else cout<<"error in (bool)ptrToSomeInstance" << endl; cout<<"finish"<<endl<<endl; return 0; }