1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: test_autoptr.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_testshl2.hxx"
40 #include <rtl/string.hxx>
41 #include <rtl/ustring.hxx>
48 AutoPtrTest(AutoPtrTest
const& );
49 AutoPtrTest
& operator =(AutoPtrTest
const& );
52 AutoPtrTest(int _nValue
= 1)
55 std::cout
<< "build Value" << std::endl
;
59 std::cout
<< "release Value" << std::endl
;
62 // int operator int() const {return m_nValue;}
63 int getValue() const {return m_nValue
;}
66 std::auto_ptr
<AutoPtrTest
> getPtr()
68 return std::auto_ptr
<AutoPtrTest
>(new AutoPtrTest(2));
71 // auto_ptr get() gibt den Pointer ohne das ownership
72 // auto_ptr release()gibt den Pointer und (!) das ownership
76 AutoPtrTest
*pValuePtr
;
77 std::cout
<< "start test" << std::endl
;
79 std::auto_ptr
<AutoPtrTest
> pValue
= getPtr();
80 std::cout
<< "Value with getValue() " << pValue
->getValue() << std::endl
;
81 // std::cout << "Value operator int() " << *pValue << std::endl;
82 // ownership weiterreichen
83 pValuePtr
= pValue
.release();
85 std::cout
<< "ValuePtr with getValue() " << pValuePtr
->getValue() << std::endl
;
87 // ownership an neuen Pointer uebergeben
88 std::auto_ptr
<AutoPtrTest
> pValue2(pValuePtr
);
90 // AutoPtrTest *pStr = getPtr();
91 std::cout
<< "end test" << std::endl
;
94 // ----------------------------------- Main -----------------------------------
95 #if (defined UNX) || (defined OS2)
96 int main( int /* argc */ , char* /* argv */ [] )
98 int _cdecl
main( int /* argc*/ , char* /*argv*/ [] )