2 Copyright (C) 2001-2006, William Joseph.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #if !defined(INCLUDED_GENERIC_REFERENCE_H)
23 #define INCLUDED_GENERIC_REFERENCE_H
26 /// \brief Wrappers to allow storing objects in templated containers using 'reference' semantics.
28 /// \brief A reference to a mutable object.
29 /// Has 'reference' semantics, except for \c 'operator==' and \c 'operator.'.
30 /// \param Type The type of the referenced object.
31 template<typename Type>
36 explicit Reference(Type& contained) : m_contained(&contained)
39 Type& operator*() const
43 Type* operator->() const
47 operator Type&() const
55 Type* get_pointer() const
61 template<typename Type>
62 bool operator<(const Reference<Type>& self, const Reference<Type>& other)
64 return self.get() < other.get();
66 template<typename Type>
67 bool operator==(const Reference<Type>& self, const Reference<Type>& other)
69 return self.get() == other.get();
72 /// \brief construct a reference to a mutable object.
73 template<typename Type>
74 inline Reference<Type> makeReference(Type& value)
76 return Reference<Type>(value);
79 /// \brief A reference to a non-mutable object.
80 /// Has 'reference' semantics, except for \c 'operator==' and \c 'operator.'.
81 /// \param Type The type of the referenced object.
82 template<typename Type>
85 const Type* m_contained;
87 explicit ConstReference(const Type& contained) : m_contained(&contained)
90 const Type& operator*() const
94 const Type* operator->() const
98 operator const Type&() const
102 const Type& get() const
106 const Type* get_pointer() const
112 template<typename Type>
113 bool operator<(const ConstReference<Type>& self, const ConstReference<Type>& other)
115 return self.get() < other.get();
117 template<typename Type>
118 bool operator==(const ConstReference<Type>& self, const ConstReference<Type>& other)
120 return self.get() == other.get();
123 /// \brief construct a reference to a non-mutable object.
124 template<typename Type>
125 inline ConstReference<Type> makeReference(const Type& value)
127 return ConstReference<Type>(value);