UDK 3.2.7 C/C++ API Reference
|
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 00002 /************************************************************************* 00003 * 00004 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 00005 * 00006 * Copyright 2000, 2010 Oracle and/or its affiliates. 00007 * 00008 * OpenOffice.org - a multi-platform office productivity suite 00009 * 00010 * This file is part of OpenOffice.org. 00011 * 00012 * OpenOffice.org is free software: you can redistribute it and/or modify 00013 * it under the terms of the GNU Lesser General Public License version 3 00014 * only, as published by the Free Software Foundation. 00015 * 00016 * OpenOffice.org is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Lesser General Public License version 3 for more details 00020 * (a copy is included in the LICENSE file that accompanied this code). 00021 * 00022 * You should have received a copy of the GNU Lesser General Public License 00023 * version 3 along with OpenOffice.org. If not, see 00024 * <http://www.openoffice.org/license.html> 00025 * for a copy of the LGPLv3 License. 00026 * 00027 ************************************************************************/ 00028 00029 #ifndef _SALHELPER_FUTURE_HXX_ 00030 #define _SALHELPER_FUTURE_HXX_ 00031 00032 #include <sal/types.h> 00033 #include <osl/diagnose.h> 00034 #include <osl/conditn.hxx> 00035 #include <salhelper/refobj.hxx> 00036 00037 namespace salhelper 00038 { 00039 00040 //---------------------------------------------------------------------------- 00041 00042 #ifndef SALHELPER_COPYCTOR_API 00043 #define SALHELPER_COPYCTOR_API(C) C (const C&); C& operator= (const C&) 00044 #endif 00045 00046 //---------------------------------------------------------------------------- 00047 00048 template<class value_type> 00049 class FutureValue : protected osl::Condition 00050 { 00053 value_type m_aValue; 00054 00057 SALHELPER_COPYCTOR_API(FutureValue<value_type>); 00058 00059 public: 00060 inline FutureValue (const value_type& value = value_type()) SAL_THROW(()) 00061 : m_aValue (value) 00062 { 00063 Condition::reset(); 00064 } 00065 00066 inline ~FutureValue() SAL_THROW(()) 00067 {} 00068 00069 inline sal_Bool is() const SAL_THROW(()) 00070 { 00071 return const_cast<FutureValue*>(this)->check(); 00072 } 00073 00074 inline void set (const value_type& value) SAL_THROW(()) 00075 { 00076 m_aValue = value; 00077 Condition::set(); 00078 } 00079 00080 inline value_type& get() SAL_THROW(()) 00081 { 00082 Condition::wait(); 00083 return m_aValue; 00084 } 00085 }; 00086 00087 //---------------------------------------------------------------------------- 00088 00089 template<class value_type> 00090 class Future : public salhelper::ReferenceObject 00091 { 00094 FutureValue<value_type> m_aValue; 00095 00098 SALHELPER_COPYCTOR_API(Future<value_type>); 00099 00100 public: 00101 inline Future (const value_type& value = value_type()) SAL_THROW(()) 00102 : m_aValue (value) 00103 {} 00104 00105 inline void set (const value_type& value) SAL_THROW(()) 00106 { 00107 OSL_PRECOND(!m_aValue.is(), "Future::set(): value already set"); 00108 m_aValue.set (value); 00109 } 00110 00111 inline value_type& get() SAL_THROW(()) 00112 { 00113 return m_aValue.get(); 00114 } 00115 }; 00116 00117 //---------------------------------------------------------------------------- 00118 00119 } // namespace salhelper 00120 00121 #endif /* !_SALHELPER_FUTURE_HXX_ */ 00122 00123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */