merge the formfield patch from ooo-build
[ooovba.git] / testshl2 / workben / test_autoptr.cxx
blob0cf514cbcadbfa434a47857fe5b3f559b5dda341
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: test_autoptr.cxx,v $
10 * $Revision: 1.6 $
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"
34 #include <stdlib.h>
35 #include <memory>
36 #include <iostream>
38 #include <stdio.h>
40 #include <rtl/string.hxx>
41 #include <rtl/ustring.hxx>
43 class AutoPtrTest
45 int m_nValue;
47 // NOCOPY
48 AutoPtrTest(AutoPtrTest const& );
49 AutoPtrTest& operator =(AutoPtrTest const& );
51 public:
52 AutoPtrTest(int _nValue = 1)
53 :m_nValue(_nValue)
55 std::cout << "build Value" << std::endl;
57 ~AutoPtrTest()
59 std::cout << "release Value" << std::endl;
60 m_nValue = 0;
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
74 void test_autoptr()
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 */ [] )
97 #else
98 int _cdecl main( int /* argc*/ , char* /*argv*/ [] )
99 #endif
101 test_autoptr();
102 return 0;