My Project
UDK 3.2.7 C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
future.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * Copyright 2000, 2010 Oracle and/or its affiliates.
7  *
8  * OpenOffice.org - a multi-platform office productivity suite
9  *
10  * This file is part of OpenOffice.org.
11  *
12  * OpenOffice.org is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 3
14  * only, as published by the Free Software Foundation.
15  *
16  * OpenOffice.org is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License version 3 for more details
20  * (a copy is included in the LICENSE file that accompanied this code).
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * version 3 along with OpenOffice.org. If not, see
24  * <http://www.openoffice.org/license.html>
25  * for a copy of the LGPLv3 License.
26  *
27  ************************************************************************/
28 
29 #ifndef _SALHELPER_FUTURE_HXX_
30 #define _SALHELPER_FUTURE_HXX_
31 
32 #include <sal/types.h>
33 #include <osl/diagnose.h>
34 #include <osl/conditn.hxx>
35 #include <salhelper/refobj.hxx>
36 
37 namespace salhelper
38 {
39 
40 //----------------------------------------------------------------------------
41 
42 #ifndef SALHELPER_COPYCTOR_API
43 #define SALHELPER_COPYCTOR_API(C) C (const C&); C& operator= (const C&)
44 #endif
45 
46 //----------------------------------------------------------------------------
47 
48 template<class value_type>
49 class FutureValue : protected osl::Condition
50 {
53  value_type m_aValue;
54 
57  SALHELPER_COPYCTOR_API(FutureValue<value_type>);
58 
59 public:
60  inline FutureValue (const value_type& value = value_type()) SAL_THROW(())
61  : m_aValue (value)
62  {
64  }
65 
66  inline ~FutureValue() SAL_THROW(())
67  {}
68 
69  inline sal_Bool is() const SAL_THROW(())
70  {
71  return const_cast<FutureValue*>(this)->check();
72  }
73 
74  inline void set (const value_type& value) SAL_THROW(())
75  {
76  m_aValue = value;
78  }
79 
80  inline value_type& get() SAL_THROW(())
81  {
83  return m_aValue;
84  }
85 };
86 
87 //----------------------------------------------------------------------------
88 
89 template<class value_type>
91 {
94  FutureValue<value_type> m_aValue;
95 
98  SALHELPER_COPYCTOR_API(Future<value_type>);
99 
100 public:
101  inline Future (const value_type& value = value_type()) SAL_THROW(())
102  : m_aValue (value)
103  {}
104 
105  inline void set (const value_type& value) SAL_THROW(())
106  {
107  OSL_PRECOND(!m_aValue.is(), "Future::set(): value already set");
108  m_aValue.set (value);
109  }
110 
111  inline value_type& get() SAL_THROW(())
112  {
113  return m_aValue.get();
114  }
115 };
116 
117 //----------------------------------------------------------------------------
118 
119 } // namespace salhelper
120 
121 #endif /* !_SALHELPER_FUTURE_HXX_ */
122 
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */