Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/gamestates3/src/libraries/util/RefToValue.h @ 10240

Last change on this file since 10240 was 5738, checked in by landauf, 15 years ago

merged libraries2 back to trunk

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1////////////////////////////////////////////////////////////////////////////////
2// The Loki Library
3// Copyright (c) 2006 Richard Sposato
4// Copyright (c) 2006 Peter Kümmel
5// Permission to use, copy, modify, distribute and sell this software for any
6//     purpose is hereby granted without fee, provided that the above copyright
7//     notice appear in all copies and that both that copyright notice and this
8//     permission notice appear in supporting documentation.
9// The authors make no representations about the
10//     suitability of this software for any purpose. It is provided "as is"
11//     without express or implied warranty.
12////////////////////////////////////////////////////////////////////////////////
13#ifndef LOKI_REFTOVALUE_INC_
14#define LOKI_REFTOVALUE_INC_
15
16// $Id: RefToValue.h 751 2006-10-17 19:50:37Z syntheticpp $
17
18
19namespace Loki
20{
21
22    ////////////////////////////////////////////////////////////////////////////////
23    ///  \class RefToValue
24    ///
25    ///  \ingroup SmartPointerGroup
26    ///  Transports a reference as a value
27    ///  Serves to implement the Colvin/Gibbons trick for SmartPtr/ScopeGuard
28    ////////////////////////////////////////////////////////////////////////////////
29
30    template <class T>
31    class RefToValue
32    {   
33    public:
34   
35        RefToValue(T& ref) : ref_(ref) 
36        {}
37
38        RefToValue(const RefToValue& rhs) : ref_(rhs.ref_)
39        {}
40
41        operator T& () const 
42        {
43            return ref_;
44        }
45
46    private:
47        // Disable - not implemented
48        RefToValue();
49        RefToValue& operator=(const RefToValue&);
50       
51        T& ref_;
52    };
53
54
55    ////////////////////////////////////////////////////////////////////////////////
56    ///  \ingroup ExceptionGroup
57    ///  RefToValue creator.
58    ////////////////////////////////////////////////////////////////////////////////
59
60    template <class T>
61    inline RefToValue<T> ByRef(T& t)
62    {
63        return RefToValue<T>(t);
64    }   
65   
66}
67
68
69#endif // end file guardian
70
Note: See TracBrowser for help on using the repository browser.